Search in sources :

Example 1 with AbstractListAttribute

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

the class AbstractEntityService method buildAttribute.

protected AttributeInterface buildAttribute(String typeCode, EntityAttributeFullDto attributeDto, Map<String, AttributeInterface> attributeMap, BindingResult bindingResult) {
    String type = attributeDto.getType();
    AttributeInterface prototype = attributeMap.get(type);
    if (null == prototype) {
        logger.warn("Undefined attribute of type {}", type);
        this.addError(EntityTypeValidator.ERRCODE_INVALID_ATTRIBUTE_TYPE, bindingResult, new String[] { typeCode, type }, "entityType.attribute.type.invalid");
        return null;
    }
    AttributeInterface attribute = (AttributeInterface) prototype.getAttributePrototype();
    attribute.setName(attributeDto.getCode());
    attribute.setDescription(attributeDto.getName());
    attribute.setIndexingType(attributeDto.isIndexable() ? IndexableAttributeInterface.INDEXING_TYPE_TEXT : null);
    List<AttributeRoleDto> dtoRoles = attributeDto.getRoles();
    if (null != dtoRoles && !dtoRoles.isEmpty()) {
        List<String> codes = dtoRoles.stream().map(AttributeRoleDto::getCode).collect(Collectors.toList());
        attribute.setRoles(codes.toArray(new String[codes.size()]));
    }
    attribute.setRequired(attributeDto.isMandatory());
    attribute.setSearchable(attributeDto.isListFilter());
    if (attribute instanceof EnumeratorAttribute) {
        // to check into validator
        String staticItems = attributeDto.getEnumeratorStaticItems();
        String extractor = attributeDto.getEnumeratorExtractorBean();
        if (StringUtils.isEmpty(staticItems) && StringUtils.isEmpty(extractor)) {
            this.addError(EntityTypeValidator.ERRCODE_INVALID_ENUMERATOR, bindingResult, new String[] { typeCode, attributeDto.getCode() }, "entityType.attribute.enumerator.invalid");
        }
        ((EnumeratorAttribute) attribute).setStaticItems(staticItems);
        ((EnumeratorAttribute) attribute).setExtractorBeanName(extractor);
        ((EnumeratorAttribute) attribute).setCustomSeparator(attributeDto.getEnumeratorStaticItemsSeparator());
    }
    IAttributeValidationRules validationRules = attribute.getValidationRules();
    validationRules.setRequired(attributeDto.isMandatory());
    EntityAttributeValidationDto validationDto = attributeDto.getValidationRules();
    if (null != validationDto) {
        validationDto.buildAttributeValidation(typeCode, attribute, bindingResult);
    }
    if (attribute instanceof AbstractListAttribute) {
        if (null != attributeDto.getNestedAttribute()) {
            EntityAttributeFullDto nestedAttributeDto = attributeDto.getNestedAttribute();
            ((AbstractListAttribute) attribute).setNestedAttributeType(this.buildAttribute(typeCode, nestedAttributeDto, attributeMap, bindingResult));
        } else {
            this.addError(EntityTypeValidator.ERRCODE_INVALID_LIST, bindingResult, new String[] { typeCode, type }, "entityType.attribute.list.missingNestedAttribute");
        }
    } else if (attribute instanceof CompositeAttribute) {
        List<EntityAttributeFullDto> compositeElementsDto = attributeDto.getCompositeAttributes();
        if (null != compositeElementsDto && !compositeElementsDto.isEmpty()) {
            for (EntityAttributeFullDto attributeElementDto : compositeElementsDto) {
                AttributeInterface attributeElement = this.buildAttribute(typeCode, attributeElementDto, attributeMap, bindingResult);
                ((CompositeAttribute) attribute).getAttributeMap().put(attributeElement.getName(), attributeElement);
                ((CompositeAttribute) attribute).getAttributes().add(attributeElement);
            }
        } else {
            this.addError(EntityTypeValidator.ERRCODE_INVALID_COMPOSITE, bindingResult, new String[] { typeCode, type }, "entityType.attribute.composite.missingElements");
        }
    }
    return attribute;
}
Also used : EnumeratorAttribute(com.agiletec.aps.system.common.entity.model.attribute.EnumeratorAttribute) CompositeAttribute(com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute) AttributeRoleDto(org.entando.entando.aps.system.services.entity.model.AttributeRoleDto) EntityAttributeFullDto(org.entando.entando.aps.system.services.entity.model.EntityAttributeFullDto) IAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.IAttributeValidationRules) ArrayList(java.util.ArrayList) List(java.util.List) IndexableAttributeInterface(com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) AbstractListAttribute(com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute) EntityAttributeValidationDto(org.entando.entando.aps.system.services.entity.model.EntityAttributeValidationDto)

Example 2 with AbstractListAttribute

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

the class EntityAttributeConfigAction method validate.

