Visualizzazione post con etichetta ridc. Mostra tutti i post
Visualizzazione post con etichetta ridc. Mostra tutti i post

giovedì 12 luglio 2012

Oracle UCM: Create Folders and Subfolders in UCM using RIDC

In this post I provide code to add another functionality to our class: create Folders and Subfolders in Content Server using RIDC.

Please note that Perform Documents Check-In using Remote IntraDoC (RIDC)  contains the prerequisite code since in this post I don't provide the full java code but just additions.

This method lets you create folders and subfolders under "Contribution Folders".
As you probably know Contribution Folders can be enabled activating "Folders_G" component in UCM Administration.

Add this code to UCMAdapter.java

    //Creates a Folder in Content Server
    public void createFolder(String folderOwner, String folderName, String Has_Parent, String ParentCollectionID,

String securityGroup) {
        ServiceResponse severiceResponse = null;
       
        try {
            System.out.println("Creating Folder: " + folderName);
           
            IdcClient client = getIdcClient();
            DataBinder dataBinderReq = client.createBinder();
            dataBinderReq.putLocal("IdcService", "COLLECTION_ADD");
            dataBinderReq.putLocal("dCollectionName", folderName);
            dataBinderReq.putLocal("hasParentCollectionID", Has_Parent);
            dataBinderReq.putLocal("dParentCollectionID", ParentCollectionID);
            dataBinderReq.putLocal("dCollectionOwner", folderOwner);
            dataBinderReq.putLocal("dSecurityGroup", securityGroup);
           

            severiceResponse = client.sendRequest(new IdcContext(folderOwner), dataBinderReq);
            DataBinder dataBinderResp = severiceResponse.getResponseAsBinder();           
   
            System.out.println("Folder " +folderName +" successfully created");
                               
        } catch(Exception ex) {
            System.out.println("Error creating Folder: " + ex.getMessage());
           
        } finally {
            if (severiceResponse != null) {
                severiceResponse.close();
            }
        }
    } //
   
   
    //Returns Folder ID
    public String getFolderIdFromPath(String username, String path){
        String folderId=null;
       
        try {
            IdcClient client = getIdcClient();
            DataBinder dataBinder = client.createBinder();
            dataBinder.putLocal("IdcService", "COLLECTION_INFO");
            dataBinder.putLocal("hasCollectionPath", "true");
            dataBinder.putLocal("dCollectionPath", path);

            ServiceResponse response = client.sendRequest(new IdcContext(username), dataBinder);
            DataBinder serverBinder = response.getResponseAsBinder();
            DataResultSet resultSet = serverBinder.getResultSet("PATH");
            DataObject dataObject = resultSet.getRows().get(resultSet.getRows().size() - 1);
            folderId = dataObject.get("dCollectionID");  
                               
        } catch(Exception ex) {
            System.out.println("Error: " + ex.getMessage());               
        }
       
        return folderId;
    } //

Then create a new Main.java and paste this code:

public class Test {
   
    public static void main(String[] args) {
   
    //EDIT THESE VARIABLES
        String username = "weblogic";
        String securityGroup = "Public";
        String mainFolderName = "MAIN FOLDER NAME";
        String subFolderName = "SUB FOLDER NAME";
        String subSubFolderName = "SUB SUB FOLDER NAME";
    //
       
    try {

        //Istanciate objects
        UCMAdapter ucm = new UCMAdapter();
        Document d = new Document();

                       
        //Create Main Folder under "Contribution Folder"
        ucm.createFolder(username, mainFolderName, "true", ucm.getFolderIdFromPath("weblogic", "/Contribution Folders"), securityGroup);
                       
        //Create Sub Folder under Main Folder
        ucm.createFolder(username, subFolderName, "true", ucm.getFolderIdFromPath("weblogic", "/Contribution Folders"+ "/" + mainFolderName), securityGroup);
                           
        //Create Sub Sub Folder under Sub Folder
        ucm.createFolder(username, subSubFolderName, "true", ucm.getFolderIdFromPath("weblogic", "/Contribution Folders" + "/" + mainFolderName + "/" + subFolderName), securityGroup);
       
        //...and so on
       
    } catch (Exception ex) {
        ex.printStackTrace();
    }
   
  }
}//end class


