public IEnumerable <NCMIS.ObjectModel.CmisObject> GetChildren(string repositoryId, string objectId, string filter, IncludeRelationships includeRelationships)
        {
            Kooboo.CMS.Content.Models.Repository repository = new Models.Repository(repositoryId);
            string folderId;

            TryPraseObjectId(objectId, out folderId);
            switch (CmisFolderHelper.IdentifyFolderType(repository, folderId))
            {
            case FolderType.Root:
                return(new[] {
                    CmisFolderHelper.CreateSystemFolderObject(CmisFolderHelper.Content_Folder_Root, CmisFolderHelper.RootFolderName),
                    CmisFolderHelper.CreateSystemFolderObject(CmisFolderHelper.Media_Folder_Root, CmisFolderHelper.RootFolderName)
                });

            case FolderType.Content_Folder_Root:
                return(ServiceFactory.TextFolderManager.All(repository, filter).Select(it => ObjectConvertor.ToCmis((TextFolder)(it.AsActual()), includeRelationships != IncludeRelationships.None)));

            case FolderType.Media_Folder_Root:
                return(ServiceFactory.MediaFolderManager.All(repository, filter).Select(it => ObjectConvertor.ToCmis((MediaFolder)(it.AsActual()), includeRelationships != IncludeRelationships.None)));

            case FolderType.Content_Folder:
                var textFolder = (TextFolder)CmisFolderHelper.Parse(repository, folderId);
                return(ServiceFactory.TextFolderManager.ChildFolders(textFolder, filter).Select(it => ObjectConvertor.ToCmis((TextFolder)(it.AsActual()), includeRelationships != IncludeRelationships.None)));

            case FolderType.Media_Folder:
                var mediaFolder = (MediaFolder)CmisFolderHelper.Parse(repository, folderId);
                return(ServiceFactory.MediaFolderManager.ChildFolders(mediaFolder, filter).Select(it => ObjectConvertor.ToCmis((MediaFolder)(it.AsActual()), includeRelationships != IncludeRelationships.None)));

            default:
                break;
            }
            return(new[] { ObjectConvertor.EmptyCmisObject() });
        }
        public CmisObject CreateFolder(string repositoryId, NCMIS.ObjectModel.CmisProperties properties, string folderId)
        {
            Kooboo.CMS.Content.Models.Repository repository = new Models.Repository(repositoryId);
            Folder parent   = null;
            var    objectId = folderId;

            var values = properties.ToNameValueCollection();

            if (string.IsNullOrEmpty(values["name"]))
            {
                throw new Exception("The property \"Name\" is required.");
            }
            if (TryPraseObjectId(objectId, out folderId))
            {
                var folderType = CmisFolderHelper.IdentifyFolderType(repository, folderId);
                switch (folderType)
                {
                case FolderType.Root:
                    throw new Exception("Could not create folder under root folder.");

                case FolderType.Content_Folder_Root:
                    parent = null;
                    return(AddContentFolder(repository, parent, values));

                case FolderType.Media_Folder_Root:
                    parent = null;
                    return(AddMediaFolder(repository, parent, values));

                case FolderType.Content_Folder:
                    parent = CmisFolderHelper.Parse(repository, folderId);
                    return(AddContentFolder(repository, parent, values));

                case FolderType.Media_Folder:
                    parent = CmisFolderHelper.Parse(repository, folderId);
                    return(AddMediaFolder(repository, parent, values));

                default:
                    break;
                }
            }
            throw new InvalidOperationException("Create folder failed.");
        }
