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!

1 commento:

  1. Hi,

    I want to get results for not substring.
    Can you please help me to get the code.

    RispondiElimina