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 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> `");   

            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();
        } catch(Exception ex) {
            System.out.println("Error Search: " + ex.getMessage());
        } finally {
            if (serviceResponse != null) {
     return list;

To perform a search we need a new main class. Overwrite previously created 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 ="weblogic", "Document Title");
         for (Document item : docs) {
             //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.