package com.chenna;
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;
/**
*
* @author chenna
*/
public class StoringInSubFolder {
public static void main(String args[])
{
//connection
Connectionclas mine=new Connectionclas();
Connection connection =mine.getMyconnection();
if(connection!=null)
{
Domain domain=Factory.Domain.fetchInstance(connection, null, null);
ObjectStore object_store=Factory.ObjectStore.fetchInstance(domain, "CMTOS", null);
System.out.println(""+object_store.get_DisplayName());
FolderSet folder_set= object_store.get_TopFolders();
Iterator<FolderSet> folder_iteraor= folder_set.iterator();
Folder current_folder=null;
Folder seleced_folder=null;
while(folder_iteraor.hasNext())
{
current_folder=(Folder)folder_iteraor.next();
if(current_folder.get_FolderName().equals("folder1"))
{
seleced_folder=current_folder;
}
}
System.out.println(""+seleced_folder.get_FolderName());
FolderSet sub_folders= seleced_folder.get_SubFolders();
Folder current_sub_folder=null;
Folder selected_sub_folder=null;
Iterator<FolderSet>sub_folder_itertor= sub_folders.iterator();
while(sub_folder_itertor.hasNext())
{
current_sub_folder=(Folder)sub_folder_itertor.next();
if(current_sub_folder.get_FolderName().equals("folder2"))
{
selected_sub_folder=current_sub_folder;
}
}
System.out.println(""+selected_sub_folder.get_FolderName());
File file=new File("C:\\Users\\chenna\\Downloads\\Case manager 2014(1).pdf");
FileInputStream input_data=null;
ContentTransfer content_transfer=null;
ContentElementList content_element_list=null;
Document document=null;
try
{
input_data=new FileInputStream(file);
content_transfer =Factory.ContentTransfer.createInstance();
content_transfer.setCaptureSource(input_data);
content_transfer.set_ContentType("application/pdf");
content_transfer.set_RetrievalName("shashiFile");
content_element_list = Factory.ContentElement.createList();
content_element_list.add(content_transfer);
document = Factory.Document.createInstance(object_store, null);
// System.out.println(""+document);
document.set_ContentElements(content_element_list);
document.set_MimeType("application/pdf");
document.getProperties().putValue("DocumentTitle", "shashi File");
document.checkin(AutoClassify.AUTO_CLASSIFY, CheckinType.MINOR_VERSION);
document.save(RefreshMode.REFRESH);
ReferentialContainmentRelationship file1 = selected_sub_folder.file(document, AutoUniqueName.AUTO_UNIQUE, "practise chenna", DefineSecurityParentage.DEFINE_SECURITY_PARENTAGE);
file1.save(RefreshMode.REFRESH);
System.out.println("Document uploaded");
}
catch(Exception e)
{
System.out.println(""+e.getLocalizedMessage());
}
}
}
}
No comments:
Post a Comment