Skip to content

Commit

Permalink
Merge pull request #22 from aosn/develop
Browse files Browse the repository at this point in the history
Ready for v0.3 release
  • Loading branch information
mikan authored Mar 30, 2017
2 parents a31af3f + f5c5fc5 commit 9921264
Show file tree
Hide file tree
Showing 56 changed files with 2,678 additions and 65 deletions.
13 changes: 10 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ buildscript {
vaadinVersion = '7.7.6'
vaadinSpringBootVersion = '1.1.1'
checkerFrameworkVersion = '2.1.5'
springFoxVersion = '2.6.1'
}
}

Expand All @@ -24,6 +25,7 @@ dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.security.oauth:spring-security-oauth2')
// Vaadin
compile("com.vaadin:vaadin-spring-boot-starter:${vaadinSpringBootVersion}")
Expand All @@ -33,11 +35,16 @@ dependencies {
compile('org.projectlombok:lombok')
compile("org.checkerframework:checker-qual:${checkerFrameworkVersion}")
compile("com.google.guava:guava:20.0")
compile('org.pegdown:pegdown:1.6.0')
compile('commons-io:commons-io:2.5')
compile('commons-validator:commons-validator:1.5.1')
compile('org.ocpsoft.prettytime:prettytime:4.0.1.Final')
// Database
runtime('com.h2database:h2') // development and test
runtime('mysql:mysql-connector-java') // production
// Others
compile('org.pegdown:pegdown:1.6.0')
// Docs
compile("io.springfox:springfox-swagger2:${springFoxVersion}")
compile("io.springfox:springfox-swagger-ui:${springFoxVersion}")
// Tests
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Expand All @@ -50,7 +57,7 @@ dependencyManagement {

war {
baseName = 'mosaic'
version = '0.2'
version = '0.3'
archiveName = baseName + "." + extension
}

Expand Down
2 changes: 1 addition & 1 deletion manifest.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
applications:
- name: aosn-mosaic
memory: 256M
memory: 384M
instances: 1
path: build/libs/mosaic.war
env:
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/github/aosn/mosaic/MosaicApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
@SpringBootApplication
public class MosaicApplication {

public static final long MOSAIC_SERIAL_VERSION_UID = 2L;
public static final long MOSAIC_SERIAL_VERSION_UID = 3L;
public static final String MOSAIC_VERSION = "0.3";
public static final String DEFAULT_TITLE = "Mosaic";

public static void main(String[] args) {
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/io/github/aosn/mosaic/config/DocConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2017 Alice on Sunday Nights Workshop Participants. All rights reserved.
*/
package io.github.aosn.mosaic.config;

import io.github.aosn.mosaic.MosaicApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
* Enables Swagger API documentation.
*
* @author mikan
* @since 0.3
*/
@Configuration
@EnableSwagger2
public class DocConfig {

@Bean
public Docket document() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("io.github.aosn.mosaic.controller"))
.paths(PathSelectors.any())
.build()
.apiInfo(new ApiInfo("Mosaic Web API", "Web API documentation for Mosaic",
MosaicApplication.MOSAIC_VERSION, null,
new Contact("Alice on Sunday Nights Workshop", "https://aosn.github.io/", ""),
null, null));
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*
* Copyright (C) 2016-2017 Alice on Sunday Nights Workshop Participants. All rights reserved.
*/
package io.github.aosn.mosaic.config;

import org.springframework.context.annotation.Bean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* Copyright (C) 2016 Alice on Sunday Nights Workshop Participants. All rights reserved.
* Copyright (C) 2016-2017 Alice on Sunday Nights Workshop Participants. All rights reserved.
*/
package io.github.aosn.mosaic.config;

import io.github.aosn.mosaic.controller.CatalogController;
import io.github.aosn.mosaic.domain.model.auth.User;
import io.github.aosn.mosaic.domain.service.auth.UserService;
import io.github.aosn.mosaic.ui.ErrorUI;
Expand Down Expand Up @@ -52,6 +53,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {

public static final String LOGIN_PATH_GITHUB = "/login/github";
public static final String CSS_PATH = "/css/mosaic.css";
public static final String NO_IMAGE_PATH = "/img/no-image.png\"";
public static final String V_PATH_PREFIX = "/VAADIN";
private final OAuth2ClientContext oauth2ClientContext;
private final UserService userService;

Expand All @@ -69,7 +72,9 @@ protected void configure(HttpSecurity http) throws Exception {
http.formLogin().disable();
http.authorizeRequests()
.antMatchers(MainUI.PATH, ErrorUI.PATH, CSS_PATH, LOGIN_PATH_GITHUB).permitAll()
.antMatchers("/VAADIN/**", "/vaadinServlet/**").permitAll()
.antMatchers(CatalogController.CATALOG_ENDPOINT).permitAll()
.antMatchers(V_PATH_PREFIX + "/**", "/vaadinServlet/**").permitAll()
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/v2/**").permitAll()
.anyRequest().authenticated()
.and()
.exceptionHandling().authenticationEntryPoint(loginPage()).accessDeniedPage(MainUI.PATH)
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/io/github/aosn/mosaic/controller/BookController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2017 Alice on Sunday Nights Workshop Participants. All rights reserved.
*/
package io.github.aosn.mosaic.controller;

import io.github.aosn.mosaic.domain.model.stock.Stock;
import io.github.aosn.mosaic.domain.service.stock.StockService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
* @author mikan
* @since 0.3
*/
@RestController
@Slf4j
public class BookController {

private final StockService stockService;

@Autowired
public BookController(StockService stockService) {
this.stockService = stockService;
}

@PostMapping(value = "/book")
@ResponseBody
public void addBook(Stock stock, HttpServletResponse response) {
try {
stockService.add(stock);
response.setStatus(HttpServletResponse.SC_CREATED);
} catch (RuntimeException e) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2017 Alice on Sunday Nights Workshop Participants. All rights reserved.
*/
package io.github.aosn.mosaic.controller;

import io.github.aosn.mosaic.domain.model.catalog.ReleasedBook;
import io.github.aosn.mosaic.domain.model.stock.Stock;
import io.github.aosn.mosaic.domain.service.catalog.CatalogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.Collections;
import java.util.List;

/**
* @author mikan
* @since 0.3
*/
@RestController
@Slf4j
public class CatalogController {

public static final String CATALOG_ENDPOINT = "/catalog";
private final CatalogService catalogService;

@Autowired
public CatalogController(CatalogService catalogService) {
this.catalogService = catalogService;
}

@GetMapping(value = CATALOG_ENDPOINT)
@ResponseBody
public List<ReleasedBook> findBooks(@RequestParam("q") String keyword, HttpServletResponse response) {
try {
String isbn = Stock.normalizeIsbn(keyword);
return catalogService.searchByIsbn(isbn);
} catch (IllegalArgumentException e) {
// Not a ISBN, search by name
return catalogService.searchByKeyword(keyword);
} catch (NullPointerException e) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
} catch (RuntimeException e) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
Expand All @@ -28,15 +27,15 @@ public class UserController {

public static final String LOGOUT_PATH = "/logout";

@RequestMapping({"/user", "/me"})
@GetMapping(value = {"/user", "/me"})
public Map<String, String> user(Principal principal) {
log.info("user(" + principal + ")");
Map<String, String> map = new LinkedHashMap<>();
map.put("name", principal.getName());
return map;
}

@RequestMapping(value = LOGOUT_PATH, method = RequestMethod.GET)
@GetMapping(value = LOGOUT_PATH)
public String logoutPage(HttpServletRequest request, HttpServletResponse response) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
@Entity
@Table(name = "users")
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -31,6 +30,7 @@ public class User implements Serializable {
private Long id;

@Column(nullable = false, length = 40)
@Getter
private String name;

@Column(nullable = false)
Expand All @@ -43,6 +43,7 @@ public class User implements Serializable {

@Column
@Temporal(TemporalType.TIMESTAMP)
@Getter
@Setter
private Date lastLogin;

Expand All @@ -58,7 +59,7 @@ public boolean equals(Object other) {
return false;
}
User otherUser = (User) other;
return id.equals(otherUser.getId());
return id.equals(otherUser.id);
}

public String getProfileUrl() {
Expand Down
Loading

0 comments on commit 9921264

Please sign in to comment.