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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations