Search in sources :

Example 1 with AttributeTracer

use of com.agiletec.aps.system.common.entity.model.AttributeTracer in project entando-core by entando.

the class AbstractResourceAttribute method validate.

@Override
public List<AttributeFieldError> validate(AttributeTracer tracer) {
    List<AttributeFieldError> errors = super.validate(tracer);
    try {
        if (null == this.getResources()) {
            return errors;
        }
        List<Lang> langs = super.getLangManager().getLangs();
        for (int i = 0; i < langs.size(); i++) {
            Lang lang = langs.get(i);
            ResourceInterface resource = this.getResource(lang.getCode());
            if (null == resource) {
                continue;
            }
            AttributeTracer resourceTracer = (AttributeTracer) tracer.clone();
            resourceTracer.setLang(lang);
            String resourceMainGroup = resource.getMainGroup();
            Content parentContent = (Content) this.getParentEntity();
            if (!resourceMainGroup.equals(Group.FREE_GROUP_NAME) && !resourceMainGroup.equals(parentContent.getMainGroup()) && !parentContent.getGroups().contains(resourceMainGroup)) {
                AttributeFieldError fieldError = new AttributeFieldError(this, ICmsAttributeErrorCodes.INVALID_RESOURCE_GROUPS, resourceTracer);
                fieldError.setMessage("Invalid resource group - " + resourceMainGroup);
                errors.add(fieldError);
            }
        }
    } catch (Throwable t) {
        logger.error("Error validating text attribute", t);
        throw new RuntimeException("Error validating text attribute", t);
    }
    return errors;
}
Also used : AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) Lang(com.agiletec.aps.system.services.lang.Lang) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 2 with AttributeTracer

use of com.agiletec.aps.system.common.entity.model.AttributeTracer in project entando-core by entando.

the class CmsHypertextAttribute method validate.

@Override
public List<AttributeFieldError> validate(AttributeTracer tracer) {
    List<AttributeFieldError> errors = super.validate(tracer);
    try {
        List<Lang> langs = this.getLangManager().getLangs();
        for (Lang lang : langs) {
            AttributeTracer textTracer = (AttributeTracer) tracer.clone();
            textTracer.setLang(lang);
            String text = this.getTextMap().get(lang.getCode());
            if (null == text) {
                continue;
            }
            List<SymbolicLink> links = HypertextAttributeUtil.getSymbolicLinksOnText(text);
            if (null != links && !links.isEmpty()) {
                SymbolicLinkValidator sler = new SymbolicLinkValidator(this.getContentManager(), this.getPageManager());
                for (SymbolicLink symbLink : links) {
                    String linkErrorCode = sler.scan(symbLink, (Content) this.getParentEntity());
                    if (null != linkErrorCode) {
                        AttributeFieldError error = new AttributeFieldError(this, linkErrorCode, textTracer);
                        error.setMessage("Invalid link - page " + symbLink.getPageDest() + " - content " + symbLink.getContentDest() + " - Error code " + linkErrorCode);
                        errors.add(error);
                    }
                }
            }
        }
    } catch (Throwable t) {
        logger.error("Error validating Attribute '{}'", this.getName(), t);
        throw new RuntimeException("Error validating Attribute '" + this.getName() + "'", t);
    }
    return errors;
}
Also used : SymbolicLinkValidator(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.util.SymbolicLinkValidator) 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) SymbolicLink(com.agiletec.plugins.jacms.aps.system.services.content.model.SymbolicLink)

Example 3 with AttributeTracer

use of com.agiletec.aps.system.common.entity.model.AttributeTracer in project entando-core by entando.

the class AbstractTestContentAttribute method getTracer.

protected AttributeTracer getTracer() {
    AttributeTracer tracer = new AttributeTracer();
    tracer.setLang(this.getLangManager().getDefaultLang());
    return tracer;
}
Also used : AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer)

Example 4 with AttributeTracer

use of com.agiletec.aps.system.common.entity.model.AttributeTracer in project entando-core by entando.

