Search in sources :

Example 86 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.setParentCode(parent.getCode());
    }
    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 87 with Category

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

the class CategoryManagerCacheWrapper method moveCategory.

@Override
public void moveCategory(String categoryCode, String newParentCode) {
    Cache cache = this.getCache();
    Category categoryNode1 = this.getCategory(categoryCode);
    Category categoryNode2 = this.getCategory(newParentCode);
    Category oldParent = this.getCategory(categoryNode1.getParentCode());
    int index1 = Arrays.asList(oldParent.getChildrenCodes()).indexOf(categoryCode);
    String[] newChildren = ArrayUtils.remove(oldParent.getChildrenCodes(), index1);
    oldParent.setChildrenCodes(newChildren);
    cache.put(CATEGORY_CACHE_NAME_PREFIX + oldParent.getCode(), oldParent);
    String[] oldChildDest = categoryNode2.getChildrenCodes();
    categoryNode1.setParentCode(categoryNode2.getCode());
    cache.put(CATEGORY_CACHE_NAME_PREFIX + categoryNode1.getCode(), categoryNode1);
    String[] newChildren2 = ArrayUtils.add(oldChildDest, categoryNode1.getCode());
    categoryNode2.setChildrenCodes(newChildren2);
    cache.put(CATEGORY_CACHE_NAME_PREFIX + categoryNode2.getCode(), categoryNode2);
}
Also used : Category(com.agiletec.aps.system.services.category.Category) Cache(org.springframework.cache.Cache)

Example 88 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 89 with Category

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

the class JAXBEntity method buildEntity.

public IApsEntity buildEntity(IApsEntity prototype, ICategoryManager categoryManager, String langCode) {
    try {
        prototype.setDescription(this.getDescription());
        prototype.setId(this.getId());
        prototype.setMainGroup(this.getMainGroup());
        prototype.setTypeCode(this.getTypeCode());
        prototype.setTypeDescription(this.getTypeDescription());
        if (null != this.getGroups() && !this.getGroups().isEmpty()) {
            Iterator<String> iter = this.getGroups().iterator();
            while (iter.hasNext()) {
                prototype.addGroup(iter.next());
            }
        }
        if (null != this.getCategories() && !this.getCategories().isEmpty()) {
            Iterator<String> iter = this.getCategories().iterator();
            while (iter.hasNext()) {
                String categoryCode = iter.next();
                Category category = categoryManager.getCategory(categoryCode);
                if (null != category) {
                    prototype.addCategory(category);
                }
            }
        }
        if (null == this.getAttributes()) {
            return prototype;
        }
        for (int i = 0; i < this.getAttributes().size(); i++) {
            AbstractJAXBAttribute jaxrAttribute = this.getAttributes().get(i);
            AttributeInterface attribute = (AttributeInterface) prototype.getAttribute(jaxrAttribute.getName());
            if (null != attribute && attribute.getType().equals(jaxrAttribute.getType())) {
                attribute.valueFrom(jaxrAttribute, langCode);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error creating Entity", t);
        throw new RuntimeException("Error creating Entity", t);
    }
    return prototype;
}
Also used : Category(com.agiletec.aps.system.services.category.Category) AbstractJAXBAttribute(com.agiletec.aps.system.common.entity.model.attribute.AbstractJAXBAttribute) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 90 with Category

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

the class TestSearchEngineManager method createDataObject_3.

private DataObject createDataObject_3() {
    DataObject content = new DataObject();
    content.setId("103");
    content.setMainGroup(Group.FREE_GROUP_NAME);
    content.setTypeCode("ART");
    TextAttribute text = new TextAttribute();
    text.setName("Articolo");
    text.setType("Text");
    text.setIndexingType(IndexableAttributeInterface.INDEXING_TYPE_TEXT);
    text.setText("La vita รจ una cosa meravigliosa", "it");
    text.setText("Life is a wonderful thing", "en");
    content.addAttribute(text);
    Category category = this._categoryManager.getCategory("general_cat1");
    content.addCategory(category);
    return content;
}
Also used : DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) Category(com.agiletec.aps.system.services.category.Category) TextAttribute(com.agiletec.aps.system.common.entity.model.attribute.TextAttribute)

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