There are several ways to do a duplication check. In this case, I assume that "username" should be unique across several aggregates.It should *always* be done client-side, by doing a query for "existing" usernames.
public String formNewAddressSubmit(@ModelAttribute("address") @Valid AddressEntry address, BindingResult bindingResult) { if (!bindingResult.hasErrors()) { RegisterAddressCommand command = new RegisterAddressCommand(); command.setAddressType(address.getAddressType()); command.setCity(address.getCity()); command.setContactId(address.getIdentifier()); command.setStreetAndNumber(address.getStreetAndNumber()); command.setZipCode(address.getZipCode()); commandBus.dispatch(command); ....This above uses a interesting way with hibernate validator to validate an incoming request server side with the query model of the Entity before moving the command forward, however in client controller code leveraging spring-mvc for the binding of the errors to the client. So how do we get the same objective if without duplication of structural validation logic? assuming a webservice client or a rest api client, which is completely dumb. Maybe the addressbook example serializing the AddressEntry Entity object to the command and the validation happening there with an exception which populates the errors? Any ideas?? Thanks return "redirect:/contacts/" + address.getIdentifier(); } |
| Constructor Summary | |
|---|---|
ConstraintViolationException(java.util.Set<ConstraintViolation<?>> constraintViolations) Creates a constraint violation report | |
ConstraintViolationException(java.lang.String message, java.util.Set<ConstraintViolation<?>> constraintViolations) Creates a constraint violation report | |