use of com.agiletec.aps.system.common.FieldSearchFilter in project entando-core by entando.
the class WidgetTypeManager method getWidgetTypes.
@Override
public SearcherDaoPaginatedResult<WidgetType> getWidgetTypes(List<FieldSearchFilter> fieldSearchFilters) throws ApsSystemException {
SearcherDaoPaginatedResult<WidgetType> pagedResult = null;
try {
List<WidgetType> widgets = new ArrayList<>();
FieldSearchFilter[] array = null;
if (null != fieldSearchFilters) {
array = fieldSearchFilters.toArray(new FieldSearchFilter[fieldSearchFilters.size()]);
}
int count = this.getWidgetTypeDAO().countWidgetTypes(array);
List<String> widgetCodes = this.getWidgetTypeDAO().searchWidgetTypes(array);
for (String widgetCode : widgetCodes) {
widgets.add(this.getWidgetType(widgetCode));
}
pagedResult = new SearcherDaoPaginatedResult<>(count, widgets);
} catch (Throwable t) {
logger.error("Error searching groups", t);
throw new ApsSystemException("Error searching groups", t);
}
return pagedResult;
}
use of com.agiletec.aps.system.common.FieldSearchFilter in project entando-core by entando.
the class TestGroupManager method test_search_by_filter.
@SuppressWarnings("rawtypes")
public void test_search_by_filter() throws ApsSystemException {
FieldSearchFilter[] fieldSearchFilters = new FieldSearchFilter[0];
FieldSearchFilter groupNameFilter = new FieldSearchFilter<>("groupname", "s", true, LikeOptionType.COMPLETE);
fieldSearchFilters = ArrayUtils.add(fieldSearchFilters, groupNameFilter);
SearcherDaoPaginatedResult<Group> result = this._groupManager.getGroups(fieldSearchFilters);
assertThat(result.getCount(), is(3));
assertThat(result.getList().size(), is(3));
fieldSearchFilters = new FieldSearchFilter[0];
FieldSearchFilter limitFilter = new FieldSearchFilter<>(2, 0);
fieldSearchFilters = ArrayUtils.add(fieldSearchFilters, groupNameFilter);
fieldSearchFilters = ArrayUtils.add(fieldSearchFilters, limitFilter);
result = this._groupManager.getGroups(fieldSearchFilters);
assertThat(result.getCount(), is(3));
assertThat(result.getList().size(), is(2));
fieldSearchFilters = new FieldSearchFilter[0];
limitFilter = new FieldSearchFilter<>(2, 2);
fieldSearchFilters = ArrayUtils.add(fieldSearchFilters, limitFilter);
fieldSearchFilters = ArrayUtils.add(fieldSearchFilters, groupNameFilter);
result = this._groupManager.getGroups(fieldSearchFilters);
assertThat(result.getCount(), is(3));
assertThat(result.getList().size(), is(1));
}
use of com.agiletec.aps.system.common.FieldSearchFilter in project entando-core by entando.
the class PageModelService method getPageModels.
@Override
public PagedMetadata<PageModelDto> getPageModels(RestListRequest restListReq) {
try {
// transforms the filters by overriding the key specified in the request with the correct one known by the dto
List<FieldSearchFilter> filters = new ArrayList<FieldSearchFilter>(restListReq.buildFieldSearchFilters());
filters.stream().filter(i -> i.getKey() != null).forEach(i -> i.setKey(PageModelDto.getEntityFieldName(i.getKey())));
SearcherDaoPaginatedResult<PageModel> pageModels = this.getPageModelManager().searchPageModels(filters);
List<PageModelDto> dtoList = null;
if (null != pageModels) {
dtoList = this.getDtoBuilder().convert(pageModels.getList());
}
PagedMetadata<PageModelDto> pagedMetadata = new PagedMetadata<>(restListReq, pageModels);
pagedMetadata.setBody(dtoList);
return pagedMetadata;
} catch (Throwable t) {
logger.error("error in search pageModels", t);
throw new RestServerError("error in search pageModels", t);
}
}
use of com.agiletec.aps.system.common.FieldSearchFilter in project entando-core by entando.
the class UserService method getUsers.
@Override
public PagedMetadata<UserDto> getUsers(RestListRequest requestList) {
try {
// transforms the filters by overriding the key specified in the request with the correct one known by the dto
List<FieldSearchFilter> filters = new ArrayList<FieldSearchFilter>(requestList.buildFieldSearchFilters());
filters.stream().filter(i -> ((i.getKey() != null) && (UserDto.getEntityFieldName(i.getKey()) != null))).forEach(i -> i.setKey(UserDto.getEntityFieldName(i.getKey())));
List<UserDetails> users = null;
if (filters.size() > 0) {
String text = (String) filters.get(0).getValue();
users = this.getUserManager().searchUsers(text);
} else {
users = this.getUserManager().getUsers();
}
List<UserDto> dtoList = dtoBuilder.convert(users);
SearcherDaoPaginatedResult<UserDetails> result = new SearcherDaoPaginatedResult<>(users.size(), users);
PagedMetadata<UserDto> pagedMetadata = new PagedMetadata<>(requestList, result);
pagedMetadata.setBody(dtoList);
return pagedMetadata;
} catch (Throwable t) {
logger.error("error in search groups", t);
throw new RestServerError("error in search groups", t);
}
}
use of com.agiletec.aps.system.common.FieldSearchFilter in project entando-core by entando.
the class WidgetService method getWidgets.
@SuppressWarnings("rawtypes")
@Override
public PagedMetadata<WidgetDto> getWidgets(RestListRequest restListReq) {
try {
// transforms the filters by overriding the key specified in the request with the correct one known by the dto
List<FieldSearchFilter> filters = new ArrayList<>(restListReq.buildFieldSearchFilters());
filters.stream().filter(i -> i.getKey() != null).forEach(i -> i.setKey(WidgetDto.getEntityFieldName(i.getKey())));
SearcherDaoPaginatedResult<WidgetType> widgets = this.getWidgetManager().getWidgetTypes(filters);
List<WidgetDto> dtoList = dtoBuilder.convert(widgets.getList());
for (WidgetDto widgetDto : dtoList) {
this.addFragments(widgetDto);
}
PagedMetadata<WidgetDto> pagedMetadata = new PagedMetadata<>(restListReq, widgets);
pagedMetadata.setBody(dtoList);
return pagedMetadata;
} catch (Throwable t) {
logger.error("error in get widgets", t);
throw new RestServerError("error in get widgets", t);
}
}
Aggregations