Monday, December 12, 2016

Using the IdcCommand Utility to Access Content Server Part1

Pada kesempatan kali ini saya ingin menulis tentang API Oracle Webcenter Content.

Webcenter Content dimanfaatkan untuk penyimpanan dokumen secara elektornik. Dokumen perlu dijaga agar dapat diakses/dicari dengan mudah jika suatu saat nanti diperlukan. Webcenter Content juga dapat digunakan untuk mengatur masa hidup dokumen mulai dari pembuatan, pencarian, konversi, hinga pemusnahan dokumen apabila diperlukan.

Istilah penyimpanan dokumen dalam Webcenter Content adalah Check-in. Profile dokumen dapat dibuat sesuai dengan jenis dokumen untuk lebih memudahkan dalam pengarsipan. Ada banyak cara untuk melakukan check-in dokumen diantaranya adalah:
  1. Check-in langsung di Document Profile Webcenter Content 
  2. Check-in di Webcenter Portal, apabila Webcenter Portal dan Content sudah ter-integrasi.
  3. Check-in dokumen via API dengan menggunakan Java.
Pada kesempatan kali ini saya ingin coba memberikan contoh penggunaan API Webcenter Content menggunakan Java. Cekidot ya guys..

Persiapan
  1. Saya menggunakan Webcenter Content versi 12.2.1.1.0
  2. lib oracle.ucm.ridc.jar
Implementasi
  1. Buat suatu class java dengan nama UcmClient.java
  2. Buat satu method khusus untuk define connection ke Webcenter Content

  3. public static final String idcConnectionUrl = "idc://localhost:4444";
    public static final String sysadmin = "weblogic";
    public static final int socketTimeout = 30000;
    public static final int connectionSize = 20;
    private IntradocClient idcClient;
    private IdcClientManager manager;
    private IdcContext userContext;
    
    public static void main(String[] args) throws IdcClientException, IOException {
        // TODO Auto-generated method stub
        UcmClient main = new UcmClient();
        main.checkInDocument();
    }
     
    public UcmClient() throws IdcClientException {
        // create the manager
        manager = new IdcClientManager();
    
        // build a client that will communicate using the intradoc protocol
        idcClient = (IntradocClient) manager.createClient(idcConnectionUrl);
    
        // get the config object and set properties
        idcClient.getConfig().setSocketTimeout(socketTimeout); // 30 seconds
        idcClient.getConfig().setConnectionSize(connectionSize); // 20
    
        // create a trusted user context
        userContext = new IdcContext(sysadmin);
    }
    

  4. Buat method checkInDocumen()
  5. public void checkInDocument() throws IdcClientException, IOException {
     // create request
     DataBinder binder = idcClient.createBinder();
     binder.putLocal("IdcService", "CHECKIN_UNIVERSAL");
    
     // get the binder
     binder.putLocal("dDocTitle", "Test Checkin Document");
     binder.putLocal("dDocName", "Test Checkin Document Using Java");
     binder.putLocal("dDocType", "Document");
     binder.putLocal("dSecurityGroup", "public");
    
     // add a file
     binder.addFile("primaryFile", new TransferFile(new File("/Test.docx")));
    
     // check in the file
     ServiceResponse response = idcClient.sendRequest(userContext, binder);
    
     DataBinder binderResult = response.getResponseAsBinder();
     Collection resultSetNames = binderResult.getResultSetNames();
      
     for (String name : resultSetNames) {
     System.out.println(name);
     }
    }
    

  6. Buat object main untuk melakukan execute method checkInDocument
  7. public static void main(String[] args) throws IdcClientException, IOException {
     // TODO Auto-generated method stub
     UcmClient main = new UcmClient();
     main.checkInDocument();
    }
    

Berikut adalah source code lengkapnya.

import java.io.File;
import java.io.IOException;
import java.util.Collection;


import oracle.stellent.ridc.IdcClientException;
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.DataResultSet.Field;
import oracle.stellent.ridc.model.TransferFile;
import oracle.stellent.ridc.model.impl.DataObjectImpl;
import oracle.stellent.ridc.model.impl.DataResultSetImpl;
import oracle.stellent.ridc.protocol.ServiceException;
import oracle.stellent.ridc.protocol.ServiceResponse;
import oracle.stellent.ridc.protocol.intradoc.IntradocClient;

public class UcmClient {

 public static final String idcConnectionUrl = "idc://localhost:4444";
 public static final String sysadmin = "weblogic";
 public static final int socketTimeout = 30000;
 public static final int connectionSize = 20;

 private IntradocClient idcClient;
 private IdcClientManager manager;
 private IdcContext userContext;

 public static void main(String[] args) throws IdcClientException, IOException {
  // TODO Auto-generated method stub
  UcmClient main = new UcmClient();
  main.checkInDocument();
 }
 
 
 public UcmClient() throws IdcClientException {
  // create the manager
  manager = new IdcClientManager();

  // build a client that will communicate using the intradoc protocol
  idcClient = (IntradocClient) manager.createClient(idcConnectionUrl);

  // get the config object and set properties
  idcClient.getConfig().setSocketTimeout(socketTimeout); // 30 seconds
  idcClient.getConfig().setConnectionSize(connectionSize); // 20

  // create a trusted user context
  userContext = new IdcContext(sysadmin);
 }
 
 public void checkInDocument() throws IdcClientException, IOException {
  // create request
  DataBinder binder = idcClient.createBinder();
  binder.putLocal("IdcService", "CHECKIN_UNIVERSAL");

  // get the binder
  binder.putLocal("dDocTitle", "Test Checkin Document");
  binder.putLocal("dDocName", "Test Checkin Document Using Java");
  binder.putLocal("dDocType", "Document");
  binder.putLocal("dSecurityGroup", "public");

  // add a file
  binder.addFile("primaryFile", new TransferFile(new File("/Test.docx")));

  // check in the file
  ServiceResponse response = idcClient.sendRequest(userContext, binder);

  DataBinder binderResult = response.getResponseAsBinder();
  Collection resultSetNames = binderResult.getResultSetNames();
  
  for (String name : resultSetNames) {
   System.out.println(name);
  }
 }
}

Ada banyak API yang dapat kita gunakan selain untuk kebutuhan Check-in dokumen, kita juga dapat melakukan create user, delete user hingga pembuatan account. Untuk contoh java create user-nya ada di part2 ya..


Referensi
https://docs.oracle.com/cd/E23943_01/doc.1111/e10807/c21_idc.htm#CSSDK325

1 comment:

  1. Hi,
    You are using RIDC to connect content server. IdcCommand Utility is different where you write a configuration file and run commands using this utility.

    ReplyDelete