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;
}
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;
}
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);
}
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;
}
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"));
}
Aggregations