use of com.agiletec.aps.system.common.util.EntityAttributeIterator in project entando-core by entando.
the class IndexerDAO method createDocument.
/**
* Crea un oggetto Document pronto per l'indicizzazione da un oggetto
* Content.
*
* @param entity Il dataobject dal quale ricavare il Document.
* @return L'oggetto Document ricavato dal dataobject.
* @throws ApsSystemException In caso di errore
*/
protected Document createDocument(IApsEntity entity) throws ApsSystemException {
Document document = new Document();
document.add(new StringField(DATAOBJECT_ID_FIELD_NAME, entity.getId(), Field.Store.YES));
document.add(new TextField(DATAOBJECT_TYPE_FIELD_NAME, entity.getTypeCode(), Field.Store.YES));
document.add(new StringField(DATAOBJECT_GROUP_FIELD_NAME, entity.getMainGroup(), Field.Store.YES));
Iterator<String> iterGroups = entity.getGroups().iterator();
while (iterGroups.hasNext()) {
String groupName = (String) iterGroups.next();
document.add(new StringField(DATAOBJECT_GROUP_FIELD_NAME, groupName, Field.Store.YES));
}
try {
EntityAttributeIterator attributesIter = new EntityAttributeIterator(entity);
while (attributesIter.hasNext()) {
AttributeInterface currentAttribute = (AttributeInterface) attributesIter.next();
List<Lang> langs = this.getLangManager().getLangs();
for (int i = 0; i < langs.size(); i++) {
Lang currentLang = (Lang) langs.get(i);
this.indexAttribute(document, currentAttribute, currentLang);
}
}
List<Category> categories = entity.getCategories();
if (null != categories && !categories.isEmpty()) {
for (int i = 0; i < categories.size(); i++) {
Category category = categories.get(i);
this.indexCategory(document, category);
}
}
} catch (Throwable t) {
_logger.error("Error creating document", t);
throw new ApsSystemException("Error creating document", t);
}
return document;
}
use of com.agiletec.aps.system.common.util.EntityAttributeIterator in project entando-core by entando.
the class IndexerDAO method createDocument.
/**
* Crea un oggetto Document pronto per l'indicizzazione da un oggetto Content.
* @param entity Il contenuto dal quale ricavare il Document.
* @return L'oggetto Document ricavato dal contenuto.
* @throws ApsSystemException In caso di errore
*/
protected Document createDocument(IApsEntity entity) throws ApsSystemException {
Document document = new Document();
document.add(new StringField(CONTENT_ID_FIELD_NAME, entity.getId(), Field.Store.YES));
document.add(new TextField(CONTENT_TYPE_FIELD_NAME, entity.getTypeCode(), Field.Store.YES));
document.add(new StringField(CONTENT_GROUP_FIELD_NAME, entity.getMainGroup(), Field.Store.YES));
Iterator<String> iterGroups = entity.getGroups().iterator();
while (iterGroups.hasNext()) {
String groupName = (String) iterGroups.next();
document.add(new StringField(CONTENT_GROUP_FIELD_NAME, groupName, Field.Store.YES));
}
try {
EntityAttributeIterator attributesIter = new EntityAttributeIterator(entity);
while (attributesIter.hasNext()) {
AttributeInterface currentAttribute = (AttributeInterface) attributesIter.next();
List<Lang> langs = this.getLangManager().getLangs();
for (int i = 0; i < langs.size(); i++) {
Lang currentLang = (Lang) langs.get(i);
this.indexAttribute(document, currentAttribute, currentLang);
}
}
List<Category> categories = entity.getCategories();
if (null != categories && !categories.isEmpty()) {
for (int i = 0; i < categories.size(); i++) {
Category category = categories.get(i);
this.indexCategory(document, category);
}
}
} catch (Throwable t) {
_logger.error("Error creating document", t);
throw new ApsSystemException("Error creating document", t);
}
return document;
}
use of com.agiletec.aps.system.common.util.EntityAttributeIterator in project entando-core by entando.
the class BaseEntityRenderer method convertSpecialCharacters.
protected List<TextAttributeCharReplaceInfo> convertSpecialCharacters(IApsEntity entity, String langCode) {
List<TextAttributeCharReplaceInfo> conversions = new ArrayList<TextAttributeCharReplaceInfo>();
Lang defaultLang = this.getLangManager().getDefaultLang();
EntityAttributeIterator attributeIter = new EntityAttributeIterator(entity);
while (attributeIter.hasNext()) {
AttributeInterface currAttribute = (AttributeInterface) attributeIter.next();
if (currAttribute instanceof ITextAttribute) {
String attributeLangCode = langCode;
ITextAttribute renderizable = (ITextAttribute) currAttribute;
if (renderizable.needToConvertSpecialCharacter()) {
String textToConvert = renderizable.getTextForLang(attributeLangCode);
if (null == textToConvert || textToConvert.trim().length() == 0) {
attributeLangCode = defaultLang.getCode();
textToConvert = renderizable.getTextForLang(attributeLangCode);
}
if (null != textToConvert && textToConvert.trim().length() > 0) {
conversions.add(new TextAttributeCharReplaceInfo(renderizable, textToConvert, attributeLangCode));
String convertedText = StringEscapeUtils.escapeHtml(textToConvert);
renderizable.setText(convertedText, attributeLangCode);
}
}
}
}
return conversions;
}
use of com.agiletec.aps.system.common.util.EntityAttributeIterator in project entando-core by entando.
the class ContentDAO method addContentRelationsRecord.
/**
* Add a record in the table 'contentrelations' for every resource, page,
* other content, role and category associated to the given content).
*
* @param content
* The current content.
* @param conn
* The connection to the database.
* @throws ApsSystemException
* when connection error are detected.
*/
protected void addContentRelationsRecord(Content content, Connection conn) throws ApsSystemException {
PreparedStatement stat = null;
try {
stat = conn.prepareStatement(ADD_CONTENT_REL_RECORD);
this.addCategoryRelationsRecord(content, true, stat);
this.addGroupRelationsRecord(content, stat);
EntityAttributeIterator attributeIter = new EntityAttributeIterator(content);
while (attributeIter.hasNext()) {
AttributeInterface currAttribute = (AttributeInterface) attributeIter.next();
if (currAttribute instanceof IReferenceableAttribute) {
IReferenceableAttribute cmsAttribute = (IReferenceableAttribute) currAttribute;
List<CmsAttributeReference> refs = cmsAttribute.getReferences(this.getLangManager().getLangs());
for (int i = 0; i < refs.size(); i++) {
CmsAttributeReference ref = refs.get(i);
stat.setString(1, content.getId());
stat.setString(2, ref.getRefPage());
stat.setString(3, ref.getRefContent());
stat.setString(4, ref.getRefResource());
stat.setString(5, null);
stat.setString(6, null);
stat.addBatch();
stat.clearParameters();
}
}
}
stat.executeBatch();
} catch (BatchUpdateException e) {
_logger.error("Error saving record into contentrelations {}", content.getId(), e.getNextException());
throw new RuntimeException("Error saving record into contentrelations " + content.getId(), e.getNextException());
} catch (Throwable t) {
_logger.error("Error saving record into contentrelations {}", content.getId(), t);
throw new RuntimeException("Error saving record into contentrelations " + content.getId(), t);
} finally {
closeDaoResources(null, stat);
}
}
Aggregations