RIDC Java code , WebCenter Imaging ,webcenter portal integration using content presenter taskflow

Wednesday 29 February 2012

Using RIDC API we can execute UCM Services.

HOW TO   CHECKIN,CHECKOUT,UPDATE,SEARCH,DELETE,CREATE USERS,GROUPS IN ORACLE UCM FROM JAVA/J2EE APPLICATIONS
USING REMOTE INTRODOC (RIDC API's)

 Below is the sample code for talking to Oracle UCM via RIDC like how to checkin a file into UCM repository
checkout a content from UCM, update an existing content item,how to perform a search and display the results,
how to delete a content item and all of its revisions from UCM repository,How to create a security group ,creating local users (of-course no use in 11g and later revision UCM),How to read a text file which is in UCM repository and display the content and etc..

Here in this code I am using Oracle UCM 10g ,we can use any version of the UCM (bcoz  the UCM services are always same)

Below is the code and  the jar for this is oracle.ucm.ridc-11.1.1.jar  download it and add it in your IDE.


I thought it would be helpful for some beginners Thanks everybody.
--------------------------------------------------------------------------------------------------------

package com.view;


import java.io.BufferedReader;
import java.io.DataInputStream;

import oracle.stellent.ridc.IdcClientManager;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import java.io.InputStreamReader;

import oracle.stellent.ridc.IdcClient;
import oracle.stellent.ridc.IdcClientException;
import oracle.stellent.ridc.IdcClientManager;
import oracle.stellent.ridc.IdcContext;
import oracle.stellent.ridc.model.DataBinder;
import oracle.stellent.ridc.model.DataObject;
import oracle.stellent.ridc.model.DataResultSet;
import oracle.stellent.ridc.model.TransferFile;
import oracle.stellent.ridc.model.impl.DataObjectEncodingUtils;
import oracle.stellent.ridc.protocol.ServiceResponse;



public class GET_FILE {
   
  private final static String idcConnectionURL = "idc://localhost:4444";
  private final static String  username = "sysadmin";
 
  public IdcClient getUCMConnection()
  throws IdcClientException, IOException{
   
   

    IdcClientManager clientManager = new IdcClientManager ();
    IdcClient client = clientManager.createClient(idcConnectionURL);
    IdcContext userContext = new IdcContext(username);
     return client;
    
  }

  public void getFile (String dID)  throws IdcClientException, IOException{
  //Get the client (from the base class) and create a new binder
    System.out.println("In The getFile method.. ");
    System.out.println("This is the dID.. "+ dID);
    IdcClient client =getUCMConnection();
    DataBinder dataBinder = client.createBinder ();
    dataBinder.putLocal ("IdcService", "GET_FILE");
    dataBinder.putLocal ("dID", dID);
    IdcContext userContext = new IdcContext(username);
    ServiceResponse response = client.sendRequest (userContext, dataBinder);
    int reportedSize = Integer.parseInt (response.getHeader ("Content-Length"));
    int retrievedSize = 0;
    String contentsInHex = "";
    //The file is streamed back to us in the response
    InputStream fstream = response.getResponseStream ();
   
      try {
          //  FileInputStream fstream = new response.getResponseStream ();
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String str;
            while ((str = br.readLine()) != null) {
              System.out.println(str);
            }
            in.close();
          } catch (Exception e) {
            System.err.println(e);
          }
   
    response.close();
    System.out.println("This is in the After conversion");
  }
    
    
     public void createUser ()  throws IdcClientException, IOException{
  
      System.out.println("In The createUser method.. ");
      IdcClient client =getUCMConnection();
      DataBinder dataBinder = client.createBinder ();
      dataBinder.putLocal ("IdcService", "ADD_USER");
      dataBinder.putLocal ("dName", "TEST_ROLE");
      dataBinder.putLocal ("dFullName", "TEST_ROLE");
      dataBinder.putLocal ("dPassword", "ibm123$$");
      dataBinder.putLocal ("dUserAuthType", "Local");
      dataBinder.putLocal ("userIsAdmin", "true");
      dataBinder.putLocal ("dEmail", "TEST_ROLE@gmail.com");
      IdcContext userContext = new IdcContext(username);
      client.sendRequest (userContext, dataBinder); 
      System.out.println("After Creating the USER.. " );    
      
    }
 
     public void getUserList()throws IdcClientException, IOException{
    
       System.out.println("In The getUserList method.. ");
       IdcClient client =getUCMConnection();
       DataBinder dataBinder = client.createBinder ();
       dataBinder.putLocal ("IdcService", "GET_USERS");
       IdcContext userContext = new IdcContext(username);
       ServiceResponse response = client.sendRequest (userContext, dataBinder); 
       DataBinder resultSet = response.getResponseAsBinder ();
     
       System.out.println ("Resultset Names :" + resultSet.getResultSetNames());
      // Collection coll = responseData.getResultSetNames();
       DataResultSet drs =  resultSet.getResultSet("Users");
       DataResultSet usrattri =  resultSet.getResultSet("UserAttribInfo");
   
       for (DataObject dataObject : drs.getRows ()) {      
     
       System.out.println ("User Name :" + dataObject.get ("dFullName"));
       }
       for (DataObject dataObject : usrattri.getRows ()) {      
     
       System.out.println (" User Name :" + dataObject.get("dUserName"));
       System.out.println (" Role :" + dataObject.get("AttributeInfo"));
       }
     
       response.close();
       System.out.println("After the getUserList method.. ");
     
  
     }
    
  public void addGroup()throws IdcClientException, IOException{
 
    System.out.println("In The addRole method.. ");
    IdcClient client =getUCMConnection();
    DataBinder dataBinder = client.createBinder ();
    dataBinder.putLocal ("IdcService", "ADD_GROUP");
    dataBinder.putLocal ("dGroupName", "TEST_GROUP");
    dataBinder.putLocal ("dPrivilege", "15");
    dataBinder.putLocal ("dDescription", "admin privileges");
    IdcContext userContext = new IdcContext(username);
    client.sendRequest (userContext, dataBinder); 
 
 
  }
 
  public void checkinFile(String Filename ,String Filepath)throws IdcClientException, IOException{
  
    System.out.println("In The createUser method.. ");
    IdcClient client =getUCMConnection();
    DataBinder binder = client.createBinder ();
  
    System.out.println("In the checkinFile method.. ");
    binder.putLocal ("IdcService", "CHECKIN_UNIVERSAL");
    binder.putLocal ("dDocTitle", "Test_Ridc");
    binder.putLocal ("dDocName", "Test_Ridc");
    binder.putLocal ("dDocType", "Document");
    binder.putLocal ("dDocAuthor", "sysadmin");
    binder.putLocal ("dSecurityGroup", "Public");
    binder.putLocal ("dDocAccount", "");
    binder.putLocal ("dOriginalName", Filename);
    binder.addFile("primaryFile", new TransferFile(new File(Filepath+Filename)));
    IdcContext userContext = new IdcContext(username);
    client.sendRequest (userContext, binder);
    System.out.println("After checkinFile method.. ");
  }
 
  public void checkOutByName(String DocName,String DocTitle) throws IdcClientException, IOException{
 
    System.out.println("In The createUser method.. ");
    IdcClient client =getUCMConnection();
    DataBinder binder = client.createBinder ();
   
    System.out.println("In the checkOutByName method.. ");
    binder.putLocal ("IdcService", "CHECKOUT_BY_NAME");
    binder.putLocal ("dDocName", "DHANU_000048");
    binder.putLocal ("dDocTitle", "TEST...");
    IdcContext userContext = new IdcContext(username);
    client.sendRequest (userContext, binder);
    System.out.println("After checkOutByName method.. ");
 
  }
 
  public void deleteDoc() throws IdcClientException ,IOException {
 
    System.out.println("In the deleteDoc method.. ");
    IdcClient client =getUCMConnection();
    DataBinder binder = client.createBinder ();
    binder.putLocal ("IdcService", "DELETE_DOC");
    binder.putLocal ("dID", "57");
    binder.putLocal ("dDocName", "TESTUPLOADING..");
    IdcContext userContext = new IdcContext(username);
    client.sendRequest (userContext, binder);
    System.out.println("After deleteDoc method.. ");
  
  }
 
 
 
  public void updateDoc()throws IdcClientException,IOException {
   
    System.out.println("In The createUser method.. ");
    IdcClient client =getUCMConnection();
    DataBinder binder = client.createBinder ();
    System.out.println("In the updateDoc method.. ");
    binder.putLocal ("IdcService", "UPDATE_DOCINFO");
    binder.putLocal ("dDocName", "DHANU_000048");
    binder.putLocal ("dID", "54");
    binder.putLocal ("dDocAuthor", "weblogic");
    binder.putLocal ("dDocTitle", "TEST00");
    binder.putLocal ("xlanguage", "UPDATE_TELUGU..");
    IdcContext userContext = new IdcContext(username);
    client.sendRequest (userContext, binder);
    System.out.println("After updateDoc method.. ");
  }
     public void getSearchResults(String querytext)throws IdcClientException, IOException{
      
       System.out.println("In The getSearchResults method.. ");
       IdcClient client =getUCMConnection();
       DataBinder dataBinder = client.createBinder ();
       dataBinder.putLocal ("IdcService", "GET_SEARCH_RESULTS");
       dataBinder.putLocal ("QueryText", querytext);      
       IdcContext userContext = new IdcContext(username);
       ServiceResponse response = client.sendRequest (userContext, dataBinder); 
       DataBinder binder = response.getResponseAsBinder ();
       DataResultSet resultSet = binder.getResultSet ("SearchResults");
       // loop over the results
       for (DataObject dataObject : resultSet.getRows ()) {
       System.out.println (" Title : " + dataObject.get ("dDocTitle") + " Author : " + dataObject.get ("dDocAuthor")   + "    Security Group : " + dataObject.get ("dSecurityGroup") );
     
       }      
     
     }

  public static void main(String[] args) throws IdcClientException,
                                                FileNotFoundException,
                                                IOException, Exception {

        GET_FILE GF = new GET_FILE();
        GF.getFile("62");
        GF.createUser();
        GF.getUserList();
        GF.addGroup();
        GF.checkOutByName("FEB_2012_PAYSLIP","Payslip_Feb_2012");
        GF.updateDoc();
        GF.getSearchResults("dDocAuthor <matches> `sysadmin` <AND> dDocType <matches> `Document`");
        GF.checkinFile("Payslip_Feb_2012.pdf" ,"C:/Documents and Settings/Administrator/Desktop/checkin_Docs/");
        GF.deleteDoc();
       
           }   

}
----------------------------------------------------------------------------------------------------------

13 comments:

  1. Hi, thanks for posting this.
    Would you mind showing me the docs with the list of mapped services you can call with the api,
    for example :

    dataBinder.putLocal ("IdcService", "GET_SEARCH_RESULTS");

    I cant seem to find a complete list of the services.
    thanks in advance!!!

    Mario.

    ReplyDelete
    Replies
    1. Hi Mario,

      Please find the below link for the Oracle UCM documentation for UCM Services Link :http://docs.oracle.com/cd/E21764_01/doc.1111/e11011/toc.htm

      Delete
  2. uhhhh.... nice!!!
    many thanks Dhanunjay, just what I was looking for.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Hi Dhanunjay,
    Is there any way by which i can list IDs of all docs with same doc Name. i.e. if i checked in different versions of file(with diff ids) by any means can i retrieve them all.
    I used this code:

    dataBinder.putLocal("QueryText", "dDocName `"+docName+"`");
    dataBinder.putLocal("SortField", "dInDate");
    dataBinder.putLocal("SortType", "DESC");
    IdcContext userContext = getIdcContext();
    ServiceResponse response = client.sendRequest(userContext, dataBinder);
    DataBinder binder = response.getResponseAsBinder();
    DataResultSet resultSet = binder.getResultSet("SearchResults");
    // loop over the results
    System.out.println("Ids matching same doc name: ");
    for (DataObject dataObject : resultSet.getRows()) {
    System.out.println("ID : " + dataObject.get("dID")+" dDocName : "+ dataObject.get("dDocName") + " Title : " + dataObject.get("dDocTitle") + " Author : " + dataObject.get("dDocAuthor") + " Security Group : " + dataObject.get("dSecurityGroup"));

    }

    But this returns only latest version-ed doc.

    Any suggestions?

    ReplyDelete
  5. Hi,
    With ridc I try to get the dPassword of the current user but i have a String like ----- , it is possible to get the real password ?
    I see the attribut dPasswordEncoding but it define the type of crypting, SHA1-CB.


    ReplyDelete
  6. Hi,

    Dhanujay mama... nuvvuu keka mama.. keep up -- yaznesh

    ReplyDelete
    Replies
    1. Dhanu,

      Can you explain RIDC step by step procedure in High level. just provide it in High level.

      Delete
  7. Hi Dhanunjay,

    Can you please let me know how i will call a service in loop like 'workflow_approve'. When i call service in loop it showing error, first document will approved but for other document it throws service exception document revision is not latest revision.
    Please help me i am stuck on this problem for a long time.

    Regards,
    Deepak Parmar

    ReplyDelete
  8. This is very useful, tks a ton for the post. I have a requirement where the ucm url is https://..., i have to download the security certificate for this? Once again thanks for your time.

    ReplyDelete
  9. Cannot able to connect onpremise ucm server

    ReplyDelete
  10. Dhanunjay, any idea on how we may remove the result count limit altogether on GET_SEARCH_RESULTS? ... as of now I am using dataBinder.putLocal("ResultCount", "2000"); to increase the limit.

    ReplyDelete
    Replies
    1. This is the Out of the box behavior of "GET_SEARCH_RESULTS"& it will return only 2000 results.Please look into the WCC service reference guide for the details.

      Delete