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
@@ -20,7 +20,7 @@ import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
// @PropertySource("persistence-h2.properties")
// @PropertySource("persistence-hsqldb.properties")
// @PropertySource("persistence-derby.properties")
//@PropertySource("persistence-sqlite.properties")
// @PropertySource("persistence-sqlite.properties")
public class DbConfig {
@Autowired
@@ -65,21 +65,23 @@ public class DbConfig {
@Configuration
@Profile("h2")
@PropertySource("classpath:persistence-h2.properties")
class H2Config {}
class H2Config {
}
@Configuration
@Profile("hsqldb")
@PropertySource("classpath:persistence-hsqldb.properties")
class HsqldbConfig {}
class HsqldbConfig {
}
@Configuration
@Profile("derby")
@PropertySource("classpath:persistence-derby.properties")
class DerbyConfig {}
class DerbyConfig {
}
@Configuration
@Profile("sqlite")
@PropertySource("classpath:persistence-sqlite.properties")
class SqliteConfig {}
class SqliteConfig {
}
@@ -11,11 +11,11 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
@EnableWebMvc
public class MvcConfig implements WebMvcConfigurer {
public MvcConfig(){
public MvcConfig() {
super();
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
@@ -27,7 +27,7 @@ public class MvcConfig implements WebMvcConfigurer {
}
@Bean
BookEventHandler bookEventHandler(){
BookEventHandler bookEventHandler() {
return new BookEventHandler();
}
@@ -12,10 +12,9 @@ import org.springframework.http.HttpMethod;
public class RestConfig implements RepositoryRestConfigurer {
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration repositoryRestConfiguration){
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration repositoryRestConfiguration) {
repositoryRestConfiguration.getProjectionConfiguration().addProjection(CustomBook.class);
ExposureConfiguration config = repositoryRestConfiguration.getExposureConfiguration();
config.forDomainType(WebsiteUser.class).withItemExposure((metadata, httpMethods) ->
httpMethods.disable(HttpMethod.PATCH));
config.forDomainType(WebsiteUser.class).withItemExposure((metadata, httpMethods) -> httpMethods.disable(HttpMethod.PATCH));
}
}
@@ -24,13 +24,7 @@ public class ValidatorEventRegister implements InitializingBean {
List<String> events = Arrays.asList("beforeCreate", "afterCreate", "beforeSave", "afterSave", "beforeLinkSave", "afterLinkSave", "beforeDelete", "afterDelete");
for (Map.Entry<String, Validator> entry : validators.entrySet()) {
events
.stream()
.filter(p -> entry
.getKey()
.startsWith(p))
.findFirst()
.ifPresent(p -> validatingRepositoryEventListener.addValidator(p, entry.getValue()));
events.stream().filter(p -> entry.getKey().startsWith(p)).findFirst().ifPresent(p -> validatingRepositoryEventListener.addValidator(p, entry.getValue()));
}
}
}
@@ -8,33 +8,34 @@ import java.util.logging.Logger;
@RepositoryEventHandler
public class AuthorEventHandler {
Logger logger = Logger.getLogger("Class AuthorEventHandler");
public AuthorEventHandler(){
super();
}
Logger logger = Logger.getLogger("Class AuthorEventHandler");
@HandleBeforeCreate
public void handleAuthorBeforeCreate(Author author){
logger.info("Inside Author Before Create....");
String name = author.getName();
}
public AuthorEventHandler() {
super();
}
@HandleAfterCreate
public void handleAuthorAfterCreate(Author author){
logger.info("Inside Author After Create ....");
String name = author.getName();
}
@HandleBeforeCreate
public void handleAuthorBeforeCreate(Author author) {
logger.info("Inside Author Before Create....");
String name = author.getName();
}
@HandleBeforeDelete
public void handleAuthorBeforeDelete(Author author){
logger.info("Inside Author Before Delete ....");
String name = author.getName();
}
@HandleAfterCreate
public void handleAuthorAfterCreate(Author author) {
logger.info("Inside Author After Create ....");
String name = author.getName();
}
@HandleAfterDelete
public void handleAuthorAfterDelete(Author author){
logger.info("Inside Author After Delete ....");
String name = author.getName();
}
@HandleBeforeDelete
public void handleAuthorBeforeDelete(Author author) {
logger.info("Inside Author Before Delete ....");
String name = author.getName();
}
@HandleAfterDelete
public void handleAuthorAfterDelete(Author author) {
logger.info("Inside Author After Delete ....");
String name = author.getName();
}
}
@@ -10,17 +10,18 @@ import org.springframework.data.rest.core.annotation.RepositoryEventHandler;
@RepositoryEventHandler
public class BookEventHandler {
Logger logger = Logger.getLogger("Class BookEventHandler");
@HandleBeforeCreate
public void handleBookBeforeCreate(Book book){
Logger logger = Logger.getLogger("Class BookEventHandler");
logger.info("Inside Book Before Create ....");
book.getAuthors();
}
@HandleBeforeCreate
public void handleBookBeforeCreate(Book book) {
@HandleBeforeCreate
public void handleAuthorBeforeCreate(Author author){
logger.info("Inside Author Before Create ....");
author.getBooks();
}
logger.info("Inside Book Before Create ....");
book.getAuthors();
}
@HandleBeforeCreate
public void handleAuthorBeforeCreate(Author author) {
logger.info("Inside Author Before Create ....");
author.getBooks();
}
}
@@ -19,12 +19,7 @@ public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionH
public ResponseEntity<Object> handleAccessDeniedException(Exception ex, WebRequest request) {
RepositoryConstraintViolationException nevEx = (RepositoryConstraintViolationException) ex;
String errors = nevEx
.getErrors()
.getAllErrors()
.stream()
.map(ObjectError::toString)
.collect(Collectors.joining("\n"));
String errors = nevEx.getErrors().getAllErrors().stream().map(ObjectError::toString).collect(Collectors.joining("\n"));
return new ResponseEntity<>(errors, new HttpHeaders(), HttpStatus.NOT_ACCEPTABLE);
}
@@ -11,7 +11,7 @@ import javax.persistence.OneToOne;
public class Address {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(nullable = false)
@@ -16,7 +16,7 @@ import javax.persistence.ManyToMany;
public class Author {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(nullable = false)
@@ -16,14 +16,14 @@ import javax.persistence.ManyToOne;
public class Book {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(nullable = false)
private String title;
private String isbn;
@ManyToOne
@JoinColumn(name = "library_id")
private Library library;
@@ -63,7 +63,6 @@ public class Book {
this.isbn = isbn;
}
public Library getLibrary() {
return library;
}
@@ -17,7 +17,7 @@ import org.springframework.data.rest.core.annotation.RestResource;
public class Library {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column
@@ -10,7 +10,7 @@ import javax.persistence.Id;
public class Subject {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(nullable = false)
@@ -8,15 +8,15 @@ import org.springframework.data.rest.core.config.Projection;
import com.baeldung.models.Author;
import com.baeldung.models.Book;
@Projection(name = "customBook", types = { Book.class })
@Projection(name = "customBook", types = { Book.class })
public interface CustomBook {
@Value("#{target.id}")
long getId();
long getId();
String getTitle();
List<Author> getAuthors();
@Value("#{target.getAuthors().size()}")
int getAuthorCount();
}
@@ -7,4 +7,5 @@ import com.baeldung.models.Book;
import com.baeldung.projections.CustomBook;
@RepositoryRestResource(excerptProjection = CustomBook.class)
public interface BookRepository extends CrudRepository<Book, Long> {}
public interface BookRepository extends CrudRepository<Book, Long> {
}
@@ -8,8 +8,8 @@ import org.springframework.data.rest.core.annotation.RestResource;
import com.baeldung.models.Subject;
public interface SubjectRepository extends PagingAndSortingRepository<Subject, Long> {
@RestResource(path = "nameContains")
public Page<Subject> findByNameContaining(@Param("name") String name, Pageable p);
}