Prerequisite untuk proses ini sama dengan yang ada di part1, jadi kita cukup menambahkan 1 method lagi untuk proses Add User.
Cukup tambahkan satu method dibawah ini pada class java UcmClient yang sudah kita buat pada part1 sebelumnya.
public String addUser(String dName, String dFullName, String account) { ServiceResponse response = null; String result = ""; try { // create request DataBinder binder = idcClient.createBinder(); binder.putLocal("IdcService", "ADD_USER"); // define UserAttributeInfo DataObjectImpl dataObject = new DataObjectImpl(); dataObject.put("dUserName", dName); dataObject.put("AttributeInfo", "account," + account); DataResultSetImpl userAttribInfo = new DataResultSetImpl(); userAttribInfo.addField(new DataResultSet.Field("dUserName"), dName); userAttribInfo.addField(new DataResultSet.Field ("AttributeInfo"), "account," + account); userAttribInfo.addRow(dataObject); userAttribInfo.addField(new DataResultSet.Field(""), ""); binder.putLocal("dName", dName); binder.putLocal("dUserAuthType", "Local"); binder.putLocal("dFullName", dFullName); binder.putLocal("dPassword", "welcome1"); binder.addResultSet("UserAttribInfo", userAttribInfo); // check in the file response = idcClient.sendRequest(userContext, binder); result = dName; // result = response.getResponseAsString(); } catch (Exception e) { e.getMessage(); } finally { response.close(); } return result; }
Maka java lengkapnya akan menjadi seperti berikut
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 String dName = "David"; String dFullName = "Isnin David"; String account = "IT"; UcmClient main = new UcmClient(); main.checkInDocument(); main.addUser(dName, dFullName, account); } 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(); CollectionresultSetNames = binderResult.getResultSetNames(); for (String name : resultSetNames) { System.out.println(name); } } public String addUser(String dName, String dFullName, String account) { ServiceResponse response = null; String result = ""; try { // create request DataBinder binder = idcClient.createBinder(); binder.putLocal("IdcService", "ADD_USER"); // define UserAttributeInfo DataObjectImpl dataObject = new DataObjectImpl(); dataObject.put("dUserName", dName); dataObject.put("AttributeInfo", "account," + account); DataResultSetImpl userAttribInfo = new DataResultSetImpl(); userAttribInfo.addField(new DataResultSet.Field ("dUserName"), dName); userAttribInfo.addField(new DataResultSet.Field ("AttributeInfo"), "account," + account); userAttribInfo.addRow(dataObject); userAttribInfo.addField(new DataResultSet.Field(""), ""); binder.putLocal("dName", dName); binder.putLocal("dUserAuthType", "Local"); binder.putLocal("dFullName", dFullName); binder.putLocal("dPassword", "welcome1"); binder.addResultSet("UserAttribInfo", userAttribInfo); // check in the file response = idcClient.sendRequest(userContext, binder); result = dName; // result = response.getResponseAsString(); } catch (Exception e) { e.getMessage(); } finally { response.close(); } return result; } }
Demikian untuk blog kali ini, semoga dapat membantu dan bermanfaat. :)
See you next!
No comments:
Post a Comment