Search in sources :

Example 26 with Filter

use of org.entando.entando.web.common.model.Filter in project entando-core by entando.

the class GroupServiceIntegrationTest method testGetGroups_filter.

@Test
public void testGetGroups_filter() throws JsonProcessingException {
    RestListRequest restListRequest = new RestListRequest();
    restListRequest.addFilter(new Filter("groupname", "fr"));
    PagedMetadata<GroupDto> res = this.groupService.getGroups(restListRequest);
    assertThat(res.getPage(), is(1));
    assertThat(res.getPageSize(), is(100));
    assertThat(res.getLastPage(), is(1));
    assertThat(res.getTotalItems(), is(1));
}
Also used : Filter(org.entando.entando.web.common.model.Filter) RestListRequest(org.entando.entando.web.common.model.RestListRequest) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto) Test(org.junit.Test)

Example 27 with Filter

use of org.entando.entando.web.common.model.Filter in project entando-core by entando.

the class LanguageServiceTest method shouldFilterByCode.

@Test
public void shouldFilterByCode() {
    RestListRequest requestList = new RestListRequest();
    Filter filter = new Filter();
    filter.setAttribute("code");
    filter.setValue("it");
    requestList.addFilter(filter);
    PagedMetadata<LanguageDto> result = languageService.getLanguages(requestList);
    assertThat(result.getBody()).hasSize(1);
    assertThat(result.getBody().get(0).getCode()).isEqualTo("it");
}
Also used : Filter(org.entando.entando.web.common.model.Filter) RestListRequest(org.entando.entando.web.common.model.RestListRequest) Test(org.junit.Test)

Example 28 with Filter

use of org.entando.entando.web.common.model.Filter in project entando-core by entando.

the class LanguageServiceTest method shouldFilterByDescription.

@Test
public void shouldFilterByDescription() {
    RestListRequest requestList = new RestListRequest();
    Filter filter = new Filter();
    filter.setAttribute("description");
    filter.setValue("English");
    requestList.addFilter(filter);
    PagedMetadata<LanguageDto> result = languageService.getLanguages(requestList);
    assertThat(result.getBody()).hasSize(1);
    assertThat(result.getBody().get(0).getCode()).isEqualTo("en");
}
Also used : Filter(org.entando.entando.web.common.model.Filter) RestListRequest(org.entando.entando.web.common.model.RestListRequest) Test(org.junit.Test)

Example 29 with Filter

use of org.entando.entando.web.common.model.Filter in project entando-core by entando.

the class ActivityStreamService method buildSearchBean.

protected ActionLogRecordSearchBean buildSearchBean(RestListRequest requestList, UserDetails userDetails) {
    ActionLogRecordApiSearchBean searchBean = new ActionLogRecordApiSearchBean();
    // groups
    if (null != requestList.getSort()) {
        String direction = requestList.getDirection();
        direction = (null != direction && (direction.equalsIgnoreCase("ASC") || direction.equalsIgnoreCase("DESC"))) ? direction : "DESC";
        searchBean.setOrderBy(ActionLogRecordDto.getEntityFieldName(requestList.getSort()));
        searchBean.setDirection(direction);
    }
    int offset = 0;
    int page = requestList.getPage() - 1;
    if (null != requestList.getPage() && requestList.getPage() != 0) {
        offset = requestList.getPageSize() * page;
    }
    searchBean.setOffset(offset);
    searchBean.setPageSize(requestList.getPageSize());
    List<Group> userGroups = this.getAuthorizationManager().getUserGroups(userDetails);
    searchBean.setUserGroupCodes(userGroups.stream().map(i -> i.getAuthority()).collect(Collectors.toList()));
    if (null == requestList.getFilters() || requestList.getFilters().length == 0) {
        return searchBean;
    }
    for (Filter f : requestList.getFilters()) {
        // creation date range
        if (f.getAttributeName().equals(KEY_FILTER_CREATION)) {
            DateRange range = new DateRange(f.getValue());
            searchBean.setStartCreation(range.getStart());
            searchBean.setEndCreation(range.getEnd());
        }
        // update date range
        if (f.getAttributeName().equals(KEY_FILTER_UPDATE)) {
            DateRange range = new DateRange(f.getValue());
            searchBean.setStartCreation(range.getStart());
            searchBean.setEndCreation(range.getEnd());
        }
        if (f.getAttributeName().equals(KEY_FILTER_USERNAME)) {
            searchBean.setUsername(f.getValue());
        }
        if (f.getAttributeName().equals(KEY_FILTER_NS)) {
            searchBean.setNamespace(f.getValue());
        }
        if (f.getAttributeName().equals(KEY_FILTER_ACTIONNAME)) {
            searchBean.setActionName(f.getValue());
        }
        if (f.getAttributeName().equals(KEY_FILTER_PARAMS)) {
            searchBean.setParams(f.getValue());
        }
    }
    return searchBean;
}
Also used : Group(com.agiletec.aps.system.services.group.Group) DateRange(org.entando.entando.web.common.model.DateRange) Filter(org.entando.entando.web.common.model.Filter) ActionLogRecordApiSearchBean(org.entando.entando.aps.system.services.actionlog.model.ActionLogRecordApiSearchBean)

Example 30 with Filter

use of org.entando.entando.web.common.model.Filter in project entando-core by entando.

the class TestPageModelManager method testSearch_with_page_filter.

public void testSearch_with_page_filter() throws ApsSystemException {
    RestListRequest restListRequest = new RestListRequest();
    restListRequest.setPageSize(2);
    restListRequest.setPage(1);
    List<FieldSearchFilter> filters = restListRequest.buildFieldSearchFilters();
    SearcherDaoPaginatedResult<PageModel> result = this._pageModelManager.searchPageModels(filters);
    assertThat(result.getCount(), is(3));
    assertThat(result.getList().size(), is(2));
    restListRequest.addFilter(new Filter("descr", "modello"));
    result = this._pageModelManager.searchPageModels(restListRequest.buildFieldSearchFilters());
    assertThat(result.getCount(), is(2));
    assertThat(result.getList().size(), is(2));
    restListRequest.setPage(0);
    result = this._pageModelManager.searchPageModels(restListRequest.buildFieldSearchFilters());
    assertThat(result.getCount(), is(2));
    assertThat(result.getList().size(), is(2));
}
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)

Aggregations

Filter (org.entando.entando.web.common.model.Filter)38 RestListRequest (org.entando.entando.web.common.model.RestListRequest)30 Test (org.junit.Test)26 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)16 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)9 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)8 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)5 UserDetails (com.agiletec.aps.system.services.user.UserDetails)4 ResultActions (org.springframework.test.web.servlet.ResultActions)4 Permission (com.agiletec.aps.system.services.role.Permission)3 Role (com.agiletec.aps.system.services.role.Role)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)3 RestServerError (org.entando.entando.aps.system.exception.RestServerError)3 GroupDto (org.entando.entando.aps.system.services.group.model.GroupDto)3 LabelDto (org.entando.entando.aps.system.services.label.model.LabelDto)3 RoleDto (org.entando.entando.aps.system.services.role.model.RoleDto)3 WidgetDto (org.entando.entando.aps.system.services.widgettype.model.WidgetDto)3 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)3