Author Topic: Code to get the data and resource file from CMOD server.  (Read 5736 times)

pankaj.puranik

  • Sr. Member
  • ****
  • Posts: 374
    • View Profile
Code to get the data and resource file from CMOD server.
« on: November 29, 2012, 02:06:59 AM »
You may use the following code if you want to get the data file and the resource file from CMOD server.
You may they use a third party tool for transformation into PDF.


package com.abc.xyz.ondemand;

import java.util.Iterator;
import java.util.Vector;

import com.ibm.edms.od.ODConfig;
import com.ibm.edms.od.ODConstant;
import com.ibm.edms.od.ODCriteria;
import com.ibm.edms.od.ODException;
import com.ibm.edms.od.ODFolder;
import com.ibm.edms.od.ODHit;
import com.ibm.edms.od.ODServer;


public class CMODAPITest {
   public static void main(String argv[]) {
      ODServer odServer;
      ODFolder odFolder;
      ODConfig odConfig;
      ODHit odHit;
      Vector hits;
      ODCriteria odCrit;
      

        String odserver = "xyz.abc.rst.com";
        String username = "user";
        String passwd = "password";

        String folder = "FolderName";

        Boolean flag = false;
        
        String searchField = "lmn";

      try {
         
         System.out.println("This testcase should:");
         System.out.println("  Logon to the specified server");
         System.out.println("  Open the specified folder");
         System.out.println("  Search the folder using the default criteria");
         System.out.println("  Retrieve LO document data via ODHit.getDocument()");
         System.out.println("  Retrieve LO document data via ODHit.getDocument(Filename)");
         System.out.println("");
         System.out.println("---------------------------------------------------");
         System.out.println("");
         
         System.setProperty("java.library.path", "C:\\Program Files\\IBM\\OnDemand Web Enablement Kit;");
         System.load("C:\\px00226\\Program Files\\IBM\\OnDemand Web Enablement Kit\\ars3wapi32.dll");

         System.load("C:\\Program Files\\IBM\\OnDemand Web Enablement Kit\\icudt36.dll");
         System.load("C:\\Program Files\\IBM\\OnDemand Web Enablement Kit\\icuuc36.dll");
         System.load("C:\\Program Files\\IBM\\OnDemand Web Enablement Kit\\arssck32.dll");
         System.load("C:\\Program Files\\IBM\\OnDemand Web Enablement Kit\\arsxapi.dll");
         System.load("C:\\Program Files\\IBM\\OnDemand Web Enablement Kit\\icuin36.dll");

         
         System.load("C:\\Program Files\\IBM\\OnDemand Web Enablement Kit\\arswwwsl32.dll");

         //----------
         //Setup ODConfig object using defaults and initialize ODServer.
         //----------
         odConfig = new ODConfig();
         
         odServer = new ODServer(odConfig);
         
         if (odServer == null){
               System.out.println("ODServer instance could not be created, exiting.");
               return;
            }

         odServer.setServerName(odserver);
         odServer.setPort(1445);
         odServer.setUserId(username);
                     odServer.setPassword(passwd);
             
             


         odServer.initialize( "CMODAPITest.java" );
         //----------
         // Logon to specified server
         //----------
         System.out.println("Logging on to " + odserver + "...");
         odServer.logon(odserver, username, passwd);
         
         System.out.println("AG names are : " + odServer.getApplicationGroupNames());
         //----------
         // Open the specified folder and search with the default criteria
         //----------

         System.out.println("Opening " + folder + " folder...");
         odFolder = odServer.openFolder(folder);
         System.out.println("Searching with default criteria...");
         odCrit = odFolder.getCriteria( "searchField" );
         odCrit.setOperator(ODConstant.OPEqual);
//         odCrit.setOperator(ODConstant.OPIn);
         odCrit.setSearchValue( searchField );
         
      
         odFolder.setOrSearchCriteria(true);
         hits = odFolder.search();
         System.out.println("Number of hits: " + hits.size());
         if (hits.size() > 0)
         {
            if (flag) {
               Iterator iter = hits.iterator();
               while (iter.hasNext()){
                  odHit = (ODHit) iter.next();
                  searchField = odHit.getDisplayValue("searchField");

                  System.out.println("\nGet the Document and write it to file");
                  String ext = odHit.getFileExt();
                  System.out.println("#");
                  System.out.println("DocID: \"" + odHit.getDocId()+"\"");
                  System.out.println("Application Group Name: " + odHit.getApplGrpName());
                  System.out.println("Folder Name: " + odHit.getFolderName());
                  System.out.println("Extension: " + ext);
                  odHit.getDocument(searchField +"." + ext ,true);
                  System.out.println("Doc data written to " + searchField + "." + ext);
               }
            } else {
               odHit = (ODHit) hits.elementAt(0);

               System.out.println("\nGet the Document and write it to file");
               String ext = odHit.getFileExt();
               System.out.println("#");
               System.out.println("DocID: \"" + odHit.getDocId()+"\"");
               System.out.println("Application Group Name: " + odHit.getApplGrpName());
               System.out.println("Folder Name: " + odHit.getFolderName());
               System.out.println("Extension: " + ext);
               odHit.getDocument(searchField +"." + ext ,true);
               System.out.println("Doc data written to " + searchField + "." + ext);

//                 System.out.println("\nGet the Document ByteArray, then write array to file.");
//                 System.out.println("NOTE This will only return the 1st segment by design.");
//                 byte[] docdata = odHit.getDocument();
//                 FileOutputStream fos1 = new FileOutputStream("Test." + ext);
//                 fos1.write(docdata);
//                 fos1.close();
//                 System.out.println("Data written to Test." + ext);

               //---------
               //If document is AFP, get the resources too
               //---------
               if(ext.equals("afp"))
               {
                  System.out.println("\nDocument is AFP, so we will now get the resource file.");
                  String rid = odHit.getResourceID();
                  System.out.println("Resource id is " + rid);
                  System.out.println("Call GetResource with filename");
                  odHit.getResources(rid+searchField+".res");
                  System.out.println("AFP Resources written to " + rid + searchField + ".res");
               }
            }
            
         }
         // Call Java implementation of AFP2xxx, Xenos or other transforms with the byte array
         // to convert the data, if required. Also, if using a 3rd party AFP viewer, the Resources and the Document
         // data can be concatenated for viewing.


         //----------
         // Cleanup
         //----------
         odFolder.close();
         odServer.logoff();
         odServer.terminate();
         System.out.println("");
         System.out
         .println("---------------------------------------------------");
      }

      catch (ODException e) {
         System.out.println("ODException: " + e);
         System.out.println("   id = " + e.getErrorId());
         System.out.println("  msg = " + e.getErrorMsg());
         e.printStackTrace(System.out);
         //e.printStackTrace();
      }
      catch (Exception e2) {
         System.out.println("exception: " + e2);
         e2.printStackTrace();
      }
   }

}
« Last Edit: November 29, 2012, 02:25:36 AM by pankaj.puranik »

Alessandro Perucchi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1002
    • View Profile
Re: Code to get the data and resource file from CMOD server.
« Reply #1 on: December 04, 2012, 09:30:12 AM »
Hello Pankaj,

Thanks :-) I don't need it now, but it's good to know it's here! :-)

Sincerely yours,
Alessandro
Alessandro Perucchi

#Install #Migrations #Conversion #Educate #Repair #Upgrade #Migrate #Enhance #Optimize #AIX #Linux #Multiplatforms #DB2 #Windows #Oracle #TSM #Tivoli #Performance #Audits #Customizing #Availability #HA #DR #JavaApi #ContentNavigator #ICN #WEBi #ODWEK #Services #PDF #AFP #XML