Search in sources :

Example 21 with FieldSearchFilter

use of com.agiletec.aps.system.common.FieldSearchFilter in project entando-core by entando.

the class ApiGuiFragmentInterface method getGuiFragments.

public List<LinkedListItem> getGuiFragments(Properties properties) throws Throwable {
    List<LinkedListItem> list = new ArrayList<LinkedListItem>();
    try {
        String code = properties.getProperty("code");
        String widgettypecode = properties.getProperty("widgettypecode");
        String plugincode = properties.getProperty("plugincode");
        FieldSearchFilter[] filters = new FieldSearchFilter[0];
        FieldSearchFilter codeFilterToAdd = null;
        if (StringUtils.isNotBlank(code)) {
            codeFilterToAdd = new FieldSearchFilter("code", code, true);
        } else {
            codeFilterToAdd = new FieldSearchFilter("code");
        }
        codeFilterToAdd.setOrder(FieldSearchFilter.Order.ASC);
        filters = this.addFilter(filters, codeFilterToAdd);
        if (StringUtils.isNotBlank(widgettypecode)) {
            FieldSearchFilter filterToAdd = new FieldSearchFilter("widgettypecode", widgettypecode, true);
            filters = this.addFilter(filters, filterToAdd);
        }
        if (StringUtils.isNotBlank(plugincode)) {
            FieldSearchFilter filterToAdd = new FieldSearchFilter("plugincode", plugincode, true);
            filters = this.addFilter(filters, filterToAdd);
        }
        List<String> codes = this.getGuiFragmentManager().searchGuiFragments(filters);
        for (int i = 0; i < codes.size(); i++) {
            String fragmantCode = codes.get(i);
            String url = this.getApiResourceUrl(fragmantCode, properties.getProperty(SystemConstants.API_APPLICATION_BASE_URL_PARAMETER), properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER), (MediaType) properties.get(SystemConstants.API_PRODUCES_MEDIA_TYPE_PARAMETER));
            LinkedListItem item = new LinkedListItem();
            item.setCode(fragmantCode);
            item.setUrl(url);
            list.add(item);
        }
    } catch (Throwable t) {
        _logger.error("Error extracting list of fragments", t);
        throw t;
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) LinkedListItem(org.entando.entando.aps.system.services.api.model.LinkedListItem) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter)

Example 22 with FieldSearchFilter

use of com.agiletec.aps.system.common.FieldSearchFilter in project entando-core by entando.

the class RestListRequestTest method should_exclude_pagination_when_pagesize_0.

@Test
public void should_exclude_pagination_when_pagesize_0() {
    RestListRequest request = new RestListRequest();
    request.setPage(1);
    request.setPageSize(0);
    request.setSort("name");
    request.setDirection(FieldSearchFilter.Order.ASC.name());
    request.addFilter(new Filter("name", "jack"));
    request.addFilter(new Filter("city", "rome"));
    request.addFilter(new Filter("mobile", "+39"));
    // filters
    List<FieldSearchFilter> filters = request.buildFieldSearchFilters();
    assertThat(filters.size(), is(4));
    assertThat(filters.get(0).getKey(), is("name"));
    assertThat(filters.get(1).getKey(), is("city"));
    assertThat(filters.get(2).getKey(), is("mobile"));
    // sort
    assertThat(filters.get(3).getKey(), is("name"));
    assertThat(filters.get(3).getOrder(), is(FieldSearchFilter.Order.ASC));
}
Also used : FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Filter(org.entando.entando.web.common.model.Filter) RestListRequest(org.entando.entando.web.common.model.RestListRequest) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Test(org.junit.Test)

Example 23 with FieldSearchFilter

use of com.agiletec.aps.system.common.FieldSearchFilter in project entando-core by entando.

the class RestListRequestTest method shuold_create_filters.

@Test
public void shuold_create_filters() {
    RestListRequest request = new RestListRequest();
    request.setPage(1);
    request.setPageSize(25);
    request.setSort("name");
    request.setDirection(FieldSearchFilter.Order.ASC.name());
    request.addFilter(new Filter("name", "jack"));
    request.addFilter(new Filter("city", "rome"));
    request.addFilter(new Filter("mobile", "+39"));
    // filters
    List<FieldSearchFilter> filters = request.buildFieldSearchFilters();
    assertThat(filters.size(), is(5));
    assertThat(filters.get(0).getKey(), is("name"));
    assertThat(filters.get(1).getKey(), is("city"));
    assertThat(filters.get(2).getKey(), is("mobile"));
    // pagination
    assertThat(filters.get(3).getKey(), is(nullValue()));
    assertThat(filters.get(3).getLimit(), is(not(nullValue())));
    assertThat(filters.get(3).getOffset(), is(not(nullValue())));
    // sort
    assertThat(filters.get(4).getKey(), is("name"));
    assertThat(filters.get(4).getOrder(), is(FieldSearchFilter.Order.ASC));
}
Also used : FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Filter(org.entando.entando.web.common.model.Filter) RestListRequest(org.entando.entando.web.common.model.RestListRequest) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Test(org.junit.Test)

