Search in sources :

Example 6 with PagedMetadata

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;
}
Also used : Logger(org.slf4j.Logger) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ArrayList(java.util.ArrayList) IPage(com.agiletec.aps.system.services.page.IPage) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) List(java.util.List) RestListRequest(org.entando.entando.web.common.model.RestListRequest) RestServerError(org.entando.entando.aps.system.exception.RestServerError) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) GuiFragmentValidator(org.entando.entando.web.guifragment.validator.GuiFragmentValidator) DataModelDto(org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto) Map(java.util.Map) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) DataObjectModelRequest(org.entando.entando.web.dataobjectmodel.model.DataObjectModelRequest) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) DataModelDto(org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto) ArrayList(java.util.ArrayList) RestServerError(org.entando.entando.aps.system.exception.RestServerError) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter)

Example 7 with 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;
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) Group(com.agiletec.aps.system.services.group.Group) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)

Example 8 with 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);
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) Group(com.agiletec.aps.system.services.group.Group) ArrayList(java.util.ArrayList) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IGroupManager(com.agiletec.aps.system.services.group.IGroupManager) Map(java.util.Map) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) GroupRequest(org.entando.entando.web.group.model.GroupRequest) GroupValidator(org.entando.entando.web.group.validator.GroupValidator) Logger(org.slf4j.Logger) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto) BeansException(org.springframework.beans.BeansException) ApplicationContext(org.springframework.context.ApplicationContext) List(java.util.List) RestListRequest(org.entando.entando.web.common.model.RestListRequest) GroupUtilizer(com.agiletec.aps.system.services.group.GroupUtilizer) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) Optional(java.util.Optional) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) ApplicationContextAware(org.springframework.context.ApplicationContextAware) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) Group(com.agiletec.aps.system.services.group.Group) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ArrayList(java.util.ArrayList) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter)

Example 9 with PagedMetadata

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;
}
Also used : PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) EntityTypeShortDto(org.entando.entando.aps.system.services.entity.model.EntityTypeShortDto) ArrayList(java.util.ArrayList) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) BeanComparator(org.apache.commons.beanutils.BeanComparator) IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity)

Example 10 with 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;
}
Also used : FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Filter(org.entando.entando.web.common.model.Filter) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) LabelDto(org.entando.entando.aps.system.services.label.model.LabelDto) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) ApsProperties(com.agiletec.aps.util.ApsProperties)

Aggregations

PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)16 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)15 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)8 ArrayList (java.util.ArrayList)8 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)8 RestListRequest (org.entando.entando.web.common.model.RestListRequest)7 RestServerError (org.entando.entando.aps.system.exception.RestServerError)6 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)5 List (java.util.List)5 IDtoBuilder (org.entando.entando.aps.system.services.IDtoBuilder)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 UserDetails (com.agiletec.aps.system.services.user.UserDetails)4 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)4 Map (java.util.Map)3 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Group (com.agiletec.aps.system.services.group.Group)2 GroupUtilizer (com.agiletec.aps.system.services.group.GroupUtilizer)2 IGroupManager (com.agiletec.aps.system.services.group.IGroupManager)2