use of com.agiletec.aps.system.common.entity.model.AttributeTracer 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.AttributeTracer in project entando-core by entando.
the class BaseAttributeValidationRules method validate.
@Override
public List<AttributeFieldError> validate(AttributeInterface attribute, AttributeTracer tracer, ILangManager langManager) {
List<AttributeFieldError> errors = new ArrayList<>();
if (this.isEmpty()) {
return errors;
}
try {
if (this.isRequired() && attribute.getStatus().equals(AttributeInterface.Status.EMPTY)) {
AttributeTracer tracerClone = tracer.clone();
tracerClone.setLang(langManager.getDefaultLang());
errors.add(new AttributeFieldError(attribute, FieldError.MANDATORY, tracerClone));
}
OgnlValidationRule ognlValidationRule = this.getOgnlValidationRule();
if (null != ognlValidationRule) {
AttributeFieldError error = ognlValidationRule.validate(attribute, tracer, langManager);
if (null != error) {
errors.add(error);
}
}
} catch (Throwable t) {
_logger.error("Error validating Attribute '{}'", attribute.getName(), t);
throw new RuntimeException("Error validating Attribute '" + attribute.getName() + "'", t);
}
return errors;
}
use of com.agiletec.aps.system.common.entity.model.AttributeTracer in project entando-core by entando.
the class ListAttribute method validate.
@Override
public List<AttributeFieldError> validate(AttributeTracer tracer) {
List<AttributeFieldError> errors = super.validate(tracer);
try {
List<Lang> langs = super.getLangManager().getLangs();
for (int i = 0; i < langs.size(); i++) {
Lang lang = langs.get(i);
List<AttributeInterface> attributeList = this.getAttributeList(lang.getCode());
for (int j = 0; j < attributeList.size(); j++) {
AttributeInterface attributeElement = attributeList.get(j);
AttributeTracer elementTracer = (AttributeTracer) tracer.clone();
elementTracer.setListElement(true);
elementTracer.setListLang(lang);
elementTracer.setListIndex(j);
Status elementStatus = attributeElement.getStatus();
if (elementStatus.equals(Status.EMPTY)) {
errors.add(new AttributeFieldError(attributeElement, FieldError.INVALID, elementTracer));
} else {
List<AttributeFieldError> elementErrors = attributeElement.validate(elementTracer);
if (null != elementErrors) {
errors.addAll(elementErrors);
}
}
}
}
} catch (Throwable t) {
// ApsSystemUtils.logThrowable(t, this, "validate");
_logger.error("Error validating list attribute", t);
throw new RuntimeException("Error validating list attribute", t);
}
return errors;
}
use of com.agiletec.aps.system.common.entity.model.AttributeTracer in project entando-core by entando.
the class UserFilterOptionBean method getIndexFieldName.
private String getIndexFieldName() {
AttributeTracer tracer = new AttributeTracer();
tracer.setLang(this.getCurrentLang());
return tracer.getFormFieldName(this.getAttribute());
}
use of com.agiletec.aps.system.common.entity.model.AttributeTracer in project entando-core by entando.
the class CompositeAttributeManager method updateAttribute.
@Override
protected void updateAttribute(AttributeInterface attribute, AttributeTracer tracer, HttpServletRequest request) {
List<AttributeInterface> attributes = ((CompositeAttribute) attribute).getAttributes();
for (int i = 0; i < attributes.size(); i++) {
AttributeInterface attributeElement = attributes.get(i);
AttributeTracer elementTracer = (AttributeTracer) tracer.clone();
elementTracer.setCompositeElement(true);
elementTracer.setParentAttribute(attribute);
AbstractAttributeManager elementManager = (AbstractAttributeManager) this.getManager(attributeElement);
if (elementManager != null) {
elementManager.updateAttribute(attributeElement, elementTracer, request);
}
}
}
Aggregations