use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class CategoryService method getCategoryReferences.
@Override
public PagedMetadata<?> getCategoryReferences(String categoryCode, String managerName, RestListRequest restListRequest) {
Category group = this.getCategoryManager().getCategory(categoryCode);
if (null == group) {
logger.warn("no category found with code {}", categoryCode);
throw new ResourceNotFoundException(CategoryValidator.ERRCODE_CATEGORY_NOT_FOUND, "category", categoryCode);
}
CategoryServiceUtilizer<?> utilizer = this.getCategoryServiceUtilizer(managerName);
if (null == utilizer) {
logger.warn("no references found for {}", managerName);
throw new ResourceNotFoundException(CategoryValidator.ERRCODE_CATEGORY_NO_REFERENCES, "reference", managerName);
}
List<?> dtoList = utilizer.getCategoryUtilizer(categoryCode);
List<?> subList = restListRequest.getSublist(dtoList);
SearcherDaoPaginatedResult<?> pagedResult = new SearcherDaoPaginatedResult(dtoList.size(), subList);
PagedMetadata<Object> pagedMetadata = new PagedMetadata<>(restListRequest, pagedResult);
pagedMetadata.setBody((List<Object>) subList);
return pagedMetadata;
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class CategoryService method deleteCategory.
@Override
public void deleteCategory(String categoryCode) {
Category category = this.getCategoryManager().getCategory(categoryCode);
if (null == category) {
throw new ResourceNotFoundException("category", categoryCode);
}
if (category.getChildrenCodes().length > 0) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(category, "category");
bindingResult.reject(CategoryValidator.ERRCODE_CATEGORY_HAS_CHILDREN, new String[] { categoryCode }, "category.cannot.delete.children");
throw new ValidationGenericException(bindingResult);
}
try {
for (CategoryUtilizer categoryUtilizer : this.getCategoryUtilizers()) {
List references = categoryUtilizer.getCategoryUtilizers(categoryCode);
if (null != references && !references.isEmpty()) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(category, "category");
bindingResult.reject(CategoryValidator.ERRCODE_CATEGORY_REFERENCES, new String[] { categoryCode }, "category.cannot.delete.references");
throw new ValidationGenericException(bindingResult);
}
}
this.getCategoryManager().deleteCategory(categoryCode);
} catch (ValidationGenericException e) {
throw e;
} catch (Exception e) {
logger.error("error deleting category " + categoryCode, e);
throw new RestServerError("error deleting category " + categoryCode, e);
}
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException 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 ResourceNotFoundException(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.exception.ResourceNotFoundException 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 ResourceNotFoundException(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.exception.ResourceNotFoundException 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 ResourceNotFoundException(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