use of org.entando.entando.web.common.model.PagedMetadata in project entando-core by entando.
the class DataObjectModelService method getDataObjectModels.
@Override
public PagedMetadata<DataModelDto> getDataObjectModels(RestListRequest restListReq) {
PagedMetadata<DataModelDto> pagedMetadata = null;
try {
List<FieldSearchFilter> filters = new ArrayList<>(restListReq.buildFieldSearchFilters());
// transforms the filters by overriding the key specified in the request with the correct one known by the dto
filters.stream().filter(searchFilter -> searchFilter.getKey() != null).forEach(searchFilter -> {
searchFilter.setKey(DataModelDto.getEntityFieldName(searchFilter.getKey()));
if (searchFilter.getKey().equals("modelid") && null != searchFilter.getValue()) {
String stringValue = searchFilter.getValue().toString();
Long value = Long.parseLong(stringValue);
searchFilter = new FieldSearchFilter("modelid", value, true);
}
});
SearcherDaoPaginatedResult<DataObjectModel> models = this.getDataObjectModelManager().getDataObjectModels(filters);
List<DataModelDto> dtoList = this.getDtoBuilder().convert(models.getList());
pagedMetadata = new PagedMetadata<>(restListReq, models);
pagedMetadata.setBody(dtoList);
} catch (Throwable t) {
logger.error("error in search data models", t);
throw new RestServerError("error in search data models", t);
}
return pagedMetadata;
}
use of org.entando.entando.web.common.model.PagedMetadata in project entando-core by entando.
the class GroupService method getGroupReferences.
@Override
public PagedMetadata<?> getGroupReferences(String groupCode, String managerName, RestListRequest restRequest) {
Group group = this.getGroupManager().getGroup(groupCode);
if (null == group) {
logger.warn("no group found with code {}", groupCode);
throw new RestRourceNotFoundException(GroupValidator.ERRCODE_GROUP_NOT_FOUND, "group", groupCode);
}
GroupServiceUtilizer<?> utilizer = this.getGroupServiceUtilizer(managerName);
if (null == utilizer) {
logger.warn("no references found for {}", managerName);
throw new RestRourceNotFoundException(GroupValidator.ERRCODE_GROUP_REFERENCES, "reference", managerName);
}
List<?> dtoList = utilizer.getGroupUtilizer(groupCode);
List<?> subList = restRequest.getSublist(dtoList);
SearcherDaoPaginatedResult<?> pagedResult = new SearcherDaoPaginatedResult(dtoList.size(), subList);
PagedMetadata<Object> pagedMetadata = new PagedMetadata<>(restRequest, pagedResult);
pagedMetadata.setBody((List<Object>) subList);
return pagedMetadata;
}
use of org.entando.entando.web.common.model.PagedMetadata in project entando-core by entando.
the class GroupService method getGroups.
@SuppressWarnings("rawtypes")
@Override
public PagedMetadata<GroupDto> getGroups(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(GroupDto.getEntityFieldName(i.getKey())));
SearcherDaoPaginatedResult<Group> groups = this.getGroupManager().getGroups(filters);
List<GroupDto> dtoList = dtoBuilder.convert(groups.getList());
PagedMetadata<GroupDto> pagedMetadata = new PagedMetadata<>(restListReq, groups);
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 org.entando.entando.web.common.model.PagedMetadata in project entando-core by entando.
the class AbstractEntityService method getShortEntityTypes.
protected PagedMetadata<EntityTypeShortDto> getShortEntityTypes(String entityManagerCode, RestListRequest requestList) {
IEntityManager entityManager = this.extractEntityManager(entityManagerCode);
List<IApsEntity> entityTypes = new ArrayList<>(entityManager.getEntityPrototypes().values());
Map<String, String> fieldMapping = this.getEntityTypeFieldNameMapping();
entityTypes.stream().filter(i -> this.filterObjects(i, requestList.getFilter(), fieldMapping));
Collections.sort(entityTypes, new BeanComparator(this.getFieldName(requestList.getSort(), fieldMapping)));
if (!RestListRequest.DIRECTION_VALUE_DEFAULT.equals(requestList.getDirection())) {
Collections.reverse(entityTypes);
}
List<IApsEntity> sublist = requestList.getSublist(entityTypes);
SearcherDaoPaginatedResult<IApsEntity> result = new SearcherDaoPaginatedResult(entityTypes.size(), sublist);
PagedMetadata<EntityTypeShortDto> pagedMetadata = new PagedMetadata<>(requestList, result);
List<EntityTypeShortDto> body = this.getEntityTypeShortDtoBuilder().convert(sublist);
for (EntityTypeShortDto entityTypeShortDto : body) {
String code = entityTypeShortDto.getCode();
entityTypeShortDto.setStatus(String.valueOf(entityManager.getStatus(code)));
}
pagedMetadata.setBody(body);
return pagedMetadata;
}
use of org.entando.entando.web.common.model.PagedMetadata in project entando-core by entando.
the class LabelService method getLabelGroups.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public PagedMetadata<LabelDto> getLabelGroups(RestListRequest restRequest) {
Map<String, ApsProperties> result = this.i18nManager.getLabelGroups();
List<LabelDto> dtoList = this.getDtoBuilder().convert(result);
if (restRequest.getDirection().equals(FieldSearchFilter.DESC_ORDER)) {
dtoList = dtoList.stream().sorted(Comparator.comparing(LabelDto::getKey).reversed()).collect(Collectors.toList());
} else {
dtoList = dtoList.stream().sorted(Comparator.comparing(LabelDto::getKey)).collect(Collectors.toList());
}
if (null != restRequest.getFilters()) {
for (Filter f : restRequest.getFilters()) {
if (f.getAttributeName().equals(LABEL_KEY_FILTER_KEY)) {
dtoList = dtoList.stream().filter(i -> i.getKey().toLowerCase().contains(f.getValue().toLowerCase())).collect(Collectors.toList());
}
if (f.getAttributeName().equals(LABEL_KEY_FILTER_VALUE)) {
dtoList = dtoList.stream().filter(i -> i.getTitles().values().stream().filter(k -> k.contains(f.getValue())).collect(Collectors.toList()).size() > 0).collect(Collectors.toList());
}
}
}
List<?> subList = restRequest.getSublist(dtoList);
SearcherDaoPaginatedResult<LabelDto> resultx = new SearcherDaoPaginatedResult(dtoList.size(), subList);
PagedMetadata<LabelDto> pagedMetadata = new PagedMetadata<>(restRequest, resultx);
pagedMetadata.setBody((List<LabelDto>) subList);
return pagedMetadata;
}
Aggregations