Esempio n. 1
0
 public virtual IEnumerable <ContentItem> GetAllVersions(int id)
 {
     return(_contentItemVersionRepository
            .Fetch(x => x.ContentItemRecord.Id == id)
            .OrderBy(x => x.Number)
            .Select(x => Get(x.Id, VersionOptions.VersionRecord(x.Id))));
 }
Esempio n. 2
0
        public IEnumerable <ContentItem> GetManyByVersionId(IEnumerable <int> versionRecordIds, QueryHints hints)
        {
            var contentItemVersionRecords = GetManyImplementation(hints, (contentItemCriteria, contentItemVersionCriteria) =>
                                                                  contentItemVersionCriteria.Add(Restrictions.In("Id", versionRecordIds.ToArray())));

            var itemsById = contentItemVersionRecords
                            .Select(r => Get(r.ContentItemRecord.Id, VersionOptions.VersionRecord(r.Id)))
                            .GroupBy(ci => ci.VersionRecord.Id)
                            .ToDictionary(g => g.Key);

            return(versionRecordIds.SelectMany(id => {
                IGrouping <int, ContentItem> values;
                return itemsById.TryGetValue(id, out values) ? values : Enumerable.Empty <ContentItem>();
            }).ToArray());
        }
Esempio n. 3
0
        public IEnumerable <T> GetMany <T>(IEnumerable <int> ids, VersionOptions options, QueryHints hints) where T : class, IContent
        {
            var contentItemVersionRecords = GetManyImplementation(hints, (contentItemCriteria, contentItemVersionCriteria) => {
                contentItemCriteria.Add(Restrictions.In("Id", ids.ToArray()));
                if (options.IsPublished)
                {
                    contentItemVersionCriteria.Add(Restrictions.Eq("Published", true));
                }
                else if (options.IsLatest)
                {
                    contentItemVersionCriteria.Add(Restrictions.Eq("Latest", true));
                }
                else if (options.IsDraft && !options.IsDraftRequired)
                {
                    contentItemVersionCriteria.Add(
                        Restrictions.And(Restrictions.Eq("Published", false),
                                         Restrictions.Eq("Latest", true)));
                }
                else if (options.IsDraft || options.IsDraftRequired)
                {
                    contentItemVersionCriteria.Add(Restrictions.Eq("Latest", true));
                }
            });

            var itemsById = contentItemVersionRecords
                            .Select(r => Get(r.ContentItemRecord.Id, options.IsDraftRequired ? options : VersionOptions.VersionRecord(r.Id)))
                            .GroupBy(ci => ci.Id)
                            .ToDictionary(g => g.Key);

            return(ids.SelectMany(id => {
                IGrouping <int, ContentItem> values;
                return itemsById.TryGetValue(id, out values) ? values : Enumerable.Empty <ContentItem>();
            }).AsPart <T>().ToArray());
        }
Esempio n. 4
0
        private IEnumerable <ContentItem> Slice(int skip, int count)
        {
            var criteria = BindItemVersionCriteria();

            criteria.ApplyVersionOptionsRestrictions(_versionOptions);

            criteria.SetFetchMode("ContentItemRecord", FetchMode.Eager);
            criteria.SetFetchMode("ContentItemRecord.ContentType", FetchMode.Eager);

            // TODO: put 'removed false' filter in place
            if (skip != 0)
            {
                criteria = criteria.SetFirstResult(skip);
            }
            if (count != 0)
            {
                criteria = criteria.SetMaxResults(count);
            }

            return(criteria
                   .List <ContentItemVersionRecord>()
                   .Select(x => ContentManager.Get(x.ContentItemRecord.Id, _versionOptions != null && _versionOptions.IsDraftRequired ? _versionOptions : VersionOptions.VersionRecord(x.Id)))
                   .ToReadOnlyCollection());
        }
Esempio n. 5
0
        public ContentItem Get(string id, VersionOptions versionOptions, string contentTypeHint = null)
        {
            var contentIdentity = new ContentIdentity(id);

            // lookup in local cache
            if (_identities.ContainsKey(contentIdentity))
            {
                if (_draftVersionRecordIds.ContainsKey(_identities[contentIdentity]))
                {
                    //draft was previously created. Recall.
                    versionOptions = VersionOptions.VersionRecord(_draftVersionRecordIds[_identities[contentIdentity]]);
                }
                var result = _contentManager.Get(_identities[contentIdentity], versionOptions);

                // if two identities are conflicting, then ensure that there types are the same
                // e.g., importing a blog as home page (alias=) and the current home page is a page, the blog
                // won't be imported, and blog posts will be attached to the page
                if (contentTypeHint == null || result.ContentType == contentTypeHint)
                {
                    return(result);
                }
            }

            ContentItem existingItem = _contentManager.ResolveIdentity(contentIdentity);

            //ensure we have the correct version
            if (existingItem != null)
            {
                existingItem = _contentManager.Get(existingItem.Id, versionOptions);
            }

            if (existingItem == null && _identities.ContainsKey(contentIdentity))
            {
                existingItem = _contentManager.Get(_identities[contentIdentity], versionOptions);
            }

            if (existingItem != null)
            {
                _identities[contentIdentity] = existingItem.Id;
                if (versionOptions.IsDraftRequired)
                {
                    _draftVersionRecordIds[existingItem.Id] = existingItem.VersionRecord.Id;
                }
                return(existingItem);
            }

            //create item if not found and draft was requested, or it is found later in the import queue
            if (versionOptions.IsDraftRequired || _allIdentitiesForImportStatus.ContainsKey(contentIdentity))
            {
                var contentType = _contentTypes.ContainsKey(contentIdentity) ? _contentTypes[contentIdentity] : contentTypeHint;

                if (!_contentTypes.ContainsKey(contentIdentity))
                {
                    throw new ArgumentException("Unknown content type for " + id);
                }

                var contentItem = _contentManager.Create(contentType, VersionOptions.Draft);

                _identities[contentIdentity] = contentItem.Id;

                //store versionrecordid in case a draft is requested again
                _draftVersionRecordIds[contentItem.Id] = contentItem.VersionRecord.Id;

                //add the requested item as a dependency if it is not the currently running item
                if (_allIdentitiesForImportStatus.ContainsKey(contentIdentity) &&
                    !_allIdentitiesForImportStatus[contentIdentity])
                {
                    _dependencyIdentities.Enqueue(contentIdentity);
                }

                return(contentItem);
            }

            return(null);
        }