use of org.entando.entando.web.common.annotation.RestAccessControl in project entando-core by entando.
the class WidgetController method getWidget.
@RestAccessControl(permission = Permission.MANAGE_PAGES)
@RequestMapping(value = "/widgets/{widgetCode}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<WidgetDto>> getWidget(@PathVariable String widgetCode) {
logger.trace("getWidget by code {}", widgetCode);
WidgetDto group = this.widgetService.getWidget(widgetCode);
return new ResponseEntity<>(new SimpleRestResponse<>(group), HttpStatus.OK);
}
use of org.entando.entando.web.common.annotation.RestAccessControl in project entando-core by entando.
the class LanguageController method updateLanguage.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{code}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<LanguageDto>> updateLanguage(@PathVariable String code, @Valid @RequestBody LanguageRequest languageRequest, BindingResult bindingResult) {
logger.trace("loading language {}", code);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
LanguageDto result = this.getLanguageService().updateLanguage(code, languageRequest.getStatus());
return new ResponseEntity<>(new SimpleRestResponse<>(result), HttpStatus.OK);
}
use of org.entando.entando.web.common.annotation.RestAccessControl 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.RestAccessControl 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.RestAccessControl 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);
}
Aggregations