EngineConnetion.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;
}
}
BulkUploading.java
---------------------
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.nio.file.Files;
import java.util.*;
public class BulkUploading {
public static void main(String args[])
{
//connect to the server
EngineConnection mine=new EngineConnection();
Connection connection = mine.giveConnection();
if(connection!=null)
{
//give a folder name from there it takes all the data and uploads it into the folder given by you
File file=new File("C:\\Users\\tempuser.TIT-JAVA-040\\Downloads\\DemoJava\\");
System.out.println(file.isDirectory());
File files_array[]=file.listFiles();
Folder current_folder=null;
Folder selected_folder=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);
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;
}
}
ContentTransfer content_transfer =null;
FileInputStream input_data=null;
Document doc=null;
ContentElementList content_element_list=null;
ReferentialContainmentRelationship file2=null;
for(File f:files_array)
{
File file1=new File(f.getAbsolutePath());
try
{
input_data =new FileInputStream(file1);
//get the instance for documnet to store above input data
doc =Factory.Document.createInstance(object_store, null);
//set trasfering method
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
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",f.getName() );
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
file2= selected_sub_folder.file(doc, AutoUniqueName.AUTO_UNIQUE, f.getName(), DefineSecurityParentage.DEFINE_SECURITY_PARENTAGE);
file2.save(RefreshMode.REFRESH);
System.out.println("Current document "+doc.get_Name()+" is Saved");
}
catch(Exception e)
{
System.out.println(""+e.getLocalizedMessage());
}
}
}
}
}
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;
}
}
BulkUploading.java
---------------------
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.nio.file.Files;
import java.util.*;
public class BulkUploading {
public static void main(String args[])
{
//connect to the server
EngineConnection mine=new EngineConnection();
Connection connection = mine.giveConnection();
if(connection!=null)
{
//give a folder name from there it takes all the data and uploads it into the folder given by you
File file=new File("C:\\Users\\tempuser.TIT-JAVA-040\\Downloads\\DemoJava\\");
System.out.println(file.isDirectory());
File files_array[]=file.listFiles();
Folder current_folder=null;
Folder selected_folder=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);
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;
}
}
ContentTransfer content_transfer =null;
FileInputStream input_data=null;
Document doc=null;
ContentElementList content_element_list=null;
ReferentialContainmentRelationship file2=null;
for(File f:files_array)
{
File file1=new File(f.getAbsolutePath());
try
{
input_data =new FileInputStream(file1);
//get the instance for documnet to store above input data
doc =Factory.Document.createInstance(object_store, null);
//set trasfering method
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
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",f.getName() );
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
file2= selected_sub_folder.file(doc, AutoUniqueName.AUTO_UNIQUE, f.getName(), DefineSecurityParentage.DEFINE_SECURITY_PARENTAGE);
file2.save(RefreshMode.REFRESH);
System.out.println("Current document "+doc.get_Name()+" is Saved");
}
catch(Exception e)
{
System.out.println(""+e.getLocalizedMessage());
}
}
}
}
}
Không có nhận xét nào:
Đăng nhận xét