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!

How do I create a folder as a child of a project using LAPI ?

Status
Not open for further replies.

Tailes

Programmer
Jan 9, 2007
3
UA
Hi All.
What I need is to create a folder inside LiveLink project using LAPI in C++. I use "LL_CreateObjectEx" function for creating project and "LL_CreateFolder" for folder. The expected result is the folder as child of project, but it is displayed as a subproject object.

Here is the source:

LL_Initialize( LL_HEADER_VERSION );
LL_SessionAllocEx( &session, m_repositoryName, m_nPort, _T("livelink"), m_userName, m_password, NULL );
LL_ValueAlloc( &objectInfo );
LL_ValueAlloc( &createInfo );
LL_ValueSetAssocInArgs( createInfo );
LL_AccessEnterpriseWS( session, objectInfo );
LL_AssocGetInteger( objectInfo, "ID", &parentID );
LL_AssocGetInteger( objectInfo, "VolumeID", &parentVol );
LL_CreateObjectEx( session, parentVol, parentID, LL_OBJECTTYPE, LL_PROJECTSUBTYPE, "Project1", createInfo, objectInfo ); //// project is created correctly
LL_AssocGetInteger( objectInfo, "ID", &parentID );
LL_CreateFolder( session, parentVol, parentID, "Folder1", objectInfo ); //This creates a subproject folder

If I create the folder manually it appears as simple subfolder. The question is what should I do to create a folder in a project that is not a subproject?

Thanks in advance,
Alexander.
 
I do not know perhaps yours is a customized lapi header/class but OT standard lapi libraries does not include a LL_CreateFolder signature.

However I would advise you to read this section on the lapi documentation
Appendix B: Valid Object Parentage which is in sort a disclaimer of how things you program.
In any case the CreateObjectEx call can actually be used to
create a folder in a project object subtype.The only pre-conditions are the folder's parentid is the project object's ID and its volume.There used to be a bug in the volume concept so in most cases volume of zero does not hurt so long as you get the parentid right.
So something like

LL_CreateObjectEx( session, parentVol of my project or zero, parentID of my Project Object, LL_OBJECTTYPE, LL_FOLDERSUBTYPE, "Folder1", createInfo2, objectInfo ); ////

Try to see if this fixes anything




Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
 
Thank you for your reply, but unfortunately it did not help. The folder is created as a child of a project, right, but it is displayed in a list of "Sub-Projects", while I need it to appear in a list of generic sub-objects.
 
Actually I meant dataid of the parent object

My Bad,

LL_CreateObjectEx( session, parentVol of my project or zero, DatatID of my Project Object, LL_OBJECTTYPE, LL_FOLDERSUBTYPE, "Folder1", createInfo2, objectInfo ); ////

Since you say it is not working to spec let me try a quick sample.
You want to create a project and add a folder in it correct ? and the folder should be a regular ll folder ...

Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
 
Here's what I could find you need to make the container object which is the project a negative,and make the volume 0.
Apologize for java code and a lot of debugging but towards the end you can see how I am doing this
This creates a project object and myuy next call I created a folder object.I did this on a 9.5 sp1 oracle machine using 9.5 lapi class libraries
Code:
/*
 * Main.java
 *
 * Created on January  11 , 2006, 8:59 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

//package mylapi;
//commented what the netbeans IDE gave me.
import com.opentext.api.*;
/*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 references
 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 jut so that we know lapi works
  Access a user account "tbarrand" as user "Admin"
 *Without checking anything strip him of the login
 *This user
 *[URL unfurl="true"]http://tek-tips.com/viewthread.cfm?qid=1273982&page=1[/URL]
 *wanted a quick and dirty answer
 THIS CODE MAY NOT BE USED FOR PRODUCTION UNLESS YOU KNOW WHAT IT DOES
 THIS IS EXPLANATORY CODE AND I AS AUTHOR CANNOT BE HELD LIABLE FOR
 ANY DAMAGE TO YOUR SYSTEM
 */


/* I compiled this on a winXp machine running JDK 5
I had to do something like C:\KMGJava>javac -source 1.4 -target 1.4 RevokeUserPrivs.java
because java advanced and I am missing something with my lapi dev
*/







/**
 *
 * @author appoos@hotmail.com
 */
public class CreateProjectFolder{

