Search in sources :

Example 31 with Category

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

the class TestCategoryAction method testAddCategory_1.

public void testAddCategory_1() throws Throwable {
    String categoryCode = "cat_temp";
    assertNull(this._categoryManager.getCategory(categoryCode));
    try {
        String result = this.saveNewCategory("admin", categoryCode);
        assertEquals(Action.SUCCESS, result);
        Category category = this._categoryManager.getCategory(categoryCode);
        assertNotNull(category);
        assertEquals("Titolo categoria In Italiano", category.getTitles().getProperty("it"));
        assertEquals(this._categoryManager.getRoot().getCode(), category.getParentCode());
    } catch (Throwable t) {
        throw t;
    } finally {
        this._categoryManager.deleteCategory(categoryCode);
        assertNull(this._categoryManager.getCategory(categoryCode));
    }
}
Also used : Category(com.agiletec.aps.system.services.category.Category)

Example 32 with Category

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

the class TestCategoryAction method testDeleteCategory_1.

public void testDeleteCategory_1() throws Throwable {
    String categoryCode = "cat_temp";
    assertNull(this._categoryManager.getCategory(categoryCode));
    try {
        String result = this.saveNewCategory("admin", categoryCode);
        assertEquals(Action.SUCCESS, result);
        Category category = this._categoryManager.getCategory(categoryCode);
        assertNotNull(category);
        this.initAction("/do/Category", "trash");
        this.addParameter("selectedNode", categoryCode);
        result = this.executeAction();
        assertEquals(Action.SUCCESS, result);
        category = this._categoryManager.getCategory(categoryCode);
        assertNotNull(category);
        Map<String, Object> references = ((CategoryAction) this.getAction()).getReferences();
        assertNull(references);
        this.initAction("/do/Category", "delete");
        this.addParameter("selectedNode", categoryCode);
        result = this.executeAction();
        assertEquals(Action.SUCCESS, result);
        category = this._categoryManager.getCategory(categoryCode);
        assertNull(category);
        references = ((CategoryAction) this.getAction()).getReferences();
        assertNull(references);
    } catch (Throwable t) {
        this._categoryManager.deleteCategory(categoryCode);
        assertNull(this._categoryManager.getCategory(categoryCode));
        throw t;
    }
}
Also used : Category(com.agiletec.aps.system.services.category.Category)

Example 33 with Category

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

the class TestCategoryAction method testCategoryDetails_1.

public void testCategoryDetails_1() throws Throwable {
    String categoryCode = "cat_temp";
    assertNull(this._categoryManager.getCategory(categoryCode));
    try {
        String result = this.executeCategoryDetail("admin", categoryCode);
        assertEquals("categoryTree", result);
        Collection<String> actionErrors = this.getAction().getActionErrors();
        assertEquals(1, actionErrors.size());
        result = this.saveNewCategory("admin", categoryCode);
        assertEquals(Action.SUCCESS, result);
        Category category = this._categoryManager.getCategory(categoryCode);
        assertNotNull(category);
        result = this.executeCategoryDetail("admin", categoryCode);
        assertEquals(Action.SUCCESS, result);
        CategoryAction action = (CategoryAction) this.getAction();
        assertEquals(categoryCode, action.getCategoryCode());
        assertEquals("Titolo categoria In Italiano", action.getTitles().get("it"));
        assertEquals("Titolo categoria In Inglese", action.getTitles().get("en"));
        assertNull(action.getReferences());
    } catch (Throwable t) {
        throw t;
    } finally {
        this._categoryManager.deleteCategory(categoryCode);
        assertNull(this._categoryManager.getCategory(categoryCode));
    }
}
Also used : Category(com.agiletec.aps.system.services.category.Category)

Example 34 with Category

use of com.agiletec.aps.system.services.category.Category 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 35 with Category

use of com.agiletec.aps.system.services.category.Category 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)

Aggregations

Category (com.agiletec.aps.system.services.category.Category)91 ArrayList (java.util.ArrayList)23 ITreeNode (com.agiletec.aps.system.common.tree.ITreeNode)9 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)7 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)6 TextAttribute (com.agiletec.aps.system.common.entity.model.attribute.TextAttribute)6 List (java.util.List)6 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)6 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)5 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)5 RestServerError (org.entando.entando.aps.system.exception.RestServerError)5 ICategoryManager (com.agiletec.aps.system.services.category.ICategoryManager)4 Lang (com.agiletec.aps.system.services.lang.Lang)4 ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)4 CategoryDto (org.entando.entando.aps.system.services.category.model.CategoryDto)4 IDataObjectSearchEngineManager (org.entando.entando.aps.system.services.dataobjectsearchengine.IDataObjectSearchEngineManager)4 SearchEngineManager (org.entando.entando.aps.system.services.dataobjectsearchengine.SearchEngineManager)4 Cache (org.springframework.cache.Cache)4 CategoryUtilizer (com.agiletec.aps.system.services.category.CategoryUtilizer)3 HashSet (java.util.HashSet)3