Search in sources :

Example 1 with AbstractComplexAttribute

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

the class TestApiContentInterface method checkAttributes.

private void checkAttributes(AttributeInterface oldAttribute, AttributeInterface newAttribute) {
    if (null == newAttribute) {
        fail();
    }
    assertEquals(oldAttribute.getName(), newAttribute.getName());
    assertEquals(oldAttribute.getType(), newAttribute.getType());
    if (!oldAttribute.isSimple()) {
        if (oldAttribute instanceof AbstractListAttribute) {
            List<AttributeInterface> oldListAttributes = ((AbstractComplexAttribute) oldAttribute).getAttributes();
            List<AttributeInterface> newListAttributes = ((AbstractComplexAttribute) newAttribute).getAttributes();
            assertEquals(oldListAttributes.size(), newListAttributes.size());
            for (int i = 0; i < oldListAttributes.size(); i++) {
                AttributeInterface oldElement = oldListAttributes.get(i);
                AttributeInterface newElement = newListAttributes.get(i);
                this.checkAttributes(oldElement, newElement);
            }
        } else if (oldAttribute instanceof CompositeAttribute) {
            Map<String, AttributeInterface> oldAttributeMap = ((CompositeAttribute) oldAttribute).getAttributeMap();
            Map<String, AttributeInterface> newAttributeMap = ((CompositeAttribute) newAttribute).getAttributeMap();
            assertEquals(oldAttributeMap.size(), newAttributeMap.size());
            Iterator<String> iterator = oldAttributeMap.keySet().iterator();
            while (iterator.hasNext()) {
                String key = iterator.next();
                AttributeInterface oldElement = oldAttributeMap.get(key);
                AttributeInterface newElement = newAttributeMap.get(key);
                this.checkAttributes(oldElement, newElement);
            }
        }
    } else {
        if (oldAttribute instanceof AbstractResourceAttribute || oldAttribute instanceof LinkAttribute) {
            return;
        }
        assertEquals(oldAttribute.getValue(), newAttribute.getValue());
    }
}
Also used : AbstractResourceAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute) LinkAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.LinkAttribute) AbstractComplexAttribute(com.agiletec.aps.system.common.entity.model.attribute.AbstractComplexAttribute) CompositeAttribute(com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute) Iterator(java.util.Iterator) Map(java.util.Map) AbstractListAttribute(com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 2 with AbstractComplexAttribute

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

the class UserProfile method getValue.

private Object getValue(AttributeInterface attribute) {
    if (null == attribute)
        return "";
    if (attribute.isTextAttribute()) {
        return ((ITextAttribute) attribute).getText();
    } else if (attribute instanceof NumberAttribute) {
        return ((NumberAttribute) attribute).getValue();
    } else if (attribute instanceof BooleanAttribute) {
        return ((BooleanAttribute) attribute).getValue();
    } else if (attribute instanceof DateAttribute) {
        return ((DateAttribute) attribute).getDate();
    } else if (!attribute.isSimple()) {
        String text = "";
        List<AttributeInterface> attributes = ((AbstractComplexAttribute) attribute).getAttributes();
        for (int i = 0; i < attributes.size(); i++) {
            if (i > 0)
                text += ",";
            AttributeInterface attributeElem = attributes.get(i);
            text += this.getValue(attributeElem);
        }
        return text;
    }
    return null;
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) BooleanAttribute(com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute) AbstractComplexAttribute(com.agiletec.aps.system.common.entity.model.attribute.AbstractComplexAttribute) NumberAttribute(com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 3 with AbstractComplexAttribute

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

the class EntityTypeDOM method createAttribute.

/**
 * Generate an attribute to insert in an Entity Type. The attribute is
 * obtained cloning one of the previously defined elements.
 *
 * @param attributeElem The element of the Attribute Type to generate.
 * @return The built attribute.
 * @throws ApsSystemException If parsing errors are detected.
 */
private AttributeInterface createAttribute(Element attributeElem) throws ApsSystemException {
    String typeCode = this.extractXmlAttribute(attributeElem, "attributetype", true);
    AttributeInterface attr = (AttributeInterface) getAttributeTypes().get(typeCode);
    if (null == attr) {
        throw new ApsSystemException("Wrong Attribute Type: " + typeCode + ", " + "found in the tag <" + attributeElem.getName() + ">");
    }
    attr = (AttributeInterface) attr.getAttributePrototype();
    attr.setAttributeConfig(attributeElem);
    if (!attr.isSimple()) {
        ((AbstractComplexAttribute) attr).setComplexAttributeConfig(attributeElem, this.getAttributeTypes());
    }
    return attr;
}
Also used : AbstractComplexAttribute(com.agiletec.aps.system.common.entity.model.attribute.AbstractComplexAttribute) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Aggregations

AbstractComplexAttribute (com.agiletec.aps.system.common.entity.model.attribute.AbstractComplexAttribute)3 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)3 AbstractListAttribute (com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute)1 BooleanAttribute (com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute)1 CompositeAttribute (com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute)1 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)1 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)1 NumberAttribute (com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute)1 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 AbstractResourceAttribute (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute)1 LinkAttribute (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.LinkAttribute)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1