//Java code to Check IN a CE document (FileNet Content Engine API)
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import javax.security.auth.Subject;
import com.filenet.api.collection.ContentElementList;
import com.filenet.api.collection.IndependentObjectSet;
import com.filenet.api.constants.AutoClassify;
import com.filenet.api.constants.CheckinType;
import com.filenet.api.constants.RefreshMode;
import com.filenet.api.constants.VersionStatus;
import com.filenet.api.core.Connection;
import com.filenet.api.core.ContentTransfer;
import com.filenet.api.core.Document;
import com.filenet.api.core.Domain;
import com.filenet.api.core.Factory;
import com.filenet.api.core.ObjectStore;
import com.filenet.api.query.SearchSQL;
import com.filenet.api.query.SearchScope;
import com.filenet.api.util.UserContext;
public class CEUtil {
private static Connection conn = null;
public static Connection getCEConnection()
{
try {
String ceURI = "http://localhost:9080/wsi/FNCEWS40MTOM/";
String userName ="username";
String password ="pwd";
if(conn==null){
conn = Factory.Connection.getConnection(ceURI);
Subject subject = UserContext.createSubject(conn, userName, password, null);
UserContext uc = UserContext.get();
uc.pushSubject(subject);
}
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("CE Connection"+conn);
return conn;
}
public static void checkInDocument(String osName) throws IOException{
try{
Connection conn = getCEConnection();
Domain domain = Factory.Domain.fetchInstance(conn,null, null);
ObjectStore objStore = Factory.ObjectStore.fetchInstance(domain, osName,null);
SearchScope searchScope = new SearchScope(objStore);
int count=0;
String sqlStr = "Select * FROM docClass where DocumentTitle='doc123.pdf'";
SearchSQL searchSQL = new SearchSQL(sqlStr);
System.out.println("Query ::"+sqlStr);
IndependentObjectSet independentObjectSet = searchScope.fetchObjects(searchSQL, new Integer(10), null, new Boolean(true));
if(!(independentObjectSet.isEmpty())){
Iterator it=independentObjectSet.iterator();
while(it.hasNext()) {
Document doc=(Document)it.next();
//Check the version
if(doc.get_IsCurrentVersion().booleanValue()== false)
{
doc= (Document) doc.get_CurrentVersion();
}
if (doc.get_IsReserved().booleanValue()== true)
{
if (doc.get_VersionStatus().getValue() !=VersionStatus.RESERVATION_AS_INT)
{
Document reservationDoc= (Document) doc.get_Reservation();
}
//Check in Document
ContentElementList contentList= Factory.ContentElement.createList();
ContentTransfer content1 = Factory.ContentTransfer.createInstance();
content1.setCaptureSource(new FileInputStream("C:/Users/Public/Pictures/Sample Pictures/Desert.jpg"));
content1.set_ContentType("image/jpeg");
contentList.add(content1);
doc.set_ContentElements(contentList);
doc.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MINOR_VERSION);
doc.save(RefreshMode.REFRESH);
}
count++;
System.out.println("Count:::"+count);
}
System.out.println("Count:::;"+count);
System.out.println("Done");
}
}
catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) throws IOException {
checkInDocument("OSNAME");
}
}
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import javax.security.auth.Subject;
import com.filenet.api.collection.ContentElementList;
import com.filenet.api.collection.IndependentObjectSet;
import com.filenet.api.constants.AutoClassify;
import com.filenet.api.constants.CheckinType;
import com.filenet.api.constants.RefreshMode;
import com.filenet.api.constants.VersionStatus;
import com.filenet.api.core.Connection;
import com.filenet.api.core.ContentTransfer;
import com.filenet.api.core.Document;
import com.filenet.api.core.Domain;
import com.filenet.api.core.Factory;
import com.filenet.api.core.ObjectStore;
import com.filenet.api.query.SearchSQL;
import com.filenet.api.query.SearchScope;
import com.filenet.api.util.UserContext;
public class CEUtil {
private static Connection conn = null;
public static Connection getCEConnection()
{
try {
String ceURI = "http://localhost:9080/wsi/FNCEWS40MTOM/";
String userName ="username";
String password ="pwd";
if(conn==null){
conn = Factory.Connection.getConnection(ceURI);
Subject subject = UserContext.createSubject(conn, userName, password, null);
UserContext uc = UserContext.get();
uc.pushSubject(subject);
}
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("CE Connection"+conn);
return conn;
}
public static void checkInDocument(String osName) throws IOException{
try{
Connection conn = getCEConnection();
Domain domain = Factory.Domain.fetchInstance(conn,null, null);
ObjectStore objStore = Factory.ObjectStore.fetchInstance(domain, osName,null);
SearchScope searchScope = new SearchScope(objStore);
int count=0;
String sqlStr = "Select * FROM docClass where DocumentTitle='doc123.pdf'";
SearchSQL searchSQL = new SearchSQL(sqlStr);
System.out.println("Query ::"+sqlStr);
IndependentObjectSet independentObjectSet = searchScope.fetchObjects(searchSQL, new Integer(10), null, new Boolean(true));
if(!(independentObjectSet.isEmpty())){
Iterator it=independentObjectSet.iterator();
while(it.hasNext()) {
Document doc=(Document)it.next();
//Check the version
if(doc.get_IsCurrentVersion().booleanValue()== false)
{
doc= (Document) doc.get_CurrentVersion();
}
if (doc.get_IsReserved().booleanValue()== true)
{
if (doc.get_VersionStatus().getValue() !=VersionStatus.RESERVATION_AS_INT)
{
Document reservationDoc= (Document) doc.get_Reservation();
}
//Check in Document
ContentElementList contentList= Factory.ContentElement.createList();
ContentTransfer content1 = Factory.ContentTransfer.createInstance();
content1.setCaptureSource(new FileInputStream("C:/Users/Public/Pictures/Sample Pictures/Desert.jpg"));
content1.set_ContentType("image/jpeg");
contentList.add(content1);
doc.set_ContentElements(contentList);
doc.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MINOR_VERSION);
doc.save(RefreshMode.REFRESH);
}
count++;
System.out.println("Count:::"+count);
}
System.out.println("Count:::;"+count);
System.out.println("Done");
}
}
catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) throws IOException {
checkInDocument("OSNAME");
}
}