Search in sources :

Example 81 with Category

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

the class CategoryManagerCacheWrapper method initCache.

private void initCache(Cache cache, List<Category> categories) throws ApsSystemException {
    Category root = null;
    Map<String, Category> categoryMap = new HashMap<>();
    for (Category cat : categories) {
        categoryMap.put(cat.getCode(), cat);
        if (cat.getCode().equals(cat.getParentCode())) {
            root = cat;
        }
    }
    for (Category cat : categories) {
        Category parent = categoryMap.get(cat.getParentCode());
        if (cat != root) {
            parent.addChildCode(cat.getCode());
        }
        cat.setParent(parent);
    }
    if (root == null) {
        throw new ApsSystemException("Error found in the category tree: undefined root");
    }
    this.insertObjectsOnCache(cache, root, categoryMap);
}
Also used : Category(com.agiletec.aps.system.services.category.Category) HashMap(java.util.HashMap) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 82 with Category

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

the class ApsEntity method getBuildJDOM.

/**
 * Return the DOM class that generates the XML corresponding to the entity
 * with its data.
 * This method must be extended to support customized XML structures;
 * this happen when, for example, a custom entity is based on an
 * object class which, in turn, extends ApsEntity.
 * @return The DOM class that generates the XML
 */
protected IApsEntityDOM getBuildJDOM() {
    IApsEntityDOM entityDom = this.getEntityDOM().clone();
    entityDom.init();
    entityDom.setId(String.valueOf(this.getId()));
    entityDom.setTypeCode(this._typeCode);
    entityDom.setTypeDescription(this._typeDescription);
    entityDom.setDescription(this._description);
    entityDom.setMainGroup(this._mainGroup);
    Iterator<String> iterGroups = this.getGroups().iterator();
    while (iterGroups.hasNext()) {
        String groupName = iterGroups.next();
        entityDom.addGroup(groupName);
    }
    Iterator<Category> iterCategory = this._categories.iterator();
    while (iterCategory.hasNext()) {
        Category category = iterCategory.next();
        entityDom.addCategory(category.getCode());
    }
    Iterator<AttributeInterface> iterAttribute = this._attributeList.iterator();
    while (iterAttribute.hasNext()) {
        AttributeInterface currentAttribute = iterAttribute.next();
        Element attributeElement = currentAttribute.getJDOMElement();
        if (attributeElement != null) {
            entityDom.addAttribute(currentAttribute.getJDOMElement());
        }
    }
    return entityDom;
}
Also used : Category(com.agiletec.aps.system.services.category.Category) IApsEntityDOM(com.agiletec.aps.system.common.entity.parse.IApsEntityDOM) Element(org.jdom.Element) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 83 with Category

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

the class CategoriesTag method doStartTag.

@Override
public int doStartTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    ICategoryManager catManager = (ICategoryManager) ApsWebApplicationUtils.getBean(SystemConstants.CATEGORY_MANAGER, this.pageContext);
    try {
        List<SelectItem> categories = new ArrayList<SelectItem>();
        Category root = (null != this.getRoot()) ? catManager.getCategory(this.getRoot()) : null;
        if (null == root) {
            root = catManager.getRoot();
        }
        Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
        String langCode = currentLang.getCode();
        String reqTitStyle = this.getTitleStyle();
        List<String> allowedStyles = Arrays.asList(ALLOWED_TITLE_TYPES);
        String titleStyle = (null != reqTitStyle && (allowedStyles.contains(reqTitStyle))) ? reqTitStyle : null;
        this.addSmallCategory(categories, root, langCode, titleStyle, catManager);
        this.pageContext.setAttribute(this.getVar(), categories);
    } catch (Throwable t) {
        _logger.error("Error starting tag", t);
        throw new JspException("Error starting tag", t);
    }
    return super.doStartTag();
}
Also used : ServletRequest(javax.servlet.ServletRequest) JspException(javax.servlet.jsp.JspException) Category(com.agiletec.aps.system.services.category.Category) SelectItem(com.agiletec.aps.util.SelectItem) ArrayList(java.util.ArrayList) Lang(com.agiletec.aps.system.services.lang.Lang) RequestContext(com.agiletec.aps.system.RequestContext) ICategoryManager(com.agiletec.aps.system.services.category.ICategoryManager)

Example 84 with Category

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

the class CategoriesTag method addSmallCategory.

private void addSmallCategory(List<SelectItem> categories, Category category, String langCode, String titleStyle, ICategoryManager catManager) {
    String[] children = category.getChildrenCodes();
    if (null == children) {
        return;
    }
    for (int i = 0; i < children.length; i++) {
        Category child = catManager.getCategory(children[i]);
        String title = null;
        if (null == titleStyle || titleStyle.equals(TITLE_TYPE_DEFAULT)) {
            title = child.getTitles().getProperty(langCode);
        } else if (titleStyle.equals(TITLE_TYPE_FULL)) {
            if (null != this.getFullTitleSeparator()) {
                title = child.getFullTitle(langCode, this.getFullTitleSeparator());
            } else {
                title = child.getFullTitle(langCode);
            }
        } else if (titleStyle.equals(TITLE_TYPE_PRETTY_FULL)) {
            if (null != this.getFullTitleSeparator()) {
                title = child.getShortFullTitle(langCode, this.getFullTitleSeparator());
            } else {
                title = child.getShortFullTitle(langCode);
            }
        }
        SelectItem catSmall = new SelectItem(child.getCode(), title);
        categories.add(catSmall);
        this.addSmallCategory(categories, child, langCode, titleStyle, catManager);
    }
}
Also used : Category(com.agiletec.aps.system.services.category.Category) SelectItem(com.agiletec.aps.util.SelectItem)

Example 85 with Category

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

the class ContentDAO method addCategoryRelationsRecord.

private void addCategoryRelationsRecord(Content content, boolean isPublicRelations, PreparedStatement stat) throws ApsSystemException {
    if (content.getCategories().size() > 0) {
        try {
            Set<String> codes = new HashSet<String>();
            Iterator<Category> categoryIter = content.getCategories().iterator();
            while (categoryIter.hasNext()) {
                Category category = (Category) categoryIter.next();
                this.addCategoryCode(category, codes);
            }
            Iterator<String> codeIter = codes.iterator();
            while (codeIter.hasNext()) {
                String code = codeIter.next();
                int i = 1;
                stat.setString(i++, content.getId());
                if (isPublicRelations) {
                    stat.setString(i++, null);
                    stat.setString(i++, null);
                    stat.setBigDecimal(i++, null);
                }
                stat.setString(i++, code);
                if (isPublicRelations) {
                    stat.setString(i++, null);
                }
                stat.addBatch();
                stat.clearParameters();
            }
        } catch (SQLException e) {
            _logger.error("Error saving content relation record for content {}", content.getId(), e.getNextException());
            throw new RuntimeException("Error saving content relation record for content " + content.getId(), e.getNextException());
        }
    }
}
Also used : Category(com.agiletec.aps.system.services.category.Category) SQLException(java.sql.SQLException) HashSet(java.util.HashSet)

Aggregations

Category (com.agiletec.aps.system.services.category.Category)85 ArrayList (java.util.ArrayList)21 ITreeNode (com.agiletec.aps.system.common.tree.ITreeNode)9 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)7 TextAttribute (com.agiletec.aps.system.common.entity.model.attribute.TextAttribute)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 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)4 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 List (java.util.List)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 CategoryUtilizer (com.agiletec.aps.system.services.category.CategoryUtilizer)3 HashSet (java.util.HashSet)3 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)3