Search in sources :

Example 1 with ResourceNotFoundException

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;
}
Also used : Category(com.agiletec.aps.system.services.category.Category) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException)

Example 2 with ResourceNotFoundException

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);
    }
}
Also used : Category(com.agiletec.aps.system.services.category.Category) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) CategoryUtilizer(com.agiletec.aps.system.services.category.CategoryUtilizer) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ArrayList(java.util.ArrayList) List(java.util.List) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Example 3 with ResourceNotFoundException

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;
}
Also used : CategoryDto(org.entando.entando.aps.system.services.category.model.CategoryDto) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) CategoryDto(org.entando.entando.aps.system.services.category.model.CategoryDto) LoggerFactory(org.slf4j.LoggerFactory) CategoryValidator(org.entando.entando.web.category.validator.CategoryValidator) Autowired(org.springframework.beans.factory.annotation.Autowired) DtoBuilder(org.entando.entando.aps.system.services.DtoBuilder) ArrayList(java.util.ArrayList) List(java.util.List) RestListRequest(org.entando.entando.web.common.model.RestListRequest) RestServerError(org.entando.entando.aps.system.exception.RestServerError) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) CategoryUtilizer(com.agiletec.aps.system.services.category.CategoryUtilizer) IManager(com.agiletec.aps.system.common.IManager) Optional(java.util.Optional) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) Category(com.agiletec.aps.system.services.category.Category) ICategoryManager(com.agiletec.aps.system.services.category.ICategoryManager) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) Category(com.agiletec.aps.system.services.category.Category) ArrayList(java.util.ArrayList) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException)

Example 4 with ResourceNotFoundException

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;
}
Also used : CategoryDto(org.entando.entando.aps.system.services.category.model.CategoryDto) Category(com.agiletec.aps.system.services.category.Category) CategoryUtilizer(com.agiletec.aps.system.services.category.CategoryUtilizer) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ArrayList(java.util.ArrayList) List(java.util.List) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Example 5 with ResourceNotFoundException

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;
}
Also used : CategoryDto(org.entando.entando.aps.system.services.category.model.CategoryDto) Category(com.agiletec.aps.system.services.category.Category) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Aggregations

ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)53 RestServerError (org.entando.entando.aps.system.exception.RestServerError)27 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)20 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)16 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)15 IPage (com.agiletec.aps.system.services.page.IPage)9 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)9 Category (com.agiletec.aps.system.services.category.Category)7 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)7 ResponseEntity (org.springframework.http.ResponseEntity)7 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)6 List (java.util.List)6 ArrayList (java.util.ArrayList)5 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)5 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 CategoryUtilizer (com.agiletec.aps.system.services.category.CategoryUtilizer)3 Group (com.agiletec.aps.system.services.group.Group)3 Widget (com.agiletec.aps.system.services.page.Widget)3 Role (com.agiletec.aps.system.services.role.Role)3