Search in sources :

Example 1 with AbstractResourceAttribute

use of com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute in project entando-core by entando.

the class TestValidateResourceAttribute method testValidate_MonolistCompositeElement.

protected void testValidate_MonolistCompositeElement(String elementName, String testResourceId) throws Throwable {
    try {
        String contentOnSessionMarker = this.executeCreateNewContent();
        Content content = this.getContentOnEdit(contentOnSessionMarker);
        AttributeTracer tracerIT = this.getTracer();
        MonoListAttribute monolistAttribute = (MonoListAttribute) content.getAttribute("MonoLCom");
        CompositeAttribute compositeElement = (CompositeAttribute) monolistAttribute.addAttribute();
        AttributeInterface attribute = compositeElement.getAttribute(elementName);
        String monolistElementFieldPrefix = "Monolist:Composite:";
        String formFieldPrefix = monolistElementFieldPrefix + attribute.getType() + ":";
        tracerIT.setListIndex(monolistAttribute.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_" + elementName + "_0", formITFieldName);
        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(1, formFieldPrefix + "MonoLCom_" + elementName + "_0");
        content = this.getContentOnEdit(contentOnSessionMarker);
        monolistAttribute = (MonoListAttribute) content.getAttribute("MonoLCom");
        compositeElement = (CompositeAttribute) monolistAttribute.getAttribute(0);
        AbstractResourceAttribute resourceAttribute = (AbstractResourceAttribute) compositeElement.getAttribute(elementName);
        ResourceInterface resource = this._resourceManager.loadResource(testResourceId);
        resourceAttribute.setResource(resource, this.getLangManager().getDefaultLang().getCode());
        this.initSaveContentAction(contentOnSessionMarker);
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, "MonoLCom_" + elementName + "_0");
    } catch (Throwable t) {
        this.deleteTestContent();
        throw t;
    }
}
Also used : AbstractResourceAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute) MonoListAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute) AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) CompositeAttribute(com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 2 with AbstractResourceAttribute

use of com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute in project entando-core by entando.

the class TestValidateResourceAttribute method testValidate_CompositeElement.

protected void testValidate_CompositeElement(String elementName, String testResourceId) 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(elementName);
        String formFieldPrefix = "Composite:" + attribute.getType() + ":";
        tracerIT.setCompositeElement(true);
        tracerIT.setParentAttribute(compositeAttribute);
        String formITFieldName = tracerIT.getFormFieldName(attribute);
        assertEquals(formFieldPrefix + "it_Composite_" + elementName, formITFieldName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, formITFieldName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.addParameter(formITFieldName, "itValue");
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(1, formFieldPrefix + "Composite_" + elementName);
        content = this.getContentOnEdit(contentOnSessionMarker);
        compositeAttribute = (CompositeAttribute) content.getAttribute("Composite");
        AbstractResourceAttribute resourceAttribute = (AbstractResourceAttribute) compositeAttribute.getAttribute(elementName);
        ResourceInterface resource = this._resourceManager.loadResource(testResourceId);
        resourceAttribute.setResource(resource, this.getLangManager().getDefaultLang().getCode());
        this.initSaveContentAction(contentOnSessionMarker);
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, formFieldPrefix + "Composite_" + elementName);
    } catch (Throwable t) {
        this.deleteTestContent();
        throw t;
    }
}
Also used : AbstractResourceAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute) AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) CompositeAttribute(com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 3 with AbstractResourceAttribute

use of com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute in project entando-core by entando.

the class TestValidateResourceAttribute method testValidate_MonoListElement.

protected void testValidate_MonoListElement(String mlAttributeName) throws Throwable {
    try {
        String contentOnSessionMarker = this.executeCreateNewContent();
        Content content = this.getContentOnEdit(contentOnSessionMarker);
        AttributeTracer tracer = this.getTracer();
        MonoListAttribute monolistAttribute = (MonoListAttribute) content.getAttribute(mlAttributeName);
        AttributeInterface newResourceAttribute = monolistAttribute.addAttribute();
        String monolistElementFieldPrefix = "Monolist:" + newResourceAttribute.getType() + ":";
        tracer.setListIndex(monolistAttribute.getAttributes().size() - 1);
        tracer.setListLang(this.getLangManager().getDefaultLang());
        tracer.setMonoListElement(true);
        tracer.setParentAttribute(monolistAttribute);
        String monolistElementName = tracer.getMonolistElementFieldName(newResourceAttribute);
        assertEquals(monolistElementFieldPrefix + mlAttributeName + "_0", monolistElementName);
        String formFieldName = tracer.getFormFieldName(newResourceAttribute);
        assertEquals(monolistElementFieldPrefix + "it_" + mlAttributeName + "_0", formFieldName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(1, monolistElementName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.addParameter(formFieldName, "resourceDescrMonolElement0Value");
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(1, monolistElementName);
        content = this.getContentOnEdit(contentOnSessionMarker);
        monolistAttribute = (MonoListAttribute) content.getAttribute(mlAttributeName);
        AbstractResourceAttribute resourceAttribute = (AbstractResourceAttribute) monolistAttribute.getAttribute(0);
        ResourceInterface resource = this._resourceManager.loadResource("7");
        resourceAttribute.setResource(resource, this.getLangManager().getDefaultLang().getCode());
        this.initSaveContentAction(contentOnSessionMarker);
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, monolistElementName);
        AttributeInterface attribute2 = monolistAttribute.addAttribute();
        tracer.setListIndex(monolistAttribute.getAttributes().size() - 1);
        String formFieldName2 = tracer.getFormFieldName(attribute2);
        assertEquals(monolistElementFieldPrefix + "it_" + mlAttributeName + "_1", formFieldName2);
        String monolistElementName2 = tracer.getMonolistElementFieldName(attribute2);
        assertEquals(monolistElementFieldPrefix + mlAttributeName + "_1", monolistElementName2);
        this.initSaveContentAction(contentOnSessionMarker);
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(1, monolistElementName2);
    } catch (Throwable t) {
        this.deleteTestContent();
        throw t;
    }
}
Also used : AbstractResourceAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute) 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) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 4 with AbstractResourceAttribute