In the code above you have a pattern that allow you to create a folder tree with sub-folders, sub-sub-folders and so on...

Obviously you need to edit some variables according to your preferences.

That's all!!

lunedì 9 luglio 2012

Oracle UCM: Download Documents from UCM to your PC using RIDC

In this post I provide another functionality to download files from Content Server to your PC using RIDC.

Please note that Perform Documents Check-In using Remote IntraDoC (RIDC)  contains the prerequisite code since in this post I don't provide the full java code but just additions.

This is a simple code snippet that downloads a single file from Oracle UCM to your PC.

Add a new method to our already discussed UCMAdapter.java

public InputStream getFile(String username, String documentId) {
        ServiceResponse severiceResponse = null;
       
        try {
            IdcClient client = getIdcClient();
            DataBinder dataBinderReq = client.createBinder();
            dataBinderReq.putLocal("IdcService", "GET_FILE");
            dataBinderReq.putLocal("dID", documentId);

            severiceResponse = client.sendRequest(new IdcContext(username), dataBinderReq);
            InputStream is = severiceResponse.getResponseStream();
            System.out.println("GET_FILE size: " + is.available()); 
            return is;           
                               
        } catch(Exception ex) {
            System.out.println("Error GetFile(): " + ex.getMessage());               
        }
        return null;
}//-

Then recreate an empty file Main.java and paste this code:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

public class Main {
   
    public static void main(String[] args) {
       
    //EDIT THESE VARIABLES
        //ID of the file to retrieve
        String docID="6231";
        //Where to download file
        String fileSaveLocation = "C:\\file.pdf";
        //User who performs file download
        String username = "weblogic";
    //   

        //Instanciate objects
         UCMAdapter ucm = new UCMAdapter();
         new Document();
        
         //Download file
         try
           {
           File f=new File(fileSaveLocation);
           InputStream inputStream= ucm.getFile(username, docID);
           OutputStream out=new FileOutputStream(f);
           byte buf[]=new byte[1024];
           int len;
           while((len=inputStream.read(buf))>0)
           out.write(buf,0,len);
           out.close();
           inputStream.close();
           System.out.println("\n File correctly created.");
           }
           catch (IOException e){
          System.out.println("\n Error creating file.");
          }
         
    }//
}//end class

Note that in the code above you need to set some variables.

docID = "6231"

Is the Document ID of the document we want to download to our PC. You can modify this code in a more elegant way which performs a document search and automatically retrieves Document ID of the file you need to download.

fileSaveLocation = "C:\\file.pdf"

Is the path where you download the file and which kind of file extension you are retrieving...this is a really basic code, you may need to introduce a more sophisticated feature like perform a check of file extension directly from Content Server and automatically set this variable using the appropriate file name and extension based on file extension readed from UCM.

Finally

username = "weblogic"

Is the username who performs file dowload.

That's all!!

venerdì 6 luglio 2012

Oracle UCM: Perform Document Search using RIDC

This post is a continuation of the previous post Perform Documents Check-In using Remote IntraDoC (RIDC) and explains how to perform a search among all documents in a Content Server using RIDC library.

For this code I assume you have already all three java classes as stated here:

Perform Documents Check-In using Remote IntraDoC (RIDC)

We need to add a new method to UCMAdapter.java class.
Copy paste this code:

