import com.filenet.api.collection.ContentElementList;
import com.filenet.api.collection.FolderSet;
import com.filenet.api.constants.AutoClassify;
import com.filenet.api.constants.AutoUniqueName;
import com.filenet.api.constants.CheckinType;
import com.filenet.api.constants.DefineSecurityParentage;
import com.filenet.api.constants.RefreshMode;
import com.filenet.api.core.*;
import java.io.File;
import java.io.FileInputStream;
import java.util.Iterator;
public class StoringDataInSubFolders {
public static void main(String args[])
{
EngineConnection mine=new EngineConnection();
Connection connection = mine.giveConnection();
if(connection!=null)
{
Domain domain=Factory.Domain.fetchInstance(connection, null, null);
System.out.println(""+domain.get_Name());
//select an object store
ObjectStore object_store=Factory.ObjectStore.fetchInstance(domain, "CMTOS", null);
System.out.println(""+object_store.get_DisplayName());
//select a folder
Folder current_folder=null;
Folder selected_folder=null;
FolderSet folder_set=object_store.get_TopFolders();
Iterator<FolderSet> folder_iterator=folder_set.iterator();
while(folder_iterator.hasNext())
{
current_folder=(Folder)folder_iterator.next();
if(current_folder.get_FolderName().equals("Practise Folder"))
{
selected_folder=current_folder;
}
}
System.out.println(""+selected_folder.get_FolderName());
//get sub folders from selected folders
FolderSet sub_folder_set= selected_folder.get_SubFolders();
//iterate through sub folders
Iterator<FolderSet> sub_folder_iterator=sub_folder_set.iterator();
Folder current_sub_folder=null;
Folder selected_sub_folder=null;
while(sub_folder_iterator.hasNext())
{
current_sub_folder=(Folder)sub_folder_iterator.next();
if(current_sub_folder.get_FolderName().equals("Practise Sub Folder"))
{
selected_sub_folder=current_sub_folder;
}
}
System.out.println(""+selected_sub_folder.get_FolderName());
//now store data of document in this sub folder only
//get the data from local system
File file=new File("C:\\Users\\tempuser.TIT-JAVA-040\\Downloads\\content navigator.pdf");
try
{
FileInputStream input_data=new FileInputStream(file);
//get the instance for documnet to store above input data
Document doc=Factory.Document.createInstance(object_store, null);
//set trasfering method
ContentTransfer content_transfer=Factory.ContentTransfer.createInstance();
//set the data to this content transfer
content_transfer.setCaptureSource(input_data);
//set the mime type
content_transfer.set_ContentType("application/pdf");
//set a name for document
content_transfer.set_RetrievalName("shashi practice");
//create a content element list and add this content transfer data to the list
ContentElementList content_element_list=Factory.ContentElement.createList();
content_element_list.add(content_transfer);
//add the content elements to the current document
doc.set_ContentElements(content_element_list);
doc.getProperties().putValue("DocumentTitle","shashi practice" );
doc.set_MimeType("application/pdf");
//check in document
doc.checkin(AutoClassify.AUTO_CLASSIFY, CheckinType.MINOR_VERSION);
doc.save(RefreshMode.REFRESH);
//set the current document under the sub folder
ReferentialContainmentRelationship file1 = selected_sub_folder.file(doc, AutoUniqueName.AUTO_UNIQUE, "shashi practice", DefineSecurityParentage.DEFINE_SECURITY_PARENTAGE);
file1.save(RefreshMode.REFRESH);
System.out.println("Your document saved ");
}
catch(Exception e)
{
System.out.println(""+e.getLocalizedMessage());
}
}
}
}
----------------------------------
EngineConnection.java
import com.filenet.api.core.*;
import com.filenet.api.util.UserContext;
import javax.security.auth.Subject;
public class EngineConnection {
Connection giveConnection()
{
String url="http://192.168.2.22:9080/wsi/FNCEWS40MTOM";
Connection connection = Factory.Connection.getConnection(url);
Subject subject =UserContext.createSubject(connection, "p8admin", "ecm@dmin1", null);
UserContext context=UserContext.get();
context.pushSubject(subject);
if(connection!=null)
return connection;
return connection;
}
}
No comments:
Post a Comment