use of com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute 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);
    }
}
Also used : AbstractResourceAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute) MonoListAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute) CompositeAttribute(com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute) ILangManager(com.agiletec.aps.system.services.lang.ILangManager) HttpSession(javax.servlet.http.HttpSession) ResourceAttributeInterface(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.ResourceAttributeInterface) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 5 with AbstractResourceAttribute

use of com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute in project entando-core by entando.

the class TestApiContentInterface method checkAttributes.

private void checkAttributes(AttributeInterface oldAttribute, AttributeInterface newAttribute) {
    if (null == newAttribute) {
        fail();
    }
    assertEquals(oldAttribute.getName(), newAttribute.getName());
    assertEquals(oldAttribute.getType(), newAttribute.getType());
    if (!oldAttribute.isSimple()) {
        if (oldAttribute instanceof AbstractListAttribute) {
            List<AttributeInterface> oldListAttributes = ((AbstractComplexAttribute) oldAttribute).getAttributes();
            List<AttributeInterface> newListAttributes = ((AbstractComplexAttribute) newAttribute).getAttributes();
            assertEquals(oldListAttributes.size(), newListAttributes.size());
            for (int i = 0; i < oldListAttributes.size(); i++) {
                AttributeInterface oldElement = oldListAttributes.get(i);
                AttributeInterface newElement = newListAttributes.get(i);
                this.checkAttributes(oldElement, newElement);
            }
        } else if (oldAttribute instanceof CompositeAttribute) {
            Map<String, AttributeInterface> oldAttributeMap = ((CompositeAttribute) oldAttribute).getAttributeMap();
            Map<String, AttributeInterface> newAttributeMap = ((CompositeAttribute) newAttribute).getAttributeMap();
            assertEquals(oldAttributeMap.size(), newAttributeMap.size());
            Iterator<String> iterator = oldAttributeMap.keySet().iterator();
            while (iterator.hasNext()) {
                String key = iterator.next();
                AttributeInterface oldElement = oldAttributeMap.get(key);
                AttributeInterface newElement = newAttributeMap.get(key);
                this.checkAttributes(oldElement, newElement);
            }
        }
    } else {
        if (oldAttribute instanceof AbstractResourceAttribute || oldAttribute instanceof LinkAttribute) {
            return;
        }
        assertEquals(oldAttribute.getValue(), newAttribute.getValue());
    }
}
Also used : AbstractResourceAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute) LinkAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.LinkAttribute) AbstractComplexAttribute(com.agiletec.aps.system.common.entity.model.attribute.AbstractComplexAttribute) CompositeAttribute(com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute) Iterator(java.util.Iterator) Map(java.util.Map) AbstractListAttribute(com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Aggregations

AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)6 AbstractResourceAttribute (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute)6 AttributeTracer (com.agiletec.aps.system.common.entity.model.AttributeTracer)4 CompositeAttribute (com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute)4 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)4 ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)4 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)3 AbstractComplexAttribute (com.agiletec.aps.system.common.entity.model.attribute.AbstractComplexAttribute)1 AbstractListAttribute (com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute)1 ILangManager (com.agiletec.aps.system.services.lang.ILangManager)1 LinkAttribute (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.LinkAttribute)1 ResourceAttributeInterface (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.ResourceAttributeInterface)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 HttpSession (javax.servlet.http.HttpSession)1