use of org.entando.entando.web.common.exceptions.ResourcePermissionsException in project entando-core by entando.
the class PageController method updatePage.
@ActivityStreamAuditable
@RestAccessControl(permission = Permission.MANAGE_PAGES)
@RequestMapping(value = "/pages/{pageCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse<PageDto, Map<String, String>>> updatePage(@ModelAttribute("user") UserDetails user, @PathVariable String pageCode, @Valid @RequestBody PageRequest pageRequest, BindingResult bindingResult) {
logger.debug("updating page {} with request {}", pageCode, pageRequest);
if (!this.getAuthorizationService().isAuth(user, pageCode)) {
throw new ResourcePermissionsException(bindingResult, user.getUsername(), pageCode);
}
// field validations
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
this.getPageValidator().validateBodyCode(pageCode, pageRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
PagePositionRequest pagePositionRequest = new PagePositionRequest();
pagePositionRequest.setParentCode(pageRequest.getParentCode());
pagePositionRequest.setCode(pageCode);
int position = pageService.getPages(pageCode).size() + 1;
pagePositionRequest.setPosition(position);
this.getPageValidator().validateMovePage(pageCode, bindingResult, pagePositionRequest);
PageDto page = this.getPageService().updatePage(pageCode, pageRequest);
Map<String, String> metadata = new HashMap<>();
return new ResponseEntity<>(new RestResponse<>(page, metadata), HttpStatus.OK);
}
Aggregations