@Override
public void validate() {
    super.validate();
    IApsEntity entityType = this.getEntityType();
    String attributeName = this.getAttributeName().trim();
    if (this.getStrutsAction() == ApsAdminSystemConstants.ADD && null != entityType.getAttribute(attributeName)) {
        String[] args = { attributeName };
        this.addFieldError("attributeName", this.getText("error.entity.attribute.name.already.exists", args));
    }
    AttributeInterface attributePrototype = this.getAttributePrototype(this.getAttributeTypeCode());
    if (null == attributePrototype) {
        String[] args = { this.getAttributeTypeCode() };
        this.addFieldError("attributeTypeCode", this.getText("error.entity.attribute.type.invalid", args));
    } else {
        if ((attributePrototype instanceof EnumeratorAttribute) && (this.getEnumeratorStaticItems() == null || this.getEnumeratorStaticItems().trim().length() == 0) && (null == this.getEnumeratorExtractorBean() || this.getEnumeratorExtractorBean().trim().length() == 0)) {
            String[] args = { this.getAttributeTypeCode() };
            this.addFieldError("enumeratorStaticItems", this.getText("error.entity.attribute.enumerator.items.missing", args));
        }
        if ((attributePrototype instanceof AbstractListAttribute) && (StringUtils.isBlank(this.getListNestedType()) || null == this.getAttributePrototype(this.getAttributeTypeCode()))) {
            String[] args = { this.getAttributeTypeCode() };
            this.addFieldError("listNestedType", this.getText("error.entity.attribute.list.handled.missing", args));
        }
    }
}
Also used : EnumeratorAttribute(com.agiletec.aps.system.common.entity.model.attribute.EnumeratorAttribute) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) AbstractListAttribute(com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute)

Example 3 with AbstractListAttribute

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

the class EntityAttributeConfigAction method getAllowedNestedTypes.

public List<AttributeInterface> getAllowedNestedTypes(AttributeInterface listType) {
    List<AttributeInterface> attributes = new ArrayList<AttributeInterface>();
    try {
        IEntityManager entityManager = this.getEntityManager();
        Map<String, AttributeInterface> attributeTypes = entityManager.getEntityAttributePrototypes();
        Iterator<AttributeInterface> attributeIter = attributeTypes.values().iterator();
        while (attributeIter.hasNext()) {
            AttributeInterface attribute = attributeIter.next();
            boolean simple = attribute.isSimple();
            boolean multiLanguage = attribute.isMultilingual();
            if ((listType instanceof ListAttribute && simple && !multiLanguage) || (listType instanceof MonoListAttribute && !(attribute instanceof AbstractListAttribute))) {
                attributes.add(attribute);
            }
        }
        Collections.sort(attributes, new BeanComparator("type"));
    } catch (Throwable t) {
        _logger.error("Error while extracting Allowed Nested Types", t);
        // ApsSystemUtils.logThrowable(t, this, "getAllowedNestedTypes");
        throw new RuntimeException("Error while extracting Allowed Nested Types", t);
    }
    return attributes;
}
Also used : ArrayList(java.util.ArrayList) BeanComparator(org.apache.commons.beanutils.BeanComparator) AbstractListAttribute(com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute) MonoListAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute) IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) AbstractListAttribute(com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute) ListAttribute(com.agiletec.aps.system.common.entity.model.attribute.ListAttribute) MonoListAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)

Example 4 with AbstractListAttribute

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

the class EntityAttributeConfigAction method editAttribute.

@Override
public String editAttribute() {
    this.setStrutsAction(ApsAdminSystemConstants.EDIT);
    this.getRequest().getSession().removeAttribute(ICompositeAttributeConfigAction.COMPOSITE_ATTRIBUTE_ON_EDIT_SESSION_PARAM);
    this.getRequest().getSession().removeAttribute(IListElementAttributeConfigAction.LIST_ATTRIBUTE_ON_EDIT_SESSION_PARAM);
    this.getRequest().getSession().removeAttribute(IListElementAttributeConfigAction.LIST_ELEMENT_ON_EDIT_SESSION_PARAM);
    try {
        AttributeInterface attribute = (AttributeInterface) this.getEntityType().getAttribute(this.getAttributeName());
        this.valueFormFields(attribute);
        if (attribute instanceof AbstractListAttribute) {
            AbstractListAttribute listAttribute = (AbstractListAttribute) attribute;
            this.setListNestedType(listAttribute.getNestedAttributeTypeCode());
        }
    } catch (Throwable t) {
        _logger.error("error in editAttribute", t);
        // ApsSystemUtils.logThrowable(t, this, "editAttribute");
        return FAILURE;
    }
    return SUCCESS;
}
Also used : AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) AbstractListAttribute(com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute)

Example 5 with AbstractListAttribute

use of com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute 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)

Aggregations

AbstractListAttribute (com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute)6 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)6 CompositeAttribute (com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute)3 EnumeratorAttribute (com.agiletec.aps.system.common.entity.model.attribute.EnumeratorAttribute)2 ListAttribute (com.agiletec.aps.system.common.entity.model.attribute.ListAttribute)2 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)2 ArrayList (java.util.ArrayList)2 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)1 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)1 AbstractComplexAttribute (com.agiletec.aps.system.common.entity.model.attribute.AbstractComplexAttribute)1 IAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.IAttributeValidationRules)1 IndexableAttributeInterface (com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface)1 Lang (com.agiletec.aps.system.services.lang.Lang)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 List (java.util.List)1 Map (java.util.Map)1 BeanComparator (org.apache.commons.beanutils.BeanComparator)1 AttributeRoleDto (org.entando.entando.aps.system.services.entity.model.AttributeRoleDto)1