Search in sources :

Example 21 with ITextAttribute

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

the class BaseFilterAction method setFilterType.

@Override
public String setFilterType() {
    try {
        Content prototype = this.getContentManager().createContentType(this.getContentType());
        String key = this.getFilterKey();
        int attrFilterType = -1;
        AttributeInterface attribute = (AttributeInterface) prototype.getAttribute(key);
        if (null != attribute) {
            if (attribute instanceof ITextAttribute) {
                attrFilterType = TEXT_ATTRIBUTE_FILTER_TYPE;
            } else if (attribute instanceof NumberAttribute) {
                attrFilterType = NUMBER_ATTRIBUTE_FILTER_TYPE;
            } else if (attribute instanceof BooleanAttribute) {
                attrFilterType = BOOLEAN_ATTRIBUTE_FILTER_TYPE;
            } else if (attribute instanceof DateAttribute) {
                attrFilterType = DATE_ATTRIBUTE_FILTER_TYPE;
            }
        } else if ((METADATA_KEY_PREFIX + IContentManager.CONTENT_CREATION_DATE_FILTER_KEY).equals(key) || (METADATA_KEY_PREFIX + IContentManager.CONTENT_MODIFY_DATE_FILTER_KEY).equals(key)) {
            key = key.substring(METADATA_KEY_PREFIX.length());
            this.setFilterKey(key);
            attrFilterType = METADATA_FILTER_TYPE;
        }
        this.setFilterTypeId(attrFilterType);
        if (this.getFilterTypeId() < 0) {
            this.setFilterKey(null);
        }
    } catch (Throwable t) {
        _logger.error("error in setFilterType", t);
        // ApsSystemUtils.logThrowable(t, this, "setFilterType");
        return FAILURE;
    }
    return SUCCESS;
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) BooleanAttribute(com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) 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 22 with ITextAttribute

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

the class TestContentPreviewAction method testPreviewContent.

public void testPreviewContent() throws Throwable {
    String contentId = "EVN192";
    Content contentForTest = this.getContentManager().loadContent(contentId, true);
    String contentOnSessionMarker = AbstractContentAction.buildContentOnSessionMarker(contentForTest, ApsAdminSystemConstants.EDIT);
    String result = this.executeEdit(contentId, "admin");
    assertEquals(Action.SUCCESS, result);
    Content content = this.getContentOnEdit(contentOnSessionMarker);
    ITextAttribute titleAttribute = (ITextAttribute) content.getAttribute("Titolo");
    assertEquals("Titolo B - Evento 2", titleAttribute.getTextForLang("it"));
    this.initContentAction("/do/jacms/Content", "preview", contentOnSessionMarker);
    this.addParameter("mainGroup", Group.FREE_GROUP_NAME);
    this.addParameter("Text:it_Titolo", "Nuovo titolo di prova");
    result = this.executeAction();
    assertEquals(Action.SUCCESS, result);
    content = this.getContentOnEdit(contentOnSessionMarker);
    titleAttribute = (ITextAttribute) content.getAttribute("Titolo");
    assertEquals("Nuovo titolo di prova", titleAttribute.getTextForLang("it"));
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content)

Example 23 with ITextAttribute

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

the class UserFilterOptionBean method extractFilter.

public SearchEngineFilter extractFilter() {
    if (null == this.getFormFieldValues()) {
        return null;
    }
    SearchEngineFilter filter = null;
    String value0 = this.getFormValue(0);
    String value1 = this.getFormValue(1);
    if (!this.isAttributeFilter()) {
        if (this.getKey().equals(KEY_FULLTEXT) && !StringUtils.isEmpty(value0)) {
            // String[] fieldsSuffix = {"", "_option"};
            filter = new SearchEngineFilter(this.getCurrentLang().getCode(), value0, this.getOption(value1));
            String attachOption = this.getFormValue(2);
            try {
                filter.setIncludeAttachments(Boolean.parseBoolean(attachOption));
            } catch (Exception e) {
            }
        } else if (this.getKey().equals(KEY_CATEGORY) && !StringUtils.isEmpty(value0)) {
            filter = new SearchEngineFilter(IIndexerDAO.CONTENT_CATEGORY_FIELD_NAME, value0, SearchEngineFilter.TextSearchOption.EXACT);
        }
    } else {
        AttributeInterface attribute = this.getAttribute();
        if (attribute instanceof ITextAttribute && !StringUtils.isEmpty(value0)) {
            filter = new SearchEngineFilter(this.getIndexFieldName(), value0, SearchEngineFilter.TextSearchOption.EXACT);
        // String[] fieldsSuffix = {"_textFieldName"};
        } else if (attribute instanceof DateAttribute && (!StringUtils.isEmpty(value0) || !StringUtils.isEmpty(value1))) {
            Date big0 = null;
            try {
                big0 = DateConverter.parseDate(value0, this.getDateFormat());
            } catch (Exception e) {
            }
            Date big1 = null;
            try {
                big1 = DateConverter.parseDate(value1, this.getDateFormat());
            } catch (Exception e) {
            }
            // String[] fieldsSuffix = {"_dateStartFieldName", "_dateEndFieldName"};
            filter = new SearchEngineFilter(this.getIndexFieldName(), big0, big1);
        } else if (attribute instanceof BooleanAttribute && (!StringUtils.isEmpty(value0) && !StringUtils.isEmpty(value1))) {
            filter = new SearchEngineFilter(this.getIndexFieldName(), value0, SearchEngineFilter.TextSearchOption.EXACT);
        // String[] fieldsSuffix = {"_booleanFieldName", "_booleanFieldName_ignore", "_booleanFieldName_control"};
        } else if (attribute instanceof NumberAttribute && (!StringUtils.isEmpty(value0) || !StringUtils.isEmpty(value1))) {
            // String[] fieldsSuffix = {"_numberStartFieldName", "_numberEndFieldName"};
            BigDecimal big0 = null;
            try {
                big0 = new BigDecimal(value0);
            } catch (Exception e) {
            }
            BigDecimal big1 = null;
            try {
                big1 = new BigDecimal(value1);
            } catch (Exception e) {
            }
            filter = new SearchEngineFilter(this.getIndexFieldName(), big0, big1);
        }
    }
    return filter;
}
Also used : SearchEngineFilter(org.entando.entando.aps.system.services.searchengine.SearchEngineFilter) 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) Date(java.util.Date) BigDecimal(java.math.BigDecimal) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 24 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 25 with ITextAttribute

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

the class TextAttributeValidationRules method checkRegExp.

protected void checkRegExp(AttributeInterface attribute, AttributeTracer tracer, Lang lang, List<AttributeFieldError> errors) {
    String text = ((ITextAttribute) attribute).getTextForLang(lang.getCode());
    if (null != text && text.trim().length() > 0 && null != this.getRegexp() && this.getRegexp().trim().length() > 0) {
        Pattern pattern = Pattern.compile(this.getRegexp());
        Matcher matcher = pattern.matcher(text);
        if (!matcher.matches()) {
            AttributeFieldError error = new AttributeFieldError(attribute, FieldError.INVALID_FORMAT, tracer);
            error.setMessage("Lang '" + lang.getDescr() + "' - invalid format");
            errors.add(error);
        }
    }
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError)

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