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