Search in sources :

Example 1 with ITextAttribute

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

the class UserProfileAttributeTag method doStartTag.

@Override
public int doStartTag() throws JspException {
    try {
        IUserProfile profile = this.getUserProfile();
        if (null == profile) {
            return super.doStartTag();
        }
        Object value = null;
        if (null != this.getAttributeRoleName()) {
            ITextAttribute textAttribute = (ITextAttribute) profile.getAttributeByRole(this.getAttributeRoleName());
            value = (null != textAttribute) ? textAttribute.getText() : null;
        } else {
            value = profile.getValue(this.getAttributeName());
        }
        if (null == value) {
            return super.doStartTag();
        }
        if (this.getVar() != null) {
            this.pageContext.setAttribute(this.getVar(), value);
        } else {
            if (this.getEscapeXml()) {
                out(this.pageContext, this.getEscapeXml(), value);
            } else {
                this.pageContext.getOut().print(value);
            }
        }
    } catch (Throwable t) {
        _logger.error("error in doStartTag", t);
        // ApsSystemUtils.logThrowable(t, this, "doStartTag");
        throw new JspException("Error during tag initialization", t);
    }
    return super.doStartTag();
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) JspException(javax.servlet.jsp.JspException) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile)

Example 2 with ITextAttribute

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

the class UserFilterOptionBean method getEntityFilter.

public EntitySearchFilter getEntityFilter() throws ApsSystemException {
    EntitySearchFilter filter = null;
    try {
        if (!this.isAttributeFilter() || null == this.getFormFieldValues()) {
            return null;
        }
        AttributeInterface attribute = this.getAttribute();
        if (attribute instanceof ITextAttribute) {
            String text = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
            filter = new EntitySearchFilter(attribute.getName(), true, text, true);
            if (attribute.isMultilingual()) {
                filter.setLangCode(this.getCurrentLang().getCode());
            }
        } else if (attribute instanceof DateAttribute) {
            String start = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
            String end = this.getFormFieldValues().get(this.getFormFieldNames()[1]);
            Date startDate = DateConverter.parseDate(start, this.getDateFormat());
            Date endDate = DateConverter.parseDate(end, this.getDateFormat());
            filter = new EntitySearchFilter(attribute.getName(), true, startDate, endDate);
        } else if (attribute instanceof BooleanAttribute) {
            String value = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
            String ignore = this.getFormFieldValues().get(this.getFormFieldNames()[1]);
            if (null != ignore) {
                return null;
            } else if (null == value || value.equals("both")) {
                // special option for three state Attribute
                filter = new EntitySearchFilter(attribute.getName(), true);
                filter.setNullOption(true);
            } else {
                filter = new EntitySearchFilter(attribute.getName(), true, value, false);
            }
        } else if (attribute instanceof NumberAttribute) {
            String start = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
            String end = this.getFormFieldValues().get(this.getFormFieldNames()[1]);
            BigDecimal startNumber = null;
            try {
                Integer startNumberInt = Integer.parseInt(start);
                startNumber = new BigDecimal(startNumberInt);
            } catch (Throwable t) {
            }
            BigDecimal endNumber = null;
            try {
                Integer endNumberInt = Integer.parseInt(end);
                endNumber = new BigDecimal(endNumberInt);
            } catch (Throwable t) {
            }
            filter = new EntitySearchFilter(attribute.getName(), true, startNumber, endNumber);
        }
    } catch (Throwable t) {
        _logger.error("Error extracting entity search filters", t);
        throw new ApsSystemException("Error extracting entity search filters", t);
    }
    return filter;
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) BooleanAttribute(com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute) NumberAttribute(com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) Date(java.util.Date) BigDecimal(java.math.BigDecimal) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 3 with ITextAttribute

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

the class TestValidateContent method testValidate_4.

