Esempio n. 1
0
        public virtual long SearchHeadwordByCriteriaQueryCount(SearchCriteriaQueryCreator creator)
        {
            HeadwordItem headwordItemAlias = null;
            Snapshot     snapshotAlias     = null;
            Project      projectAlias      = null;

            var headwordRestrictions = creator.GetHeadwordRestrictions();

            var projectIds = SearchProjectIdByCriteriaQuery(creator).Select(x => x.ProjectId);

            var query = GetSession().QueryOver <HeadwordResource>()
                        .JoinAlias(x => x.Snapshots, () => snapshotAlias)
                        .JoinAlias(() => snapshotAlias.Project, () => projectAlias)
                        .Where(x => snapshotAlias.Id == projectAlias.LatestPublishedSnapshot.Id)
                        .AndRestrictionOn(x => projectAlias.Id).IsInG(projectIds);

            if (creator.HasHeadwordRestrictions())
            {
                query.JoinAlias(x => x.HeadwordItems, () => headwordItemAlias)
                .And(headwordRestrictions);
            }

            var result = query
                         .Select(Projections.CountDistinct <HeadwordResource>(x => x.Id))
                         .SingleOrDefault <int>();

            return(result);
        }
Esempio n. 2
0
        public virtual IList <HeadwordSearchResult> SearchHeadwordByCriteriaQuery(SearchCriteriaQueryCreator creator)
        {
            HeadwordSearchResult resultAlias       = null;
            HeadwordItem         headwordItemAlias = null;
            Snapshot             snapshotAlias     = null;
            Project projectAlias = null;

            var headwordRestrictions = creator.GetHeadwordRestrictions();

            var projectIds = SearchProjectIdByCriteriaQuery(creator).Select(x => x.ProjectId);

            var query = GetSession().QueryOver <HeadwordResource>()
                        .JoinAlias(x => x.Snapshots, () => snapshotAlias)
                        .JoinAlias(() => snapshotAlias.Project, () => projectAlias)
                        .Where(x => snapshotAlias.Id == projectAlias.LatestPublishedSnapshot.Id)
                        .AndRestrictionOn(x => projectAlias.Id).IsInG(projectIds);

            if (creator.HasHeadwordRestrictions())
            {
                query.JoinAlias(x => x.HeadwordItems, () => headwordItemAlias)
                .And(headwordRestrictions);
            }

            var result = query
                         .SelectList(list => list
                                     .SelectGroup(x => x.Id).WithAlias(() => resultAlias.Id)
                                     .SelectMin(x => x.Sorting).WithAlias(() => resultAlias.Sorting))
                         .OrderBy(x => x.Sorting).Asc
                         .TransformUsing(Transformers.AliasToBean <HeadwordSearchResult>())
                         .Take(creator.GetCount())
                         .Skip(creator.GetStart())
                         .List <HeadwordSearchResult>();

            return(result);
        }
Esempio n. 3
0
        public virtual HeadwordResource GetLatestHeadword(long projectId, string externalId)
        {
            Resource     resourceAlias     = null;
            HeadwordItem headwordItemAlias = null;
            Project      projectAlias      = null;

            return(GetSession().QueryOver <HeadwordResource>()
                   .JoinAlias(x => x.Resource, () => resourceAlias)
                   .JoinAlias(x => x.HeadwordItems, () => headwordItemAlias)
                   .JoinAlias(() => resourceAlias.Project, () => projectAlias)
                   .Where(x => resourceAlias.Project.Id == projectId && resourceAlias.LatestVersion.Id == x.Id && !resourceAlias.IsRemoved && projectAlias.IsRemoved == false)
                   .And(x => x.ExternalId == externalId)
                   .Fetch(SelectMode.Fetch, x => x.HeadwordItems)
                   .OrderBy(() => headwordItemAlias.Headword).Asc
                   .SingleOrDefault());
        }
        public SearchCriteriaQuery CreateCriteriaQuery(SearchCriteriaContract searchCriteriaContract, Dictionary <string, object> metadataParameters)
        {
            HeadwordItem headwordItemAlias = null;
            var          wordListCriteria  = (WordListCriteriaContract)searchCriteriaContract;
            var          disjunction       = new Disjunction();

            foreach (WordCriteriaContract wordCriteria in wordListCriteria.Disjunctions)
            {
                var parameter   = CriteriaConditionBuilder.Create(wordCriteria);
                var restriction = Restrictions.Like(Projections.Property(() => headwordItemAlias.Headword), parameter, MatchMode.Exact);

                disjunction.Add(restriction);
            }

            return(new SearchCriteriaQuery
            {
                CriteriaKey = CriteriaKey,
                Join = string.Empty,
                Where = string.Empty,
                Restriction = disjunction,
            });
        }
Esempio n. 5
0
        private void CreateHeadwordResource(int version, Resource resource, List <BookHeadwordData> headwordDataList, User user, DateTime now, BookVersionResource bookVersion, Dictionary <string, PageResource> dbPagesByImage)
        {
            var firstHeadwordData = headwordDataList.First();

            var newDbHeadword = new HeadwordResource
            {
                Resource        = resource,
                BookVersion     = bookVersion,
                Comment         = null,
                CreateTime      = now,
                CreatedByUser   = user,
                VersionNumber   = version,
                HeadwordItems   = null, // Headword Items are created in following for-each
                ExternalId      = firstHeadwordData.XmlEntryId,
                DefaultHeadword = firstHeadwordData.DefaultHeadword,
                Sorting         = firstHeadwordData.SortOrder,
            };

            resource.LatestVersion = newDbHeadword;

            m_resourceRepository.Create(newDbHeadword);
            m_importedResourceVersionIds.Add(newDbHeadword.Id);

            foreach (var bookHeadwordData in headwordDataList)
            {
                var dbPage            = GetPageResourceByImage(dbPagesByImage, bookHeadwordData.Image);
                var newDbHeadwordItem = new HeadwordItem
                {
                    HeadwordResource = newDbHeadword,
                    Headword         = bookHeadwordData.Headword,
                    HeadwordOriginal = bookHeadwordData.HeadwordOriginal,
                    ResourcePage     = dbPage?.Resource
                };
                m_resourceRepository.Create(newDbHeadwordItem);
            }
        }