Example 24 with FieldSearchFilter

use of com.agiletec.aps.system.common.FieldSearchFilter in project entando-core by entando.

the class RestListRequestTest method should_default_direction.

@Test
public void should_default_direction() {
    RestListRequest request = new RestListRequest();
    request.setPage(1);
    request.setPageSize(0);
    request.setSort("name");
    request.setDirection("wrong");
    // filters
    List<FieldSearchFilter> filters = request.buildFieldSearchFilters();
    assertThat(filters.size(), is(1));
    assertThat(filters.get(0).getOrder(), is(FieldSearchFilter.Order.ASC));
}
Also used : RestListRequest(org.entando.entando.web.common.model.RestListRequest) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Test(org.junit.Test)

Example 25 with FieldSearchFilter

use of com.agiletec.aps.system.common.FieldSearchFilter in project entando-core by entando.

the class ActionLogDAO method createFilters.

protected FieldSearchFilter[] createFilters(IActionLogRecordSearchBean searchBean) {
    FieldSearchFilter[] filters = new FieldSearchFilter[0];
    if (null != searchBean) {
        String username = searchBean.getUsername();
        if (null != username && username.trim().length() > 0) {
            FieldSearchFilter filter = new FieldSearchFilter("username", this.extractSearchValues(username), true);
            filters = super.addFilter(filters, filter);
        }
        String namespace = searchBean.getNamespace();
        if (null != namespace && namespace.trim().length() > 0) {
            FieldSearchFilter filter = new FieldSearchFilter("namespace", this.extractSearchValues(namespace), true);
            filters = super.addFilter(filters, filter);
        }
        String actionName = searchBean.getActionName();
        if (null != actionName && actionName.trim().length() > 0) {
            FieldSearchFilter filter = new FieldSearchFilter("actionname", this.extractSearchValues(actionName), true);
            filters = super.addFilter(filters, filter);
        }
        String parameters = searchBean.getParams();
        if (null != parameters && parameters.trim().length() > 0) {
            FieldSearchFilter filter = new FieldSearchFilter("parameters", this.extractSearchValues(parameters), true);
            filters = super.addFilter(filters, filter);
        }
        Date startCreation = searchBean.getStartCreation();
        Date endCreation = searchBean.getEndCreation();
        if (null != startCreation || null != endCreation) {
            Timestamp tsStart = (null != startCreation) ? new Timestamp(startCreation.getTime()) : null;
            Timestamp tsEnd = (null != endCreation) ? new Timestamp(endCreation.getTime()) : null;
            FieldSearchFilter filter = new FieldSearchFilter("actiondate", tsStart, tsEnd);
            filter.setOrder(FieldSearchFilter.Order.DESC);
            filters = super.addFilter(filters, filter);
        }
        Date startUpdate = searchBean.getStartUpdate();
        Date endUpdate = searchBean.getEndUpdate();
        if (null != startUpdate || null != endUpdate) {
            Timestamp tsStart = (null != startUpdate) ? new Timestamp(startUpdate.getTime()) : null;
            Timestamp tsEnd = (null != endUpdate) ? new Timestamp(endUpdate.getTime()) : null;
            FieldSearchFilter filter = new FieldSearchFilter("updatedate", tsStart, tsEnd);
            filter.setOrder(FieldSearchFilter.Order.DESC);
            filters = super.addFilter(filters, filter);
        }
        if (searchBean instanceof IActivityStreamSearchBean) {
            FieldSearchFilter filter = new FieldSearchFilter("activitystreaminfo");
            filters = super.addFilter(filters, filter);
        }
    }
    return filters;
}
Also used : IActivityStreamSearchBean(org.entando.entando.aps.system.services.actionlog.model.IActivityStreamSearchBean) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Aggregations

FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)32 ArrayList (java.util.ArrayList)15 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)13 RestListRequest (org.entando.entando.web.common.model.RestListRequest)10 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)5 List (java.util.List)5 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)5 RestServerError (org.entando.entando.aps.system.exception.RestServerError)5 IDtoBuilder (org.entando.entando.aps.system.services.IDtoBuilder)5 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)4 Map (java.util.Map)3 GuiFragment (org.entando.entando.aps.system.services.guifragment.GuiFragment)3 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)3 Filter (org.entando.entando.web.common.model.Filter)3 Test (org.junit.Test)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 GroupUtilizer (com.agiletec.aps.system.services.group.GroupUtilizer)2