use of org.entando.entando.web.common.exceptions.ValidationConflictException in project entando-core by entando.
the class GroupService method removeGroup.
@Override
public void removeGroup(String groupName) {
try {
Group group = this.getGroupManager().getGroup(groupName);
BeanPropertyBindingResult validationResult = this.checkGroupForDelete(group);
if (validationResult.hasErrors()) {
throw new ValidationConflictException(validationResult);
}
if (null != group) {
this.getGroupManager().removeGroup(group);
}
} catch (ApsSystemException e) {
logger.error("Error in delete group {}", groupName, e);
throw new RestServerError("error in delete group", e);
}
}
use of org.entando.entando.web.common.exceptions.ValidationConflictException in project entando-core by entando.
the class DataTypeController method addDataTypes.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> addDataTypes(@Valid @RequestBody DataTypeDtoRequest bodyRequest, BindingResult bindingResult) throws JsonProcessingException {
// field validations
this.getDataTypeValidator().validate(bodyRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
// business validations
if (this.getDataTypeValidator().existType(bodyRequest.getCode())) {
bindingResult.reject(DataTypeValidator.ERRCODE_ENTITY_TYPE_ALREADY_EXISTS, new String[] { bodyRequest.getCode() }, "entityType.exists");
}
if (bindingResult.hasErrors()) {
throw new ValidationConflictException(bindingResult);
}
DataTypeDto result = this.getDataObjectService().addDataType(bodyRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
logger.debug("Main Response -> {}", result);
return new ResponseEntity<>(new RestResponse(result), HttpStatus.OK);
}
use of org.entando.entando.web.common.exceptions.ValidationConflictException in project entando-core by entando.
the class GroupController method addGroup.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> addGroup(@Valid @RequestBody GroupRequest groupRequest, BindingResult bindingResult) throws ApsSystemException {
// field validations
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
// business validations
getGroupValidator().validate(groupRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationConflictException(bindingResult);
}
GroupDto dto = this.getGroupService().addGroup(groupRequest);
return new ResponseEntity<>(new RestResponse(dto), HttpStatus.OK);
}
use of org.entando.entando.web.common.exceptions.ValidationConflictException in project entando-core by entando.
the class PageController method addPage.
@RestAccessControl(permission = Permission.MANAGE_PAGES)
@RequestMapping(value = "/pages", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> addPage(@ModelAttribute("user") UserDetails user, @Valid @RequestBody PageRequest pageRequest, BindingResult bindingResult) throws ApsSystemException {
logger.debug("creating page with request {}", pageRequest);
// field validations
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
// business validations
getPageValidator().validate(pageRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationConflictException(bindingResult);
}
PageDto dto = this.getPageService().addPage(pageRequest);
Map<String, String> metadata = new HashMap<>();
return new ResponseEntity<>(new RestResponse(dto, new ArrayList<>(), metadata), HttpStatus.OK);
}
use of org.entando.entando.web.common.exceptions.ValidationConflictException in project entando-core by entando.
the class ProfileTypeController method addUserProfileTypes.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> addUserProfileTypes(@Valid @RequestBody ProfileTypeDtoRequest bodyRequest, BindingResult bindingResult) throws JsonProcessingException {
// field validations
this.getProfileTypeValidator().validate(bodyRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
// business validations
if (this.getProfileTypeValidator().existType(bodyRequest.getCode())) {
bindingResult.reject(DataTypeValidator.ERRCODE_ENTITY_TYPE_ALREADY_EXISTS, new String[] { bodyRequest.getCode() }, "entityType.exists");
}
if (bindingResult.hasErrors()) {
throw new ValidationConflictException(bindingResult);
}
UserProfileTypeDto result = this.getUserProfileTypeService().addUserProfileType(bodyRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
logger.debug("Main Response -> {}", result);
return new ResponseEntity<>(new RestResponse(result), HttpStatus.OK);
}
Aggregations