Search in sources :

Example 1 with CategoryUtilizer

use of com.agiletec.aps.system.services.category.CategoryUtilizer 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;
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) 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) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Example 2 with CategoryUtilizer

use of com.agiletec.aps.system.services.category.CategoryUtilizer 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) {
        return;
    }
    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) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Example 3 with CategoryUtilizer

use of com.agiletec.aps.system.services.category.CategoryUtilizer in project entando-core by entando.

the class DataObjectService method getCategoryUtilizer.

@Override
public List getCategoryUtilizer(String categoryCode) {
    try {
        DataObjectManager entityManager = (DataObjectManager) this.extractEntityManager(this.getManagerName());
        List<String> idList = ((CategoryUtilizer) entityManager).getCategoryUtilizers(categoryCode);
        return this.buildDtoList(idList, entityManager);
    } catch (ApsSystemException ex) {
        logger.error("Error loading dataobject references for category {}", categoryCode, ex);
        throw new RestServerError("Error loading dataobject references for category", ex);
    }
}
Also used : CategoryUtilizer(com.agiletec.aps.system.services.category.CategoryUtilizer) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 4 with CategoryUtilizer

use of com.agiletec.aps.system.services.category.CategoryUtilizer in project entando-core by entando.

the class TestCategoryUtilizer method testGetCategoryUtilizers_1.

public void testGetCategoryUtilizers_1() throws Throwable {
    String[] names = this.getApplicationContext().getBeanNamesForType(CategoryUtilizer.class);
    assertTrue(names.length >= 2);
    for (int i = 0; i < names.length; i++) {
        CategoryUtilizer service = (CategoryUtilizer) this.getApplicationContext().getBean(names[i]);
        List utilizers = service.getCategoryUtilizers("evento");
        if (names[i].equals(JacmsSystemConstants.CONTENT_MANAGER)) {
            assertTrue(utilizers.size() == 2);
        }
    }
}
Also used : CategoryUtilizer(com.agiletec.aps.system.services.category.CategoryUtilizer) List(java.util.List)

Example 5 with CategoryUtilizer

use of com.agiletec.aps.system.services.category.CategoryUtilizer in project entando-core by entando.

the class TestCategoryUtilizer method testGetCategoryUtilizers_2.

public void testGetCategoryUtilizers_2() throws Throwable {
    String[] names = this.getApplicationContext().getBeanNamesForType(CategoryUtilizer.class);
    assertTrue(names.length >= 2);
    for (int i = 0; i < names.length; i++) {
        CategoryUtilizer service = (CategoryUtilizer) this.getApplicationContext().getBean(names[i]);
        List utilizers = service.getCategoryUtilizers("resCat1");
        if (names[i].equals(JacmsSystemConstants.RESOURCE_MANAGER)) {
            assertTrue(utilizers.size() == 1);
        } else {
            assertTrue(utilizers.size() == 0);
        }
    }
}
Also used : CategoryUtilizer(com.agiletec.aps.system.services.category.CategoryUtilizer) List(java.util.List)

Aggregations

CategoryUtilizer (com.agiletec.aps.system.services.category.CategoryUtilizer)8 List (java.util.List)7 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)3 RestServerError (org.entando.entando.aps.system.exception.RestServerError)3 Category (com.agiletec.aps.system.services.category.Category)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)2 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)2 CategoryDto (org.entando.entando.aps.system.services.category.model.CategoryDto)1 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)1