Ejemplo n.º 1
0
        public PagedResultList <FeedbackContract> GetFeedbackList(int?start, int?count, FeedbackSortEnumContract sort,
                                                                  SortDirectionEnumContract sortDirection, IList <FeedbackCategoryEnumContract> filterCategories, PortalTypeContract portalTypeContract)
        {
            var startValue           = PagingHelper.GetStart(start);
            var countValue           = PagingHelper.GetCount(count);
            var sortValue            = m_mapper.Map <FeedbackSortEnum>(sort);
            var filterCategoryValues = m_mapper.Map <List <FeedbackCategoryEnum> >(filterCategories);
            var portalType           = m_mapper.Map <PortalTypeEnum>(portalTypeContract);

            var result = m_portalRepository.InvokeUnitOfWork(repository =>
            {
                var dbFeedbacks = repository.GetFeedbackList(startValue, countValue, sortValue, sortDirection, filterCategoryValues, portalType);

                var headwordFeedbackIds = dbFeedbacks.List.Where(x => x.FeedbackType == FeedbackType.Headword)
                                          .Select(x => x.Id);
                repository.FetchHeadwordFeedbacks(headwordFeedbackIds);

                return(dbFeedbacks);
            });

            return(new PagedResultList <FeedbackContract>
            {
                List = m_userDetailManager.AddUserDetails(m_mapper.Map <List <FeedbackContract> >(result.List)),
                TotalCount = result.Count,
            });
        }
