Search in sources :

Example 6 with EntityAttributeIterator

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;
}
Also used : Category(com.agiletec.aps.system.services.category.Category) Lang(com.agiletec.aps.system.services.lang.Lang) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) Document(org.apache.lucene.document.Document) StringField(org.apache.lucene.document.StringField) TextField(org.apache.lucene.document.TextField) IndexableAttributeInterface(com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) EntityAttributeIterator(com.agiletec.aps.system.common.util.EntityAttributeIterator)

Example 7 with EntityAttributeIterator

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;
}
Also used : Category(com.agiletec.aps.system.services.category.Category) Lang(com.agiletec.aps.system.services.lang.Lang) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) Document(org.apache.lucene.document.Document) StringField(org.apache.lucene.document.StringField) TextField(org.apache.lucene.document.TextField) IndexableAttributeInterface(com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface) ResourceAttributeInterface(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.ResourceAttributeInterface) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) EntityAttributeIterator(com.agiletec.aps.system.common.util.EntityAttributeIterator)

Example 8 with EntityAttributeIterator

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;
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) ArrayList(java.util.ArrayList) Lang(com.agiletec.aps.system.services.lang.Lang) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) EntityAttributeIterator(com.agiletec.aps.system.common.util.EntityAttributeIterator)

Example 9 with EntityAttributeIterator

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);
    }
}
Also used : IReferenceableAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.IReferenceableAttribute) PreparedStatement(java.sql.PreparedStatement) CmsAttributeReference(com.agiletec.plugins.jacms.aps.system.services.content.model.CmsAttributeReference) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) EntityAttributeIterator(com.agiletec.aps.system.common.util.EntityAttributeIterator) BatchUpdateException(java.sql.BatchUpdateException)

Aggregations

AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)9 EntityAttributeIterator (com.agiletec.aps.system.common.util.EntityAttributeIterator)9 Lang (com.agiletec.aps.system.services.lang.Lang)3 CmsAttributeReference (com.agiletec.plugins.jacms.aps.system.services.content.model.CmsAttributeReference)3 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)3 IReferenceableAttribute (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.IReferenceableAttribute)3 ArrayList (java.util.ArrayList)3 IndexableAttributeInterface (com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface)2 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 Category (com.agiletec.aps.system.services.category.Category)2 BatchUpdateException (java.sql.BatchUpdateException)2 PreparedStatement (java.sql.PreparedStatement)2 Document (org.apache.lucene.document.Document)2 StringField (org.apache.lucene.document.StringField)2 TextField (org.apache.lucene.document.TextField)2 AttributeSearchInfo (com.agiletec.aps.system.common.entity.model.AttributeSearchInfo)1 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)1 MonoTextAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute)1 IPage (com.agiletec.aps.system.services.page.IPage)1 ResourceAttributeInterface (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.ResourceAttributeInterface)1