use of org.entando.entando.web.common.annotation.ActivityStreamAuditable 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);
}
use of org.entando.entando.web.common.annotation.ActivityStreamAuditable in project entando-core by entando.
the class PageController method deletePage.
@ActivityStreamAuditable
@RestAccessControl(permission = Permission.MANAGE_PAGES)
@RequestMapping(value = "/pages/{pageCode}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<?>> deletePage(@ModelAttribute("user") UserDetails user, @PathVariable String pageCode) throws ApsSystemException {
logger.debug("deleting {}", pageCode);
if (!this.getAuthorizationService().isAuth(user, pageCode)) {
return new ResponseEntity<>(new SimpleRestResponse<>(new PageDto()), HttpStatus.UNAUTHORIZED);
}
DataBinder binder = new DataBinder(pageCode);
BindingResult bindingResult = binder.getBindingResult();
// field validations
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
// business validations
getPageValidator().validateOnlinePage(pageCode, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
// business validations
getPageValidator().validateChildren(pageCode, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
this.getPageService().removePage(pageCode);
Map<String, String> payload = new HashMap<>();
payload.put("code", pageCode);
return new ResponseEntity<>(new SimpleRestResponse<>(payload), HttpStatus.OK);
}
use of org.entando.entando.web.common.annotation.ActivityStreamAuditable in project entando-core by entando.
the class PageController method addPage.
@ActivityStreamAuditable
@RestAccessControl(permission = Permission.MANAGE_PAGES)
@RequestMapping(value = "/pages", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<PageDto>> 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);
return new ResponseEntity<>(new SimpleRestResponse<>(dto), HttpStatus.OK);
}
use of org.entando.entando.web.common.annotation.ActivityStreamAuditable in project entando-core by entando.
the class PageController method updatePageStatus.
@ActivityStreamAuditable
@RestAccessControl(permission = Permission.MANAGE_PAGES)
@RequestMapping(value = "/pages/{pageCode}/status", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse<PageDto, Map<String, String>>> updatePageStatus(@ModelAttribute("user") UserDetails user, @PathVariable String pageCode, @Valid @RequestBody PageStatusRequest pageStatusRequest, BindingResult bindingResult) {
logger.debug("changing status for page {} with request {}", pageCode, pageStatusRequest);
Map<String, String> metadata = new HashMap<>();
if (!this.getAuthorizationService().isAuth(user, pageCode)) {
return new ResponseEntity<>(new RestResponse<>(new PageDto(), metadata), HttpStatus.UNAUTHORIZED);
}
// field validations
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
PageDto page = this.getPageService().updatePageStatus(pageCode, pageStatusRequest.getStatus());
metadata.put("status", pageStatusRequest.getStatus());
return new ResponseEntity<>(new RestResponse<>(page, metadata), HttpStatus.OK);
}
use of org.entando.entando.web.common.annotation.ActivityStreamAuditable in project entando-core by entando.
the class PageController method movePage.
@ActivityStreamAuditable
@RestAccessControl(permission = Permission.MANAGE_PAGES)
@RequestMapping(value = "/pages/{pageCode}/position", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<PageDto>> movePage(@ModelAttribute("user") UserDetails user, @PathVariable String pageCode, @Valid @RequestBody PagePositionRequest pageRequest, BindingResult bindingResult) {
logger.debug("changing position for page {} with request {}", pageCode, pageRequest);
// field validations
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
this.getPageValidator().validateMovePage(pageCode, bindingResult, pageRequest);
if (!this.getAuthorizationService().isAuth(user, pageCode)) {
return new ResponseEntity<>(new SimpleRestResponse<>(new PageDto()), HttpStatus.UNAUTHORIZED);
}
PageDto page = this.getPageService().movePage(pageCode, pageRequest);
return new ResponseEntity<>(new SimpleRestResponse<>(page), HttpStatus.OK);
}
Aggregations