//This method search for all documents in Content Server with a given title
public List<Document> search(String username, String title) {

        System.out.println("Search Username: " + username);
     
        ServiceResponse serviceResponse = null;
        List<Document> list = new ArrayList<Document>();
       
        try {
            StringBuilder query = new StringBuilder();

        //If title is not null build the query
            if (title != null) {
                query.append("dDocTitle <matches> `");   
                query.append(title);
                query.append("`");
            }

           
            System.out.println("Search Query: " + query.toString());
           
            IdcClient client = getIdcClient();
            DataBinder dataBinderReq = client.createBinder();

        //Perform the search using IDC Service GET_SEARCH_RESULTS
            dataBinderReq.putLocal("IdcService", "GET_SEARCH_RESULTS");
            dataBinderReq.putLocal("QueryText", query.toString());
       
        //Display first 100 results
            dataBinderReq.putLocal("ResultCount", "100");
   
            serviceResponse = client.sendRequest(new IdcContext(username), dataBinderReq);
            DataBinder dataBinderRes = serviceResponse.getResponseAsBinder();
            DataResultSet resultSet = dataBinderRes.getResultSet("SearchResults");
       
        //Add results to a list
            for (DataObject dataObject : resultSet.getRows()) {
                Document d = new Document();
                d.setContentId(dataObject.get("dDocName"));
                d.setDocumentId(dataObject.get("dID"));
                d.setOwner(dataObject.get("dDocAuthor"));
                d.setTitle(dataObject.get("dDocTitle"));
               
                list.add(d);
            }
           
       
        } catch(Exception ex) {
            System.out.println("Error Search: " + ex.getMessage());
        } finally {
            if (serviceResponse != null) {
                serviceResponse.close();
            }
        } 
     return list;
}//

To perform a search we need a new main class. Overwrite previously created Main.java with this code:

import java.util.List;

public class Main {
   
    public static void main(String[] args) {

         UCMAdapter ucm = new UCMAdapter();
         new Document();
        
         //Here we search for all documents with a title of "Document Title". Weblogic is the user who perform the search
         List<Document> docs = ucm.search("weblogic", "Document Title");
         for (Document item : docs) {
            
             item.getDocumentId();
             //As output returns Document ID, Document Title and Document Owner   
             System.out.println(item.getDocumentId() +" "+ item.getTitle() +" "+ item.getOwner());
             
         }   
         
    }
}//


That's all!

lunedì 2 luglio 2012

Perform Documents Check-In using Remote IntraDoC (RIDC)

It's a pretty common task to perform document operations using RIDC Libraries.

In this post I provide a sample code to perform a new document chech-in on Oracle WebCenter Content, also known as Universal Content Management or simply "UCM".
In following posts I will increase the set of operations that you will able to perform on WebCenter Content using RIDC.

I use Eclipse for coding.

For using RIDC on a Content Server you need first to download RIDC libraries from here:

http://download.oracle.com/otn/content_management/ContentIntegrationSuite_10gR3_20081218.zip

Open Eclipse and create a new Java Project.

Extract oracle-ridc-client-10g.jar from previously downloaded file and import this library in you Eclipse Project (Right Click on your project --> Properties --> Java Build Path --> Libraries)


Under "src" folder create a new folder called "resources", in this folder create a file named ucm.properties with following content:

UCM_URL=idc://10.0.0.12:4444

The string above rapresents IP Address of your Content Server and IntraDoC port (by default this port is 4444, you have set this value during Content Server initial configuration).

Now create three Java Classes:

1) UCMAdapter.java - The class providing all methods to perform operations on Content Server
2) Document.java - The class which contains document properties
3) Main.java - The main class which will be launched and will invoke methods in UCMAdapter.java

Copy this code in UCMAdaper.java

import java.io.InputStream;

import java.util.ArrayList;
import java.util.List;

import java.util.Properties;

import oracle.stellent.ridc.IdcClient;
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.protocol.ServiceResponse;




public class UCMAdapter {
   private String IDC_URL = null;
   
   //Retrieving configuration
   public UCMAdapter() {
        try {
            InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("resources/ucm.properties");
            Properties p = new Properties();
            p.load(is);
           
            IDC_URL = p.getProperty("UCM_URL");
           
            System.out.println("Load configuration DONE: " + IDC_URL);
           
        } catch(Exception ex) {
            System.out.println("Error load configuration: " + ex.getMessage());
        }
    }//
   
