Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Web service: assign category 1

Status
Not open for further replies.

ahaboub

Technical User
Jul 31, 2009
41
LB
how to assign a category to an existing document in CS, using web services?
 
do you not have access to the webervice forum or the tree appication?
in essence you need a metadata objects and some setter and getter methods to accomplish what you want.
many examples are in the KB

Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
Certified OT Developer,Livelink ECM Champion 2008,Livelink ECM Champion 2010
 
yes, i have access. but didnt find any example for assigning to an already existing document in CS.
 
If you cannot get help at the KB post your new document web service code that attaches a sample category.If I have time I will re-work it to make it into what you want it for.All I require is a simple cs file with just the bare minimum code.
I only know how to do this in C#.If it is VB.NET I will try but know guarantees

Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
Certified OT Developer,Livelink ECM Champion 2008,Livelink ECM Champion 2010
 
hi appnair,
thanks for your reply.
my code only works when the category is already assigned to the document, so it only updates the attributes... if there is no category assigned this will not work.
here is my code:

Code:
        public string AssignCategory(string sessionID, string categoryID, string documentID, string[][] attributes)
        {
            try
            {
                docauth.AuthenticationToken = sessionID;

                DocumentManagement.AttributeGroup[] attributegroups = new DocumentManagement.AttributeGroup[1];
                DocumentManagement.DataValue[] datavalues = new DocumentManagement.DataValue[2];
                DocumentManagement.AttributeGroup attributegroup = new DocumentManagement.AttributeGroup();
                metadata = new DocumentManagement.Metadata();

                DocumentManagement.Node n = new DocumentManagement.Node();
                n = doc.GetNode(ref docauth, int.Parse(documentID));
                DocumentManagement.AttributeGroupDefinition attgrdefinition = doc.GetCategoryDefinition(ref docauth, int.Parse(categoryID));
                attributegroup = doc.GetAttributeGroupTemplate(ref docauth, attgrdefinition.Type, attgrdefinition.Key);
                metadata.AttributeGroups = new DocumentManagement.AttributeGroup[1];
                metadata.AttributeGroups.SetValue(attributegroup, 0);
                datavalues = metadata.AttributeGroups[0].Values;

                n.Metadata = GenerateMetadata(metadata, datavalues, ConvertArrayToList(attributes));
                doc.UpdateNode(ref docauth, n);
            }
            catch (Exception ex)
            {
                return "";
            }
            return "1";
        }
 
hi appnair,
do you have any updates? i will really appreciate it.

regards,
 
I was able to do what you wanted.In the interest of time I consider the implementation very hurried and not prod worthy.But if you have time this is the correct way to do it.

1)GetNode based on dataid or Name
2)Initialize a metadata object
3)Get Category template(or definition which did not work for me on my instance)
4)Ask node if you already have a category.This is important as if you supply a new metadata object it will remove the old category and put the new one that you give.My code is doing that I do not have time or bandwidth to check it further.
5)Populate the metadata object(what a pain) with name value pairs.This could be because i am not webservice savvy as I think everybody except me agrees websvcs is easier than lapi.
6)Update the node.

I will shortly put a link to communities with my C# solution file.In the interest of time create a category and add two keys "Name" and "Job" and hopefully if you do it correctly livelink will put attributeid 2 and 3 respectively.
Then download the solution file and play with it .Let me just say that I will

When time permits I will try to fix most of the hard codings.




Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
Certified OT Developer,Livelink ECM Champion 2008,Livelink ECM Champion 2010
 
I created a new place in the wiki here

In there you should get two files one is the solution file and one is just the C# code.
Hope the links work

Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
Certified OT Developer,Livelink ECM Champion 2008,Livelink ECM Champion 2010
 
hi appnair,
i checked the link, but it seems i do not have enough access on the Content Web Services inside it...
if you can paste your code here, this will be great

and thank you a lot for all the efforts you are doing
 
In the FAQ object there is a See Details link that is where I have embedded the code.It is open for "Public Access" but here it is any way
I have put the whole solution file there as well.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; //for using the file info



/*HUGE DISCLAIMER

THIS DOCUMENT IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SAMPLE CODE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. BY USING THIS CODE YOU AGREE TO THE ABOVE TERMS.*/

//APPOOS AT HOTMAIL.COM FOR AHABAOUB USING 9.7.1 LIVELINK AND C# EXPRESS 2010 WITH 
//[URL unfurl="true"]http://www.tek-tips.com/viewthread.cfm?qid=1684806[/URL]

//SYNOPSIS: WE START WITH A PRIV USER ADMIN/PASSWORD
//WE GET A AUTH TOKEN FOR THIS USER
//WE SET THAT ENCRYPTED COOKIE(TOKEN) INTO OUR DMOTAUTHENTICATION OBJECT
//USING THAT DMOTAUTH OBJECT WE IMPERSONATE A USER IMPUSER AND SET ITS TOKEN
//WE GET A TOKEN THIS IS THE IMP USER
//WE RESET THE DOCUMENTACCESS TOKEN WITH IT SO IT IS AS IF WE HAVE LOGGED ON IN AS THE IMPERSONATED USER

