//Specify import directives
import com.opentext.api.*;
import java.util.*;
public class CreateDocumentAndVersion
{
//class member functions
public static void main (String args[])
{
try
{
//Create a new Livelink Session
LLSession session;
session = new LLSession ("localhost", 4099, "", "Admin", "livelink", null);
//Initialize any LAPI Objects
LAPI_DOCUMENTS doc = new LAPI_DOCUMENTS(session);
LLValue myEntValues=new LLValue();
int volumeID=0, objectID=0,versionID=0;
//we are accessing the enterprise workspace
if (doc.AccessEnterpriseWS(myEntValues) == 0)
{
volumeID = myEntValues.toInteger("VolumeID");
objectID = myEntValues.toInteger("ID");
System.out.println("This and other better Lapi samples at [URL unfurl="true"]http://www.greggriffiths.org");[/URL]
System.out.println("My objID -->"+objectID+" My VolumeID is -->"+volumeID);
System.out.println("I love LAPI.Dr Lapi");
}//if ends
// we need a folder to create our document
//in this example we are trying to create in
//enterprise workspace,change this call to
//any valid folder id for this lapi users
//has 'Add item' perms
int myFolderObjID=objectID;
String myDocToBeUploaded="c:\\temp\\test.txt";
//////////////////////////////////////////////////////////////////////
//Code to Create a Document
//First we create the document node subtype
//Then we add a version
//Demonstrates why this lapi call is superior
//than AddDocument
//////////////////////////////////////////////////////////////////////
//Finally, we can create the document
//create the output variable objectInfo, which will contain the object's information
LLValue objectInfo = (new LLValue()).setAssocNotSet();
//Setup any information for creation
LLValue createInfo = (new LLValue()).setAssocNotSet();
createInfo.add("Comments","These are the document's comments.");
//Create the document object in Livelink
//By changing the subtype you get to create
//the differnet objecrs
if(doc.CreateObjectEx(volumeID, myFolderObjID, doc.OBJECTTYPE, doc.DOCUMENTSUBTYPE, "New Document Name", createInfo, objectInfo) != 0)
{
GetErrors(session);
//if it has errored out we should really be checking what the
//error was .But since this is a createVersion on a pre-existing
//node excercise we will assume that the error is due to a
//pre-existing node we grab its information.For this we need
//to list objects and we are interested in finding only the
//documents
/********************************************************/
CreateVersion(session,doc,volumeID,objectID,objectInfo,myDocToBeUploaded);
return;
}
else
System.out.println("Document Object Created.");
}
catch (Throwable e)
{
System.err.println(e.getMessage());
e.printStackTrace(System.err);
}
}
//This function creates any number of versions if the node already exists
public static void CreateVersion(LLSession session,LAPI_DOCUMENTS doc,int volumeID,int objectID,LLValue objectInfo,String path)
{
LLValue children=(new LLValue()).setTable();
//create the output variable versionInfo, which will contain the version's information
LLValue versionInfo = (new LLValue()).setAssocNotSet();
doc.ListObjects(volumeID,objectID,"DTREE","subtype=144",doc.PERM_FULL,children);
/*since children is a RecArray we have to use content enumeration methods to figure
out the type of the object.The subtype=144 limits returning documents where the
PERM_FULL is applied to the lapi user making this call*/
/* see the full out put of this recarray.For simplicity we take the "Name" out
of it and compare to the name we are trying to give */
}
//This function outputs any errors from the session
public static void GetErrors(LLSession session)
{
System.out.println("Status Code: " + session.getStatus());
System.out.println("Api Error: " + session.getApiError());
System.out.println("Error Message: " + session.getErrMsg());
System.out.println("Status Message: " + session.getStatusMessage());
}
}//Class Ends