Exemple #3
0
        public override NCMIS.ObjectModel.PathedCmisObjectList GetChildren(string repositoryId, string folderId, int?maxItems, int skipCount, string orderBy, string filter, IncludeRelationships includeRelationships, string renditionFilter, bool includeAllowableActions, bool includePathSegment)
        {
            Kooboo.CMS.Content.Models.Repository repository = new Models.Repository(repositoryId);
            IObjectService folderService = ObjectService.GetService(typeof(Folder));
            string         objectId      = folderId;

            folderService.TryPraseObjectId(objectId, out folderId);

            FolderType folderType = CmisFolderHelper.IdentifyFolderType(repository, folderId);

            PathedCmisObjectList           pathedList = new PathedCmisObjectList();
            IEnumerable <PathedCmisObject> children   = folderService.GetChildren(repositoryId, objectId, filter, includeRelationships)
                                                        .Select(it => new PathedCmisObject()
            {
                Object = it
            });

            var count = children.Count();

            pathedList.NumItems     = count.ToString();
            pathedList.HasMoreItems = false;

            //IEnumerable<ContentBase> contents = new ContentBase[0];
            if (folderType == FolderType.Content_Folder || folderType == FolderType.Media_Folder)
            {
                var folder = CmisFolderHelper.Parse(repository, folderId).AsActual();
                IContentQuery <ContentBase> contentQuery = null;
                if (folder is TextFolder)
                {
                    var textFolder = (TextFolder)folder;
                    var schema     = new Schema(repository, textFolder.SchemaName).AsActual();
                    contentQuery = textFolder.CreateQuery();
                    if (!string.IsNullOrEmpty(filter))
                    {
                        foreach (var item in schema.Columns)
                        {
                            contentQuery = contentQuery.Or(new WhereContainsExpression(null, item.Name, filter));
                        }
                    }
                }
                else
                {
                    var mediaFolder = (TextFolder)folder;
                    contentQuery = mediaFolder.CreateQuery();
                    if (!string.IsNullOrEmpty(filter))
                    {
                        contentQuery = contentQuery.WhereContains("FileName", filter);
                    }
                }
                if (!string.IsNullOrEmpty(orderBy))
                {
                    contentQuery = contentQuery.OrderBy(orderBy);
                }

                count = contentQuery.Count();
                var take = maxItems.HasValue ? maxItems.Value : count;
                pathedList.NumItems     = count.ToString();
                pathedList.HasMoreItems = count > count + take;

                children = children.Concat(contentQuery.Select(it => new PathedCmisObject()
                {
                    Object = ObjectConvertor.ToCmis((TextContent)(it), includeRelationships != IncludeRelationships.None)
                }).Take(take));
            }

            pathedList.Objects = children.ToArray();

            return(pathedList);
        }
 public NCMIS.ObjectModel.MetaData.AllowableActions GetAllowableActions(string repositoryId, string objectId)
 {
     if (IsSystemFolder(objectId))
     {
         return(new NCMIS.ObjectModel.MetaData.AllowableActions()
         {
             CanAddObjectToFolder = false,
             CanApplyACL = false,
             CanApplyPolicy = false,
             CanCancelCheckOut = false,
             CanCheckIn = false,
             CanCheckOut = false,
             CanCreateDocument = false,
             CanCreateFolder = CmisFolderHelper.IdentifyFolderType(new Kooboo.CMS.Content.Models.Repository(repositoryId), objectId) != FolderType.Root,
             CanCreateRelationship = false,
             CanDeleteContentStream = false,
             CanDeleteObject = true,
             CanDeleteTree = false,
             CanGetACL = false,
             CanGetAllVersions = false,
             CanGetAppliedPolicies = false,
             CanGetChildren = true,
             CanGetContentStream = false,
             CanGetDescendants = false,
             CanGetFolderParent = false,
             CanGetFolderTree = false,
             CanGetObjectParents = false,
             CanGetObjectRelationships = true,
             CanGetProperties = false,
             CanGetRenditions = false,
             CanMoveObject = false,
             CanRemoveObjectFromFolder = false,
             CanRemovePolicy = false,
             CanSetContentStream = false,
             CanUpdateProperties = false
         });
     }
     else
     {
         return(new NCMIS.ObjectModel.MetaData.AllowableActions()
         {
             CanAddObjectToFolder = false,
             CanApplyACL = false,
             CanApplyPolicy = false,
             CanCancelCheckOut = false,
             CanCheckIn = false,
             CanCheckOut = false,
             CanCreateDocument = true,
             CanCreateFolder = true,
             CanCreateRelationship = true,
             CanDeleteContentStream = false,
             CanDeleteObject = true,
             CanDeleteTree = false,
             CanGetACL = false,
             CanGetAllVersions = false,
             CanGetAppliedPolicies = false,
             CanGetChildren = true,
             CanGetContentStream = true,
             CanGetDescendants = false,
             CanGetFolderParent = true,
             CanGetFolderTree = false,
             CanGetObjectParents = false,
             CanGetObjectRelationships = true,
             CanGetProperties = true,
             CanGetRenditions = false,
             CanMoveObject = false,
             CanRemoveObjectFromFolder = false,
             CanRemovePolicy = false,
             CanSetContentStream = false,
             CanUpdateProperties = true
         });
     }
 }