//READ THIS WITHOUT FAIL
//IF A NEWER WEBSVCS SUCH AS CS10 WEBSVCS ARE USED THEN YOU ARE SUPPOSED TO USE THE REF KEY WORK LIKE
////ref keyword to be used when dealing with CS10 webbsvcs
//string impUserToken = authClient.ImpersonateUser(ref impUser, "APPU");
//I CONVERETED A CS10 WEBSVCS CODE TO A 9.7.1 CODE AND I HAD TO COMMENT OUT ALL THE REF STUFF


//FINAL NOTE THIS WAS WRITTEN FOR AHABAOUB IN TEKTIPS HENCE THE FIRST PERSON CALL IN MANY PLACES


namespace AddDocWithCategory
{
    class CreateFolderMoveFolder
    {
        private static Dictionary<int, string> timeZones = new Dictionary<int, string>();

        static void Main(string[] args)
        {
            //==================================================================================
            //  1) Create clients that use the service references
            //==================================================================================
         //  TomCatServiceAuth.AuthenticationClient authClient = new TomCatServiceAuth.AuthenticationClient();
            Authentication.AuthenticationClient authClient = new Authentication.AuthenticationClient();
            Authentication.OTAuthentication impUser= new Authentication.OTAuthentication(); //for impersonating somebody

            DocumentManagement.DocumentManagementClient dc = new DocumentManagement.DocumentManagementClient();
            DocumentManagement.Metadata md = new DocumentManagement.Metadata();

            //call and create clients if we were messing with workflow and users and groups
            //we don't use it here but just as well if somebody asked how to work with workflow or users and groups
            MemberService.MemberServiceClient ms=new MemberService.MemberServiceClient();
            WorkflowService.WorkflowServiceClient ws = new WorkflowService.WorkflowServiceClient();

            
            //  2) Authenticate with the Livelink Server and obtain an authentication token
            //==================================================================================

            DocumentManagement.OTAuthentication dmOTAuth = new DocumentManagement.OTAuthentication();
            DocumentManagement.MoveOptions mo = new DocumentManagement.MoveOptions();
            mo.AddVersion = true;

            

            // mo.AttrSourceType=AddDocWithCategory.AttributeSourceType.ORIGINAL;//it is a ENUM
            // mo.AttrSourceType = AddDocWithCategory.AttributeSourceType.DESTINATION;//it is a ENUM did not work
            //  mo.AttrSourceType = AddDocWithCategory.AttributeSourceType.MERGE;
           // mo.ForceInheritPermissions = true;

             //everything upto this point is on the client nothing really has happened till the next things are done.
            //we have a livelink authenticated webserver at this point no IWA
            try
            {
                string username = "livelink";
                string password = "livelink";
                //string token = authClient.AuthenticateUser(username, password);
                string token = authClient.AuthenticateUser(username, password);
               

                if (token != null)
                {
                    //ESENTIALLY WE GET A DATABASE CONNECTION AND WE HAVE TO SET TO THE INDIVIDUAL SERVICE OBJECTS THOSE
                    //FOR EXAMPLE IF WE WERE USING USERS AND GROUPS CODE WE NEED TO SET THAT TOKEN TO THE MEMEBR SERVICE
                    //LIKEWISE FOR WORKFLOW
                    //msOTAuth.AuthenticationToken = token;
                    dmOTAuth.AuthenticationToken = token;
                    Console.WriteLine("Cookie for Admin user--" + token);

                    

                    DocumentManagement.Node enterprise = dc.GetRootNode( dmOTAuth, "EnterpriseWS");
                    DocumentManagement.Node folder = dc.CreateFolder( dmOTAuth, enterprise.ID, "TEST" + dmOTAuth.AuthenticationToken.ToString(), null, null);
                    //In lapi it was always a Method with a session,and any aother parms for it
                    //that is the same thing that we pass dmOTAuth although webservices do return session tokens to us ?
                    Console.WriteLine(folder.Name + "was created by " + folder.CreatedBy);
                   //NOW THESE ARE SIMPLE DOCUMENT MANAGEMENT CALLS
                    
                  

                  //the user wants to add a document and assign categories to it for this i have created a category called 1 test
                    //its dataid in my system is 559729 it has two keys Name and Job so for livelink code it is akin to saying
                   // 559279.1.2 and 559279.1.3 defid that number its version
                     //ahaboub please see if you understand this
                    int myCategoryID = 559279;
                    
                      //we need to ask the sytem for the category definition or you can get it from the node as well if you were adding 
                    //to afolder that had a category attched to it.In this case you are getting the values of the category from a known node

                    DocumentManagement.AttributeGroup[] attributegroups = new DocumentManagement.AttributeGroup[1];
                    DocumentManagement.DataValue[] datavalues = new DocumentManagement.DataValue[2];
                    DocumentManagement.AttributeGroup attributegroup = new DocumentManagement.AttributeGroup();
                    attributegroup = dc.GetCategoryTemplate(dmOTAuth, 559279);
                     //once we get the categorytemplate we should put the values that need to go in
                    //we have two fields in our category called NAME JOB both are manadatory

                    /*SETTERS FOR INDIVIDUAL VALUES OF THE CATEGORY*/

                    DocumentManagement.StringValue Name = new AddDocWithCategory.DocumentManagement.StringValue();
                    Name.Values = new string[1];
                    Name.Values[0] = "appu";
                    Name.Key = "559279.1.2";  //VERY VERY BAD PARSING HARD CODING AT ITS BEST
                    Name.Description = "my name";
                    DocumentManagement.StringValue Job = new AddDocWithCategory.DocumentManagement.StringValue();
                    Job.Values = new string[1];
                    Job.Values[0] = "myjob";
                    Job.Key = "559279.1.3";  //VERY VERY BAD PARSING HARD CODING AT ITS BEST
                    Job.Description = "my job";
                    //you go on adding the contorted data structure here
                    attributegroup.Values[0] = Name;
                    attributegroup.Values[1] = Job;

                  
                    /*SETTERS FOR ATTRIBUTEGROUPS OF THE CATEGORY*/
                    md.AttributeGroups = new AddDocWithCategory.DocumentManagement.AttributeGroup[1];
                    md.AttributeGroups[0] = attributegroup;
                    /*add a file to the folder we created above*/
                    string filePath = "C:/temp/SAP.pdf";
                    int newdocid = CreateDocumentInAttachmentID(dc, dmOTAuth, folder.ID, filePath,md);
                    Console.WriteLine("A Document was uploaded with cats/atts its ID is " + newdocid);  
                  

                    //AHABOUB PLEASE NOTE THAT ONCE A NODE EXISTS YOU JUST HAVE TO FIND IT AND 
                    //DO THE SAME THING WITH A UPDATE NODE
                    int EXISTINGDOCUMENT_IN_MYLIVELINK = 555096;
                    DocumentManagement.Node EXISTINGDOCUMENT_IN_MYLIVELINK_NODE = dc.GetNode(dmOTAuth, EXISTINGDOCUMENT_IN_MYLIVELINK);
                    EXISTINGDOCUMENT_IN_MYLIVELINK_NODE.Metadata = md;
                    dc.UpdateNode(dmOTAuth, EXISTINGDOCUMENT_IN_MYLIVELINK_NODE);
                    //VERY VERY IMPORTANT
                    //IF THE DOCUMENT IN QUESTION HAS ANOTHER CATEGORY ATTACHED THE ABOVE CALL WILL WIPE IT OUT
                    //SO REALLY YOU HAVE TO ASK THE NODE IF YOU HAVE A CATEGORY AND IF SO ADD THIS NEW METADATA PIECE

                    Console.ReadLine();

                 
                }
                else
                    throw new Exception("Problem obtaining a valid authentication token.");

                authClient.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.Message);
                Console.WriteLine(e.StackTrace);
                Console.ReadLine();
                authClient.Close();
                dc.Close();
                ms.Close(); //we do not use this in this code
                ws.Close();//we do not use this in this code
                
                return;
            }//catch ends
        }//main ends

