minor formatting cleanup

This commit is contained in:
Eugen Paraschiv 2019-01-27 14:25:36 +02:00
parent 8ccec9a413
commit 2e733c3867
18 changed files with 122 additions and 132 deletions

View File

@ -65,21 +65,23 @@ public class DbConfig {
@Configuration @Configuration
@Profile("h2") @Profile("h2")
@PropertySource("classpath:persistence-h2.properties") @PropertySource("classpath:persistence-h2.properties")
class H2Config {} class H2Config {
}
@Configuration @Configuration
@Profile("hsqldb") @Profile("hsqldb")
@PropertySource("classpath:persistence-hsqldb.properties") @PropertySource("classpath:persistence-hsqldb.properties")
class HsqldbConfig {} class HsqldbConfig {
}
@Configuration @Configuration
@Profile("derby") @Profile("derby")
@PropertySource("classpath:persistence-derby.properties") @PropertySource("classpath:persistence-derby.properties")
class DerbyConfig {} class DerbyConfig {
}
@Configuration @Configuration
@Profile("sqlite") @Profile("sqlite")
@PropertySource("classpath:persistence-sqlite.properties") @PropertySource("classpath:persistence-sqlite.properties")
class SqliteConfig {} class SqliteConfig {
}

View File

@ -15,7 +15,6 @@ public class RestConfig implements RepositoryRestConfigurer {
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration repositoryRestConfiguration) { public void configureRepositoryRestConfiguration(RepositoryRestConfiguration repositoryRestConfiguration) {
repositoryRestConfiguration.getProjectionConfiguration().addProjection(CustomBook.class); repositoryRestConfiguration.getProjectionConfiguration().addProjection(CustomBook.class);
ExposureConfiguration config = repositoryRestConfiguration.getExposureConfiguration(); ExposureConfiguration config = repositoryRestConfiguration.getExposureConfiguration();
config.forDomainType(WebsiteUser.class).withItemExposure((metadata, httpMethods) -> config.forDomainType(WebsiteUser.class).withItemExposure((metadata, httpMethods) -> httpMethods.disable(HttpMethod.PATCH));
httpMethods.disable(HttpMethod.PATCH));
} }
} }

View File

@ -24,13 +24,7 @@ public class ValidatorEventRegister implements InitializingBean {
List<String> events = Arrays.asList("beforeCreate", "afterCreate", "beforeSave", "afterSave", "beforeLinkSave", "afterLinkSave", "beforeDelete", "afterDelete"); List<String> events = Arrays.asList("beforeCreate", "afterCreate", "beforeSave", "afterSave", "beforeLinkSave", "afterLinkSave", "beforeDelete", "afterDelete");
for (Map.Entry<String, Validator> entry : validators.entrySet()) { for (Map.Entry<String, Validator> entry : validators.entrySet()) {
events events.stream().filter(p -> entry.getKey().startsWith(p)).findFirst().ifPresent(p -> validatingRepositoryEventListener.addValidator(p, entry.getValue()));
.stream()
.filter(p -> entry
.getKey()
.startsWith(p))
.findFirst()
.ifPresent(p -> validatingRepositoryEventListener.addValidator(p, entry.getValue()));
} }
} }
} }

View File

@ -9,6 +9,7 @@ import java.util.logging.Logger;
@RepositoryEventHandler @RepositoryEventHandler
public class AuthorEventHandler { public class AuthorEventHandler {
Logger logger = Logger.getLogger("Class AuthorEventHandler"); Logger logger = Logger.getLogger("Class AuthorEventHandler");
public AuthorEventHandler() { public AuthorEventHandler() {
super(); super();
} }

View File

@ -11,6 +11,7 @@ import org.springframework.data.rest.core.annotation.RepositoryEventHandler;
@RepositoryEventHandler @RepositoryEventHandler
public class BookEventHandler { public class BookEventHandler {
Logger logger = Logger.getLogger("Class BookEventHandler"); Logger logger = Logger.getLogger("Class BookEventHandler");
@HandleBeforeCreate @HandleBeforeCreate
public void handleBookBeforeCreate(Book book) { public void handleBookBeforeCreate(Book book) {

View File

@ -19,12 +19,7 @@ public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionH
public ResponseEntity<Object> handleAccessDeniedException(Exception ex, WebRequest request) { public ResponseEntity<Object> handleAccessDeniedException(Exception ex, WebRequest request) {
RepositoryConstraintViolationException nevEx = (RepositoryConstraintViolationException) ex; RepositoryConstraintViolationException nevEx = (RepositoryConstraintViolationException) ex;
String errors = nevEx String errors = nevEx.getErrors().getAllErrors().stream().map(ObjectError::toString).collect(Collectors.joining("\n"));
.getErrors()
.getAllErrors()
.stream()
.map(ObjectError::toString)
.collect(Collectors.joining("\n"));
return new ResponseEntity<>(errors, new HttpHeaders(), HttpStatus.NOT_ACCEPTABLE); return new ResponseEntity<>(errors, new HttpHeaders(), HttpStatus.NOT_ACCEPTABLE);
} }

View File

@ -63,7 +63,6 @@ public class Book {
this.isbn = isbn; this.isbn = isbn;
} }
public Library getLibrary() { public Library getLibrary() {
return library; return library;
} }

View File

@ -7,4 +7,5 @@ import com.baeldung.models.Book;
import com.baeldung.projections.CustomBook; import com.baeldung.projections.CustomBook;
@RepositoryRestResource(excerptProjection = CustomBook.class) @RepositoryRestResource(excerptProjection = CustomBook.class)
public interface BookRepository extends CrudRepository<Book, Long> {} public interface BookRepository extends CrudRepository<Book, Long> {
}

View File

@ -29,7 +29,6 @@ public class SpringDataProjectionLiveTest {
private static final String BOOK_ENDPOINT = "http://localhost:8080/books"; private static final String BOOK_ENDPOINT = "http://localhost:8080/books";
private static final String AUTHOR_ENDPOINT = "http://localhost:8080/authors"; private static final String AUTHOR_ENDPOINT = "http://localhost:8080/authors";
@Autowired @Autowired
private BookRepository bookRepo; private BookRepository bookRepo;
@ -59,7 +58,6 @@ public class SpringDataProjectionLiveTest {
// System.out.println(response.asString()); // System.out.println(response.asString());
} }
@Test @Test
public void whenGetBookProjection_thenOK() { public void whenGetBookProjection_thenOK() {
final Response response = RestAssured.get(BOOK_ENDPOINT + "/1?projection=customBook"); final Response response = RestAssured.get(BOOK_ENDPOINT + "/1?projection=customBook");