Search in sources :

Example 16 with AttributeTracer

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;
    }
}
Also used : MonoListAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute) AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 17 with AttributeTracer

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;
}
Also used : AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) ArrayList(java.util.ArrayList) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError)

Example 18 with AttributeTracer

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;
}
Also used : AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) Lang(com.agiletec.aps.system.services.lang.Lang)

Example 19 with AttributeTracer

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());
}
Also used : AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer)

Example 20 with AttributeTracer

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);
        }
    }
}
Also used : CompositeAttribute(com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute) AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Aggregations

AttributeTracer (com.agiletec.aps.system.common.entity.model.AttributeTracer)51 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)39 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)35 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)18 CompositeAttribute (com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute)13 AttributeFieldError (com.agiletec.aps.system.common.entity.model.AttributeFieldError)9 Lang (com.agiletec.aps.system.services.lang.Lang)7 ListAttribute (com.agiletec.aps.system.common.entity.model.attribute.ListAttribute)5 ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)5 AbstractResourceAttribute (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute)4 IndexableAttributeInterface (com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface)3 ArrayList (java.util.ArrayList)3 AttributeSearchInfo (com.agiletec.aps.system.common.entity.model.AttributeSearchInfo)2 AttributeManagerInterface (com.agiletec.apsadmin.system.entity.attribute.manager.AttributeManagerInterface)1 SymbolicLink (com.agiletec.plugins.jacms.aps.system.services.content.model.SymbolicLink)1 ResourceAttributeInterface (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.ResourceAttributeInterface)1 SymbolicLinkValidator (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.util.SymbolicLinkValidator)1 Field (org.apache.lucene.document.Field)1 IntField (org.apache.lucene.document.IntField)1 StringField (org.apache.lucene.document.StringField)1