In this post I provide code to add another functionality to our class: create Folders and Subfolders in Content Server using RIDC.
Please note that Perform Documents Check-In using Remote IntraDoC (RIDC) contains the prerequisite code since in this post I don't provide the full java code but just additions.
This method lets you create folders and subfolders under "Contribution Folders".
As you probably know Contribution Folders can be enabled activating "Folders_G" component in UCM Administration.
Add this code to UCMAdapter.java
//Creates a Folder in Content Server
public void createFolder(String folderOwner, String folderName, String Has_Parent, String ParentCollectionID,
String securityGroup) {
ServiceResponse severiceResponse = null;
try {
System.out.println("Creating Folder: " + folderName);
IdcClient client = getIdcClient();
DataBinder dataBinderReq = client.createBinder();
dataBinderReq.putLocal("IdcService", "COLLECTION_ADD");
dataBinderReq.putLocal("dCollectionName", folderName);
dataBinderReq.putLocal("hasParentCollectionID", Has_Parent);
dataBinderReq.putLocal("dParentCollectionID", ParentCollectionID);
dataBinderReq.putLocal("dCollectionOwner", folderOwner);
dataBinderReq.putLocal("dSecurityGroup", securityGroup);
severiceResponse = client.sendRequest(new IdcContext(folderOwner), dataBinderReq);
DataBinder dataBinderResp = severiceResponse.getResponseAsBinder();
System.out.println("Folder " +folderName +" successfully created");
} catch(Exception ex) {
System.out.println("Error creating Folder: " + ex.getMessage());
} finally {
if (severiceResponse != null) {
severiceResponse.close();
}
}
} //
//Returns Folder ID
public String getFolderIdFromPath(String username, String path){
String folderId=null;
try {
IdcClient client = getIdcClient();
DataBinder dataBinder = client.createBinder();
dataBinder.putLocal("IdcService", "COLLECTION_INFO");
dataBinder.putLocal("hasCollectionPath", "true");
dataBinder.putLocal("dCollectionPath", path);
ServiceResponse response = client.sendRequest(new IdcContext(username), dataBinder);
DataBinder serverBinder = response.getResponseAsBinder();
DataResultSet resultSet = serverBinder.getResultSet("PATH");
DataObject dataObject = resultSet.getRows().get(resultSet.getRows().size() - 1);
folderId = dataObject.get("dCollectionID");
} catch(Exception ex) {
System.out.println("Error: " + ex.getMessage());
}
return folderId;
} //
Then create a new Main.java and paste this code:
public class Test {
public static void main(String[] args) {
//EDIT THESE VARIABLES
String username = "weblogic";
String securityGroup = "Public";
String mainFolderName = "MAIN FOLDER NAME";
String subFolderName = "SUB FOLDER NAME";
String subSubFolderName = "SUB SUB FOLDER NAME";
//
try {
//Istanciate objects
UCMAdapter ucm = new UCMAdapter();
Document d = new Document();
//Create Main Folder under "Contribution Folder"
ucm.createFolder(username, mainFolderName, "true", ucm.getFolderIdFromPath("weblogic", "/Contribution Folders"), securityGroup);
//Create Sub Folder under Main Folder
ucm.createFolder(username, subFolderName, "true", ucm.getFolderIdFromPath("weblogic", "/Contribution Folders"+ "/" + mainFolderName), securityGroup);
//Create Sub Sub Folder under Sub Folder
ucm.createFolder(username, subSubFolderName, "true", ucm.getFolderIdFromPath("weblogic", "/Contribution Folders" + "/" + mainFolderName + "/" + subFolderName), securityGroup);
//...and so on
} catch (Exception ex) {
ex.printStackTrace();
}
}
}//end class
In the code above you have a pattern that allow you to create a folder tree with sub-folders, sub-sub-folders and so on...
Obviously you need to edit some variables according to your preferences.
That's all!!
Hello hc just a question, is there a way to do the same under 'Framework Folders'?
RispondiEliminaMax