use of org.entando.entando.aps.system.services.category.model.CategoryDto 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.aps.system.services.category.model.CategoryDto 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.aps.system.services.category.model.CategoryDto 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.aps.system.services.category.model.CategoryDto in project entando-core by entando.
the class CategoryService method getTree.
@Override
public List<CategoryDto> getTree(String parentCode) {
List<CategoryDto> res = new ArrayList<>();
Category parent = this.getCategoryManager().getCategory(parentCode);
if (null == parent) {
throw new RestRourceNotFoundException(CategoryValidator.ERRCODE_PARENT_CATEGORY_NOT_FOUND, "category", parentCode);
}
Optional.ofNullable(parent.getChildrenCodes()).ifPresent(children -> Arrays.asList(children).forEach(childCode -> {
Category child = this.getCategoryManager().getCategory(childCode);
CategoryDto childDto = this.getDtoBuilder().convert(child);
childDto.setChildren(Arrays.asList(child.getChildrenCodes()));
res.add(childDto);
}));
return res;
}
use of org.entando.entando.aps.system.services.category.model.CategoryDto in project entando-core by entando.
the class CategoryService method addCategory.
@Override
public CategoryDto addCategory(CategoryDto categoryDto) {
Category parentCategory = this.getCategoryManager().getCategory(categoryDto.getParentCode());
if (null == parentCategory) {
throw new RestRourceNotFoundException(CategoryValidator.ERRCODE_PARENT_CATEGORY_NOT_FOUND, "parent category", categoryDto.getParentCode());
}
Category category = this.getCategoryManager().getCategory(categoryDto.getCode());
if (null != category) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(category, "category");
bindingResult.reject(CategoryValidator.ERRCODE_CATEGORY_ALREADY_EXISTS, new String[] { category.getCode() }, "category.exists");
throw new ValidationGenericException(bindingResult);
}
CategoryDto dto = null;
try {
Category categoryToAdd = new Category();
categoryToAdd.setCode(categoryDto.getCode());
categoryToAdd.setParentCode(categoryDto.getParentCode());
categoryToAdd.getTitles().putAll(categoryDto.getTitles());
this.getCategoryManager().addCategory(categoryToAdd);
dto = this.getDtoBuilder().convert(this.getCategoryManager().getCategory(categoryDto.getCode()));
} catch (Exception e) {
logger.error("error adding category " + categoryDto.getCode(), e);
throw new RestServerError("error adding category " + categoryDto.getCode(), e);
}
return dto;
}
Aggregations