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!

Fetch Category Info of a document

Status
Not open for further replies.

otovb

Programmer
Mar 6, 2008
4
US
Hi all,
I am writing a java program for creating a category and attributes and finally associating this category with a document that is also being created through this code. Now once this document gets created,i want to fetch the category information(NAME) that i assigned to it. But i am unable to do so. kindly suggest some solution. Any code snippet will be appreciated.
thnks
otovb
 
Please confirm whether or not you will be creating a category object and then using that for any document.In most cases the category object is created thru the GUI and somebody gives you its objid.You then use a lapi call to FetchVersion of it,then you manipulate the values to it so that when the document s created it has those values.As far as I can see nobody creates a category and use it only once.
the below java file shows you how you use an existing category version to a newly created document.If you do need code to create a category,it is in lapi online help as well.This code was written and tested on a 9.5 system but I doubt if anything very significant has changed since then.
Code:
import java.util.*;//for our date manip
import java.io.*;
import com.opentext.api.*;	//import LAPI objects

public class ADWC
{

private static String Server = "localhost"; //livelink host
private static int Port = 2099; //livelink server port see opentext.ini
private static String DFT = ""; //default database file or schema
private static String User = "Admin"; //username
private static String Pass = "Admin"; //passwd
public static void main (String args[])
{

	LLSession session;
    LAPI_DOCUMENTS doc;
	session = new LLSession (Server, Port, DFT, User, Pass);
    doc = new LAPI_DOCUMENTS (session);
    LAPI_ATTRIBUTES attr = new LAPI_ATTRIBUTES(session);
  //Grab some value objects
	LLValue entInfo = (new LLValue()).setAssocNotSet();
	LLValue createInfo = (new LLValue()).setAssocNotSet();
	LLValue objectInfo = (new LLValue()).setAssocNotSet();
	LLValue versionInfo = (new LLValue()).setAssocNotSet();
	//Category stuff
	LLValue catID = (new LLValue()).setAssocNotSet();
	LLValue catVersion = new LLValue();
	LLValue attrValues = new LLValue().setList();
	LLValue	attrValPath = new LLValue();
	LLValue categories = new LLValue().setList();
	LLValue cRequest = new LLValue().setAssoc();
	LLValue extData = new LLValue().setAssoc();
	int volumeID;
	int objectID;
		if(doc.AccessEnterpriseWS(entInfo) != 0)
		{
			System.out.println("AccessEnterpriseWS Failed.");
						return;
		}
		  //Show that we got the volumeID and objectID for the EnterpriseWS

			volumeID = entInfo.toInteger("VolumeID");
			objectID = entInfo.toInteger("ID");
			System.out.println("Volume"+volumeID+"ObjID"+objectID);

			//Setup catID, hardcode the categories objectID
			//19280 is the objID of my category called
			//test and it is at version 1
			//Populate the LLValue Object catID with that
			catID.add("ID", 19280);
	        catID.add("Version", 0);
	       //Use the catID to fetch the category Version
		   	if (doc.FetchCategoryVersion(catID, catVersion) != 0)
		   	{
		   		System.out.println("None of that category mate");
		   			   		return;
		   	}

		   	//Add the values to attrValues to be in the attribute
		   	//I have a text attribute called Test that will take
		   	//clear text trash
		   	//I guess if I had a date i would have to set it with a date
		   	//I cannot get both the attributes updated for some reason

		   Date myDate=new Date();//get system date to update this para

           attrValues.add(myDate);

		  	if (attr.AttrSetValues(catVersion, "Test Date", attr.ATTR_DATAVALUES, attrValPath, attrValues) != 0)
					   	{
					   		System.out.println("AttrSetValues Failed.");

					   		return;
		   	}

	        // attrValues.add("This is a test");
		 //  	if (attr.AttrSetValues(catVersion, "Test", attr.ATTR_DATAVALUES, attrValPath, attrValues) != 0)
		   //	{
		   	//	System.out.println("AttrSetValues Failed.");

		   	//	return;
		   //	}



		   	//Add category Version Assoc to categories List
		   	categories.add( catVersion );

		   	//Fill createInfo to spec (see documentation for the structure)
		   	cRequest.add("Comment", "");
		   	createInfo.add("request", cRequest);
		   	createInfo.add("extendedData", extData);
		   	createInfo.add("Categories", categories);


		   	//Create document in enterpriseWS
		   	if(doc.CreateObjectEx(volumeID, objectID, doc.OBJECTTYPE,
		   			doc.DOCUMENTSUBTYPE, "PSMELLO's Docs", createInfo, objectInfo) != 0)
		   	{
		   		System.out.println("CreateObjectEx Failed.");

		   		return;
		   	}
		   	else
		   		System.out.println("Document created successfully");

		   	//Set objectID to objectID of the new document
		   	objectID = objectInfo.toInteger("ID");

		   	//Now upload version to complete document creation
		   	//if this file is not there io errors will happen
		   	if(doc.CreateVersion(volumeID, objectID, "c:\\development\\test.txt", versionInfo) != 0)
		   	{
		   		System.out.println("CreateVersion Failed.");
		   		return;
		   	}
		   	else
		   	{
		   		System.out.println("Version created successfully");

		   	}


}
}

Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
 