public void testValidate_4() throws Throwable {
    String shortTitle = "short";
    String longTitle = "Titolo che supera la lunghezza massima di cento caratteri; " + "Ripeto, Titolo che supera la lunghezza massima di cento caratteri";
    try {
        Content content = this.createNewVoid("RAH", "descr", Content.STATUS_DRAFT, Group.FREE_GROUP_NAME, "admin");
        ITextAttribute textAttribute = (ITextAttribute) content.getAttribute("Titolo");
        textAttribute.setText(shortTitle, "it");
        List<FieldError> errors = content.validate(this._groupManager);
        assertEquals(1, errors.size());
        FieldError error = errors.get(0);
        assertEquals("Text:it_Titolo", error.getFieldCode());
        assertEquals(FieldError.INVALID_MIN_LENGTH, error.getErrorCode());
        textAttribute.setText(longTitle, "it");
        errors = content.validate(this._groupManager);
        assertEquals(1, errors.size());
        error = errors.get(0);
        assertEquals("Text:it_Titolo", error.getFieldCode());
        assertEquals(FieldError.INVALID_MAX_LENGTH, error.getErrorCode());
        textAttribute.setText(shortTitle, "en");
        errors = content.validate(this._groupManager);
        assertEquals(2, errors.size());
        error = errors.get(0);
        assertEquals("Text:it_Titolo", error.getFieldCode());
        assertEquals(FieldError.INVALID_MAX_LENGTH, error.getErrorCode());
        error = errors.get(1);
        assertEquals("Text:en_Titolo", error.getFieldCode());
        assertEquals(FieldError.INVALID_MIN_LENGTH, 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 4 with ITextAttribute

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

the class UserFilterOptionBean method extractFormParameters.

protected void extractFormParameters(HttpServletRequest request) throws Throwable {
    String[] formFieldNames = null;
    try {
        String frameIdSuffix = (null != this.getCurrentFrame()) ? "_frame" + this.getCurrentFrame().toString() : "";
        if (!this.isAttributeFilter()) {
            if (this.getKey().equals(KEY_FULLTEXT)) {
                String fieldName = TYPE_METADATA + "_fulltext" + frameIdSuffix;
                String[] fieldsSuffix = { "", "_option", "_attachSearch" };
                formFieldNames = this.extractParams(fieldName, fieldsSuffix, frameIdSuffix, request);
            } else if (this.getKey().equals(KEY_CATEGORY)) {
                formFieldNames = new String[1];
                formFieldNames[0] = TYPE_METADATA + "_category" + frameIdSuffix;
                String value = request.getParameter(formFieldNames[0]);
                this.addFormValue(formFieldNames[0], value, formFieldNames.length);
            }
        } else {
            AttributeInterface attribute = this.getAttribute();
            if (attribute instanceof ITextAttribute) {
                String[] fieldsSuffix = { "_textFieldName" };
                formFieldNames = this.extractAttributeParams(fieldsSuffix, frameIdSuffix, request);
            } else if (attribute instanceof DateAttribute) {
                String[] fieldsSuffix = { "_dateStartFieldName", "_dateEndFieldName" };
                formFieldNames = this.extractAttributeParams(fieldsSuffix, frameIdSuffix, request);
                this.checkRange(formFieldNames);
            } else if (attribute instanceof BooleanAttribute) {
                String[] fieldsSuffix = { "_booleanFieldName", "_booleanFieldName_ignore", "_booleanFieldName_control" };
                formFieldNames = this.extractAttributeParams(fieldsSuffix, frameIdSuffix, request);
            } else if (attribute instanceof NumberAttribute) {
                String[] fieldsSuffix = { "_numberStartFieldName", "_numberEndFieldName" };
                formFieldNames = this.extractAttributeParams(fieldsSuffix, frameIdSuffix, request);
                this.checkRange(formFieldNames);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error extracting form parameters", t);
        throw new ApsSystemException("Error extracting form parameters", t);
    }
    this.setFormFieldNames(formFieldNames);
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) BooleanAttribute(com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute) NumberAttribute(com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 5 with ITextAttribute

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

the class DataObjectActionHelper method updateEntity.

@Override
public void updateEntity(IApsEntity entity, HttpServletRequest request) {
    DataObject dataObject = (DataObject) entity;
    try {
        if (null != dataObject) {
            String descr = request.getParameter("descr");
            if (descr != null) {
                dataObject.setDescription(descr.trim());
            }
            String status = request.getParameter("status");
            if (status != null) {
                dataObject.setStatus(status);
            }
            if (null == dataObject.getId()) {
                String mainGroup = request.getParameter("mainGroup");
                if (mainGroup != null) {
                    request.getSession().setAttribute("dataObjectGroupOnSession", mainGroup);
                }
            }
            super.updateEntity(dataObject, request);
            String description = dataObject.getDescription();
            if (null == description || description.trim().length() == 0) {
                ITextAttribute titleAttribute = (ITextAttribute) dataObject.getAttributeByRole(SystemConstants.DATA_TYPE_ATTRIBUTE_ROLE_TITLE);
                if (null != titleAttribute && StringUtils.isNotEmpty(titleAttribute.getText())) {
                    dataObject.setDescription(titleAttribute.getText());
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("DataObjectActionHelper - updateDataObject", t);
        throw new RuntimeException("Error updating DataObject", t);
    }
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject)

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