Skip Headers
Oracle® Fusion Middleware Developer's Guide for Imaging and Process Management
11g Release 1 (11.1.1)

Part Number E12784-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to current chapter
Up
Go to next page
Next
View PDF

5.4 Execute Search Sample

The following sample demonstrates the basic concepts discussed in this section.

Example 5-1 Sample Search Execution

package devguidesamples;

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

import oracle.imaging.BasicUserToken;
import oracle.imaging.ImagingException;
import oracle.imaging.NameId;
import oracle.imaging.Search;
import oracle.imaging.SearchArgument;
import oracle.imaging.SearchService;
import oracle.imaging.SearchValue;
import oracle.imaging.ServicesFactory;
import oracle.imaging.TypedValue;
import oracle.imaging.UserToken;

public class ExecuteSearchSample {
   public static void main(String[] args) {
      try { // try-catch
         UserToken credentials = new BasicUserToken("ipmuser", "ipmuserpwd");
         ServicesFactory servicesFactory = 
            ServicesFactory.login(credentials, Locale.US,
               "http://ipmhost:16000/imaging/ws");

         try { // try-finally to ensure logout
            SearchService searchService = servicesFactory.getSearchService();

            NameId invoiceSearchNameId = null;

            // List the viewable applications to confirm that "Invoices" exists
            List<NameId> searchList = 
               searchService.listSearches(Search.Ability.VIEW);
            for (NameId nameId: searchList) {
               if (nameId.getName().equals("Invoices")) {
                  invoiceSearchNameId = nameId;
               }
            }

            if (invoiceSearchNameId == null) {
               System.out.println("Invoices search not found.");
               return;
            }

            SearchValue searchValue = new SearchValue(SearchValue.Type.NUMBER, 1234);
            SearchArgument searchArgument = 
               new SearchArgument("Invoice Number", searchValue);
            searchArgument.setOperatorValue(Search.Operator.EQUAL);

            List<SearchArgument> searchArguments =
               new ArrayList<SearchArgument>();
            searchArguments.add(searchArgument);

            Search.ResultSet resultSet = searchService.executeSavedSearch(invoiceSearchNameId,                                                                         searchArguments);

            // Display Column Headers
            System.out.print("DocumentId" + "  ");
            for (String column: resultSet.getColumns()) {
               System.out.print(column + "  ");
            }
            System.out.println();

            // Display result Rows
            for (Search.Result row: resultSet.getResults()) {
               System.out.println(row.getDocument().getId());
               for (TypedValue typedValue: row.getColumnValues()) {
                  System.out.print(typedValue.getStringValue() + "  ");
               }
               System.out.println();
            }
         }
         finally {
            if (servicesFactory != null) {
               servicesFactory.logout();
            }
         }
      }
      catch (ImagingException e) {
         System.out.println(e.getMessage());
      }
   }
}