use of com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute in project entando-core by entando.
the class EntityAttributeConfigAction method fillAttributeFields.
/**
* Fill attribute fields.
*
* @param attribute The attribute to edit with the form values.
* @return A custom return code in the attribute neads a extra
* configuration, else null.
*/
@Override
protected String fillAttributeFields(AttributeInterface attribute) {
super.fillAttributeFields(attribute);
AttributeInterface nestedType = null;
if (attribute instanceof AbstractListAttribute) {
AbstractListAttribute listAttribute = (AbstractListAttribute) attribute;
if (this.getStrutsAction() == ApsAdminSystemConstants.EDIT && listAttribute.getNestedAttributeTypeCode().equals(this.getListNestedType())) {
if (listAttribute instanceof ListAttribute) {
Lang defaultLang = this.getLangManager().getDefaultLang();
// Composite Element
nestedType = ((ListAttribute) listAttribute).addAttribute(defaultLang.getCode());
((ListAttribute) listAttribute).getAttributeList(defaultLang.getCode()).clear();
} else {
// Composite Element
nestedType = ((MonoListAttribute) listAttribute).addAttribute();
((MonoListAttribute) listAttribute).getAttributes().clear();
}
} else {
nestedType = this.getAttributePrototype(this.getListNestedType());
if (nestedType != null) {
nestedType.setName(this.getAttributeName());
} else {
_logger.info("******** List Type NULL!!!!");
}
}
listAttribute.setNestedAttributeType(nestedType);
nestedType.setName(attribute.getName());
}
if ((attribute instanceof CompositeAttribute) || (nestedType != null && nestedType instanceof CompositeAttribute)) {
CompositeAttribute composite = ((attribute instanceof CompositeAttribute) ? (CompositeAttribute) attribute : (CompositeAttribute) nestedType);
if (null != nestedType) {
this.getRequest().getSession().setAttribute(IListElementAttributeConfigAction.LIST_ATTRIBUTE_ON_EDIT_SESSION_PARAM, (AbstractListAttribute) attribute);
}
this.getRequest().getSession().setAttribute(ICompositeAttributeConfigAction.COMPOSITE_ATTRIBUTE_ON_EDIT_SESSION_PARAM, composite);
return "configureCompositeAttribute";
}
if (nestedType != null) {
this.getRequest().getSession().setAttribute(IListElementAttributeConfigAction.LIST_ATTRIBUTE_ON_EDIT_SESSION_PARAM, (AbstractListAttribute) attribute);
this.getRequest().getSession().setAttribute(IListElementAttributeConfigAction.LIST_ELEMENT_ON_EDIT_SESSION_PARAM, nestedType);
return "configureListElementAttribute";
}
return null;
}
use of com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute in project entando-core by entando.
the class TestValidateTextAttribute method testValidate_CompositeElement.
public void testValidate_CompositeElement() 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("Text");
tracerIT.setCompositeElement(true);
tracerIT.setParentAttribute(compositeAttribute);
String formITFieldName = tracerIT.getFormFieldName(attribute);
String formFieldPrefix = "Composite:" + attribute.getType() + ":";
assertEquals(formFieldPrefix + "it_Composite_Text", formITFieldName);
AttributeTracer tracerEN = tracerIT.clone();
tracerEN.setLang(this.getLangManager().getLang("en"));
String formENFieldName = tracerEN.getFormFieldName(attribute);
assertEquals(formFieldPrefix + "en_Composite_Text", formENFieldName);
this.initSaveContentAction(contentOnSessionMarker);
this.executeAction(Action.INPUT);
this.checkFieldErrors(0, formITFieldName);
this.initSaveContentAction(contentOnSessionMarker);
this.addParameter(formITFieldName, "itValue");
this.executeAction(Action.INPUT);
this.checkFieldErrors(0, formITFieldName);
this.initSaveContentAction(contentOnSessionMarker);
this.addParameter(formITFieldName, "");
this.addParameter(formENFieldName, "enValue");
this.executeAction(Action.INPUT);
this.checkFieldErrors(0, formITFieldName);
} 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 TestValidateTextAttribute method testValidate_MonolistCompositeElement.
public void testValidate_MonolistCompositeElement() throws Throwable {
try {
String contentOnSessionMarker = this.executeCreateNewContent();
Content content = this.getContentOnEdit(contentOnSessionMarker);
AttributeTracer tracerIT = this.getTracer();
MonoListAttribute monolist = (MonoListAttribute) content.getAttribute("MonoLCom");
CompositeAttribute compositeElement = (CompositeAttribute) monolist.addAttribute();
AttributeInterface attribute = compositeElement.getAttribute("Text");
String monolistElementFieldPrefix = "Monolist:Composite:";
String formFieldPrefix = monolistElementFieldPrefix + attribute.getType() + ":";
tracerIT.setListIndex(monolist.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_Text_0", formITFieldName);
AttributeTracer tracerEN = tracerIT.clone();
tracerEN.setLang(this.getLangManager().getLang("en"));
String formENFieldName = tracerEN.getFormFieldName(attribute);
assertEquals(formFieldPrefix + "en_MonoLCom_Text_0", formENFieldName);
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(0, formITFieldName);
this.initSaveContentAction(contentOnSessionMarker);
this.addParameter(formITFieldName, "");
this.addParameter(formENFieldName, "enValue");
this.executeAction(Action.INPUT);
this.checkFieldErrors(1, monolistElementName);
this.initSaveContentAction(contentOnSessionMarker);
this.addParameter(formITFieldName, "itValue");
this.addParameter(formENFieldName, "enValue");
this.executeAction(Action.INPUT);
this.checkFieldErrors(0, monolistElementName);
} catch (Throwable t) {
this.deleteTestContent();
throw t;
}
}
Aggregations