use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.
the class CategoryController method getCategories.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getCategories(@RequestParam(value = "parentCode", required = false, defaultValue = "home") String parentCode) {
logger.debug("getting category tree for parent {}", parentCode);
List<CategoryDto> result = this.getCategoryService().getTree(parentCode);
Map<String, String> metadata = new HashMap<>();
metadata.put("parentCode", parentCode);
return new ResponseEntity<>(new RestResponse(result, new ArrayList<>(), metadata), HttpStatus.OK);
}
use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.
the class CategoryController method getCategory.
@RestAccessControl(permission = Permission.MANAGE_PAGES)
@RequestMapping(value = "/{categoryCode}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getCategory(@PathVariable String categoryCode) {
logger.debug("getting category {}", categoryCode);
CategoryDto category = this.getCategoryService().getCategory(categoryCode);
return new ResponseEntity<>(new RestResponse(category, new ArrayList<>(), new HashMap<>()), HttpStatus.OK);
}
use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.
the class CategoryController method addCategory.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> addCategory(@Valid @RequestBody CategoryDto categoryRequest, BindingResult bindingResult) throws ApsSystemException {
// field validations
this.getCategoryValidator().validate(categoryRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
// business validations
this.getCategoryValidator().validatePostReferences(categoryRequest, bindingResult);
CategoryDto category = this.getCategoryService().addCategory(categoryRequest);
return new ResponseEntity<>(new RestResponse(category, new ArrayList<>(), new HashMap<>()), HttpStatus.OK);
}
use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.
the class RestExceptionHandler method processValidationError.
@ExceptionHandler(value = ValidationUpdateSelfException.class)
@ResponseStatus(HttpStatus.FORBIDDEN)
@ResponseBody
public RestResponse processValidationError(ValidationUpdateSelfException ex) {
logger.debug("Handling {} error", ex.getClass().getSimpleName());
BindingResult result = ex.getBindingResult();
RestResponse response = processAllErrors(result);
return response;
}
use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.
the class RestExceptionHandler method processRestRourceNotFoundEx.
@ExceptionHandler(value = RestRourceNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
@ResponseBody
public RestResponse processRestRourceNotFoundEx(RestRourceNotFoundException ex) {
logger.debug("Handling {} error", ex.getClass().getSimpleName());
RestResponse response = null;
if (null != ex.getBindingResult()) {
BindingResult result = ex.getBindingResult();
response = processAllErrors(result);
} else {
response = new RestResponse();
RestError error = new RestError(ex.getErrorCode(), this.resolveLocalizedErrorMessage("NOT_FOUND", new Object[] { ex.getObjectName(), ex.getObjectCode() }));
List<RestError> errors = new ArrayList<>();
errors.add(error);
response.setErrors(errors);
response.setMetaData(new HashMap<>());
}
return response;
}
Aggregations