Search in sources :

Example 11 with ListAttribute

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

the class ListAttributeAction method addListElement.

@Override
public String addListElement() {
    try {
        super.addListElement();
        Content content = this.getContent();
        int index = -1;
        ListAttributeInterface currentAttribute = (ListAttributeInterface) content.getAttribute(this.getAttributeName());
        String nestedType = currentAttribute.getNestedAttributeTypeCode();
        if (!nestedType.equals("Attach") && !nestedType.equals("Image") && !nestedType.equals("Link")) {
            return SUCCESS;
        }
        if (currentAttribute instanceof MonoListAttribute) {
            List<AttributeInterface> attributes = ((MonoListAttribute) currentAttribute).getAttributes();
            index = attributes.size() - 1;
        } else if (currentAttribute instanceof ListAttribute) {
            List<AttributeInterface> attributes = ((ListAttribute) currentAttribute).getAttributeList(this.getListLangCode());
            index = attributes.size() - 1;
        }
        this.setElementIndex(index);
        if (nestedType.equals("Attach") || nestedType.equals("Image")) {
            this.setResourceTypeCode(nestedType);
            return "chooseResource";
        } else {
            return "chooseLink";
        }
    } catch (Throwable t) {
        _logger.error("error in addListElement", t);
        // ApsSystemUtils.logThrowable(t, this, "addListElement");
        return FAILURE;
    }
}
Also used : ListAttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.ListAttributeInterface) MonoListAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) List(java.util.List) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) ListAttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.ListAttributeInterface) ListAttribute(com.agiletec.aps.system.common.entity.model.attribute.ListAttribute) MonoListAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)

Example 12 with ListAttribute

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

the class TestValidateBooleanAttributes method validateListElement.

protected void validateListElement(String listAttributeName) throws Throwable {
    try {
        String contentOnSessionMarker = this.executeCreateNewContent();
        Content content = this.getContentOnEdit(contentOnSessionMarker);
        AttributeTracer tracerIT = this.getTracer();
        ListAttribute list = (ListAttribute) content.getAttribute(listAttributeName);
        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_" + listAttributeName + "_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(0, formFieldItName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.addParameter(formFieldItName, "true");
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, formFieldItName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.addParameter(formFieldItName, "false");
        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_" + listAttributeName + "_1", formFieldItName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, formFieldItName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.addParameter(formFieldItName, "true");
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, formFieldItName);
        AttributeInterface attributeEN = list.addAttribute("en");
        String formFieldEnName = tracerEN.getFormFieldName(attributeEN);
        assertEquals(formFieldPrefix + "en_" + listAttributeName + "_0", formFieldEnName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, formFieldEnName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.addParameter(formFieldEnName, "true");
        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)

Example 13 with ListAttribute

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

the class EntityAttributeConfigAction method fillAttributeFields.

/**
 * Fill attribute fields.
 *
 * @param attribute The attribute to edit with the form values.
 * @return A custom return code in the attribute neads a extra
 * configuration, else null.
 */
@Override
protected String fillAttributeFields(AttributeInterface attribute) {
    super.fillAttributeFields(attribute);
    AttributeInterface nestedType = null;
    if (attribute instanceof AbstractListAttribute) {
        AbstractListAttribute listAttribute = (AbstractListAttribute) attribute;
        if (this.getStrutsAction() == ApsAdminSystemConstants.EDIT && listAttribute.getNestedAttributeTypeCode().equals(this.getListNestedType())) {
            if (listAttribute instanceof ListAttribute) {
                Lang defaultLang = this.getLangManager().getDefaultLang();
                // Composite Element
                nestedType = ((ListAttribute) listAttribute).addAttribute(defaultLang.getCode());
                ((ListAttribute) listAttribute).getAttributeList(defaultLang.getCode()).clear();
            } else {
                // Composite Element
                nestedType = ((MonoListAttribute) listAttribute).addAttribute();
                ((MonoListAttribute) listAttribute).getAttributes().clear();
            }
        } else {
            nestedType = this.getAttributePrototype(this.getListNestedType());
            if (nestedType != null) {
                nestedType.setName(this.getAttributeName());
            } else {
                _logger.info("******** List Type NULL!!!!");
            }
        }
        listAttribute.setNestedAttributeType(nestedType);
        nestedType.setName(attribute.getName());
    }
    if ((attribute instanceof CompositeAttribute) || (nestedType != null && nestedType instanceof CompositeAttribute)) {
        CompositeAttribute composite = ((attribute instanceof CompositeAttribute) ? (CompositeAttribute) attribute : (CompositeAttribute) nestedType);
        if (null != nestedType) {
            this.getRequest().getSession().setAttribute(IListElementAttributeConfigAction.LIST_ATTRIBUTE_ON_EDIT_SESSION_PARAM, (AbstractListAttribute) attribute);
        }
        this.getRequest().getSession().setAttribute(ICompositeAttributeConfigAction.COMPOSITE_ATTRIBUTE_ON_EDIT_SESSION_PARAM, composite);
        return "configureCompositeAttribute";
    }
    if (nestedType != null) {
        this.getRequest().getSession().setAttribute(IListElementAttributeConfigAction.LIST_ATTRIBUTE_ON_EDIT_SESSION_PARAM, (AbstractListAttribute) attribute);
        this.getRequest().getSession().setAttribute(IListElementAttributeConfigAction.LIST_ELEMENT_ON_EDIT_SESSION_PARAM, nestedType);
        return "configureListElementAttribute";
    }
    return null;
}
Also used : CompositeAttribute(com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute) Lang(com.agiletec.aps.system.services.lang.Lang) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) AbstractListAttribute(com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute) AbstractListAttribute(com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute) ListAttribute(com.agiletec.aps.system.common.entity.model.attribute.ListAttribute) MonoListAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)

Aggregations

ListAttribute (com.agiletec.aps.system.common.entity.model.attribute.ListAttribute)13 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)12 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)11 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)6 AttributeTracer (com.agiletec.aps.system.common.entity.model.AttributeTracer)5 ListAttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.ListAttributeInterface)4 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)3 CompositeAttribute (com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute)3 AbstractListAttribute (com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute)2 CheckBoxAttribute (com.agiletec.aps.system.common.entity.model.attribute.CheckBoxAttribute)2 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)2 EnumeratorAttribute (com.agiletec.aps.system.common.entity.model.attribute.EnumeratorAttribute)2 HypertextAttribute (com.agiletec.aps.system.common.entity.model.attribute.HypertextAttribute)2 MonoTextAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute)2 NumberAttribute (com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute)2 TextAttribute (com.agiletec.aps.system.common.entity.model.attribute.TextAttribute)2 ThreeStateAttribute (com.agiletec.aps.system.common.entity.model.attribute.ThreeStateAttribute)2 Lang (com.agiletec.aps.system.services.lang.Lang)2 List (java.util.List)2 EnumeratorMapAttribute (org.entando.entando.aps.system.common.entity.model.attribute.EnumeratorMapAttribute)2