    /** Creates a new instance of Main */
    public CreateProjectFolder() {
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here


    System.out.println("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();
         LLValue createInfo = ( new LLValue() ).setAssocNotSet();
            // Instantiate session object
         session = new LLSession( "localhost", 2099, "","Admin", "", null );
         // Instantiate documents object
         documents = new LAPI_DOCUMENTS( session );


          // Access the user's Personal Workspace
         status = documents.AccessEnterpriseWS( pwsInfo );

         if ( status == 0 )
         {
            System.out.println ( "Accessed Enterprise Workspace" );
            parentVol = pwsInfo.toInteger( "VolumeID" );
            parentID = pwsInfo.toInteger( "ID" );
         }


//create something in my personal workspace and add a folder to it no error traps



status = documents.CreateObjectEx(parentVol,parentID,LAPI_DOCUMENTS.OBJECTTYPE,LAPI_DOCUMENTS.PROJECTSUBTYPE,"My project",createInfo,objInfo);

 System.out.println ( "Project objID"+objInfo.toInteger( "ID" ) );

 //make the container holding it negative

status = documents.CreateObjectEx(0,-(objInfo.toInteger( "ID" )),LAPI_DOCUMENTS.OBJECTTYPE,LAPI_DOCUMENTS.FOLDERSUBTYPE,"My FOLDER",createInfo,objInfo);

//Did not like the negative volume id concept
//status = documents.CreateObjectEx(-(objInfo.toInteger( "VolumeID" )),-(objInfo.toInteger( "ID" )),LAPI_DOCUMENTS.OBJECTTYPE,LAPI_DOCUMENTS.FOLDERSUBTYPE,"My FOLDER",createInfo,objInfo);




// Handle any errors
         if ( status != 0 )
         {
            // Display status code in both integer and hex
            System.err.println( "Status=" + status +
                  " (0x" + Integer.toHexString( status ) +")" );

               // If the session handle is valid, get the session's error information
            if ( session instanceof LLSession )
            {
               // Get the error information
               int stat = session.getStatus();
               String message = session.getStatusMessage();
               String errMsg = session.getErrMsg();
               String apiError = session.getApiError();


                  System.err.println ("Session failure status is " + stat +
                  " (0x" + Integer.toHexString( stat ) + ")" );

               if ( message != "" || errMsg != "" || apiError != "" )
               {
                  System.err.println( "Message=" + message );
                  System.err.println( "errMsg=" + errMsg );
                  System.err.println( "apiError=" + apiError );
               }
            }
         }


            System.out.println( "End of sample" );

         System.exit(status );
      }

 catch ( Throwable e )
      {
         // Display exception

     //Catch and finally will run only lastly
     //Use status var effectively when doing lapi development
         System.err.println( "Application encountered an exception:" );
         System.err.println( e.getMessage() );
         e.printStackTrace( System.err );
      }














    }

}

Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
 
Thenk you for your help. After several tests I have finally found out the way it has to be in my case.

LL_Initialize( LL_HEADER_VERSION );

LL_SessionAllocEx( &session, m_repositoryName, m_nPort, _T("livelink"), m_userName, m_password, NULL );

LL_ValueAlloc( &objectInfo );
LL_ValueAlloc( &createInfo );
LL_ValueSetAssocInArgs( createInfo );

LL_AccessEnterpriseWS( session, objectInfo );
LL_AssocGetInteger( objectInfo, "ID", &parentID );
LL_AssocGetInteger( objectInfo, "VolumeID", &parentVol );

LL_CreateObjectEx( session, parentVol, parentID, LL_OBJECTTYPE, LL_PROJECTSUBTYPE, "Project1", createInfo, objectInfo );

LL_AssocGetInteger( objectInfo, "ID", &projectID );
LL_AssocGetInteger( objectInfo, "VolumeID", &projectVol );

LL_CreateObjectEx( session, projectID, -projectID, LL_OBJECTTYPE, LL_FOLDERSUBTYPE, "Folder1", createInfo, objectInfo ); // this creates a generic subfolder

//LL_CreateObjectEx( session, projectVol, projectID, LL_OBJECTTYPE, LL_FOLDERSUBTYPE, "Folder1", createInfo, objectInfo ); // this created the Sub-Project item.

Now it is working the way I need. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top