Search in sources :

Example 16 with ITextAttribute

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

the class UserProfile method getValue.

private Object getValue(AttributeInterface attribute) {
    if (null == attribute)
        return "";
    if (attribute.isTextAttribute()) {
        return ((ITextAttribute) attribute).getText();
    } else if (attribute instanceof NumberAttribute) {
        return ((NumberAttribute) attribute).getValue();
    } else if (attribute instanceof BooleanAttribute) {
        return ((BooleanAttribute) attribute).getValue();
    } else if (attribute instanceof DateAttribute) {
        return ((DateAttribute) attribute).getDate();
    } else if (!attribute.isSimple()) {
        String text = "";
        List<AttributeInterface> attributes = ((AbstractComplexAttribute) attribute).getAttributes();
        for (int i = 0; i < attributes.size(); i++) {
            if (i > 0)
                text += ",";
            AttributeInterface attributeElem = attributes.get(i);
            text += this.getValue(attributeElem);
        }
        return text;
    }
    return null;
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) BooleanAttribute(com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute) AbstractComplexAttribute(com.agiletec.aps.system.common.entity.model.attribute.AbstractComplexAttribute) NumberAttribute(com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 17 with ITextAttribute

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

the class TestValidateContent method testValidate_3.

public void testValidate_3() throws Throwable {
    try {
        Content content = this.createNewVoid("RAH", "descr", Content.STATUS_DRAFT, Group.FREE_GROUP_NAME, "admin");
        ITextAttribute emailAttribute = (ITextAttribute) content.getAttribute("email");
        emailAttribute.setText("wrongEmailAddress", null);
        List<FieldError> errors = content.validate(this._groupManager);
        assertEquals(1, errors.size());
        FieldError error = errors.get(0);
        assertEquals("Monotext:email", error.getFieldCode());
        assertEquals(FieldError.INVALID_FORMAT, error.getErrorCode());
    } catch (Throwable t) {
        throw t;
    }
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) FieldError(com.agiletec.aps.system.common.entity.model.FieldError)

Example 18 with ITextAttribute

use of com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute 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 19 with ITextAttribute

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

the class TestListAttributeAction method verifyText.

private void verifyText(List<AttributeInterface> attributes, String[] expected) {
    assertEquals(expected.length, attributes.size());
    for (int i = 0; i < attributes.size(); i++) {
        ITextAttribute textAttribute = (ITextAttribute) attributes.get(i);
        assertEquals(expected[i], textAttribute.getText());
    }
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)

Example 20 with ITextAttribute

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

the class ContentActionHelper method updateEntity.

@Override
public void updateEntity(IApsEntity entity, HttpServletRequest request) {
    Content content = (Content) entity;
    try {
        if (null != content) {
            String descr = request.getParameter("descr");
            if (descr != null) {
                content.setDescription(descr.trim());
            }
            String status = request.getParameter("status");
            if (status != null) {
                content.setStatus(status);
            }
            if (null == content.getId()) {
                String mainGroup = request.getParameter("mainGroup");
                if (mainGroup != null) {
                    request.getSession().setAttribute(ContentActionConstants.SESSION_PARAM_NAME_CURRENT_CONTENT_GROUP, mainGroup);
                }
            }
            super.updateEntity(content, request);
            String description = content.getDescription();
            if (null == description || description.trim().length() == 0) {
                ITextAttribute titleAttribute = (ITextAttribute) content.getAttributeByRole(JacmsSystemConstants.ATTRIBUTE_ROLE_TITLE);
                if (null != titleAttribute && StringUtils.isNotEmpty(titleAttribute.getText())) {
                    content.setDescription(titleAttribute.getText());
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("ContentActionHelper - updateContent", t);
        throw new RuntimeException("Error updating Content", t);
    }
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content)

Aggregations

ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)27 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)16 BooleanAttribute (com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute)10 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)10 NumberAttribute (com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute)10 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)9 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)7 BigDecimal (java.math.BigDecimal)5 Date (java.util.Date)5 FieldError (com.agiletec.aps.system.common.entity.model.FieldError)4 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)4 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)3 TextAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules)2 Lang (com.agiletec.aps.system.services.lang.Lang)2 ArrayList (java.util.ArrayList)2 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)2 SearchEngineFilter (org.entando.entando.aps.system.services.searchengine.SearchEngineFilter)2 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)1 AttributeFieldError (com.agiletec.aps.system.common.entity.model.AttributeFieldError)1 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)1