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