Search in sources :

Example 86 with AttributeInterface

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

the class DataObjectModelAction method getAllowedAttributeMethods.

public List<String> getAllowedAttributeMethods(DataObject prototype, String attributeName) {
    List<String> methods = new ArrayList<String>();
    try {
        AttributeInterface attribute = (AttributeInterface) prototype.getAttribute(attributeName);
        if (null == attribute) {
            throw new ApsSystemException("Null Attribute '" + attributeName + "' for Data Type '" + prototype.getTypeCode() + "' - '" + prototype.getTypeDescr());
        }
        String methodsString = this.getAllowedPublicAttributeMethods().getProperty(attribute.getType());
        if (null != methodsString) {
            String[] methodsArray = methodsString.split(";");
            methods = Arrays.asList(methodsArray);
        } else {
            BeanInfo beanInfo = Introspector.getBeanInfo(attribute.getClass(), AbstractAttribute.class);
            PropertyDescriptor[] prDescrs = beanInfo.getPropertyDescriptors();
            for (int i = 0; i < prDescrs.length; i++) {
                PropertyDescriptor propertyDescriptor = prDescrs[i];
                if (null != propertyDescriptor.getReadMethod()) {
                    methods.add(propertyDescriptor.getDisplayName());
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("error in getAllowedAttributeMethods", t);
    }
    return methods;
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) ArrayList(java.util.ArrayList) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 87 with AttributeInterface

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

the class TestEntityManagersAction method testEditAttribute.

public void testEditAttribute() throws Throwable {
    // Search an entity manager
    String[] defNames = this.getApplicationContext().getBeanNamesForType(ApsEntityManager.class);
    if (null == defNames || defNames.length == 0)
        return;
    String entityManagerName = defNames[0];
    IEntityManager entityManager = (IEntityManager) this.getApplicationContext().getBean(entityManagerName);
    // get the entites managed by the ApsEntityManager
    Map<String, IApsEntity> entities = entityManager.getEntityPrototypes();
    if (null == entities || entities.size() == 0)
        return;
    List<String> enitiesTypeCodes = new ArrayList<String>();
    enitiesTypeCodes.addAll(entities.keySet());
    // get the first entity type code available
    String entityTypeCode = enitiesTypeCodes.get(0);
    List<AttributeInterface> attributes = entities.get(entityTypeCode).getAttributeList();
    // get the first attribute
    for (int i = 0; i < attributes.size(); i++) {
        AttributeInterface currentAttribute = attributes.get(i);
        String attributeName = currentAttribute.getName();
        String result = this.executeEditAttribute("admin", attributeName, entityTypeCode, entityManagerName);
        assertEquals(Action.SUCCESS, result);
        EntityAttributeConfigAction action = (EntityAttributeConfigAction) this.getAction();
        assertEquals(currentAttribute.getType(), action.getAttributeTypeCode());
        assertEquals(currentAttribute.isRequired(), action.getRequired().booleanValue());
        assertEquals(currentAttribute.isSearchable(), action.getSearchable().booleanValue());
        assertEquals(currentAttribute.getIndexingType().equalsIgnoreCase(IndexableAttributeInterface.INDEXING_TYPE_TEXT), action.getIndexable().booleanValue());
        if (currentAttribute.isTextAttribute()) {
            ITextAttribute attr = (ITextAttribute) currentAttribute;
            if (attr.getMaxLength() == -1) {
                assertNull(action.getMaxLength());
            } else {
                assertEquals(attr.getMaxLength(), action.getMaxLength().intValue());
            }
            if (attr.getMinLength() == -1) {
                assertNull(action.getMinLength());
            } else {
                assertEquals(attr.getMinLength(), action.getMinLength().intValue());
            }
            assertEquals(attr.getRegexp(), action.getRegexp());
        }
        assertEquals(ApsAdminSystemConstants.EDIT, action.getStrutsAction());
    }
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) ArrayList(java.util.ArrayList) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) IndexableAttributeInterface(com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) EntityAttributeConfigAction(com.agiletec.apsadmin.system.entity.type.EntityAttributeConfigAction)

Example 88 with AttributeInterface

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

the class TestLinkAttributeAction method testChooseLink_2.

public void testChooseLink_2() throws Throwable {
    String contentId = "EVN191";
    String contentOnSessionMarker = this.extractSessionMarker(contentId, ApsAdminSystemConstants.EDIT);
    this.executeEdit(contentId, "admin");
    this.initContentAction("/do/jacms/Content", "chooseLink", contentOnSessionMarker);
    this.addParameter("attributeName", "LinkCorrelati");
    this.addParameter("elementIndex", "0");
    this.addParameter("langCode", "it");
    String result = this.executeAction();
    // FALLIMENTO PER LISTA VUOTA
    assertEquals(BaseAction.FAILURE, result);
    Content currentContent = this.getContentOnEdit(contentOnSessionMarker);
    MonoListAttribute monoListAttribute = (MonoListAttribute) currentContent.getAttribute("LinkCorrelati");
    List<AttributeInterface> attributes = monoListAttribute.getAttributes();
    assertEquals(0, attributes.size());
    this.initContentAction("/do/jacms/Content", "addListElement", contentOnSessionMarker);
    this.addParameter("attributeName", "LinkCorrelati");
    this.addParameter("listLangCode", "it");
    result = this.executeAction();
    assertEquals("chooseLink", result);
    currentContent = this.getContentOnEdit(contentOnSessionMarker);
    monoListAttribute = (MonoListAttribute) currentContent.getAttribute("LinkCorrelati");
    attributes = monoListAttribute.getAttributes();
    assertEquals(1, attributes.size());
    this.initContentAction("/do/jacms/Content", "chooseLink", contentOnSessionMarker);
    this.addParameter("attributeName", "LinkCorrelati");
    this.addParameter("elementIndex", "0");
    this.addParameter("langCode", "it");
    result = this.executeAction();
    assertEquals(Action.SUCCESS, result);
    HttpSession session = this.getRequest().getSession();
    assertEquals("LinkCorrelati", session.getAttribute(ILinkAttributeActionHelper.ATTRIBUTE_NAME_SESSION_PARAM));
    assertEquals("it", session.getAttribute(ILinkAttributeActionHelper.LINK_LANG_CODE_SESSION_PARAM));
    assertNotNull(session.getAttribute(ILinkAttributeActionHelper.LIST_ELEMENT_INDEX_SESSION_PARAM));
    assertEquals(new Integer(0), session.getAttribute(ILinkAttributeActionHelper.LIST_ELEMENT_INDEX_SESSION_PARAM));
    currentContent = this.getContentOnEdit(contentOnSessionMarker);
    assertNotNull(currentContent);
    assertEquals("EVN191", currentContent.getId());
    assertEquals("Evento 1", currentContent.getDescription());
}
Also used : MonoListAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) HttpSession(javax.servlet.http.HttpSession) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 89 with AttributeInterface

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

the class LinkAttributeActionHelper method joinLink.

@Override
public void joinLink(String[] destinations, int destType, HttpServletRequest request) {
    HttpSession session = request.getSession();
    Content currentContent = getContent(request);
    String attributeName = (String) session.getAttribute(ATTRIBUTE_NAME_SESSION_PARAM);
    AttributeInterface attribute = (AttributeInterface) currentContent.getAttribute(attributeName);
    joinLink(attribute, destinations, destType, request);
    removeSessionParams(session);
}
Also used : HttpSession(javax.servlet.http.HttpSession) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 90 with AttributeInterface

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

the class LinkAttributeActionHelper method initSessionParams.

@Override
public void initSessionParams(ILinkAttributeAction action, HttpServletRequest request) {
    AttributeInterface attribute = null;
    HttpSession session = request.getSession();
    if (null != action.getParentAttributeName()) {
        attribute = (AttributeInterface) getContent(request).getAttribute(action.getParentAttributeName());
        session.setAttribute(ATTRIBUTE_NAME_SESSION_PARAM, action.getParentAttributeName());
        session.setAttribute(INCLUDED_ELEMENT_NAME_SESSION_PARAM, action.getAttributeName());
    } else {
        attribute = (AttributeInterface) getContent(request).getAttribute(action.getAttributeName());
        session.setAttribute(ATTRIBUTE_NAME_SESSION_PARAM, action.getAttributeName());
    }
    if (action.getElementIndex() >= 0) {
        session.setAttribute(LIST_ELEMENT_INDEX_SESSION_PARAM, new Integer(action.getElementIndex()));
    }
    session.setAttribute(LINK_LANG_CODE_SESSION_PARAM, action.getLangCode());
    LinkAttribute linkAttribute = (LinkAttribute) getLinkAttribute(attribute, request);
    session.setAttribute(SYMBOLIC_LINK_SESSION_PARAM, linkAttribute.getSymbolicLink());
}
Also used : LinkAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.LinkAttribute) HttpSession(javax.servlet.http.HttpSession) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Aggregations

AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)147 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)55 AttributeTracer (com.agiletec.aps.system.common.entity.model.AttributeTracer)38 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)37 CompositeAttribute (com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute)27 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)22 ArrayList (java.util.ArrayList)18 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)17 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)16 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)14 NumberAttribute (com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute)12 ListAttribute (com.agiletec.aps.system.common.entity.model.attribute.ListAttribute)11 BooleanAttribute (com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute)10 IndexableAttributeInterface (com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface)10 HttpSession (javax.servlet.http.HttpSession)10 EntityAttributeIterator (com.agiletec.aps.system.common.util.EntityAttributeIterator)9 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)7 MonoTextAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute)7 Lang (com.agiletec.aps.system.services.lang.Lang)7 Date (java.util.Date)7