Added BeforeCreateEvent and AfterCreateEvent and needed changes to accommodate a Validator that might want to validate a new entity differently than it does one that's already been saved.
This commit is contained in:
@@ -124,8 +124,6 @@ public class AbstractRepositoryRestController implements ApplicationContextAware
|
||||
* @param t
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@ExceptionHandler({
|
||||
InvocationTargetException.class,
|
||||
@@ -145,7 +143,7 @@ public class AbstractRepositoryRestController implements ApplicationContextAware
|
||||
public ResponseEntity handleConstraintViolationException(ConstraintViolationException cve) {
|
||||
return response(null,
|
||||
new ConstraintViolationExceptionMessage(cve, applicationContext),
|
||||
HttpStatus.CONFLICT);
|
||||
HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@ExceptionHandler({
|
||||
@@ -155,7 +153,7 @@ public class AbstractRepositoryRestController implements ApplicationContextAware
|
||||
public ResponseEntity handleRepositoryConstraintViolationException(RepositoryConstraintViolationException rcve) {
|
||||
return response(null,
|
||||
new RepositoryConstraintViolationExceptionMessage(rcve, applicationContext),
|
||||
HttpStatus.CONFLICT);
|
||||
HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,8 +18,10 @@ import org.springframework.data.repository.support.Repositories;
|
||||
import org.springframework.data.rest.config.RepositoryRestConfiguration;
|
||||
import org.springframework.data.rest.config.ResourceMapping;
|
||||
import org.springframework.data.rest.repository.PersistentEntityResource;
|
||||
import org.springframework.data.rest.repository.context.AfterCreateEvent;
|
||||
import org.springframework.data.rest.repository.context.AfterDeleteEvent;
|
||||
import org.springframework.data.rest.repository.context.AfterSaveEvent;
|
||||
import org.springframework.data.rest.repository.context.BeforeCreateEvent;
|
||||
import org.springframework.data.rest.repository.context.BeforeDeleteEvent;
|
||||
import org.springframework.data.rest.repository.context.BeforeSaveEvent;
|
||||
import org.springframework.data.rest.repository.invoke.RepositoryMethodInvoker;
|
||||
@@ -179,9 +181,9 @@ public class RepositoryEntityController extends AbstractRepositoryRestController
|
||||
throw new NoSuchMethodError();
|
||||
}
|
||||
|
||||
applicationContext.publishEvent(new BeforeSaveEvent(incoming.getContent()));
|
||||
applicationContext.publishEvent(new BeforeCreateEvent(incoming.getContent()));
|
||||
Object obj = repoMethodInvoker.save(incoming.getContent());
|
||||
applicationContext.publishEvent(new AfterSaveEvent(obj));
|
||||
applicationContext.publishEvent(new AfterCreateEvent(obj));
|
||||
|
||||
Link selfLink = repoRequest.buildEntitySelfLink(obj, conversionService);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
Reference in New Issue
Block a user