import java.io.*;
import com.opentext.api.*; //import LAPI objects
//lapi.jar should be available in classpath
public class AddDocument
{
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[])
{
//variables
LLSession session;
LAPI_DOCUMENTS doc;
//create a new session
//Get into livelink
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;
//Get the volumeID and objectID for the EnterpriseWS
if(doc.AccessEnterpriseWS(entInfo) != 0)
{
System.out.println("AccessEnterpriseWS Failed.");
return;
}
//Grab the info from entInfo
volumeID = entInfo.toInteger("VolumeID");
objectID = entInfo.toInteger("ID");
System.out.println("Volume"+volumeID+"ObjID"+objectID);
/*
Setup catID, hardcode the categories objectID we have the session now let's mess on categories
Note that we are NOT creating a category but rather APPLYING a category to a library object
such as a folder or document.If the Category has a mandatory value LL will forgive you for
folder creation but not for version object such as a document.There is athird type of metadata
in livelink called AdditionalNodeAttributes that can be understaood by looking at the GUI for object
creation
*/
catID.add("ID", 152278);
catID.add("Version", 0);
//Use the catID to fetch the category Version
if (doc.FetchCategoryVersion(catID, catVersion) != 0)
{
System.out.println("FetchCategoryVersion Failed.");
return;
}
//Add the values to attrValues to be in the attribute
//This is a validval which is a list object or appears as
//a TEXT POPUP in livelink
attrValues.add("7 - Pending Transmittal");
if (attr.AttrSetValues(catVersion, "Status", attr.ATTR_DATAVALUES, attrValPath, attrValues) != 0)
{
System.out.println("AttrSetValues Failed.");
return;
}
LLValue attrValues1 = (new LLValue()).setList();
attrValues1.add("1.000");
//See I have added the mandatory stuff for documents only
if (attr.AttrSetValues(catVersion, "Documentation Code", LAPI_ATTRIBUTES.ATTR_DATAVALUES, attrValPath, attrValues1) != 0)
{
System.out.println("AttrSetValues Failed.");
return;
}
/*In prod worthy code you will write a routine to find the catversion datastructure and see if the key/value
pair aka ASSOC that you are setting is matched up on datatypes*/
//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);
//If there is more than one category applied hence the reason for categories being a list
//see how efficient data structures are in input/output
//IN LL you create an OBJECT and then follow up additional stuff for eg
//Folder is just a marker in a database,whereas a document needs a non zero
//byte document to serve somebody with.But true to OOP an Object is the base class
//then you have Folder,Document et al.Never use the AddDocument LAPI command
//it is severely limited in metadata capabilities.
//Create document in enterpriseWS
if(doc.CreateObjectEx(volumeID, objectID, doc.OBJECTTYPE,
doc.DOCUMENTSUBTYPE, "BrandNewDocWithCategory1", createInfo, objectInfo) != 0)
{
System.out.println("CreateObjectEx Failed.");
return;
}
else
{
System.out.println("Document Object created successfully:Next we have to add a version to complete it");
}
//Set objectID to objectID of the new document
objectID = objectInfo.toInteger("ID");
//Now upload version to complete document creation
if(doc.CreateVersion(volumeID, objectID, "c:\\test.txt", versionInfo) != 0)
{
System.out.println("CreateVersion Failed.be sure to remove the 0 byte stub in livelink if this happens");
return;
}
else
{
System.out.println("Version created successfully");
}
} //Main ends
}//Class ends