Search in sources :

Example 11 with AttributeInterface

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

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

the class AbstractEntityService method createEntityType.

protected I createEntityType(IEntityManager entityManager, EntityTypeDtoRequest dto, BindingResult bindingResult) throws Throwable {
    Class entityClass = entityManager.getEntityClass();
    ApsEntity entityType = (ApsEntity) entityClass.newInstance();
    if (StringUtils.isEmpty(dto.getCode()) || dto.getCode().length() != 3) {
        this.addError(EntityTypeValidator.ERRCODE_INVALID_TYPE_CODE, bindingResult, new String[] { dto.getCode() }, "entityType.typeCode.invalid");
    }
    entityType.setTypeCode(dto.getCode());
    if (StringUtils.isEmpty(dto.getName())) {
        this.addError(EntityTypeValidator.ERRCODE_INVALID_TYPE_DESCR, bindingResult, new String[] {}, "entityType.typeDescription.invalid");
    }
    entityType.setTypeDescription(dto.getName());
    if (bindingResult.hasErrors()) {
        return (I) entityType;
    }
    Map<String, AttributeInterface> attributeMap = entityManager.getEntityAttributePrototypes();
    List<EntityAttributeFullDto> attributeDtos = dto.getAttributes();
    if (null != attributeDtos) {
        for (EntityAttributeFullDto attributeDto : attributeDtos) {
            AttributeInterface attribute = this.buildAttribute(dto.getCode(), attributeDto, attributeMap, bindingResult);
            if (null != attribute) {
                entityType.addAttribute(attribute);
            } else {
                logger.warn("Create Entity Type - Attribute type {} undefined in manager {}", attributeDto.getType(), entityManager.getName());
            }
        }
    }
    return (I) entityType;
}
Also used : IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsEntity(com.agiletec.aps.system.common.entity.model.ApsEntity) EntityAttributeFullDto(org.entando.entando.aps.system.services.entity.model.EntityAttributeFullDto) IndexableAttributeInterface(com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 13 with AttributeInterface

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

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

the class TestDataObjectDAO method getMockDataObject.

private DataObject getMockDataObject() {
    DataObject dataObject = this._dataObjectManager.createDataObject("ART");
    dataObject.setId("temp");
    dataObject.setMainGroup(Group.FREE_GROUP_NAME);
    dataObject.addGroup("firstGroup");
    dataObject.addGroup("secondGroup");
    dataObject.addGroup("thirdGroup");
    AttributeInterface attribute = new MonoTextAttribute();
    attribute.setName("temp");
    attribute.setDefaultLangCode("it");
    attribute.setRenderingLang("it");
    attribute.setSearchable(true);
    attribute.setType("Monotext");
    dataObject.addAttribute(attribute);
    dataObject.setDefaultLang("it");
    dataObject.setDefaultModel("dataObject_viewer");
    dataObject.setDescription("temp");
    dataObject.setListModel("Monolist");
    dataObject.setRenderingLang("it");
    dataObject.setStatus("Bozza");
    dataObject.setTypeCode("ART");
    dataObject.setTypeDescription("Articolo rassegna stampa");
    return dataObject;
}
Also used : DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) MonoTextAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute)

Example 15 with AttributeInterface

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

the class TestDataObjectManager method testLoadDataObject.

public void testLoadDataObject() throws Throwable {
    DataObject dataObject = this._dataObjectManager.loadDataObject("ART111", false);
    assertEquals(DataObject.STATUS_PUBLIC, dataObject.getStatus());
    assertEquals("coach", dataObject.getMainGroup());
    assertEquals(2, dataObject.getGroups().size());
    assertTrue(dataObject.getGroups().contains("customers"));
    assertTrue(dataObject.getGroups().contains("helpdesk"));
    Map<String, AttributeInterface> attributes = dataObject.getAttributeMap();
    assertEquals(5, attributes.size());
    TextAttribute title = (TextAttribute) attributes.get("Titolo");
    assertEquals("Titolo Contenuto 3 Coach", title.getTextForLang("it"));
    assertNull(title.getTextForLang("en"));
    MonoListAttribute authors = (MonoListAttribute) attributes.get("Autori");
    assertEquals(4, authors.getAttributes().size());
    HypertextAttribute hypertext = (HypertextAttribute) attributes.get("CorpoTesto");
    assertEquals("<p>Corpo Testo Contenuto 3 Coach</p>", hypertext.getTextForLang("it").trim());
    assertNull(hypertext.getTextForLang("en"));
    DateAttribute date = (DateAttribute) attributes.get("Data");
    assertEquals("13/12/2006", DateConverter.getFormattedDate(date.getDate(), "dd/MM/yyyy"));
}
Also used : MonoListAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute) HypertextAttribute(com.agiletec.aps.system.common.entity.model.attribute.HypertextAttribute) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) TextAttribute(com.agiletec.aps.system.common.entity.model.attribute.TextAttribute) MonoTextAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

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