It's a pretty common task to perform document operations using RIDC Libraries.
In this post I provide a sample code to perform a new document chech-in on Oracle WebCenter Content, also known as Universal Content Management or simply "UCM".
In following posts I will increase the set of operations that you will able to perform on WebCenter Content using RIDC.
I use Eclipse for coding.
For using RIDC on a Content Server you need first to download RIDC libraries from here:
http://download.oracle.com/otn/content_management/ContentIntegrationSuite_10gR3_20081218.zip
Open Eclipse and create a new Java Project.
Extract oracle-ridc-client-10g.jar from previously downloaded file and import this library in you Eclipse Project (Right Click on your project --> Properties --> Java Build Path --> Libraries)
Under "src" folder create a new folder called "resources", in this folder create a file named ucm.properties with following content:
UCM_URL=idc://10.0.0.12:4444
The string above rapresents IP Address of your Content Server and IntraDoC port (by default this port is 4444, you have set this value during Content Server initial configuration).
Now create three Java Classes:
1) UCMAdapter.java - The class providing all methods to perform operations on Content Server
2) Document.java - The class which contains document properties
3) Main.java - The main class which will be launched and will invoke methods in UCMAdapter.java
Copy this code in UCMAdaper.java
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import oracle.stellent.ridc.IdcClient;
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.TransferFile;
import oracle.stellent.ridc.protocol.ServiceResponse;
public class UCMAdapter {
private String IDC_URL = null;
//Retrieving configuration
public UCMAdapter() {
try {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("resources/ucm.properties");
Properties p = new Properties();
p.load(is);
IDC_URL = p.getProperty("UCM_URL");
System.out.println("Load configuration DONE: " + IDC_URL);
} catch(Exception ex) {
System.out.println("Error load configuration: " + ex.getMessage());
}
}//
//This method performs a check-in of a new document in Content Server
public void checkIn(String username, Document doc, InputStream attachment, String contentType) {
ServiceResponse severiceResponse = null;
try {
System.out.println("CheckIn Workflow: title: " + doc.getTitle() + " - type: " + contentType);
IdcClient client = getIdcClient();
DataBinder dataBinderReq = client.createBinder();
dataBinderReq.putLocal("IdcService", "CHECKIN_UNIVERSAL");
dataBinderReq.putLocal("dSecurityGroup", doc.getSecurityGroup());
dataBinderReq.putLocal("dDocAccount", "");
dataBinderReq.putLocal("dDocName", doc.getDocumentId());
dataBinderReq.putLocal("dDocType", doc.getDocType());
dataBinderReq.putLocal("dDocAuthor", username);
dataBinderReq.putLocal("dDocTitle", doc.getTitle());
dataBinderReq.putLocal("dCollectionID", doc.getContentId());
dataBinderReq.putLocal("isFinished", "true");
TransferFile tf = new TransferFile(attachment, doc.getTitle(), attachment.available(), contentType);
dataBinderReq.addFile("primaryFile", tf);
severiceResponse = client.sendRequest(new IdcContext(username), dataBinderReq);
DataBinder dataBinderResp = severiceResponse.getResponseAsBinder();
} catch(Exception ex) {
System.out.println("Error CheckIn: " + ex.getMessage());
} finally {
if (severiceResponse != null) {
severiceResponse.close();
}
}
}//
}//end class
Copy this in Document.java
public class Document {
private String contentId;
private String documentId;
private String owner;
private String title;
private String doctype;
private String securitygroup;
public void setContentId(String contentId) {
this.contentId = contentId;
}
public String getContentId() {
return contentId;
}
public void setDocumentId(String documentId) {
this.documentId = documentId;
}
public String getDocumentId() {
return documentId;
}
public void setOwner(String owner) {
this.owner = owner;
}
public String getOwner() {
return owner;
}
public void setDocType(String doctype) {
this.doctype = doctype;
}
public String getDocType() {
return doctype;
}
public void setSecurityGroup(String securitygroup) {
this.securitygroup = securitygroup;
}
public String getSecurityGroup() {
return securitygroup;
}
public void setTitle(String title) {
this.title = title;
}
public String getTitle() {
return title;
}
}//end class
And finally copy this in Main.java
import java.io.File;
import java.io.FileInputStream;
public class Main {
private static String Username = "weblogic"; //User who performs upload
private static String DocumentID_Read = "This is the title of my document"; //Title of the Document
private static String FolderID_Read = "344543302850000202"; //This is Folder ID, "Folders_G" component needs to be activated in Content Server
private static String DocType_Read = "Document"; //Document Type
private static String SecurityGroup_Read = "Public"; //Security Group of Document
private static String FileLocation = "C:\\file.txt"; //File to upload from your PC
public static void Main() {
try {
//Istantiate UCMAdapter
UCMAdapter ucm = new UCMAdapter();
File f = new File(FileLocation);
FileInputStream fs = new FileInputStream(f);
//Set Document values...
Document d = new Document();
d.setTitle(DocumentID_Read);
d.setDocumentId(DocumentID_Read);
d.setContentId(FolderID_Read);
d.setDocType(DocType_Read);
d.setSecurityGroup(SecurityGroup_Read);
//...perform check-in
ucm.checkIn(Username, d, fs, "text/plain");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
You need to modify Main.java values according to your desired values, then launch it an if everythings went fine you will get the message confirmation for your Check-in!!
That's all!!
Nessun commento:
Posta un commento