Ejemplo n.º 2
0
        public List <PageResultContextContract> SearchHitsWithPageContext(long projectId, SearchHitsRequestContract request)
        {
            m_authorizationManager.AuthorizeBook(projectId, PermissionFlag.ShowPublished);

            var fulltextConditions = ExtractFulltextConditions(request.ConditionConjunction);

            if (fulltextConditions.Count == 0)
            {
                throw new MainServiceException(MainServiceErrorCode.NoSupportedSearch,
                                               "No supported search criteria was specified"
                                               );
            }

            var projectIdentification = m_bookRepository.InvokeUnitOfWork(x => x.GetProjectIdentification(projectId));

            var fulltextStorage = m_fulltextStorageProvider.GetFulltextStorage(projectIdentification.ProjectType);
            var start           = PagingHelper.GetStart(request.Start);
            var count           = PagingHelper.GetCount(request.Count);
            var fulltextResult  = fulltextStorage.SearchHitsWithPageContext(start, count, request.ContextLength, fulltextConditions, projectIdentification);

            switch (fulltextResult.SearchResultType)
            {
            case PageSearchResultType.TextId:
                return(ConvertSearchResultsByStandardId(fulltextResult.ResultList));

            case PageSearchResultType.TextExternalId:
                return(ConvertSearchResultsByExternalId(projectId, fulltextResult.ResultList));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 3
0
        public PagedResultList <RoleContract> GetRoleList(int?start, int?count, string filterByName)
        {
            var startValue = PagingHelper.GetStart(start);
            var countValue = PagingHelper.GetCount(count);

            var client = m_communicationProvider.GetAuthRoleApiClient();

            var authResult = client.GetRoleListAsync(startValue, countValue, filterByName).GetAwaiter().GetResult();

            var resultList = new List <RoleContract>();

            foreach (var authRoleContract in authResult.Items)
            {
                var synchronizeRoleWork = new SynchronizeRoleWork(m_permissionRepository, m_communicationProvider, authRoleContract);
                synchronizeRoleWork.Execute();

                var resultRoleContract = m_mapper.Map <RoleContract>(authRoleContract);
                resultRoleContract.Id = synchronizeRoleWork.LocalId;

                resultList.Add(resultRoleContract);
            }

            return(new PagedResultList <RoleContract>
            {
                List = resultList,
                TotalCount = authResult.ItemsCount,
            });
        }
Ejemplo n.º 4
0
        public PagedResultList <SnapshotAggregatedInfoContract> GetPublishedSnapshotWithAggregatedInfo(long projectId, int?start, int?count, string filterByComment)
        {
            var startValue = PagingHelper.GetStart(start);
            var countValue = PagingHelper.GetCount(count);

            var publishedSnapshots = m_snapshotRepository.InvokeUnitOfWork(x => x.GetPublishedSnapshots(projectId, startValue, countValue, filterByComment));
            var snapshotInfo       = m_snapshotRepository.InvokeUnitOfWork(x => x.GetSnapshotsResourcesCount(publishedSnapshots.List.Select(s => s.Id).ToArray()));

            var snapshotContracts = m_mapper.Map <List <SnapshotAggregatedInfoContract> >(publishedSnapshots.List);

            foreach (var snapshotContract in snapshotContracts)
            {
                var dbSnapshot = publishedSnapshots.List.FirstOrDefault(x => x.Id == snapshotContract.Id);
                if (dbSnapshot != null)
                {
                    snapshotContract.Author        = m_userDetailManager.GetUserFullName(dbSnapshot.CreatedByUser);
                    snapshotContract.ResourcesInfo = new List <SnapshotResourcesInfoContract>();

                    foreach (var aggregatedInfo in snapshotInfo.Where(x => x.Id == snapshotContract.Id))
                    {
                        snapshotContract.ResourcesInfo.Add(new SnapshotResourcesInfoContract
                        {
                            ResourceType   = m_mapper.Map <ResourceTypeEnumContract>(aggregatedInfo.Type),
                            PublishedCount = aggregatedInfo.ResourcesCount
                        });
                    }
                }
            }

            return(new PagedResultList <SnapshotAggregatedInfoContract>
            {
                List = snapshotContracts,
                TotalCount = publishedSnapshots.Count
            });
        }
Ejemplo n.º 5
0
        public List <SearchResultContract> SearchByCriteria(AdvancedSearchRequestContract request, ProjectTypeContract projectType)
        {
            m_authorizationManager.AddAuthorizationCriteria(request.ConditionConjunction);

            var processedCriterias   = m_metadataSearchCriteriaProcessor.ProcessSearchCriterias(request.ConditionConjunction);
            var nonMetadataCriterias = processedCriterias.NonMetadataCriterias;
            var mainProjectTypeEnum  = m_mapper.Map <ProjectTypeEnum>(projectType);
            var projectTypeEnums     = new List <ProjectTypeEnum> {
                mainProjectTypeEnum
            };

            if (request.Parameters != null && request.Parameters.IncludeAdditionalProjectTypes)
            {
                projectTypeEnums.AddRange(request.Parameters.AdditionalProjectTypes.Select(x => m_mapper.Map <ProjectTypeEnum>(x)));
            }

            var queryCreator = new SearchCriteriaQueryCreator(processedCriterias.ConjunctionQuery, processedCriterias.MetadataParameters, projectTypeEnums)
            {
                Sort          = request.Sort,
                SortDirection = request.SortDirection,
                Start         = PagingHelper.GetStart(request.Start),
                Count         = PagingHelper.GetCountForProject(request.Count)
            };

            if (processedCriterias.NonMetadataCriterias.Count > 0)
            {
                // Search in fulltext DB

                // 1) search in metadata
                var projectIdentificatorList = m_bookRepository.InvokeUnitOfWork(x => x.SearchProjectIdByCriteriaQuery(queryCreator));
                if (projectIdentificatorList.Count == 0)
                {
                    return(new List <SearchResultContract>());
                }

                // 2) search in fulltext
                var fulltextStorage          = m_fulltextStorageProvider.GetFulltextStorage(projectType);
                var fulltextSearchResultData = fulltextStorage.SearchProjectIdByCriteria(queryCreator.GetStart(), queryCreator.GetCount(), request.Sort, request.SortDirection, nonMetadataCriterias, projectIdentificatorList);

                // 3) load paged result
                var termCriteria = CreateTermConditionCreatorOrDefault(request, processedCriterias);
                var searchByCriteriaFulltextResultWork = new SearchByCriteriaFulltextResultWork(m_metadataRepository, m_bookRepository, fulltextSearchResultData, termCriteria, mainProjectTypeEnum);
                var dbResult = searchByCriteriaFulltextResultWork.Execute();

                var resultList = MapToSearchResult(dbResult, searchByCriteriaFulltextResultWork.PageCounts, searchByCriteriaFulltextResultWork.TermHits);
                return(resultList);
            }
            else
            {
                // Search in relational DB

                var termCriteria         = CreateTermConditionCreatorOrDefault(request, processedCriterias);
                var searchByCriteriaWork = new SearchByCriteriaWork(m_metadataRepository, m_bookRepository, queryCreator, termCriteria);
                var dbResult             = searchByCriteriaWork.Execute();

                var resultList = MapToSearchResult(dbResult, searchByCriteriaWork.PageCounts, searchByCriteriaWork.TermHits);
                return(resultList);
            }
        }
Ejemplo n.º 6
0
        public PagedResultList <ProjectDetailContract> GetProjectsByAuthor(int authorId, int?start, int?count)
        {
            var startValue     = PagingHelper.GetStart(start);
            var countValue     = PagingHelper.GetCount(count);
            var dbMetadataList = m_metadataRepository.InvokeUnitOfWork(x => x.GetMetadataByAuthor(authorId, startValue, countValue));
            var result         = MapPagedProjectsToContractList(dbMetadataList);

            return(result);
        }
Ejemplo n.º 7
0
        public List <ExternalRepositoryContract> GetExternalRepositoryList([FromQuery] int?start, [FromQuery] int?count)
        {
            var startValue = PagingHelper.GetStart(start);
            var countValue = PagingHelper.GetCount(count);

            var result = m_externalRepositoryManager.GetExternalRepositoryList(startValue, countValue);

            SetTotalCountHeader(result.TotalCount);

            return(result.List);
        }
Ejemplo n.º 8
0
        public List <FilteringExpressionSetContract> GetFilteringExpressionSetList([FromQuery] int?start, [FromQuery] int?count)
        {
            var startValue = PagingHelper.GetStart(start);
            var countValue = PagingHelper.GetCount(count);

            var result = m_filteringExpressionSetManager.GetFilteringExpressionSetList(startValue, countValue);

            SetTotalCountHeader(result.TotalCount);

            return(result.List);
        }
Ejemplo n.º 9
0
        public List <HeadwordContract> SearchHeadwordByCriteria(HeadwordSearchRequestContract request, ProjectTypeContract projectType)
        {
            m_authorizationManager.AddAuthorizationCriteria(request.ConditionConjunction);

            var processedCriterias   = m_metadataSearchCriteriaProcessor.ProcessSearchCriterias(request.ConditionConjunction);
            var nonMetadataCriterias = processedCriterias.NonMetadataCriterias;
            var projectTypeEnum      = m_mapper.Map <ProjectTypeEnum>(projectType);

            var queryCreator = new SearchCriteriaQueryCreator(processedCriterias.ConjunctionQuery, processedCriterias.MetadataParameters, projectTypeEnum)
            {
                Start = PagingHelper.GetStart(request.Start),
                Count = PagingHelper.GetCount(request.Count)
            };

            if (processedCriterias.NonMetadataCriterias.Count > 0)
            {
                // Search in fulltext DB

                // 1) search in metadata
                var projectIdentificatorList = m_bookRepository.InvokeUnitOfWork(x => x.SearchProjectIdByCriteriaQuery(queryCreator));
                if (projectIdentificatorList.Count == 0)
                {
                    return(new List <HeadwordContract>());
                }

                // 2) search in fulltext
                var fulltextStorage          = m_fulltextStorageProvider.GetFulltextStorage(projectType);
                var fulltextSearchResultData = fulltextStorage.SearchHeadwordByCriteria(queryCreator.GetStart(), queryCreator.GetCount(), nonMetadataCriterias, projectIdentificatorList);

                // 3) load paged result
                switch (fulltextSearchResultData.SearchResultType)
                {
                case FulltextSearchResultType.ProjectId:
                    return(m_headwordSearchManager.GetHeadwordSearchResultByStandardIds(fulltextSearchResultData.List));

                case FulltextSearchResultType.ProjectExternalId:
                    return(m_headwordSearchManager.GetHeadwordSearchResultByExternalIds(fulltextSearchResultData.List, projectTypeEnum));

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            else
            {
                // Search in relational DB

                var searchByCriteriaWork = new SearchHeadwordByCriteriaWork(m_resourceRepository, m_bookRepository, queryCreator);
                var dbResult             = searchByCriteriaWork.Execute();

                var resultList = m_mapper.Map <List <HeadwordContract> >(dbResult);
                return(resultList);
            }
        }
Ejemplo n.º 10
0
        public PagedResultList <KeywordContract> GetKeywordList(int?start, int?count)
        {
            var startValue = PagingHelper.GetStart(start);
            var countValue = PagingHelper.GetCount(count);
            var dbResult   = m_catalogValueRepository.InvokeUnitOfWork(x => x.GetKeywordList(startValue, countValue));

            return(new PagedResultList <KeywordContract>
            {
                List = m_mapper.Map <List <KeywordContract> >(dbResult.List),
                TotalCount = dbResult.Count,
            });
        }
Ejemplo n.º 11
0
        public PagedResultList <OriginalAuthorContract> GetOriginalAuthorList(int?start, int?count)
        {
            var startValue = PagingHelper.GetStart(start);
            var countValue = PagingHelper.GetCount(count);
            var dbResult   = m_personRepository.InvokeUnitOfWork(x => x.GetOriginalAuthorList(startValue, countValue));
            var resultList = m_mapper.Map <List <OriginalAuthorContract> >(dbResult.List);

            return(new PagedResultList <OriginalAuthorContract>
            {
                List = resultList,
                TotalCount = dbResult.Count
            });
        }
Ejemplo n.º 12
0
        public PagedResultList <FavoriteBaseInfoContract> GetFavoriteItems(int?start, int?count, long?labelId, FavoriteTypeEnumContract?filterByType, string filterByTitle, FavoriteSortEnumContract sort)
        {
            var user       = TryGetUser();
            var startValue = PagingHelper.GetStart(start);
            var countValue = PagingHelper.GetCount(count);
            var typeFilter = m_mapper.Map <FavoriteTypeEnum?>(filterByType);

            var dbResult = m_favoritesRepository.InvokeUnitOfWork(x => x.GetFavoriteItems(labelId, typeFilter, filterByTitle, sort, startValue, countValue, user.Id));

            return(new PagedResultList <FavoriteBaseInfoContract>
            {
                List = m_mapper.Map <List <FavoriteBaseInfoContract> >(dbResult.List),
                TotalCount = dbResult.Count
            });
        }
Ejemplo n.º 13
0
        public PagedResultList <FavoriteQueryContract> GetFavoriteQueries(int?start, int?count, long?labelId, BookTypeEnumContract bookType, QueryTypeEnumContract queryType, string filterByTitle)
        {
            var user          = TryGetUser();
            var startValue    = PagingHelper.GetStart(start);
            var countValue    = PagingHelper.GetCount(count);
            var bookTypeEnum  = m_mapper.Map <BookTypeEnum>(bookType);
            var queryTypeEnum = m_mapper.Map <QueryTypeEnum>(queryType);

            var dbResult = m_favoritesRepository.InvokeUnitOfWork(x => x.GetFavoriteQueries(labelId, bookTypeEnum, queryTypeEnum, filterByTitle, startValue, countValue, user.Id));

            return(new PagedResultList <FavoriteQueryContract>
            {
                List = m_mapper.Map <List <FavoriteQueryContract> >(dbResult.List),
                TotalCount = dbResult.Count,
            });
        }
Ejemplo n.º 14
0
        public PagedResultList <NewsSyndicationItemContract> GetNewsSyndicationItems(int?start, int?count, NewsTypeEnumContract?itemType, PortalTypeContract portalTypeContract)
        {
            var startValue          = PagingHelper.GetStart(start);
            var countValue          = PagingHelper.GetCount(count);
            var syndicationItemType = m_mapper.Map <SyndicationItemType?>(itemType);
            var portalType          = m_mapper.Map <PortalTypeEnum>(portalTypeContract);

            var result = m_portalRepository.InvokeUnitOfWork(x =>
                                                             x.GetNewsSyndicationItems(startValue, countValue, syndicationItemType, portalType));

            return(new PagedResultList <NewsSyndicationItemContract>
            {
                List = m_userDetailManager.AddUserDetails(m_mapper.Map <List <NewsSyndicationItemContract> >(result.List)),
                TotalCount = result.Count
            });
        }
Ejemplo n.º 15
0
        public PagedResultList <SpecialPermissionContract> GetPermissions(int?start, int?count, string filterByName)
        {
            var startValue = PagingHelper.GetStart(start);
            var countValue = PagingHelper.GetCount(count);

            var client = m_communicationProvider.GetAuthPermissionApiClient();

            var result = client.GetPermissionListAsync(startValue, countValue, filterByName).GetAwaiter()
                         .GetResult();
            var permissionContracts = m_mapper.Map <List <SpecialPermissionContract> >(result.Items);

            return(new PagedResultList <SpecialPermissionContract>
            {
                List = permissionContracts,
                TotalCount = result.ItemsCount
            });
        }
Ejemplo n.º 16
0
        public PagedResultList <UserContract> GetUsersByGroup(int groupId, int?start, int?count, string filterByName)
        {
            // Method required for Role management (select role, load users)

            var role = m_permissionRepository.InvokeUnitOfWork(x => x.FindById <UserGroup>(groupId));

            if (role is RoleUserGroup roleUserGroup)
            {
                // If UserGroup has relation to Roles on Auth service, use user list from Auth service (the main data source)

                var client = m_communicationProvider.GetAuthRoleApiClient();
                var result = client.GetUserListByRoleAsync(roleUserGroup.ExternalId, start, count, filterByName).GetAwaiter().GetResult();
                var users  = m_mapper.Map <List <UserContract> >(result.Items);
                m_userDetailManager.AddIdForExternalUsers(users);

                return(new PagedResultList <UserContract>
                {
                    List = users,
                    TotalCount = result.ItemsCount
                });
            }
            else
            {
                // If UserGroup has no relation to Auth service (permissions to books), use local user list

                var startValue = PagingHelper.GetStart(start);
                var countValue = PagingHelper.GetCount(count);
                var dbUsers    = m_userRepository.InvokeUnitOfWork(x => x.GetUsersByGroup(groupId, startValue, countValue, filterByName));

                var resultList = new List <UserContract>();
                foreach (var dbUser in dbUsers.List)
                {
                    var resultUser = m_mapper.Map <UserContract>(dbUser);
                    resultUser.FirstName = dbUser.ExtFirstName;
                    resultUser.LastName  = dbUser.ExtLastName;
                    resultUser.UserName  = dbUser.ExtUsername;
                    resultList.Add(resultUser);
                }

                return(new PagedResultList <UserContract>
                {
                    List = resultList,
                    TotalCount = dbUsers.Count,
                });
            }
        }
Ejemplo n.º 17
0
        public long SearchByCriteriaCount(AdvancedSearchRequestContract request, ProjectTypeContract projectType)
        {
            m_authorizationManager.AddAuthorizationCriteria(request.ConditionConjunction);

            var processedCriterias = m_metadataSearchCriteriaProcessor.ProcessSearchCriterias(request.ConditionConjunction);
            var projectTypeEnums   = new List <ProjectTypeEnum> {
                m_mapper.Map <ProjectTypeEnum>(projectType)
            };

            if (request.Parameters != null && request.Parameters.IncludeAdditionalProjectTypes)
            {
                projectTypeEnums.AddRange(request.Parameters.AdditionalProjectTypes.Select(x => m_mapper.Map <ProjectTypeEnum>(x)));
            }

            var queryCreator = new SearchCriteriaQueryCreator(processedCriterias.ConjunctionQuery, processedCriterias.MetadataParameters, projectTypeEnums)
            {
                Sort          = request.Sort,
                SortDirection = request.SortDirection,
                Start         = PagingHelper.GetStart(request.Start),
                Count         = PagingHelper.GetCountForProject(request.Count)
            };

            if (processedCriterias.NonMetadataCriterias.Count > 0)
            {
                // Search in fulltext DB

                // 1) search in metadata
                var projectIdentificatorList = m_bookRepository.InvokeUnitOfWork(x => x.SearchProjectIdByCriteriaQuery(queryCreator));
                if (projectIdentificatorList.Count == 0)
                {
                    return(0);
                }

                // 2) search in fulltext
                var fulltextStorage = m_fulltextStorageProvider.GetFulltextStorage(projectType);
                var result          = fulltextStorage.SearchByCriteriaCount(processedCriterias.NonMetadataCriterias, projectIdentificatorList);
                return(result);
            }
            else
            {
                // Search in relational DB

                var result = m_bookRepository.InvokeUnitOfWork(x => x.SearchByCriteriaQueryCount(queryCreator));
                return(result);
            }
        }
Ejemplo n.º 18
0
        public PagedResultList <UserDetailContract> GetUserList(int?start, int?count, string filterByName)
        {
            var startValue = PagingHelper.GetStart(start);
            var countValue = PagingHelper.GetCount(count);

            var client = m_communicationProvider.GetAuthUserApiClient();

            var result = client.GetUserListAsync(startValue, countValue, filterByName).GetAwaiter().GetResult();
            var userDetailContracts = m_mapper.Map <List <UserDetailContract> >(result.Items);

            m_userDetailManager.AddIdForExternalUsers(userDetailContracts);

            return(new PagedResultList <UserDetailContract>
            {
                List = userDetailContracts,
                TotalCount = result.ItemsCount,
            });
        }
Ejemplo n.º 19
0
        public List <AudioBookSearchResultContract> SearchAudioByCriteria(SearchRequestContract request, ProjectTypeContract projectType)
        {
            m_authorizationManager.AddAuthorizationCriteria(request.ConditionConjunction);

            var processedCriterias = m_metadataSearchCriteriaProcessor.ProcessSearchCriterias(request.ConditionConjunction);
            var projectTypeEnum    = m_mapper.Map <ProjectTypeEnum>(projectType);

            var queryCreator = new SearchCriteriaQueryCreator(processedCriterias.ConjunctionQuery, processedCriterias.MetadataParameters, projectTypeEnum)
            {
                Sort          = request.Sort,
                SortDirection = request.SortDirection,
                Start         = PagingHelper.GetStart(request.Start),
                Count         = PagingHelper.GetCountForProject(request.Count)
            };

            // Search only in relational DB

            var searchByCriteriaWork = new SearchAudioByCriteriaWork(m_metadataRepository, m_bookRepository, queryCreator);
            var dbResult             = searchByCriteriaWork.Execute();

            //var resultList = MapToSearchResult(dbResult, searchByCriteriaWork.PageCounts);
            var resultList = new List <AudioBookSearchResultContract>(dbResult.Count);

            foreach (var dbMetadata in dbResult)
            {
                var resultItem = m_mapper.Map <AudioBookSearchResultContract>(dbMetadata);
                resultList.Add(resultItem);

                if (searchByCriteriaWork.FullBookRecordingsByProjectId.TryGetValue(dbMetadata.Resource.Project.Id, out var audioList))
                {
                    resultItem.FullBookRecordings = m_mapper.Map <List <AudioContract> >(audioList);
                }
                else
                {
                    resultItem.FullBookRecordings = new List <AudioContract>();
                }
            }

            return(resultList);
        }
Ejemplo n.º 20
0
        public PagedResultList <UserGroupContract> GetUserGroupsByProject(long projectId, int?start, int?count, string filterByName)
        {
            var startValue = PagingHelper.GetStart(start);
            var countValue = PagingHelper.GetCount(count);

            var result = m_permissionRepository.InvokeUnitOfWork(x => x.FindGroupsByBook(projectId, startValue, countValue, filterByName, true));

            if (result == null)
            {
                return(null);
            }

            var resultRoles = new List <UserGroupContract>();

            foreach (var group in result.List)
            {
                if (group is RoleUserGroup roleUserGroup)
                {
                    var work = new SynchronizeRoleWork(m_permissionRepository, m_communicationProvider, roleUserGroup.ExternalId);
                    work.Execute();
                    var authRoleContract = work.GetRoleContract();

                    var roleContract = m_mapper.Map <UserGroupContract>(authRoleContract);
                    roleContract.Id = group.Id;

                    resultRoles.Add(roleContract);
                }
                else
                {
                    var roleContract = m_mapper.Map <UserGroupContract>(group);
                    resultRoles.Add(roleContract);
                }
            }

            return(new PagedResultList <UserGroupContract>
            {
                List = resultRoles,
                TotalCount = result.Count,
            });
        }
Ejemplo n.º 21
0
        public long SearchHeadwordByCriteriaCount(HeadwordSearchRequestContract request, ProjectTypeContract projectType)
        {
            m_authorizationManager.AddAuthorizationCriteria(request.ConditionConjunction);

            var processedCriterias = m_metadataSearchCriteriaProcessor.ProcessSearchCriterias(request.ConditionConjunction);
            var projectTypeEnum    = m_mapper.Map <ProjectTypeEnum>(projectType);

            var queryCreator = new SearchCriteriaQueryCreator(processedCriterias.ConjunctionQuery, processedCriterias.MetadataParameters, projectTypeEnum)
            {
                Start = PagingHelper.GetStart(request.Start),
                Count = PagingHelper.GetCount(request.Count)
            };

            if (processedCriterias.NonMetadataCriterias.Count > 0)
            {
                // Search in fulltext DB

                // 1) search in metadata
                var projectIdentificatorList = m_bookRepository.InvokeUnitOfWork(x => x.SearchProjectIdByCriteriaQuery(queryCreator));
                if (projectIdentificatorList.Count == 0)
                {
                    return(0);
                }

                // 2) search in fulltext
                var fulltextStorage = m_fulltextStorageProvider.GetFulltextStorage(projectType);
                var result          = fulltextStorage.SearchHeadwordByCriteriaCount(processedCriterias.NonMetadataCriterias, projectIdentificatorList);
                return(result);
            }
            else
            {
                // Search in relational DB

                var result = m_bookRepository.InvokeUnitOfWork(x => x.SearchHeadwordByCriteriaQueryCount(queryCreator));
                return(result);
            }
        }
Ejemplo n.º 22
0
        public PagedResultList <ProjectDetailContract> GetProjectList(int?start, int?count, ProjectTypeContract?projectType,
                                                                      ProjectOwnerTypeContract projectOwnerType, string filterByName, bool fetchPageCount, bool fetchAuthors,
                                                                      bool fetchResponsiblePersons, bool fetchLatestChangedResource, bool fetchPermissions)
        {
            var startValue      = PagingHelper.GetStart(start);
            var countValue      = PagingHelper.GetCountForProject(count);
            var projectTypeEnum = m_mapper.Map <ProjectTypeEnum?>(projectType);

            var userId = m_authenticationManager.GetCurrentUserId();

            var work = new GetProjectListWork(m_projectRepository, m_metadataRepository, startValue, countValue, projectTypeEnum,
                                              projectOwnerType, userId, filterByName, fetchPageCount, fetchAuthors, fetchResponsiblePersons, fetchLatestChangedResource, fetchPermissions);
            var resultEntities = work.Execute();

            var metadataList       = work.GetMetadataResources();
            var pageCountList      = work.GetPageCountList();
            var latestChangesList  = work.GetLatestChangedResources();
            var userPermissionDict = work.GetUserPermission();
            var resultList         = m_mapper.Map <List <ProjectDetailContract> >(resultEntities);

            foreach (var projectContract in resultList)
            {
                var metadataResource   = metadataList.FirstOrDefault(x => x.Resource.Project.Id == projectContract.Id);
                var pageCountResult    = pageCountList.FirstOrDefault(x => x.ProjectId == projectContract.Id);
                var latestChangeResult = latestChangesList.FirstOrDefault(x => x.ProjectId == projectContract.Id);

                var metadataContract = m_mapper.Map <ProjectMetadataContract>(metadataResource);
                projectContract.LatestMetadata = metadataContract;
                projectContract.PageCount      = pageCountResult?.PageCount;
                projectContract.CreatedByUser  = m_userDetailManager.GetUserContractForUser(projectContract.CreatedByUser);

                if (fetchAuthors && metadataResource != null)
                {
                    projectContract.Authors = m_mapper.Map <List <OriginalAuthorContract> >(metadataResource.Resource.Project.Authors);
                }

                if (fetchResponsiblePersons && metadataResource != null)
                {
                    projectContract.ResponsiblePersons =
                        m_mapper.Map <List <ProjectResponsiblePersonContract> >(metadataResource.Resource.Project.ResponsiblePersons);
                }

                if (fetchLatestChangedResource && latestChangeResult != null)
                {
                    projectContract.LatestChangeTime = latestChangeResult.CreateTime;
                    projectContract.EditedByUser     = m_userDetailManager.GetUserContract(latestChangeResult.CreatedByUserId);
                }

                if (fetchPermissions)
                {
                    userPermissionDict.TryGetValue(projectContract.Id, out var permissions);
                    projectContract.CurrentUserPermissions = m_projectPermissionConverter.GetAggregatedPermissions(permissions);
                }
            }

            return(new PagedResultList <ProjectDetailContract>
            {
                List = resultList,
                TotalCount = work.GetResultCount()
            });
        }