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