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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating different versions of a document in LAPI

Status
Not open for further replies.

hanreb

Technical User
Jan 23, 2008
90
US
Hi,

Thru LAPI, I am adding a document to livelink.Now, next time when the user tries to add the same file it should be created as a version of the first file.
I have written code for that, I was trying to create a version the second time the file is uploaded in the catch statement.
I use java to program.I am attaching the rpogram here.
/****************My Java program****************
import java.io.*;
import java.util.*;
import java.text.DateFormat.*;
import com.opentext.api.*;

import org.apache.log4j.FileAppender;
import org.apache.log4j.Category;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.Logger.*;


public class versionDocument
{
static Category cat = Category.getInstance(AddDocumentWCategory.class.getName());

private static String Server = ""; //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 = ""; //username
private static String Pass = ""; //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);
LAPI_ATTRIBUTES attributes= 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 defaultValues = new LLValue().setList();
int status;
LLValue objID = new LLValue().setAssoc();
LLValue attrValPath = new LLValue();
LLValue categories = new LLValue().setList();
LLValue cRequest = new LLValue().setAssoc();
LLValue extData = new LLValue().setAssoc();
LLValue attrInfo = new LLValue();
int volumeID=0;
int objectID=0;
int docObjectID=0;
//Get the volumeID and objectID for the EnterpriseWS
try
{
PropertyConfigurator.configure("c://PTDI//log4j.properties");

cat.info("Starting this batch");
if(doc.AccessEnterpriseWS(entInfo) != 0)
{
System.out.println("AccessEnterpriseWS Failed.");
cat.error("Accessing Enterprise workspace failed");
return;
}
//Grab the info from entInfo
volumeID = entInfo.toInteger("VolumeID");
objectID = entInfo.toInteger("ID");
System.out.println("Volume"+volumeID+"ObjID"+objectID);


catID.add("ID", 255917);
catID.add("Version", 0);
//Use the catID to fetch the category Version
if (doc.FetchCategoryVersion(catID, catVersion) != 0)
{
System.out.println("FetchCategoryVersion Failed.");
cat.error("FetchCategoryVersion Failed.");
return;
}

attrValues.add("3-Pending");
if (attr.AttrSetValues(catVersion, "Status", attr.ATTR_DATAVALUES, attrValPath, attrValues) != 0)
{
System.out.println("AttrSetValues Failed here.");
cat.error("Status attrsetvalue failed");
return;
}
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(doc.CreateObjectEx(volumeID, objectID, doc.OBJECTTYPE,
doc.DOCUMENTSUBTYPE, "logfile.txt", createInfo, objectInfo) != 0)
{

cat.error("Create object failed");
// objectID = entInfo.toInteger("ID");

System.out.println("CreateObjectEx Failed.");

System.out.println("Error Message: " + session.getErrMsg());
cat.error("Error Message: " + session.getErrMsg());

// return;
}
else
{

System.out.println("Document Object created successfully:Next we have to add a version to complete it");
}

docObjectID = objectInfo.toInteger("ID");

if(doc.CreateVersion(volumeID, docObjectID, "c:\\temp\\tlist.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");
}
objID.add("ID",docObjectID);

}
catch(Exception ex)
{
cat.error("in catch");
System.out.println("in catch ");

int m =doc.CreateVersion(volumeID, docObjectID, "c:\\temp\\tlist.txt", versionInfo);
System.out.println("value of m is"+ m);

}

} //Main ends
}//Class ends



*/
I greatly appreciate your help.

Thanks,
Sunu
 
Hi Sunu,this is very simple,Before you create the document object run the command doc.listobjects with subtype=144(document subtype).That will return you all the objectid's underneath that container.The return value is a list you iterate the size of it and check if the objid's .name is equal to what you are about to add,once you determine that you have your objid,all you now do is doc.addVersion.I wrote this a while back for the community.It is a csharp file that is freely portable to java.After all C# is java.... for all practical purposes
Code:
using System;
using System.Collections.Generic;
using System.Text;
using com.opentext.api;
using System.IO;
using System.Security.Permissions;

/*For more samples on java you could always visit 
 [URL unfurl="true"]http://www.greggriffiths.org/livelink/development/lapi/[/URL]
 I started with java so C# was a pretty easy switch
 Just follow the rudimentaries on your proj refrences
 which are using com.opentext.api which should eb installed on the 
 client.LAPI_Netp and LAPI_SSPIp if you are doing dir svcs stuff 
 rather than socket calls.vjslib so that you can get native java stuff
 I also work and program in oscript so debugging lapi is kind of easy for me
 but basically lapi gives everything out to you as huge beautiful data structures
 so rev up your Sartaj Sahni and Ellis Horowitz books  Data Structures(the things
 you learned   in CS but never thought would use)
 */

/*
  Intent of the program
  Access a livelink personal workspace
  Add a version to a document that is pre existing
  code to add a document is not here
  you may have to add thru the GUI
  or get code for that
 THIS CODE MAY NOT BE USED FOR PRODUCTION UNLESS YOU KNOW WHAT IT DOES 
 THIS IS EXPLANATORY CODE AND I AS AUTHOR CANNOT B HELD LIABLE FOR
 ANY DAMAGE TO YOUR SYSTEM
 */

