use of org.entando.entando.aps.system.services.category.model.CategoryDto in project entando-core by entando.
the class CategoryService method getCategory.
@Override
public CategoryDto getCategory(String categoryCode) {
Category category = this.getCategoryManager().getCategory(categoryCode);
if (null == category) {
throw new RestRourceNotFoundException(CategoryValidator.ERRCODE_CATEGORY_NOT_FOUND, "category", categoryCode);
}
CategoryDto dto = null;
try {
dto = this.getDtoBuilder().convert(category);
for (CategoryUtilizer categoryUtilizer : this.getCategoryUtilizers()) {
List references = categoryUtilizer.getCategoryUtilizers(categoryCode);
dto.getReferences().put(((IManager) categoryUtilizer).getName(), (null != references && !references.isEmpty()));
}
} catch (Exception e) {
logger.error("error extracting category " + categoryCode, e);
throw new RestServerError("error extracting category " + categoryCode, e);
}
return dto;
}
use of org.entando.entando.aps.system.services.category.model.CategoryDto in project entando-core by entando.
the class CategoryService method updateCategory.
@Override
public CategoryDto updateCategory(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) {
throw new RestRourceNotFoundException(CategoryValidator.ERRCODE_CATEGORY_NOT_FOUND, "category", categoryDto.getCode());
}
CategoryDto dto = null;
try {
category.setParentCode(categoryDto.getParentCode());
category.getTitles().clear();
category.getTitles().putAll(categoryDto.getTitles());
this.getCategoryManager().updateCategory(category);
dto = this.getDtoBuilder().convert(this.getCategoryManager().getCategory(categoryDto.getCode()));
} catch (Exception e) {
logger.error("error updating category " + categoryDto.getCode(), e);
throw new RestServerError("error updating category " + categoryDto.getCode(), e);
}
return dto;
}
use of org.entando.entando.aps.system.services.category.model.CategoryDto in project entando-core by entando.
the class CategoryController method updateCategory.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{categoryCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> updateCategory(@PathVariable String categoryCode, @Valid @RequestBody CategoryDto categoryRequest, BindingResult bindingResult) {
logger.debug("updating category {} with request {}", categoryCode, categoryRequest);
// field validations
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
this.getCategoryValidator().validatePutReferences(categoryCode, categoryRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
CategoryDto category = this.getCategoryService().updateCategory(categoryRequest);
Map<String, String> metadata = new HashMap<>();
return new ResponseEntity<>(new RestResponse(category, new ArrayList<>(), metadata), HttpStatus.OK);
}
Aggregations