        static int CreateDocumentInAttachmentID(DocumentManagement.DocumentManagementClient dc, DocumentManagement.OTAuthentication dmOTAuth, int attachmentID, string filePath, DocumentManagement.Metadata md)
        {
           // DocumentManagement.Metadata md = new DocumentManagement.Metadata();
            DocumentManagement.Attachment attach = new DocumentManagement.Attachment();
            // Additional objects needed for the upload...

            FileInfo fileInfo = new System.IO.FileInfo(filePath);
            byte[] contents = File.ReadAllBytes(filePath);
            attach.FileName = Path.GetFileName(filePath);
            attach.Contents = contents;
            attach.FileSize = contents.Length;
            attach.CreatedDate = fileInfo.CreationTime;
            attach.ModifiedDate = fileInfo.LastWriteTime;
            AddDocWithCategory.DocumentManagement.Node myattdoc = dc.CreateDocument(dmOTAuth, attachmentID, "Added document To Attachment", "No Comments", false, md, attach);
            return myattdoc.ID;
        }






    }//class ends
}//namespace ends

Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
Certified OT Developer,Livelink ECM Champion 2008,Livelink ECM Champion 2010
 
appnair, i really appreciate the time you are dedicating.

i reviewed your code (didnt test it yet), but as i see, you are creating the document and assigning the metadata (category) with the same function.
that is great, but what i needed is that i have a document already existing in CS, with no categories attached to it, so i simply need to assign a category to the document.

sorry to waste your time.

regards,
 
appologies appnair, i guess i didnt read the code to the end, i will test it and reply on monday, please ignore my previous message

regards,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top