use of com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute in project entando-core by entando.
the class TestValidateTextAttribute method testValidate_MonoListElement_2.
public void testValidate_MonoListElement_2() throws Throwable {
try {
String contentOnSessionMarker = this.executeCreateNewContent();
Content content = this.getContentOnEdit(contentOnSessionMarker);
AttributeTracer tracerIT = this.getTracer();
MonoListAttribute monolistAttribute = (MonoListAttribute) content.getAttribute("MonoLText");
AttributeInterface textAttribute = monolistAttribute.addAttribute();
String formFieldPrefix = "Monolist:" + textAttribute.getType() + ":";
tracerIT.setListIndex(monolistAttribute.getAttributes().size() - 1);
tracerIT.setListLang(this.getLangManager().getDefaultLang());
tracerIT.setMonoListElement(true);
tracerIT.setParentAttribute(monolistAttribute);
AttributeTracer tracerEN = tracerIT.clone();
tracerEN.setLang(this.getLangManager().getLang("en"));
String monolistElementName = tracerIT.getMonolistElementFieldName(textAttribute);
assertEquals(formFieldPrefix + "MonoLText_0", monolistElementName);
String formITFieldName = tracerIT.getFormFieldName(textAttribute);
assertEquals(formFieldPrefix + "it_MonoLText_0", formITFieldName);
String formENFieldName = tracerEN.getFormFieldName(textAttribute);
assertEquals(formFieldPrefix + "en_MonoLText_0", formENFieldName);
this.initSaveContentAction(contentOnSessionMarker);
this.executeAction(Action.INPUT);
this.checkFieldErrors(1, monolistElementName);
this.initSaveContentAction(contentOnSessionMarker);
this.addParameter(formENFieldName, "MonoLMonotElement0ValueEN");
this.executeAction(Action.INPUT);
this.checkFieldErrors(1, monolistElementName);
this.initSaveContentAction(contentOnSessionMarker);
this.addParameter(formENFieldName, "MonoLMonotElement0ValueEN");
this.addParameter(formITFieldName, "MonoLMonotElement0ValueIT");
this.executeAction(Action.INPUT);
this.checkFieldErrors(0, monolistElementName);
AttributeInterface attribute2 = monolistAttribute.addAttribute();
tracerIT.setListIndex(monolistAttribute.getAttributes().size() - 1);
tracerEN.setListIndex(monolistAttribute.getAttributes().size() - 1);
String formITFieldName2 = tracerIT.getFormFieldName(attribute2);
assertEquals(formFieldPrefix + "it_MonoLText_1", formITFieldName2);
String formENFieldName2 = tracerEN.getFormFieldName(attribute2);
assertEquals(formFieldPrefix + "en_MonoLText_1", formENFieldName2);
String monolistElementName2 = tracerIT.getMonolistElementFieldName(attribute2);
assertEquals(formFieldPrefix + "MonoLText_1", monolistElementName2);
this.initSaveContentAction(contentOnSessionMarker);
this.addParameter(formENFieldName2, "MonoLMonotElement1ValueEN");
this.executeAction(Action.INPUT);
this.checkFieldErrors(1, monolistElementName2);
this.initSaveContentAction(contentOnSessionMarker);
this.addParameter(formENFieldName2, "MonoLMonotElement1ValueEN");
this.addParameter(formITFieldName2, "MonoLMonotElement1ValueIT");
this.executeAction(Action.INPUT);
this.checkFieldErrors(0, monolistElementName2);
} catch (Throwable t) {
this.deleteTestContent();
throw t;
}
}
use of com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute 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);
}
}
use of com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute in project entando-core by entando.
the class LinkAttributeActionHelper method joinLink.
protected void joinLink(AttributeInterface attribute, String[] destinations, int destType, 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);
updateLink(includedAttribute, destinations, destType);
} else if (attribute instanceof MonoListAttribute) {
Integer elementIndex = (Integer) session.getAttribute(LIST_ELEMENT_INDEX_SESSION_PARAM);
AttributeInterface attributeElement = ((MonoListAttribute) attribute).getAttribute(elementIndex.intValue());
joinLink(attributeElement, destinations, destType, request);
} else if (attribute instanceof LinkAttribute) {
updateLink(attribute, destinations, destType);
}
}
use of com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute in project entando-core by entando.
the class ResourceAttributeActionHelper method removeResource.
private static void removeResource(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);
removeResource(includedAttribute, request);
} else if (attribute instanceof AbstractResourceAttribute) {
ILangManager langManager = (ILangManager) ApsWebApplicationUtils.getBean(SystemConstants.LANGUAGE_MANAGER, request);
String langCode = (String) session.getAttribute(RESOURCE_LANG_CODE_SESSION_PARAM);
AbstractResourceAttribute resourceAttribute = (AbstractResourceAttribute) attribute;
if (langCode == null || langCode.length() == 0 || langManager.getDefaultLang().getCode().equals(langCode)) {
resourceAttribute.getResources().clear();
resourceAttribute.getTextMap().clear();
} else {
resourceAttribute.setResource(null, langCode);
resourceAttribute.setText(null, langCode);
}
} else if (attribute instanceof MonoListAttribute) {
int elementIndex = ((Integer) session.getAttribute(LIST_ELEMENT_INDEX_SESSION_PARAM)).intValue();
AttributeInterface attributeElement = ((MonoListAttribute) attribute).getAttribute(elementIndex);
removeResource(attributeElement, request);
}
}
use of com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute in project entando-core by entando.
the class CompositeAttributeConfigAction method saveCompositeAttribute.
@Override
public String saveCompositeAttribute() {
try {
CompositeAttribute composite = this.getCompositeAttributeOnEdit();
IApsEntity entityType = this.getEntityType();
AttributeInterface attribute = (AttributeInterface) entityType.getAttribute(composite.getName());
if (attribute instanceof MonoListAttribute) {
((MonoListAttribute) attribute).setNestedAttributeType(composite);
} else if (!attribute.getName().equals(composite.getName())) {
throw new ApsSystemException("Attribute Name '" + attribute.getName() + "' incompatible with composite Attribute name '" + composite.getName() + "'");
} else if (!attribute.getType().equals(composite.getType())) {
throw new ApsSystemException("Attribute Type '" + attribute.getType() + "' incompatible with composite Attribute type '" + composite.getType() + "'");
}
this.getRequest().getSession().removeAttribute(COMPOSITE_ATTRIBUTE_ON_EDIT_SESSION_PARAM);
} catch (Throwable t) {
_logger.error("error in saveAttribute", t);
// ApsSystemUtils.logThrowable(t, this, "saveAttribute");
return FAILURE;
}
return SUCCESS;
}
Aggregations