Search in sources :

Example 1 with CompositeAttribute

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

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

the class TestValidateNumberAttribute method testValidate_CompositeElement.

public void testValidate_CompositeElement() throws Throwable {
    try {
        String contentOnSessionMarker = this.executeCreateNewContent();
        Content content = this.getContentOnEdit(contentOnSessionMarker);
        AttributeTracer tracer = this.getTracer();
        CompositeAttribute compositeAttribute = (CompositeAttribute) content.getAttribute("Composite");
        AttributeInterface attribute = compositeAttribute.getAttribute("Number");
        tracer.setCompositeElement(true);
        tracer.setParentAttribute(compositeAttribute);
        String formFieldName = tracer.getFormFieldName(attribute);
        String formFieldPrefix = "Composite:" + attribute.getType() + ":";
        assertEquals(formFieldPrefix + "Composite_Number", formFieldName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, formFieldName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.addParameter(formFieldName, "wrongNumberValue");
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(1, formFieldName);
        // OGNL VALIDATION - evalOnValuedAttribute="true"
        // #entity.getAttribute(''Number'').value == null || (#entity.getAttribute(''Number'').value != null && value > #entity.getAttribute(''Number'').value)
        this.initSaveContentAction(contentOnSessionMarker);
        this.addParameter(formFieldName, "58");
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, formFieldName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.addParameter("Number:Number", "100");
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(1, formFieldName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.addParameter(formFieldName, "101");
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, formFieldName);
    } catch (Throwable t) {
        this.deleteTestContent();
        throw t;
    }
}
Also used : AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) CompositeAttribute(com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 3 with CompositeAttribute

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

the class TestValidateResourceAttribute method testValidate_MonolistCompositeElement.

protected void testValidate_MonolistCompositeElement(String elementName, String testResourceId) throws Throwable {
    try {
        String contentOnSessionMarker = this.executeCreateNewContent();
        Content content = this.getContentOnEdit(contentOnSessionMarker);
        AttributeTracer tracerIT = this.getTracer();
        MonoListAttribute monolistAttribute = (MonoListAttribute) content.getAttribute("MonoLCom");
        CompositeAttribute compositeElement = (CompositeAttribute) monolistAttribute.addAttribute();
        AttributeInterface attribute = compositeElement.getAttribute(elementName);
        String monolistElementFieldPrefix = "Monolist:Composite:";
        String formFieldPrefix = monolistElementFieldPrefix + attribute.getType() + ":";
        tracerIT.setListIndex(monolistAttribute.getAttributes().size() - 1);
        tracerIT.setListLang(this.getLangManager().getDefaultLang());
        tracerIT.setMonoListElement(true);
        tracerIT.setCompositeElement(true);
        tracerIT.setParentAttribute(compositeElement);
        String formITFieldName = tracerIT.getFormFieldName(attribute);
        assertEquals(formFieldPrefix + "it_MonoLCom_" + elementName + "_0", formITFieldName);
        String monolistElementName = tracerIT.getMonolistElementFieldName(compositeElement);
        assertEquals(monolistElementFieldPrefix + "MonoLCom_0", monolistElementName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(1, monolistElementName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.addParameter(formITFieldName, "itValue");
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(1, formFieldPrefix + "MonoLCom_" + elementName + "_0");
        content = this.getContentOnEdit(contentOnSessionMarker);
        monolistAttribute = (MonoListAttribute) content.getAttribute("MonoLCom");
        compositeElement = (CompositeAttribute) monolistAttribute.getAttribute(0);
        AbstractResourceAttribute resourceAttribute = (AbstractResourceAttribute) compositeElement.getAttribute(elementName);
        ResourceInterface resource = this._resourceManager.loadResource(testResourceId);
        resourceAttribute.setResource(resource, this.getLangManager().getDefaultLang().getCode());
        this.initSaveContentAction(contentOnSessionMarker);
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, "MonoLCom_" + elementName + "_0");
    } catch (Throwable t) {
        this.deleteTestContent();
        throw t;
    }
}
Also used : AbstractResourceAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute) MonoListAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute) AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) CompositeAttribute(com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 4 with CompositeAttribute

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

the class TestValidateResourceAttribute method testValidate_CompositeElement.

protected void testValidate_CompositeElement(String elementName, String testResourceId) throws Throwable {
    try {
        String contentOnSessionMarker = this.executeCreateNewContent();
        Content content = this.getContentOnEdit(contentOnSessionMarker);
        AttributeTracer tracerIT = this.getTracer();
        CompositeAttribute compositeAttribute = (CompositeAttribute) content.getAttribute("Composite");
        AttributeInterface attribute = compositeAttribute.getAttribute(elementName);
        String formFieldPrefix = "Composite:" + attribute.getType() + ":";
        tracerIT.setCompositeElement(true);
        tracerIT.setParentAttribute(compositeAttribute);
        String formITFieldName = tracerIT.getFormFieldName(attribute);
        assertEquals(formFieldPrefix + "it_Composite_" + elementName, formITFieldName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, formITFieldName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.addParameter(formITFieldName, "itValue");
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(1, formFieldPrefix + "Composite_" + elementName);
        content = this.getContentOnEdit(contentOnSessionMarker);
        compositeAttribute = (CompositeAttribute) content.getAttribute("Composite");
        AbstractResourceAttribute resourceAttribute = (AbstractResourceAttribute) compositeAttribute.getAttribute(elementName);
        ResourceInterface resource = this._resourceManager.loadResource(testResourceId);
        resourceAttribute.setResource(resource, this.getLangManager().getDefaultLang().getCode());
        this.initSaveContentAction(contentOnSessionMarker);
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, formFieldPrefix + "Composite_" + elementName);
    } catch (Throwable t) {
        this.deleteTestContent();
        throw t;
    }
}
Also used : AbstractResourceAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute) AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) CompositeAttribute(com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 5 with CompositeAttribute

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

the class LinkAttributeActionHelper method removeLink.

protected void removeLink(AttributeInterface attribute, HttpServletRequest request) {
    HttpSession session = request.getSession();
    if (attribute instanceof CompositeAttribute) {
        String includedAttributeName = (String) session.getAttribute(INCLUDED_ELEMENT_NAME_SESSION_PARAM);
        AttributeInterface includedAttribute = ((CompositeAttribute) attribute).getAttribute(includedAttributeName);
        removeLink(includedAttribute, request);
    } else if (attribute instanceof LinkAttribute) {
        ((LinkAttribute) attribute).setSymbolicLink(null);
        ((LinkAttribute) attribute).getTextMap().clear();
    } else if (attribute instanceof MonoListAttribute) {
        Integer elementIndex = (Integer) session.getAttribute(LIST_ELEMENT_INDEX_SESSION_PARAM);
        AttributeInterface attributeElement = ((MonoListAttribute) attribute).getAttribute(elementIndex.intValue());
        removeLink(attributeElement, request);
    }
}
Also used : LinkAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.LinkAttribute) MonoListAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute) CompositeAttribute(com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute) HttpSession(javax.servlet.http.HttpSession) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Aggregations

CompositeAttribute (com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute)28 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)27 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)15 AttributeTracer (com.agiletec.aps.system.common.entity.model.AttributeTracer)13 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)13 AbstractResourceAttribute (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute)4 LinkAttribute (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.LinkAttribute)4 HttpSession (javax.servlet.http.HttpSession)4 AbstractListAttribute (com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute)3 EnumeratorAttribute (com.agiletec.aps.system.common.entity.model.attribute.EnumeratorAttribute)3 ListAttribute (com.agiletec.aps.system.common.entity.model.attribute.ListAttribute)3 ResourceAttributeInterface (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.ResourceAttributeInterface)3 CheckBoxAttribute (com.agiletec.aps.system.common.entity.model.attribute.CheckBoxAttribute)2 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)2 HypertextAttribute (com.agiletec.aps.system.common.entity.model.attribute.HypertextAttribute)2 MonoTextAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute)2 NumberAttribute (com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute)2 TextAttribute (com.agiletec.aps.system.common.entity.model.attribute.TextAttribute)2 ThreeStateAttribute (com.agiletec.aps.system.common.entity.model.attribute.ThreeStateAttribute)2 ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)2