Search in sources :

Example 41 with Category

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

the class CategoryAction method moveTree.

public String moveTree() {
    String selectedNode = this.getSelectedNode();
    String parentCategoryCode = this.getRequest().getParameter("parentCategoryCode");
    try {
        String check = this.checkMoveCategory(selectedNode, parentCategoryCode);
        if (null != check) {
            return check;
        }
        this.extractReferencingObjectsForMove(this.getSelectedNode());
        if (null != this.getReferences() && this.getReferences().size() > 0) {
            return "moveReferences";
        }
        Category currentCategory = this.getCategory(this.getSelectedNode());
        Category parent = this.getCategory(parentCategoryCode);
        this.getCategoryManager().moveCategory(currentCategory, parent);
    } catch (Throwable t) {
        _logger.error("error in move category", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : Category(com.agiletec.aps.system.services.category.Category)

Example 42 with Category

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

the class CategoryActionHelper method buildNewCategory.

@Override
public Category buildNewCategory(String code, String parentCode, ApsProperties titles) throws ApsSystemException {
    Category category = new Category();
    try {
        category.setParentCode(parentCode);
        category.setTitles(titles);
        String newCategoryCode = code;
        if (null != newCategoryCode && newCategoryCode.trim().length() > 0) {
            category.setCode(newCategoryCode);
        } else {
            String defaultLangCode = this.getLangManager().getDefaultLang().getCode();
            String defaultTitle = category.getTitles().getProperty(defaultLangCode);
            String categoryCode = this.buildCode(defaultTitle, "category", 25);
            category.setCode(categoryCode);
        }
    } catch (Throwable t) {
        _logger.error("Error creating new category", t);
        throw new ApsSystemException("Error creating new category", t);
    }
    return category;
}
Also used : Category(com.agiletec.aps.system.services.category.Category) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 43 with Category

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

the class CategoryAction method getAvailableNodesForMoveTreeAjax.

public List<TreeNodeWrapper> getAvailableNodesForMoveTreeAjax() {
    List<TreeNodeWrapper> result = new ArrayList<TreeNodeWrapper>();
    try {
        String startCategoryCode = this.getSelectedNode();
        if (StringUtils.isBlank(startCategoryCode)) {
            _logger.warn("required parameter 'selectedNode' missing");
            return result;
        }
        Category nodeToMove = this.getCategory(startCategoryCode);
        if (null == nodeToMove) {
            _logger.warn("category {} is null", startCategoryCode);
            return result;
        }
        this.setCategoryCodeToken(super.getParameter("categoryCodeToken"));
        List<Category> searchResult = this.getCategoryManager().searchCategories(this.getCategoryCodeToken());
        if (null == searchResult || searchResult.isEmpty()) {
            return result;
        }
        BeanComparator comparator = new BeanComparator("code");
        Collections.sort(result, comparator);
        int maxIndex = 30;
        String maxParam = super.getParameter("max");
        if (StringUtils.isNotBlank(maxParam) && StringUtils.isNumeric(maxParam)) {
            maxIndex = new Integer(maxParam).intValue();
        }
        Iterator<Category> it = searchResult.iterator();
        while (result.size() < maxIndex && it.hasNext()) {
            ITreeNode candidate = it.next();
            if (!candidate.isChildOf(nodeToMove.getCode(), this.getCategoryManager()) && !candidate.getCode().equals(nodeToMove.getParentCode())) {
                ITreeNode parent = this.getCategoryManager().getNode(candidate.getParentCode());
                result.add(new TreeNodeWrapper(candidate, parent, this.getCurrentLang().getCode(), this.getCategoryManager()));
            }
        }
    } catch (Throwable t) {
        _logger.error("Error on searching categories ajax", t);
        throw new RuntimeException("Error on searching categories ajax", t);
    }
    return result;
}
Also used : Category(com.agiletec.aps.system.services.category.Category) TreeNodeWrapper(com.agiletec.apsadmin.system.TreeNodeWrapper) ArrayList(java.util.ArrayList) BeanComparator(org.apache.commons.beanutils.BeanComparator) ITreeNode(com.agiletec.aps.system.common.tree.ITreeNode)

Example 44 with Category

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

the class CategoryAction method getBreadCrumbsTargets.

public List<Category> getBreadCrumbsTargets(String categoryCode) {
    Category category = this.getCategoryManager().getCategory(categoryCode);
    if (null == category) {
        return null;
    }
    List<Category> categories = new ArrayList<>();
    this.getSubBreadCrumbsTargets(categories, category);
    return categories;
}
Also used : Category(com.agiletec.aps.system.services.category.Category) ArrayList(java.util.ArrayList)

Example 45 with Category

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

the class CategoryManagerCacheWrapper method createRoot.

protected Category createRoot(ILangManager langManager) {
    Category root = new Category();
    root.setCode("home");
    root.setParentCode("home");
    List<Lang> langs = langManager.getLangs();
    ApsProperties titles = new ApsProperties();
    for (Lang lang : langs) {
        titles.setProperty(lang.getCode(), "Home");
    }
    root.setTitles(titles);
    return root;
}
Also used : Category(com.agiletec.aps.system.services.category.Category) Lang(com.agiletec.aps.system.services.lang.Lang) ApsProperties(com.agiletec.aps.util.ApsProperties)

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