the class TestValidateBooleanAttributes method validateMonolistElement.

protected void validateMonolistElement(String monolistAttributeName) throws Throwable {
    try {
        String contentOnSessionMarker = this.executeCreateNewContent();
        Content content = this.getContentOnEdit(contentOnSessionMarker);
        AttributeTracer tracer = this.getTracer();
        MonoListAttribute monolist = (MonoListAttribute) content.getAttribute(monolistAttributeName);
        AttributeInterface attribute = monolist.addAttribute();
        String formFieldPrefix = "Monolist:" + attribute.getType() + ":";
        tracer.setListIndex(monolist.getAttributes().size() - 1);
        tracer.setListLang(this.getLangManager().getDefaultLang());
        tracer.setMonoListElement(true);
        String formFieldName = tracer.getFormFieldName(attribute);
        assertEquals(formFieldPrefix + monolistAttributeName + "_0", formFieldName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, formFieldName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.addParameter(formFieldName, "true");
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, formFieldName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.addParameter(formFieldName, "false");
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, formFieldName);
        AttributeInterface attribute2 = monolist.addAttribute();
        tracer.setListIndex(monolist.getAttributes().size() - 1);
        String formFieldName2 = tracer.getFormFieldName(attribute2);
        assertEquals(formFieldPrefix + monolistAttributeName + "_1", formFieldName2);
        this.initSaveContentAction(contentOnSessionMarker);
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, formFieldName2);
    } 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 5 with AttributeTracer

use of com.agiletec.aps.system.common.entity.model.AttributeTracer in project entando-core by entando.

the class TestValidateDateAttribute method testValidate_ListElement.

public void testValidate_ListElement() throws Throwable {
    try {
        String contentOnSessionMarker = this.executeCreateNewContent();
        Content content = this.getContentOnEdit(contentOnSessionMarker);
        AttributeTracer tracerIT = this.getTracer();
        ListAttribute list = (ListAttribute) content.getAttribute("ListDate");
        AttributeInterface attributeIT = list.addAttribute("it");
        assertEquals(0, list.getAttributeList("en").size());
        assertEquals(1, list.getAttributeList("it").size());
        tracerIT.setListIndex(list.getAttributeList("it").size() - 1);
        tracerIT.setListLang(this.getLangManager().getLang("it"));
        tracerIT.setListElement(true);
        String formFieldItName = tracerIT.getFormFieldName(attributeIT);
        String formFieldPrefix = "List:" + attributeIT.getType() + ":";
        assertEquals(formFieldPrefix + "it_ListDate_0", formFieldItName);
        AttributeTracer tracerEN = tracerIT.clone();
        tracerEN.setLang(this.getLangManager().getLang("en"));
        tracerEN.setListLang(this.getLangManager().getLang("en"));
        this.initSaveContentAction(contentOnSessionMarker);
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(1, formFieldItName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.addParameter(formFieldItName, "ListDateElement0Value");
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(1, formFieldItName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.addParameter(formFieldItName, "26/11/2007");
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, formFieldItName);
        AttributeInterface attribute2 = list.addAttribute("it");
        tracerIT.setListIndex(list.getAttributes().size() - 1);
        formFieldItName = tracerIT.getFormFieldName(attribute2);
        assertEquals(formFieldPrefix + "it_ListDate_1", formFieldItName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(1, formFieldItName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.addParameter(formFieldItName, "26/11/2007");
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, formFieldItName);
        AttributeInterface attributeEN = list.addAttribute("en");
        String formFieldEnName = tracerEN.getFormFieldName(attributeEN);
        assertEquals(formFieldPrefix + "en_ListDate_0", formFieldEnName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(1, formFieldEnName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.addParameter(formFieldEnName, "06/07/1987");
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, formFieldEnName);
    } catch (Throwable t) {
        this.deleteTestContent();
        throw t;
    }
}
Also used : AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) ListAttribute(com.agiletec.aps.system.common.entity.model.attribute.ListAttribute) MonoListAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute) 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