Search in sources :

Example 1 with ResourcePermissionsException

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) PagePositionRequest(org.entando.entando.web.page.model.PagePositionRequest) HashMap(java.util.HashMap) ResourcePermissionsException(org.entando.entando.web.common.exceptions.ResourcePermissionsException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) ActivityStreamAuditable(org.entando.entando.web.common.annotation.ActivityStreamAuditable) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

HashMap (java.util.HashMap)1 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)1 ActivityStreamAuditable (org.entando.entando.web.common.annotation.ActivityStreamAuditable)1 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)1 ResourcePermissionsException (org.entando.entando.web.common.exceptions.ResourcePermissionsException)1 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)1 PagePositionRequest (org.entando.entando.web.page.model.PagePositionRequest)1 ResponseEntity (org.springframework.http.ResponseEntity)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1