Search in sources :

Example 1 with RestListRequest

use of org.entando.entando.web.common.model.RestListRequest 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);
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) ArrayList(java.util.ArrayList) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) PageModelValidator(org.entando.entando.web.pagemodel.validator.PageModelValidator) RestServerError(org.entando.entando.aps.system.exception.RestServerError) Frame(com.agiletec.aps.system.services.pagemodel.Frame) Service(org.springframework.stereotype.Service) Map(java.util.Map) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) PageModelUtilizer(com.agiletec.aps.system.services.pagemodel.PageModelUtilizer) Logger(org.slf4j.Logger) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) BeansException(org.springframework.beans.BeansException) Collectors(java.util.stream.Collectors) PageModelFrameReq(org.entando.entando.web.pagemodel.model.PageModelFrameReq) PageModelRequest(org.entando.entando.web.pagemodel.model.PageModelRequest) ApplicationContext(org.springframework.context.ApplicationContext) List(java.util.List) RestListRequest(org.entando.entando.web.common.model.RestListRequest) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) IPageModelManager(com.agiletec.aps.system.services.pagemodel.IPageModelManager) PageModelDto(org.entando.entando.aps.system.services.pagemodel.model.PageModelDto) ApplicationContextAware(org.springframework.context.ApplicationContextAware) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ArrayList(java.util.ArrayList) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) PageModelDto(org.entando.entando.aps.system.services.pagemodel.model.PageModelDto)

Example 2 with RestListRequest

use of org.entando.entando.web.common.model.RestListRequest 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);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) IAuthenticationProviderManager(com.agiletec.aps.system.services.user.IAuthenticationProviderManager) UserAuthoritiesRequest(org.entando.entando.web.user.model.UserAuthoritiesRequest) Logger(org.slf4j.Logger) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) UserDto(org.entando.entando.aps.system.services.user.model.UserDto) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) UserAuthorityDto(org.entando.entando.aps.system.services.user.model.UserAuthorityDto) UserRequest(org.entando.entando.web.user.model.UserRequest) UserPasswordRequest(org.entando.entando.web.user.model.UserPasswordRequest) ArrayList(java.util.ArrayList) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) List(java.util.List) User(com.agiletec.aps.system.services.user.User) 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) IUserManager(com.agiletec.aps.system.services.user.IUserManager) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) IAuthorizationManager(com.agiletec.aps.system.services.authorization.IAuthorizationManager) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) UserDto(org.entando.entando.aps.system.services.user.model.UserDto) ArrayList(java.util.ArrayList) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) UserDetails(com.agiletec.aps.system.services.user.UserDetails) RestServerError(org.entando.entando.aps.system.exception.RestServerError) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter)

Example 3 with RestListRequest

use of org.entando.entando.web.common.model.RestListRequest 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);
    }
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) LoggerFactory(org.slf4j.LoggerFactory) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ApsProperties(com.agiletec.aps.util.ApsProperties) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) IPage(com.agiletec.aps.system.services.page.IPage) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IGroupManager(com.agiletec.aps.system.services.group.IGroupManager) IPageManager(com.agiletec.aps.system.services.page.IPageManager) Service(org.springframework.stereotype.Service) IManager(com.agiletec.aps.system.common.IManager) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) GroupServiceUtilizer(org.entando.entando.aps.system.services.group.GroupServiceUtilizer) WidgetRequest(org.entando.entando.web.widget.model.WidgetRequest) Logger(org.slf4j.Logger) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) IGuiFragmentManager(org.entando.entando.aps.system.services.guifragment.IGuiFragmentManager) 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) WidgetValidator(org.entando.entando.web.widget.validator.WidgetValidator) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ArrayList(java.util.ArrayList) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto)

Example 4 with RestListRequest

use of org.entando.entando.web.common.model.RestListRequest 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 5 with RestListRequest

use of org.entando.entando.web.common.model.RestListRequest 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)

Aggregations

RestListRequest (org.entando.entando.web.common.model.RestListRequest)26 Test (org.junit.Test)19 UserDetails (com.agiletec.aps.system.services.user.UserDetails)11 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)10 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)9 Filter (org.entando.entando.web.common.model.Filter)9 ResultActions (org.springframework.test.web.servlet.ResultActions)9 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)7 ArrayList (java.util.ArrayList)7 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)7 GroupDto (org.entando.entando.aps.system.services.group.model.GroupDto)6 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)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 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)4 Map (java.util.Map)3