Showing posts with label CE Folder API. Show all posts
Showing posts with label CE Folder API. Show all posts

Tuesday, 10 May 2016

Retrieving all documents and objects in Folder (FileNet CE API)

//Retrieving all documents and objects in Folder (FileNet CE API)

public void FetchCEObjectsInFolder(Connection conn) {  //FileNet CE Connection 

try {
Domain domain = Factory.Domain.fetchInstance(conn, null, null);
ObjectStore objStore = Factory.ObjectStore.fetchInstance(domain,"OSNAME", null);
System.out.println("Object Store ="+ objStore.get_DisplayName() );

String folder= "/Test"; // Folder name

com.filenet.api.core.Folder folderOj= Factory.Folder.fetchInstance(objStore,folder, null);
System.out.println("del"+folderOj.get_Name());

DocumentSet documents = folderOj.get_ContainedDocuments(); //For documents

ReferentialContainmentRelationshipSet refConRelSet= folderOj.get_Containees(); // for objects
Iterator it = documents.iterator(); 
while(it.hasNext())
{

//Retrieving documents
Document retrieveDoc= (Document)it.next();
String name = retrieveDoc.get_Name();
System.out.println("Document Name :: "+ name);

//Retrieving Objects
ReferentialContainmentRelationship retrieveObj=(ReferentialContainmentRelationship)it.next();
IndependentObject containee=retrieveObj.get_Head();
String className= containee.getClassName();
String displayName= retrieveObj.get_Name(); 
System.out.println("Class Name = "+ className);
System.out.println("Display Name = "+ displayName);
}
} catch (Exception e) {
e.printStackTrace();
}
}

Deleting Sub Folders and Root Folder in CE

//Deleting Sub Folders and Root Folder in CE

public void deleteCEFolder(Connection conn) {  //FileNet CE Connection

try {
Domain domain = Factory.Domain.fetchInstance(conn, null, null);
ObjectStore objStore = Factory.ObjectStore.fetchInstance(domain,"OSNAME", null);
System.out.println("Object Store ="+ objStore.get_DisplayName() );

String folder= "/NewFolder";

com.filenet.api.core.Folder folderOj= Factory.Folder.fetchInstance(objStore,folder, null);
System.out.println("del"+folderOj.get_Name());

FolderSet subFolders= folderOj.get_SubFolders();
Iterator it = subFolders.iterator();
while(it.hasNext()){

com.filenet.api.core.Folder subFolder= (com.filenet.api.core.Folder) it.next();

String name = ((com.filenet.api.core.Folder) subFolder).get_FolderName();
System.out.println("Subfolder = "+name);

//1. First Delete sub folders
subFolder.delete();
subFolder.save(RefreshMode.NO_REFRESH);
System.out.println("Subfolder = "+name+" is Deleted");
}


  //2. Delete Root folder

folderOj.delete();
folderOj.save(RefreshMode.REFRESH);
System.out.println("Root Folder "+folderOj + "is Deleted");

} catch (Exception e) {
e.printStackTrace();
}
}

Fetching folders and sub folders in CE

//Fetching folders and sub folders in CE

public void FetchCEFolder(Connection conn) {     //FileNet CE Connection 

try {
Domain domain = Factory.Domain.fetchInstance(conn, null, null);
ObjectStore objStore = Factory.ObjectStore.fetchInstance(domain,"OSNAME", null);
System.out.println("Object Store ="+ objStore.get_DisplayName() );

String folder= "/NewFolder";

// Fetching Parent folder
com.filenet.api.core.Folder folderOj= Factory.Folder.fetchInstance(objStore,folder, null);
System.out.println("del"+folderOj.get_Name());

//Fetching sub folders 
FolderSet subFolders= folderOj.get_SubFolders(); 
Iterator it = subFolders.iterator();
while(it.hasNext()){
com.filenet.api.core.Folder subFolder= (com.filenet.api.core.Folder) it.next(); 
String name = ((com.filenet.api.core.Folder) subFolder).get_FolderName();
System.out.println("Subfolder = "+name);

// Fetching hidden folders
if(subFolder.getProperties().getBooleanValue("IsHiddenContainer"))
System.out.println("Folder "+ name + "is hidden");

}

} catch (Exception e) {
e.printStackTrace();
}
}

Creating folder and sub folder in CE (CE API)

// Creating folder and sub folder in CE (CE API)

public void createCEFolder(Connection conn) {    //FileNet CE Connection 

try {
//fetching Domain
Domain domain = Factory.Domain.fetchInstance(conn, null, null);
//fetching Object Store
ObjectStore objStore = Factory.ObjectStore.fetchInstance(domain,"OSNAME", null);
System.out.println("Object Store ="+ objStore.get_DisplayName() );

//Creating Root folder 
com.filenet.api.core.Folder testFolder= Factory.Folder.createInstance(objStore,null);
com.filenet.api.core.Folder rootFolder= objStore.get_RootFolder(); 
System.out.println(rootFolder);
testFolder.set_Parent(rootFolder);
testFolder.set_FolderName("NewFolder"); //Folder Name
testFolder.save(RefreshMode.REFRESH);

//Creating Sub folder
com.filenet.api.core.Folder subFolder= testFolder.createSubFolder("newSubFolder");
subFolder.save(RefreshMode.REFRESH);

} catch (Exception e) {
e.printStackTrace();
}
}