namespace ConsoleApplication6
{
    class DoesObjectExist
    {
        static void Main(string[] args)
        {
            Console.Out.WriteLine("Hello World");

            try
            {

                LLSession session = null;
                LAPI_DOCUMENTS documents = null;
                int status = 0;
                int nodeID = 0;
                int parentID = 0;
                int nodeVol = 0;
                int parentVol = 0;

                LLValue pwsInfo = (new LLValue()).setAssocNotSet();
                LLValue objInfo = (new LLValue()).setAssocNotSet();
                LLValue versionInfo = (new LLValue()).setAssocNotSet();

                //Testing for lee starts
                LLValue fileInfo = (new LLValue()).setAssocNotSet();
                

                

                //My instance
                //session = new LLSession("localhost", 2099, "", "Admin", "Admin", null);

                

                // Instantiate documents object
                documents = new LAPI_DOCUMENTS(session);

                // Access the user's Personal Workspace
                status = documents.AccessPersonalWS(pwsInfo);
                if (status == 0)
                {
                    Console.WriteLine("Accessed Personal  Workspace");
                    parentVol = pwsInfo.toInteger("VolumeID");
                    parentID = pwsInfo.toInteger("ID");
                    Console.WriteLine("ParentVol****" + parentVol);
                    Console.WriteLine("ParentID****" + parentID);
                }



                //Trying out lee's code
                int LLExistingFolder = parentID;
                string ExistingFileName = "aa.las";
                string LLFilepath2 = @"C:\kmg.com\hou-files\Well_Data\Checked\US_Offshore-GOM\Viosca_Knoll\207\06_Single_Well\003S0B0\A_Pre-Spud-Information\vk_207_003s0b0_60816404030000_reg_form_wy.txt";
     
                LLValue children = (new LLValue()).setTable();
                status=documents.ListObjects(parentVol,parentID,"DTREE",null,8,children);
               
                LLValueEnumeration enumeration;
                enumeration = children.enumerateValues();

                /*Picture the ListObjects like this we asked for listobjects of 234
                select * from dtree where parentid=234
                VolID,ParentID,DataID,SubType,VersionNum,name lots more ------ almost 80 fields....
                123,234,354,0,0,myfolder
                123,234,355,144,aa.las
                123,234,356,144,11.last This api calls DAPI.ListContents */
                
                /*look for gurus such as Steve Piatt,Christopher Meyer,Paul Huelskamp
                 Glenn Heying to name a few in the OT knowledge base.I learnt/hacked from them
                 If you learnt something from this give us in your mind thanks and spread
                 some good thing about livelink and its API's rather than *****ing about it
                 */


                while (enumeration.hasMoreElements())
                {
                    LLValue currentRec = enumeration.nextValue();
                    //Console.WriteLine( "Name = " + currentRec.toString( "Name" ) );
                                     
                    if (currentRec.toString( "Name" ).Equals( ExistingFileName))
                    {
                    String messageStr="An object of subtype: "+currentRec.toString("SubType");
                           messageStr=messageStr + " and Name :" + currentRec.toString("Name");   
                           messageStr=messageStr+ " and ObjID :"+currentRec.toString("ID");
                           messageStr=messageStr+ " exist with version num of  :"+currentRec.toString("VERSIONNUM");
                           Console.WriteLine(messageStr);
                           Console.WriteLine(currentRec.toInteger("SubType"));
                        //if we enter this block and our subtype is 144 we add the version
                             
                             if (currentRec.toInteger("SubType") == LAPI_DOCUMENTS.DOCUMENTSUBTYPE)
                             {
                             Console.WriteLine("We should add a version for this "+messageStr);
                             status = documents.CreateVersion(currentRec.toInteger("VolumeID"), currentRec.toInteger("ID"), LLFilepath2, versionInfo);
                             Console.WriteLine("What is our status here is "+status);
                            //In prod worthy code you really look at the status and do what needs to be done

                             }
                             else
                             {
                             //we still have to abort livelink will not allow objects
                             //Tell that to the caller graciously.This else is handling a situation like 
                             //I created a folder called aa.las and user is adding a document called aa.las
                             Console.WriteLine("Aborting");
                             }
                    
                    
                    
                    }

                }
                
                           


                if (status != 0)
                {
                    // Display status code in both integer and hex
                    System.Console.WriteLine("Status=" + status +
                          " (0x" + Convert.ToString(status, 16) + ")");
                   
                    // If the session handle is valid, get the session's error 
                    // information
                    if (session != null)
                    {
                        // Get the error information
                        int stat = session.getStatus();
                        string message = session.getStatusMessage();
                        string errMsg = session.getErrMsg();
                        string apiError = session.getApiError();

                        Console.WriteLine("Session failure status is " + stat +
                                   " (0x" + Convert.ToString(stat) + ")");

                        if (message != "" || errMsg != "" || apiError != "")
                        {
                            Console.WriteLine("Message=" + message);
                            Console.WriteLine("errMsg=" + errMsg);
                            Console.WriteLine("apiError=" + apiError);
                        }
                    }
                }





                Console.ReadLine();
            }
            catch (Exception e)
            {
                // Display exception
                Console.WriteLine("Application encountered an exception:");
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
              
            }


        }
    }
}

Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
 
Sorry forgot to say listobjects is not a list but a recarray aka setTable.The code excerpt however is correct.

Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
 
Hi Nair,

Thanks for your response. I got it working after going thru your c# code.
I appreciate your help.

Thanks,
Sunu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top