hi appnair,
Thnks for the reply. i have used the similiar code and i am able to create the document also and i have associated a category also with it.
For example,
first i created a category say, TestCat and within it I have created an attribute say testDate and then i have created a Document say NewDoc.This whole functionality is working fine. Now once this NewDoc gets created I am also able to see the TestCat associated with it.
Now i am using GetObjectInfo(volumeID, objectID,objectInfo) method to fetch the information(like its name,create date etc) of this NewDoc. I also want to fetch the name of the category(ie TestCat)which i assigned to this NewDoc. But I am unable to do so. Kindly suggest me the way. I am using Livelink 9.7 .
below if the reference code
System.out.println("Document created successfully");
objectID = objectInfo.toInteger("ID");
volumeID = objectInfo.toInteger("VolumeID");

int getobjectinfo;
getobjectinfo=doc.GetObjectInfo(volumeID, objectID,objectInfo);
if(getobjectinfo==0)
{
System.out.println("********Document related Information********");

//System.out.println("This version's created at "+createInfo.toDate("CreateDate"));
System.out.println("Name of the Document "+objectInfo.toString("Name"));
System.out.println("Object ID of the Document "+objectInfo.toInteger("ID"));
System.out.println("Parent ID of the Document"+objectInfo.toInteger("ParentID"));
System.out.println("This version's of the Document created at "+objectInfo.toDate("CreateDate"));
System.out.println("Category Name of the Document "+objectInfo.toString("Category"));

Thnks
otovb
 
If you want to get the categories attached to a document(pls note thi is an assimilation of information stored in different tables) you should use the LAPI call.I am assming that you want user defined categories and not the other one NodeCategories,which are entirely different.

ListObjectCategoryIDs

This function retrieves a list of Category identifiers for Category versions assigned to an object.

So if you have more than one category ID assigned to this you will get that in a list.This ia a list something like
{12345.23456.7891011} these are the objectid's of the category.

For each of these id's you could do a GetObjectInfo and that would give you the name,stuff etc of that category object.

If then you find your test category ,you can do further maniplation like FetchCategoryVersion etc to show in a page or even use its XML cousing to do some stylesheeted stuff.


These are documented in LAPI documentation the same place where you found FetchCategory stuff



Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
 
Oh let me qualify the statement correctly as in true OOP.
If you want to get the categories attached to a document(

it should read
If you want to get the categories attached to an objectt(

I did not want to sound like categories are used only for documents.For all practical purposes you use categories to use a advanced search query.

The ground rules are Documents,Folders,Categories are all objects in LL.You create Objects and you assign categories so you can effectively search on them

Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
 
Thnks appnair,
U are right I am trying to fetch the category info for the user defined categories only.If you can provide some sample code i'll be highly grateful.
Thnks a lot.
otovb
 
I did not test this but here I show you how to parse the list the variables are form your code,maynot work straight out but atleast this is probably how I would do it(obviously it has to work:)Instead of also asking for code please try to understand LLValue objects.They are datastructures.You cannot ver do lapi seriously if you cannot understand them.
Code:
LLValue catIDList = new LLValue();
LLValue objectInfo = new LLValue();
int getObjectCat;
getObjectCat=doc.ListObjectCategoryIDs(objectID,catIDList);


    if getObjectCat == 0
    {
    //the call worked otherwise we may have to exit 
    //what if the good value is not a list as we think it is
        if catIDList.type() ==  LLValue.LL_LIST
         {
         //then we can rest assured we got things we are looking for
         //We just parse the list
             for(int i = 0; i < catIDList.size(); i++) {
               int getObjectInfo;
		getObjectInfo=doc.GetObjectInfo(volumeID, catIDList.toValue(i),objectInfo);
		if(getObjectInfo==0)
                {
                System.out.println("********Category  related Information********");
                System.out.println("Name of the Document "+objectInfo.toString("Name"));
                System.out.println("Object ID of the Document "+objectInfo.toInteger("ID"));
                System.out.println("Parent ID of the Document"+objectInfo.toInteger("ParentID"));
                System.out.println("This version's of the Document created at "+objectInfo.toDate("CreateDate"));		
		}
         
         }

    }


}

Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top