    //This method performs a check-in of a new document in Content Server
    public void checkIn(String username, Document doc, InputStream attachment, String contentType) {
        ServiceResponse severiceResponse = null;
       
        try {
            System.out.println("CheckIn Workflow: title: " + doc.getTitle() + " - type: " + contentType);
           
            IdcClient client = getIdcClient();
            DataBinder dataBinderReq = client.createBinder();
            dataBinderReq.putLocal("IdcService", "CHECKIN_UNIVERSAL");
            dataBinderReq.putLocal("dSecurityGroup", doc.getSecurityGroup());
            dataBinderReq.putLocal("dDocAccount", "");
            dataBinderReq.putLocal("dDocName", doc.getDocumentId());
            dataBinderReq.putLocal("dDocType", doc.getDocType());
            dataBinderReq.putLocal("dDocAuthor", username);
            dataBinderReq.putLocal("dDocTitle", doc.getTitle());
            dataBinderReq.putLocal("dCollectionID", doc.getContentId());
            dataBinderReq.putLocal("isFinished", "true");
           
            TransferFile tf = new TransferFile(attachment, doc.getTitle(), attachment.available(), contentType);
            dataBinderReq.addFile("primaryFile", tf);

            severiceResponse = client.sendRequest(new IdcContext(username), dataBinderReq);
            DataBinder dataBinderResp = severiceResponse.getResponseAsBinder();           
                               
           
                               
        } catch(Exception ex) {
           
            System.out.println("Error CheckIn: " + ex.getMessage());
 
        } finally {
            if (severiceResponse != null) {
                severiceResponse.close();
            }
        }
    }//   
   
}//end class

Copy this in Document.java

public class Document {
    private String contentId;
    private String documentId;
    private String owner;
    private String title;
    private String doctype;
    private String securitygroup;

   
    public void setContentId(String contentId) {
        this.contentId = contentId;
    }

    public String getContentId() {
        return contentId;
    }
   
    public void setDocumentId(String documentId) {
        this.documentId = documentId;
    }

    public String getDocumentId() {
        return documentId;
    }

    public void setOwner(String owner) {
        this.owner = owner;
    }

    public String getOwner() {
        return owner;
    }
   
    public void setDocType(String doctype) {
        this.doctype = doctype;
    }

    public String getDocType() {
        return doctype;
    }
   
    public void setSecurityGroup(String securitygroup) {
        this.securitygroup = securitygroup;
    }

    public String getSecurityGroup() {
        return securitygroup;
    }


    public void setTitle(String title) {
        this.title = title;
    }

    public String getTitle() {
        return title;
    }

}//end class

And finally copy this in Main.java

import java.io.File;
import java.io.FileInputStream;
 
public class Main {
    private static String Username = "weblogic"; //User who performs upload
    private static String DocumentID_Read = "This is the title of my document"; //Title of the Document
    private static String FolderID_Read = "344543302850000202"; //This is Folder ID, "Folders_G" component needs to be activated in Content Server
    private static String DocType_Read = "Document"; //Document Type
    private static String SecurityGroup_Read = "Public"; //Security Group of Document
    private static String FileLocation = "C:\\file.txt"; //File to upload from your PC
 
    public static void Main()  {

        try {
           
            //Istantiate UCMAdapter
            UCMAdapter ucm = new UCMAdapter();
           
            File f = new File(FileLocation);  
            FileInputStream fs = new FileInputStream(f);
           
           
            //Set Document values...
            Document d = new Document();
           
            d.setTitle(DocumentID_Read);
            d.setDocumentId(DocumentID_Read);
            d.setContentId(FolderID_Read);
            d.setDocType(DocType_Read);
            d.setSecurityGroup(SecurityGroup_Read);
           
            //...perform check-in
            ucm.checkIn(Username, d, fs, "text/plain");
              
        } catch (Exception ex) {
               ex.printStackTrace();
        }      

      
    }  
 
}


You need to modify Main.java values according to your desired values, then launch it an if everythings went fine you will get the message confirmation for your Check-in!!

That's all!!