Search in sources :

Example 41 with AttributeInterface

use of com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface in project entando-core by entando.

the class ApsEntity method getEntityPrototype.

/**
 * Create an object from the prototype.
 * @return The object created from the prototype.
 */
@Override
public IApsEntity getEntityPrototype() {
    IApsEntity entity = null;
    try {
        Class entityClass = Class.forName(this.getClass().getName());
        entity = (IApsEntity) entityClass.newInstance();
        entity.setId(null);
        entity.setTypeCode(this.getTypeCode());
        entity.setTypeDescription(this.getTypeDescription());
        entity.setDescription(this.getDescription());
        AttributeInterface attr;
        for (int i = 0; i < this._attributeList.size(); i++) {
            attr = (AttributeInterface) this._attributeList.get((i));
            attr = (AttributeInterface) attr.getAttributePrototype();
            attr.setParentEntity(entity);
            entity.addAttribute(attr);
        }
        entity.setEntityDOM(this.getEntityDOM());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        _logger.error("Error creating entity prototype", e);
        throw new RuntimeException("Error creating entity prototype", e);
    }
    return entity;
}
Also used : AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 42 with AttributeInterface

use of com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface in project entando-core by entando.

the class ApsEntity method validate.

@Override
public List<FieldError> validate(IGroupManager groupManager) {
    List<FieldError> errors = new ArrayList<>();
    if (null != this.getMainGroup() && null == groupManager.getGroup(this.getMainGroup())) {
        FieldError error = new FieldError("mainGroup", FieldError.INVALID);
        error.setMessage("Invalid main group - " + this.getMainGroup());
        errors.add(error);
    }
    if (null != this.getGroups()) {
        Iterator<String> groupsIter = this.getGroups().iterator();
        while (groupsIter.hasNext()) {
            String groupName = groupsIter.next();
            if (null == groupManager.getGroup(groupName)) {
                FieldError error = new FieldError("extraGroup", FieldError.INVALID);
                error.setMessage("Invalid extra group - " + groupName);
                errors.add(error);
            }
        }
    }
    if (null != this.getAttributeList()) {
        List<AttributeInterface> attributes = this.getAttributeList();
        for (int i = 0; i < attributes.size(); i++) {
            AttributeInterface attribute = attributes.get(i);
            AttributeTracer tracer = new AttributeTracer();
            List<AttributeFieldError> attributeErrors = attribute.validate(tracer);
            if (null != attributeErrors) {
                errors.addAll(attributeErrors);
            }
        }
    }
    return errors;
}
Also used : ArrayList(java.util.ArrayList) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 43 with AttributeInterface

use of com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface in project entando-core by entando.

the class JAXBEntity method buildEntity.

public IApsEntity buildEntity(IApsEntity prototype, ICategoryManager categoryManager) {
    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);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error creating Entity", t);
        throw new RuntimeException("Error creating Entity", t);
    }
    return prototype;
}
Also used : Category(com.agiletec.aps.system.services.category.Category) AbstractJAXBAttribute(com.agiletec.aps.system.common.entity.model.attribute.AbstractJAXBAttribute) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 44 with AttributeInterface

use of com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface 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 45 with AttributeInterface

use of com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface 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)147 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)55 AttributeTracer (com.agiletec.aps.system.common.entity.model.AttributeTracer)38 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)37 CompositeAttribute (com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute)27 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)22 ArrayList (java.util.ArrayList)18 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)17 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)16 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)14 NumberAttribute (com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute)12 ListAttribute (com.agiletec.aps.system.common.entity.model.attribute.ListAttribute)11 BooleanAttribute (com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute)10 IndexableAttributeInterface (com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface)10 HttpSession (javax.servlet.http.HttpSession)10 EntityAttributeIterator (com.agiletec.aps.system.common.util.EntityAttributeIterator)9 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)7 MonoTextAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute)7 Lang (com.agiletec.aps.system.services.lang.Lang)7 Date (java.util.Date)7