Create a document in filenet use API JavaScript
package createdoc_api;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Iterator;
import javax.security.auth.Subject;
import java.io.*;
import java.security.PrivilegedAction;
import javax.security.auth.Subject;
import javax.security.auth.callback.*;
import javax.security.auth.login.*;
import com.filenet.api.admin.StorageArea;
import com.filenet.api.collection.ContentElementList;
import com.filenet.api.collection.ObjectStoreSet;
import com.filenet.api.constants.AutoClassify;
import com.filenet.api.constants.AutoUniqueName;
import com.filenet.api.constants.CheckinType;
import com.filenet.api.constants.ClassNames;
import com.filenet.api.constants.DefineSecurityParentage;
import com.filenet.api.constants.RefreshMode;
import com.filenet.api.core.Connection;
import com.filenet.api.core.ContentTransfer;
import com.filenet.api.core.Domain;
import com.filenet.api.core.Document;
import com.filenet.api.core.Factory;
import com.filenet.api.core.Folder;
import com.filenet.api.core.ObjectStore;
import com.filenet.api.core.ReferentialContainmentRelationship;
import com.filenet.api.property.Properties;
import com.filenet.api.util.Id;
import com.filenet.api.util.UserContext;
public class create_doc_v2 {
public static void main(String[] args)
{
{
// Set connection parameters; substitute for the placeholders.
String uri = "http://ecmdemo1.ecm.ibm.local:9080/wsi/FNCEWS40MTOM/";
String username = "xx";
String password = "xx";
// Make connection.
Connection conn = Factory.Connection.getConnection(uri);
Subject subject = UserContext.createSubject(conn, username, password, null);
UserContext.get().pushSubject(subject);
try
{
// Get default domain.
Domain domain = Factory.Domain.fetchInstance(conn, null, null);
System.out.println("Domain: " + domain.get_Name());
// Get object stores for domain.
ObjectStoreSet osSet = domain.get_ObjectStores();
ObjectStore store;
Iterator osIter = osSet.iterator();
while (osIter.hasNext())
{
store = (ObjectStore) osIter.next();
System.out.println("Object store: " + store.get_Name());
}
System.out.println("Connection to Content Platform Engine successful");
// Create a document instance.
ObjectStore os = Factory.ObjectStore.getInstance(domain, "CMTOS");
System.out.println("ObjectStore " + os);
//class LP_Donxinnghiphep
String docClass = "LP_Donxinnghiphep";
File file= new File("C:\\APT001.tif");
//class
System.out.println("file" + file);
InputStream is = new FileInputStream(file);
System.out.println("FileInputStream" + file);
String fileName="APT001.tif";
Document doc = Factory.Document.createInstance(os, docClass);
System.out.println("doc" + doc);
// if (file != null && fileSize > 0)
System.out.println("ContentElementList 123");
{
ContentTransfer contentTransfer = Factory.ContentTransfer.createInstance();
contentTransfer.setCaptureSource(is);
System.out.println("contentTransfer");
ContentElementList contentList = Factory.ContentElement.createList();
contentList.add(contentTransfer);
doc.set_ContentElements(contentList);
contentTransfer.set_RetrievalName(fileName);
// doc.set_MimeType();
}
// clas DK
//Check-in the doc
doc.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY,CheckinType.MAJOR_VERSION);
//Get and put the doc properties
String documentName ="APT001.tif";
Properties p = doc.getProperties();
p.putValue("DocumentTitle","APT001");
p.putValue("LP_project","ECM");
p.putValue("LP_reason","Xin nghi");
doc.save(RefreshMode.REFRESH);
//Stores above content to the folder
Folder folder = Factory.Folder.getInstance(os, ClassNames.FOLDER, new Id("{2FD4D724-B216-4C93-838F-79551997CDF9}") );
ReferentialContainmentRelationship rc = folder.file(doc,
AutoUniqueName.AUTO_UNIQUE,
documentName,
DefineSecurityParentage.DO_NOT_DEFINE_SECURITY_PARENTAGE);
rc.save(RefreshMode.REFRESH);
/// class DK
String docClass_sup = "LP_Support_DK";
File file_sup= new File("C:\\APT002.tif");
//class
System.out.println("file_sup" + file_sup);
InputStream is_sup = new FileInputStream(file_sup);
System.out.println("FileInputStream" + file_sup);
String fileName_sup="APT002.tif";
Document doc_sup = Factory.Document.createInstance(os, docClass_sup);
System.out.println("doc" + doc_sup);
// if (file != null && fileSize > 0)
System.out.println("ContentElementList 123");
{
ContentTransfer contentTransfer = Factory.ContentTransfer.createInstance();
contentTransfer.setCaptureSource(is_sup);
System.out.println("contentTransfer");
ContentElementList contentList = Factory.ContentElement.createList();
contentList.add(contentTransfer);
doc.set_ContentElements(contentList);
contentTransfer.set_RetrievalName(fileName_sup);
// doc.set_MimeType();
}
// clas DK
//Check-in the doc
doc_sup.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY,CheckinType.MAJOR_VERSION);
//Get and put the doc properties
String documentName_sup ="APT002.tif";
Properties p_sup = doc_sup.getProperties();
p_sup.putValue("DocumentTitle","APT002");
doc_sup.save(RefreshMode.REFRESH);
//Stores above content to the folder
Folder folder_sup = Factory.Folder.getInstance(os, ClassNames.FOLDER, new Id("{2FD4D724-B216-4C93-838F-79551997CDF9}") );
ReferentialContainmentRelationship rc_sup = folder_sup.file(doc_sup,
AutoUniqueName.AUTO_UNIQUE,
documentName_sup,
DefineSecurityParentage.DO_NOT_DEFINE_SECURITY_PARENTAGE);
rc_sup.save(RefreshMode.REFRESH);
System.out.println("Connection to Content Platform Engine successful");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
UserContext.get().popSubject();
}
}
}
}
Không có nhận xét nào:
Đăng nhận xét