Search in sources :

Example 1 with EntityAttributeIterator

use of com.agiletec.aps.system.common.util.EntityAttributeIterator in project entando-core by entando.

the class DataObjectDAO method addDataObjectRelationsRecord.

/**
 * Add a record in the table 'dataobjectrelations' for every resource, page,
 * other dataobject, role and category associated to the given dataobject).
 *
 * @param dataobject The current dataobject.
 * @param conn The connection to the database.
 * @throws ApsSystemException when connection error are detected.
 */
protected void addDataObjectRelationsRecord(DataObject dataobject, Connection conn) throws ApsSystemException {
    PreparedStatement stat = null;
    try {
        stat = conn.prepareStatement(ADD_DATAOBJECT_REL_RECORD);
        this.addCategoryRelationsRecord(dataobject, true, stat);
        this.addGroupRelationsRecord(dataobject, stat);
        EntityAttributeIterator attributeIter = new EntityAttributeIterator(dataobject);
        while (attributeIter.hasNext()) {
            AttributeInterface currAttribute = (AttributeInterface) attributeIter.next();
        }
        stat.executeBatch();
    } catch (BatchUpdateException e) {
        _logger.error("Error saving record into dataobjectrelations {}", dataobject.getId(), e.getNextException());
        throw new RuntimeException("Error saving record into dataobjectrelations " + dataobject.getId(), e.getNextException());
    } catch (Throwable t) {
        _logger.error("Error saving record into dataobjectrelations {}", dataobject.getId(), t);
        throw new RuntimeException("Error saving record into dataobjectrelations " + dataobject.getId(), t);
    } finally {
        closeDaoResources(null, stat);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) EntityAttributeIterator(com.agiletec.aps.system.common.util.EntityAttributeIterator) BatchUpdateException(java.sql.BatchUpdateException)

Example 2 with EntityAttributeIterator

use of com.agiletec.aps.system.common.util.EntityAttributeIterator in project entando-core by entando.

the class TestContentAttributeIterator method testIterator.

public void testIterator() throws ApsSystemException {
    Content content = new Content();
    AttributeInterface attribute = new MonoTextAttribute();
    attribute.setName("temp");
    attribute.setDefaultLangCode("it");
    attribute.setRenderingLang("it");
    attribute.setSearchable(true);
    attribute.setType("Monotext");
    content.addAttribute(attribute);
    EntityAttributeIterator attributeIterator = new EntityAttributeIterator(content);
    boolean contains = false;
    while (attributeIterator.hasNext()) {
        attribute = (AttributeInterface) attributeIterator.next();
        contains = attribute.getName().equals("temp");
    }
    assertTrue(contains);
}
Also used : Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) MonoTextAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute) EntityAttributeIterator(com.agiletec.aps.system.common.util.EntityAttributeIterator)

Example 3 with EntityAttributeIterator

use of com.agiletec.aps.system.common.util.EntityAttributeIterator in project entando-core by entando.

the class AbstractEntityDAO method addEntitySearchRecord.

protected void addEntitySearchRecord(String id, IApsEntity entity, PreparedStatement stat) throws Throwable {
    EntityAttributeIterator attributeIter = new EntityAttributeIterator(entity);
    while (attributeIter.hasNext()) {
        AttributeInterface currAttribute = (AttributeInterface) attributeIter.next();
        List<AttributeSearchInfo> infos = currAttribute.getSearchInfos(this.getLangManager().getLangs());
        if (currAttribute.isSearchable() && null != infos) {
            for (int i = 0; i < infos.size(); i++) {
                AttributeSearchInfo searchInfo = infos.get(i);
                stat.setString(1, id);
                stat.setString(2, currAttribute.getName());
                stat.setString(3, searchInfo.getString());
                if (searchInfo.getDate() != null) {
                    stat.setTimestamp(4, new java.sql.Timestamp(searchInfo.getDate().getTime()));
                } else {
                    stat.setDate(4, null);
                }
                stat.setBigDecimal(5, searchInfo.getBigDecimal());
                stat.setString(6, searchInfo.getLangCode());
                stat.addBatch();
                stat.clearParameters();
            }
        }
    }
    stat.executeBatch();
}
Also used : AttributeSearchInfo(com.agiletec.aps.system.common.entity.model.AttributeSearchInfo) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) EntityAttributeIterator(com.agiletec.aps.system.common.util.EntityAttributeIterator)

Example 4 with EntityAttributeIterator

use of com.agiletec.aps.system.common.util.EntityAttributeIterator in project entando-core by entando.

the class ContentInspectionAction method getReferencedContentsId.

/**
 * Return the list of the id of the referenced contents
 * @return The list of content id.
 */
public List<String> getReferencedContentsId() {
    List<String> referencedContentsId = new ArrayList<String>();
    try {
        Content content = this.getContent();
        if (null == content)
            return referencedContentsId;
        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.getLangs());
                for (int scanRefs = 0; scanRefs < refs.size(); scanRefs++) {
                    CmsAttributeReference ref = refs.get(scanRefs);
                    String contentId = ref.getRefContent();
                    if (null == contentId)
                        continue;
                    if (!referencedContentsId.contains(contentId))
                        referencedContentsId.add(contentId);
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("Error getting referenced contents id by content {}", this.getContentId(), t);
        String msg = "Error getting referenced contents id by content " + this.getContentId();
        throw new RuntimeException(msg, t);
    }
    return referencedContentsId;
}
Also used : IReferenceableAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.IReferenceableAttribute) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) ArrayList(java.util.ArrayList) 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)

Example 5 with EntityAttributeIterator

use of com.agiletec.aps.system.common.util.EntityAttributeIterator in project entando-core by entando.

the class ContentInspectionAction method getReferencedPages.

public List<IPage> getReferencedPages() {
    List<IPage> referencedPages = new ArrayList<IPage>();
    try {
        Content content = this.getContent();
        if (null == content)
            return referencedPages;
        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.getLangs());
                for (int scanRefs = 0; scanRefs < refs.size(); scanRefs++) {
                    CmsAttributeReference ref = refs.get(scanRefs);
                    if (null == ref.getRefPage())
                        continue;
                    IPage page = this.getPageManager().getOnlinePage(ref.getRefPage());
                    if (null == page)
                        continue;
                    if (!referencedPages.contains(page)) {
                        referencedPages.add(page);
                    }
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("Error getting referenced pages by content {}", this.getContentId(), t);
        String msg = "Error getting referenced pages by content " + this.getContentId();
        throw new RuntimeException(msg, t);
    }
    return referencedPages;
}
Also used : IReferenceableAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.IReferenceableAttribute) ArrayList(java.util.ArrayList) IPage(com.agiletec.aps.system.services.page.IPage) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) 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)

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