public ProfileConfigurations getProfileConfigurations()
        {
            String profileConfigURI        = LinkRelations.FindLinkAsString(Links, LinkRelations.PROFILE_CONFIGURATION.Rel);
            ProfileConfigurations pConfigs = Client.Get <ProfileConfigurations>(profileConfigURI, null);

            return(pConfigs);
        }
        public SearchConfigurations getSearchConfigurations()
        {
            String searchConfigURI        = LinkRelations.FindLinkAsString(Links, LinkRelations.SEARCH_CONFIGURATION.Rel);
            SearchConfigurations sConfigs = Client.Get <SearchConfigurations>(searchConfigURI, null);

            return(sConfigs);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Perfomrs DELETE method
        /// </summary>
        /// <param name="links"></param>
        /// <param name="rel"></param>
        /// <param name="options"></param>
        public void Delete(List <Link> links, string rel, GenericOptions options)
        {
            string followingUri = LinkRelations.FindLinkAsString(
                links,
                rel);

            this.Delete(followingUri, options == null ? null : options.ToQueryList());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets a feed
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="links"></param>
        /// <param name="rel"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public Feed <T> GetFeed <T>(List <Link> links, string rel, FeedGetOptions options)
        {
            string followingUri = LinkRelations.FindLinkAsString(
                links,
                rel);

            return(GetFeed <T>(followingUri, options));
        }
        public bool isD2Rest()
        {
            string d2ConfigLink = LinkRelations.FindLinkAsString(
                Links,
                LinkRelations.D2_CONFIGURATION.Rel);

            return(d2ConfigLink != null);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets a single object
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="links"></param>
        /// <param name="rel"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public T GetSingleton <T>(List <Link> links, string rel, SingleGetOptions options)
        {
            string followingUri = LinkRelations.FindLinkAsString(
                links,
                rel);
            T result = this.Get <T>(followingUri, options == null ? null : options.ToQueryList());

            return(result);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Find 'self' link relation
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="links"></param>
        /// <returns></returns>
        public T Self <T>(List <Link> links)
        {
            string followingUri = LinkRelations.FindLinkAsString(
                links,
                LinkRelations.SELF.Rel);
            T result = this.Get <T>(followingUri, null);

            return(result);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Perfomrs POST method
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="links"></param>
        /// <param name="rel"></param>
        /// <param name="input"></param>
        /// <param name="otherParts"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public T Post <T>(List <Link> links, string rel, T input, IDictionary <Stream, string> otherParts, GenericOptions options)
        {
            string followingUri = LinkRelations.FindLinkAsString(
                links,
                rel);
            T result = this.PostMultiparts <T>(followingUri, input, otherParts, options == null ? null : options.ToQueryList());

            return(result);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Perfomrs POST method
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="links"></param>
        /// <param name="rel"></param>
        /// <param name="input"></param>
        /// <param name="mime"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public T Post <T>(List <Link> links, string rel, Stream input, string mime, GenericOptions options)
        {
            string followingUri = LinkRelations.FindLinkAsString(
                links,
                rel);
            T result = this.PostRaw <T>(followingUri, input, mime, options == null ? null : options.ToQueryList());

            return(result);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Performs PUT method
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="R"></typeparam>
        /// <param name="links"></param>
        /// <param name="rel"></param>
        /// <param name="input"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public R Put <T, R>(List <Link> links, string rel, T input, GenericOptions options)
        {
            string followingUri = LinkRelations.FindLinkAsString(
                links,
                rel);
            R result = this.Put <T, R>(followingUri, input, options == null ? null : options.ToQueryList());

            return(result);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Self link to the item
        /// </summary>
        /// <returns></returns>
        protected string SelfLink()
        {
            string self = LinkRelations.FindLinkAsString(this.Links, LinkRelations.EDIT.Rel);

            if (self == null)
            {
                self = LinkRelations.FindLinkAsString(this.Links, LinkRelations.SELF.Rel);
            }
            return(self);
        }
 /// <summary>
 /// Get parent type for this type
 /// </summary>
 /// <param name="options"></param>
 /// <returns></returns>
 public DmType GetParentType(SingleGetOptions options)
 {
     if (LinkRelations.FindLinkAsString(GetFullLinks(), LinkRelations.PARENT.Rel) == null)
     {
         return(null);
     }
     else
     {
         return(Client.GetSingleton <DmType>(
                    GetFullLinks(),
                    LinkRelations.PARENT.Rel,
                    options));
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// Download the content media of this content to a local file
        /// </summary>
        /// <returns>Returns System FileInfo</returns>
        public FileInfo DownloadContentMediaFile()
        {
            string contentMediaUri = LinkRelations.FindLinkAsString(this.Links, LinkRelations.CONTENT_MEDIA.Rel);
            string fileName        = (string)GetPropertyValue("object_name");
            string dosExtension    = (string)GetPropertyValue("dos_extension");

            if (String.IsNullOrEmpty(fileName))
            {
                fileName = "namelessobj-" + System.Guid.NewGuid().ToString();
            }

            // This is meant to avoid duplication extensions while also ensuring that
            // known formats get a proper extension if they do not have one.
            String fileExtension = fileName.Contains('.') ? fileName.Substring(fileName.LastIndexOf('.') + 1) : "";

            if (dosExtension != null && fileName.ToLower().EndsWith(dosExtension.ToLower()))
            {
                // The extension is already on the object name, do not append anthing
                fileExtension = "";
            }
            else
            {
                if (dosExtension != null && !dosExtension.Trim().Equals(""))
                {
                    fileExtension = dosExtension;
                }
                else
                {
                    fileExtension = ObjectUtil.getDosExtensionFromFormat(GetPropertyValue("full_format").ToString());
                }
            }

            fileName = ObjectUtil.getSafeFileName(fileName);
            // Ensure file extension is not already there

            string fullPath = Path.Combine(Path.GetTempPath(), fileName + ((fileExtension == null || fileExtension.Equals("")) ? "" : "." + fileExtension));

            using (Stream media = DownloadContentMediaStream())
            {
                if (media == null)
                {
                    throw new Exception("Stream came back null. This is normally caused by an unreachable ACS Server (DNS problem or Method Server DOWN). ACS URL is: " + contentMediaUri);
                }
                FileStream fs = File.Create(fullPath);
                media.CopyTo(fs);
                fs.Dispose();
            }

            return(new FileInfo(fullPath));
        }
Exemplo n.º 14
0
        /// <summary>
        ///  Executes a Full Text Query against this repository with simple search language
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="search"></param>
        /// <returns>Feed</returns>
        public Feed <T> ExecuteSimpleSearch <T>(SearchOptions search) where T : PersistentObject
        {
            decimal count     = 0;
            double  pageCount = 0;

            if (search == null)
            {
                search = new SearchOptions();
            }
            string searchUri = LinkRelations.FindLinkAsString(this.Links, LinkRelations.SEARCH.Rel);
            List <KeyValuePair <string, object> > pa = search.ToQueryList();
            Feed <T> feed = this.Client.Get <Feed <T> >(searchUri, pa);

            return(feed);
        }
        /// <summary>
        /// Used to update the rentention condition date (close date) on a folder. To re-open, set closeDate = new DateTime() aka NullDate
        /// </summary>
        /// <param name="folderId"></param>
        /// <param name="closeDate"></param>
        /// <returns>Feeed</returns>
        public Feed <PersistentObject> UpdateCloseDate(String folderId, DateTime closeDate)
        {
            //http://localhost:8080/dctm-rest/repositories/Process/retention.xml?folderId=xxxxxxxxxxxxxxxx&closeDate=12/2/2014
            String updateCloseDateUri = LinkRelations.FindLinkAsString(Links, "self") + LinkRelations.RETENTION;

            if (closeDate.Ticks == new DateTime().Ticks)
            {
                // If we have a DateTime nulldate, convert to java null date value
                closeDate = DateTime.Parse("1/1/1970 00:00:00");
            }
            FeedGetOptions options = new FeedGetOptions();

            options.SetQuery("folderId", folderId);
            options.SetQuery("closeDate", closeDate);
            return(Client.GetFeed <PersistentObject>(updateCloseDateUri, options));
        }
        /// <summary>
        /// Creates a new cabinet object with the needed self link to allow the new object to be created.
        /// The TypeName set for the repository instance is what is used for creation. The default is
        /// dm_cabinet.
        /// </summary>
        /// <param name="name"></param>
        /// <returns>Cabinet</returns>
        public Cabinet NewCabinet(String name)
        {
            Cabinet obj = new Cabinet();

            obj.Client = Client;
            obj.Name   = "cabinet";
            Link cabinets = new Link();

            cabinets.Href = LinkRelations.FindLink(Links, "cabinets").Href;
            cabinets.Rel  = "self";
            obj.Links.Add(cabinets);
            obj.Type = "dm_cabinet";
            obj.SetPropertyValue("object_name", name);
            obj.SetPropertyValue("r_object_type", CabinetType);
            obj.Save();
            return(obj);
        }
        private static void AddGroupToGroup(Group group, Group subGroup, bool printResult)
        {
            object groupName;
            object subGroupName;

            group.Properties.TryGetValue("group_name", out groupName);
            subGroup.Properties.TryGetValue("group_name", out subGroupName);
            Console.WriteLine("\nAdding group <" + subGroupName + "> to group <" + groupName + ">...");
            Group memberGroup = new Group();

            memberGroup.Href = LinkRelations.FindLinkAsString(subGroup.Links, LinkRelations.SELF.Rel);
            group.AddSubGroup(memberGroup);
            if (printResult)
            {
                Console.WriteLine("\nSuccessfully add the sub-group to the group.");
            }
        }
        private static void AddUserToGroup(Group group, User user, bool printResult)
        {
            object groupName;
            object userName;

            group.Properties.TryGetValue("group_name", out groupName);
            user.Properties.TryGetValue("user_name", out userName);
            Console.WriteLine("\nAdding user <" + userName + "> to group <" + groupName + ">...");
            User memberUser = new User();

            memberUser.Href = LinkRelations.FindLinkAsString(user.Links, LinkRelations.SELF.Rel);
            group.AddUserToGroup(memberUser);
            if (printResult)
            {
                Console.WriteLine("\nSuccessfully add the user to the group.");
            }
        }
 /// <summary>
 /// Get relation type for this relation
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="options"></param>
 /// <returns></returns>
 public T GetChild <T>(SingleGetOptions options) where T : PersistentObject
 {
     // child link relation is not returned by feed for performance
     if (LinkRelations.FindLinkAsString(GetFullLinks(), LinkRelations.CHILD.Rel) == null)
     {
         this.Links = this.Fetch <Relation>().Links;
     }
     if (LinkRelations.FindLinkAsString(GetFullLinks(), LinkRelations.CHILD.Rel) == null)
     {
         return(null);
     }
     else
     {
         return(Client.GetSingleton <T>(
                    GetFullLinks(),
                    LinkRelations.CHILD.Rel,
                    options));
     }
 }
Exemplo n.º 20
0
        /// <summary>
        /// Execute a DQL query in this repository
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dql"></param>
        /// <param name="options"></param>
        /// <returns>Feed</returns>
        public Feed <T> ExecuteDQL <T>(string dql, FeedGetOptions options)
        {
            decimal count     = 0;
            double  pageCount = 0;

            if (options == null)
            {
                options = new FeedGetOptions();
            }
            string dqlUri = LinkRelations.FindLinkAsString(this.Links, LinkRelations.DQL.Rel);
            string dqlUriWithoutTemplateParams = dqlUri.Substring(0, dqlUri.IndexOf("{"));

            /******************** BEGIN GET TOTAL IF SPECIFIED *****************************/
            if (options != null && options.IncludeTotal)
            {
                String countDql = "select count(*) as total " + dql.Substring(dql.IndexOf("from"));
                List <KeyValuePair <string, object> > cl = options.ToQueryList();
                cl.Add(new KeyValuePair <string, object>("dql", countDql));
                Feed <PersistentObject>          countFeed = Client.Get <Feed <PersistentObject> >(dqlUriWithoutTemplateParams, cl);
                List <Entry <PersistentObject> > res       = (List <Entry <PersistentObject> >)countFeed.Entries;

                foreach (Entry <PersistentObject> obj in res) // There will only be one result
                {
                    count = decimal.Parse(obj.Content.GetPropertyValue("total").ToString());
                }
            }
            /********************* END GET TOTAL IF SPECIFIED ******************************/

            // Now execute the real query
            List <KeyValuePair <string, object> > pa = options.ToQueryList();

            pa.Add(new KeyValuePair <string, object>("dql", dql));
            Feed <T> feed = this.Client.Get <Feed <T> >(dqlUriWithoutTemplateParams, pa);

            if (count > 0)
            {
                feed.Total = (int)count;
            }
            return(feed);
        }
Exemplo n.º 21
0
 /// <summary>
 /// Get the content media URL
 /// </summary>
 /// <returns></returns>
 public String GetMediaUri()
 {
     return(LinkRelations.FindLinkAsString(GetFullLinks(), LinkRelations.CONTENT_MEDIA.Rel));
 }
Exemplo n.º 22
0
 /// <summary>
 /// Whether the document can be checked in
 /// </summary>
 /// <returns></returns>
 public bool CanCheckin()
 {
     return(LinkRelations.FindLinkAsString(GetFullLinks(), LinkRelations.CHECKIN_NEXT_MAJOR.Rel) != null ||
            LinkRelations.FindLinkAsString(GetFullLinks(), LinkRelations.CHECKIN_NEXT_MINOR.Rel) != null ||
            LinkRelations.FindLinkAsString(GetFullLinks(), LinkRelations.CHECKIN_BRANCH_VERSION.Rel) != null);
 }
Exemplo n.º 23
0
 /// <summary>
 /// Cancel check out the document
 /// </summary>
 /// <returns></returns>
 public bool CanCancelCheckout()
 {
     return(LinkRelations.FindLinkAsString(this.Links, LinkRelations.CANCEL_CHECKOUT.Rel) != null);
 }
Exemplo n.º 24
0
 /// <summary>
 /// Whether the document has a predecessor version
 /// </summary>
 /// <returns></returns>
 public bool HasPredecessorVersion()
 {
     return(LinkRelations.FindLinkAsString(this.Links, LinkRelations.PREDECESSOR_VERSION.Rel) != null);
 }
        public static void Run(RestController client, string RestHomeUri, string repositoryName)
        {
            HomeDocument      home         = client.Get <HomeDocument>(RestHomeUri, null);
            Feed <Repository> repositories = home.GetRepositories <Repository>(new FeedGetOptions {
                Inline = true, Links = true
            });
            Repository repository = repositories.FindInlineEntry(repositoryName);

            BatchCapabilities batchCapabilities = repository.GetBatchCapabilities();

            Console.WriteLine("Batch capabilities for this repository:");
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("  - transactional or non-transactional? {0}", batchCapabilities.Transactions);
            Console.WriteLine("  - sequential or non-sequential?       {0}", batchCapabilities.Sequence);
            Console.WriteLine("  - fail on error or continue on error? {0}", batchCapabilities.OnError);
            Console.WriteLine("  - all resources are batch-able except these [{0}] ", String.Join(",", batchCapabilities.NonBatchableResources.ToArray <string>()));
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Press any key to continue batch test..");
            Console.ReadKey();

            Console.WriteLine(String.Format("\r\nPreparing data for the batch.."));
            User currentUser = repository.GetCurrentUser(new SingleGetOptions());

            Console.WriteLine("\t - Fetched current user: "******"user_name"));
            Cabinet homeCabinet = currentUser.GetHomeCabinet(new SingleGetOptions());

            Console.WriteLine("\t - Fetched home cabinet: " + homeCabinet.GetPropertyString("object_name"));

            // start a batch - create 1 folder & 1 document under home cabinet + get dql + create a new relation
            Console.WriteLine("\r\nReady to create a batch with 5 operations:");
            string folderNamePrefix = "BatchTestFolder-";

            Console.WriteLine("\t - (1) create a new folder under home cabinet with name prefix: " + folderNamePrefix);
            string docNamePrefix = "BatchTestDoc-";

            Console.WriteLine("\t - (2) create a new document under home cabinet with name: " + docNamePrefix);
            string dql = "select * from dm_group";

            Console.WriteLine("\t - (3) execute a dql query: " + dql);
            Console.WriteLine("\t - (4) get all relations");
            Console.WriteLine("\t - (5) create a new cabinet with empty name (should fail)");
            Console.WriteLine("Press any key to run batch..");
            Console.ReadKey();

            List <KeyValuePair <string, object> > dqlParams = new List <KeyValuePair <string, object> >();

            dqlParams.Add(new KeyValuePair <string, object>("dql", dql));
            string dqlUri = UriUtil.BuildUri(LinkRelations.FindLinkAsString(repository.Links, LinkRelations.DQL.Rel), dqlParams);

            Batch batch = Batch.CreateFromBuilder()
                          .Description("a sample batch with 4 operations")
                          .BatchSpec(new BatchSpec {
                Transactional = false, Sequential = false, FailOnError = false, ReturnRequest = false
            })
                          .AddOperation <Folder>(
                "batch-opt-1", homeCabinet, LinkRelations.FOLDERS.Rel, "POST", ObjectUtil.NewRandomFolder(folderNamePrefix, "dm_folder")
                )
                          .AddOperation <Document>(
                "batch-opt-2", homeCabinet, LinkRelations.DOCUMENTS.Rel, "POST", ObjectUtil.NewRandomDocument(docNamePrefix, "dm_document")
                )
                          .AddOperation(
                "batch-opt-3", dqlUri, "GET"
                )
                          .AddOperation(
                "batch-opt-4", homeCabinet, LinkRelations.RELATIONS.Rel, "GET"
                )
                          .AddOperation(
                "batch-opt-5", repository, LinkRelations.CABINETS.Rel, "POST", new Cabinet()
                )
                          .Build();

            Batch result = repository.CreateBatch(batch);

            Console.WriteLine("\r\nPrinting batch result..");
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine(String.Format(" - description [{0}]", result.Description));
            Console.WriteLine(String.Format(" - owner       [{0}]", result.Owner));
            Console.WriteLine(String.Format(" - state       [{0}]", result.State));
            Console.WriteLine(String.Format(" - submitted   [{0}]", result.Submitted));
            Console.WriteLine(String.Format(" - started     [{0}]", result.Started));
            Console.WriteLine(String.Format(" - finished    [{0}]", result.Finished));

            foreach (BatchOperation operation in result.Operations)
            {
                Console.WriteLine(String.Format("\r\n - operation    [{0}]", operation.Id));
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(String.Format("\t--> state        [{0}]", operation.State));
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(String.Format("\t--> started      [{0}]", operation.Started));
                Console.WriteLine(String.Format("\t--> finished     [{0}]", operation.Finished));
                Console.WriteLine("\t--> response");
                Console.WriteLine(String.Format("\t-----------> status  [{0}]", operation.Response.Status));

                if (operation.Response.HasError())
                {
                    Error error = operation.Response.GetError();
                    Console.WriteLine(String.Format("\t-----------> entity  [{0}:{1}]", error.Code, error.Message));
                }
                else
                {
                    if (operation.Id.Equals("batch-opt-1") || operation.Id.Equals("batch-opt-2"))
                    {
                        PersistentObject po = operation.Response.GetObject <PersistentObject>();
                        Console.WriteLine(String.Format("\t-----------> entity  [object of URI {0}]", LinkRelations.FindLinkAsString(po.Links, LinkRelations.SELF.Rel)));
                    }
                    else if (operation.Id.Equals("batch-opt-3") || operation.Id.Equals("batch-opt-4"))
                    {
                        Feed <PersistentObject> feed = operation.Response.GetObject <Feed <PersistentObject> >();
                        Console.WriteLine(String.Format("\t-----------> entity  [feed with title {0} and entry count {1}]", feed.Title, feed.Entries.Count));
                    }
                }
            }
            Console.ForegroundColor = ConsoleColor.White;
        }
 /// <summary>
 ///  Delete a user
 /// </summary>
 public void Delete()
 {
     Client.Delete(LinkRelations.FindLinkAsString(GetFullLinks(), LinkRelations.DELETE.Rel));
 }
Exemplo n.º 27
0
 /// <summary>
 /// Whether the object can be updated
 /// </summary>
 /// <returns>Returns Boolean value</returns>
 public bool CanUpdate()
 {
     return(LinkRelations.FindLinkAsString(GetFullLinks(), LinkRelations.EDIT.Rel) != null);
 }
Exemplo n.º 28
0
 /// <summary>
 /// Whether the object can be deleted
 /// </summary>
 /// <returns></returns>
 public bool CanDelete()
 {
     return(LinkRelations.FindLinkAsString(GetFullLinks(), LinkRelations.DELETE.Rel) != null);
 }
Exemplo n.º 29
0
        /// <summary>
        /// Download the content media as stream
        /// </summary>
        /// <returns></returns>
        public Stream DownloadContentMediaStream()
        {
            string contentMediaUri = LinkRelations.FindLinkAsString(GetFullLinks(), LinkRelations.CONTENT_MEDIA.Rel);

            return(Client.GetRaw(contentMediaUri));
        }
Exemplo n.º 30
0
 /// <summary>
 /// Whether the folder has parent folders
 /// </summary>
 /// <returns>Returns Boolean value</returns>
 public bool HasParent()
 {
     return(LinkRelations.FindLinkAsString(GetFullLinks(), LinkRelations.PARENT.Rel) != null);
 }