Search in sources :

Example 1 with EntitySearchFilter

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

the class ContentListFilterTag method doEndTag.

@Override
public int doEndTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    try {
        if (!this.isRightKey()) {
            StringBuilder message = new StringBuilder();
            for (int i = 0; i < IContentListWidgetHelper.allowedMetadataFilterKeys.length; i++) {
                if (i != 0) {
                    message.append(",");
                }
                message.append(IContentListWidgetHelper.allowedMetadataFilterKeys[i]);
            }
            throw new RuntimeException("The key '" + this.getKey() + "' is unknown; " + "Please use a valid one - " + message);
        }
        IContentListWidgetHelper helper = (IContentListWidgetHelper) ApsWebApplicationUtils.getBean(JacmsSystemConstants.CONTENT_LIST_HELPER, this.pageContext);
        IContentListTagBean parent = (IContentListTagBean) findAncestorWithClass(this, IContentListTagBean.class);
        String contentType = parent.getContentType();
        EntitySearchFilter filter = helper.getFilter(contentType, (IEntityFilterBean) this, reqCtx);
        if (null != filter) {
            parent.addFilter(filter);
        }
    } catch (Throwable t) {
        _logger.error("error in end tag", t);
        throw new JspException("Tag error detected ", t);
    }
    return super.doEndTag();
}
Also used : ServletRequest(javax.servlet.ServletRequest) JspException(javax.servlet.jsp.JspException) IContentListWidgetHelper(com.agiletec.plugins.jacms.aps.system.services.content.widget.IContentListWidgetHelper) IContentListTagBean(com.agiletec.plugins.jacms.aps.system.services.content.widget.IContentListTagBean) RequestContext(com.agiletec.aps.system.RequestContext) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter)

Example 2 with EntitySearchFilter

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

the class BaseDataListHelper method buildCacheKey.

protected static String buildCacheKey(IDataTypeListBean bean, Collection<String> userGroupCodes) {
    StringBuilder cacheKey = new StringBuilder();
    if (null != bean.getListName()) {
        cacheKey.append("LISTNAME_").append(bean.getListName());
    }
    if (null != bean.getDataType()) {
        cacheKey.append("TYPE_").append(bean.getDataType());
    }
    List<String> groupCodes = new ArrayList<String>(userGroupCodes);
    if (!groupCodes.contains(Group.FREE_GROUP_NAME)) {
        groupCodes.add(Group.FREE_GROUP_NAME);
    }
    Collections.sort(groupCodes);
    for (int i = 0; i < groupCodes.size(); i++) {
        if (i == 0) {
            cacheKey.append("-GROUPS");
        }
        String code = groupCodes.get(i);
        cacheKey.append("_").append(code);
    }
    if (null != bean.getCategories()) {
        List<String> categoryCodes = Arrays.asList(bean.getCategories());
        Collections.sort(categoryCodes);
        for (int j = 0; j < categoryCodes.size(); j++) {
            if (j == 0) {
                cacheKey.append("-CATEGORIES");
            }
            String code = categoryCodes.get(j);
            cacheKey.append("_").append(code);
        }
    }
    if (null != bean.getFilters()) {
        for (int k = 0; k < bean.getFilters().length; k++) {
            if (k == 0) {
                cacheKey.append("-FILTERS");
            }
            EntitySearchFilter filter = bean.getFilters()[k];
            cacheKey.append("_").append(filter.toString());
        }
    }
    return cacheKey.toString();
}
Also used : ArrayList(java.util.ArrayList) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter)

Example 3 with EntitySearchFilter

use of com.agiletec.aps.system.common.entity.model.EntitySearchFilter 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 4 with EntitySearchFilter

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

the class TestContentEntityManager method testLoadPastEvents2.

public void testLoadPastEvents2() throws ApsSystemException {
    Date today = DateConverter.parseDate("2008-10-01", "yyyy-MM-dd");
    EntitySearchFilter filter = new EntitySearchFilter("DataInizio", true, null, today);
    filter.setOrder(EntitySearchFilter.DESC_ORDER);
    EntitySearchFilter[] filters = { filter };
    List<String> contents2 = this._contentManager.searchId("EVN", filters);
    String[] expectedOrderedEntitiesId = { "EVN23", "EVN41", "EVN25", "EVN20", "EVN21", "EVN103", "EVN192", "EVN191" };
    assertEquals(expectedOrderedEntitiesId.length, contents2.size());
    for (int i = 0; i < expectedOrderedEntitiesId.length; i++) {
        assertEquals(expectedOrderedEntitiesId[i], contents2.get(i));
    }
}
Also used : EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter) Date(java.util.Date)

Example 5 with EntitySearchFilter

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

the class TestContentEntityManager method testLoadEvents2.

public void testLoadEvents2() throws ApsSystemException {
    Date start = DateConverter.parseDate("1997-06-10", "yyyy-MM-dd");
    Date end = DateConverter.parseDate("2020-09-19", "yyyy-MM-dd");
    EntitySearchFilter filter = new EntitySearchFilter("DataInizio", true, start, end);
    EntitySearchFilter filter2 = new EntitySearchFilter(IContentManager.CONTENT_DESCR_FILTER_KEY, false, "Even", true);
    filter2.setOrder(EntitySearchFilter.DESC_ORDER);
    EntitySearchFilter[] filters = { filter, filter2 };
    List<String> contents = _contentManager.searchId("EVN", filters);
    assertEquals(2, contents.size());
    assertEquals("EVN193", contents.get(0));
    assertEquals("EVN192", contents.get(1));
    EntitySearchFilter filter3 = new EntitySearchFilter(IContentManager.CONTENT_STATUS_FILTER_KEY, false, "pronto", true);
    EntitySearchFilter[] filters2 = { filter, filter3, filter2 };
    contents = _contentManager.searchId("EVN", filters2);
    assertEquals(0, contents.size());
    EntitySearchFilter[] filters2_bis = { filter, filter2, filter3 };
    contents = _contentManager.searchId("EVN", filters2_bis);
    assertEquals(0, contents.size());
    filter2 = new EntitySearchFilter(IContentManager.CONTENT_DESCR_FILTER_KEY, false);
    filter2.setOrder(EntitySearchFilter.DESC_ORDER);
    EntitySearchFilter[] filters3 = { filter, filter2 };
    contents = _contentManager.searchId("EVN", filters3);
    String[] expectedOrderedContentsId = { "EVN25", "EVN21", "EVN20", "EVN41", "EVN193", "EVN192", "EVN103", "EVN23", "EVN24" };
    assertEquals(expectedOrderedContentsId.length, contents.size());
    for (int i = 0; i < expectedOrderedContentsId.length; i++) {
        assertEquals(expectedOrderedContentsId[i], contents.get(i));
    }
}
Also used : EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter) Date(java.util.Date)

Aggregations

EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)157 ArrayList (java.util.ArrayList)51 Date (java.util.Date)46 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)12 RequestContext (com.agiletec.aps.system.RequestContext)9 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)7 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)6 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)5 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)5 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)4 BigDecimal (java.math.BigDecimal)4 HashSet (java.util.HashSet)4 ApsEntityRecord (com.agiletec.aps.system.common.entity.model.ApsEntityRecord)3 BooleanAttribute (com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute)3 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)3 NumberAttribute (com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute)3 Properties (java.util.Properties)3 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)3 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)2 MonoTextAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute)2