Showing posts with label Content Engine API. Show all posts
Showing posts with label Content Engine API. Show all posts

Monday, 23 April 2018

Java Code to get choice value from Choice-lists in Object Stores

//Java Code to get choice value from Choice-lists in Object Stores

import java.io.IOException;
import java.util.Iterator;
import javax.security.auth.Subject;
import com.filenet.api.collection.ChoiceListSet;
import com.filenet.api.core.Connection;
import com.filenet.api.core.Domain;
import com.filenet.api.core.Factory;
import com.filenet.api.core.ObjectStore;
import com.filenet.api.util.UserContext;

public class GetChoiceListValues {
private static Connection conn = null;
public static Connection getCEConn(String ceURI)
{
try {

String userName ="userName";
String password ="password";
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) {
e1.printStackTrace();
}
System.out.println("CE Connection"+conn);
return conn;
}

public static void getChoiceListValues() throws IOException{
String ceURI = null;
try{

    ceURI="http://localhost:9080/wsi/FNCEWS40MTOM/";
      conn = getCEConn(ceURI);
Domain domain = Factory.Domain.fetchInstance(conn,null, null);
ObjectStore objStore = Factory.ObjectStore.fetchInstance(domain,"ObjectStore",null);
ChoiceListSet cls = objStore.get_ChoiceLists();
Iterator it = cls.iterator();
while(it.hasNext()){
com.filenet.api.admin.ChoiceList cl = (com.filenet.api.admin.ChoiceList) it.next();
com.filenet.api.collection.ChoiceList choicelis = cl.get_ChoiceValues();
Iterator choice_it = choicelis.iterator();
System.out.println(cl.get_DisplayName());
while(choice_it.hasNext()){
com.filenet.api.admin.Choice c = (com.filenet.api.admin.Choice) choice_it.next();
System.out.println(c.get_Name());
   
}

}
        System.out.println("Done");
}
    
  catch(Exception e){
e.printStackTrace();
}
}

public static void main(String[] args) throws IOException {
getChoiceListValues();
        }
}

Friday, 26 May 2017

Java code for Event Subscription (FileNet Content Engine API)

//Java code for Event Subscription (FileNet Content Engine API)

import java.util.Iterator;
import com.filenet.api.engine.EventActionHandler;
import com.filenet.api.events.ObjectChangeEvent;
import com.filenet.api.util.Id;
import com.filenet.api.property.*;
import com.filenet.api.core.*;
import com.filenet.api.constants.*;

public class MyCustomeEventHandler implements EventActionHandler
 {
public void onEvent(ObjectChangeEvent event, Id subId)
  {
try
     {
ObjectStore os = event.getObjectStore();
        Id id = event.get_SourceObjectId();
        System.out.println("Event Action Call Started");
        System.out.println("guid="+id);
        PropertyFilter pf = new PropertyFilter();
        pf.addIncludeType(0, null, Boolean.TRUE, FilteredPropertyType.ANY, null);
        Document doc = Factory.Document.fetchInstance(os,id,pf);
        doc.fetchProperties(pf);
        com.filenet.api.property.Properties props = doc.getProperties();      
        Iterator iter = props.iterator();
        System.out.println("Property" +"\t" + "Value");
 
        while (iter.hasNext() )
        {
            Property prop = (Property)iter.next();
            
            if (prop.getPropertyName().equals("DocumentTitle"))
            {
            String docTitle = prop.getStringValue();
                System.out.println("Doc title" + "\t" + docTitle );
            }

            if (prop.getPropertyName().equals("Creator"))
            {
            String createdBy = prop.getStringValue();
                System.out.println("Creator" + "\t" +createdBy );
            }
            if (prop.getPropertyName().equals("DateCreated"))
            {
            String createdOn = prop.getDateTimeValue().toString();
                System.out.println("Date Created" + "\t" +createdOn );
                
            }
        }
       
        doc.getProperties().putObjectValue("DocumentTitle", "changedtoEvent");
doc.save(RefreshMode.NO_REFRESH);
     
     }
     catch (Exception e)
     {
        throw new RuntimeException(e);
     }
  }

}

Java code for Downloading Document Content (Attachments) (FileNet Content Engine API)

//Java code for Downloading Document Content (Attachments) (FileNet Content Engine API)

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
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.RefreshMode;
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.property.Properties;
import com.filenet.api.query.SearchSQL;
import com.filenet.api.query.SearchScope;
import com.filenet.api.util.UserContext;

public class DownloadContent {

private static Connection conn = null;
public static Connection getCEConn()
{

try {

String ceURI = "http://localhost:9080/wsi/FNCEWS40MTOM/";
String userName ="username";
String password ="password";
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 Conn :: "+conn);
return conn;
}
public static void downloadDoc(String osName) throws IOException{

try{
//get the CE document

Connection conn = getCEConn();
Domain domain = Factory.Domain.fetchInstance(conn,null, null);
ObjectStore objStore = Factory.ObjectStore.fetchInstance(domain, osName,null);
SearchScope searchScope = new SearchScope(objStore);

int count=1;
String sqlStr = "Select * FROM DocClass where Title='abcd'";
SearchSQL searchSQL = new SearchSQL(sqlStr);
System.out.println("Query ::"+sqlStr);
IndependentObjectSet independentObjectSet = searchScope.fetchObjects(searchSQL, new Integer(10), null, new Boolean(true)); 
String docTitle=null;
if(!(independentObjectSet.isEmpty())){
Iterator it=independentObjectSet.iterator();
while(it.hasNext()) {
Document doc=(Document)it.next();
Properties documentProperties = doc.getProperties();
docTitle=documentProperties.getStringValue("DocumentTitle");
System.out.println("Doc Title :: "+ docTitle);
ContentElementList docContentList = doc.get_ContentElements();
Iterator iter = docContentList.iterator();
String filepath = "D:\\";
FileOutputStream fos = new FileOutputStream(filepath+docTitle);
count++; 
while (iter.hasNext() )
{
   ContentTransfer ct = (ContentTransfer) iter.next();
   // Print element sequence number and content type of the element.
   System.out.println("\nElement Sequence number: " + ct.get_ElementSequenceNumber().intValue() + "\n" +"Content type: " + ct.get_ContentType() + "\n");
   InputStream stream = ct.accessContentStream();
   byte[] buffer = new byte[4096000];
   int bytesRead = 0;
   while ((bytesRead = stream.read(buffer)) != -1) {
    System.out.print(".");
    fos.write(buffer,0,bytesRead);
   }
   System.out.println("done!");
       fos.close();
   stream.close();
    }
}
System.out.println("Count:::;"+count);
System.out.println("Done");
}
}
catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) throws IOException {
downloadDoc("ObjectStore");
}


}

Sample Java code for Compound Document (Adding child documents to Parent document) (FileNet Content Engine api)

//Sample Java code for Compound Document (Adding child documents to Parent document)


import javax.security.auth.Subject;
import com.filenet.api.constants.ComponentRelationshipType;
import com.filenet.api.constants.CompoundDocumentState;
import com.filenet.api.constants.FilteredPropertyType;
import com.filenet.api.constants.RefreshMode;
import com.filenet.api.constants.VersionBindType;
import com.filenet.api.core.ComponentRelationship;
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.property.PropertyFilter;
import com.filenet.api.util.Id;
import com.filenet.api.util.UserContext;


public class CompoudDoc {
public static void main(String[] args)
{
String[] childDocs = new String[10];
childDocs[0]="{GUID}";
childDocs[1]="{GUID}";
childDocs[2]="{GUID}";
String parentDocument = "{GUID}";
String jassStanzaName = "FileNetP8";
String password = "UserName";
String username = "password";
String objectStoreName = "ObjectStore";

String bootstrap_ceuri = "http://localhost:9080/wsi/FNCEWS40MTOM/";
Id parentDocumentId = null;
Id supportDocumentID=null;
String attachment = null;
com.filenet.api.core.Connection ceConnection = null;
String uri  = null;
String versionSeriesID = null;
String returnValue="start";
boolean att_found=false;
Document parentDoc=null;
Document ChildDoc = null;
PropertyFilter pf = new PropertyFilter();
try
{
if(bootstrap_ceuri!=null && !bootstrap_ceuri.equals(""))
uri=bootstrap_ceuri;
else
uri = System.getProperty("filenet.pe.bootstrap.ceuri");
returnValue += "pe.bootstrap.ceuri= : " + uri;

ceConnection = Factory.Connection.getConnection(uri); 
Subject subject = UserContext.createSubject( ceConnection,username,password,jassStanzaName); 
UserContext uc = UserContext.get(); 
uc.pushSubject(subject); 
Domain domain = Factory.Domain.fetchInstance(ceConnection, null,null); 
returnValue += "In domain : " + domain.get_Name();
ObjectStore os = Factory.ObjectStore.fetchInstance(domain, objectStoreName, null); 
returnValue += "In Object Store : " + os.get_Name();
pf.addIncludeType(0, null, Boolean.TRUE, FilteredPropertyType.ANY, null);

for (int count=0;count<childDocs.length;count++) {
attachment = childDocs[count];
System.out.println("attachment :: "+attachment);

if(attachment!=null && attachment!=null && !attachment.equals(""))
{

if(!att_found)
{
Document parent_doc = Factory.Document.fetchInstance(os,parentDocument,pf);
        parent_doc.fetchProperties(pf);
        parentDocumentId= parent_doc.get_VersionSeries().get_Id();
System.out.println("Vs ID :: "+parentDocumentId);
returnValue+="Src Id : "+parentDocumentId+ "\n";
att_found=true;
versionSeriesID = parentDocumentId.toString(); 
com.filenet.api.core.VersionSeries parentVersionSeries = (com.filenet.api.core.VersionSeries)com.filenet.api.core.Factory.VersionSeries.fetchInstance(os,new Id(versionSeriesID),null); 
parentDoc = (com.filenet.api.core.Document) parentVersionSeries.get_CurrentVersion(); 
parentDoc.set_CompoundDocumentState(CompoundDocumentState.COMPOUND_DOCUMENT);
parentDoc.save(RefreshMode.REFRESH);
}

        Document child_doc = Factory.Document.fetchInstance(os,attachment,null);
        child_doc.fetchProperties(pf);
        supportDocumentID= child_doc.get_VersionSeries().get_Id();
System.out.println("Vs ID :: "+supportDocumentID);
returnValue+="Src Id : "+supportDocumentID+ "\n";
attachment=supportDocumentID.toString();
returnValue+="Child ID:"+attachment+ "\n";
com.filenet.api.core.VersionSeries childVersionSeries =(com.filenet.api.core.VersionSeries)com.filenet.api.core.Factory.VersionSeries.fetchInstance(os,new Id(attachment),null); 
ChildDoc = (com.filenet.api.core.Document) childVersionSeries.get_CurrentVersion();
ComponentRelationship cr = Factory.ComponentRelationship.createInstance(os, null);
cr.set_ParentComponent(parentDoc);
cr.set_ChildComponent(ChildDoc);
cr.set_ComponentSortOrder(new Integer(count));
cr.set_ComponentRelationshipType(ComponentRelationshipType.DYNAMIC_CR);            
cr.set_VersionBindType(VersionBindType.LATEST_VERSION);
cr.save(RefreshMode.NO_REFRESH);
}
}
System.out.println("Return Value :: "+returnValue);
}

catch(Exception exp){
returnValue += "Exception:"+ exp.getMessage();
System.out.println("Exception :: "+returnValue);
}
}

}

Sample JAVA code to retrieve Realm, Group names and User names in FileNet (FileNet Content Engine API)

//Sample JAVA code to retrieve Realm, Group names and User names in FileNet

import java.io.IOException;
import java.util.Iterator;
import javax.security.auth.Subject;
import com.filenet.api.collection.GroupSet;
import com.filenet.api.collection.UserSet;
import com.filenet.api.constants.PrincipalSearchAttribute;
import com.filenet.api.constants.PrincipalSearchSortType;
import com.filenet.api.constants.PrincipalSearchType;
import com.filenet.api.core.Connection;
import com.filenet.api.core.Factory;
import com.filenet.api.util.UserContext;
public class CEUtil {
    private static Connection conn = null;

    public static Connection getCEConn()
    {
        try {
            String ceURI =    "http://localhost:9080/wsi/FNCEWS40MTOM/";
            String userName ="user";
            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 getRealm(String osName) throws IOException{
       
        try{
            Connection conn = getCEConn();
            com.filenet.api.core.EntireNetwork entireNetwork= Factory.EntireNetwork.fetchInstance(conn, null);
            com.filenet.api.security.Realm realm= entireNetwork.get_MyRealm();String realmName= realm.get_Name();
            System.out.println(realmName+ " is retrieved");
           
            //retrieve user names
            String pattern ="username";
            UserSet users = realm.findUsers(pattern, PrincipalSearchType.PREFIX_MATCH,PrincipalSearchAttribute.SHORT_NAME,PrincipalSearchSortType.NONE,Integer.valueOf("50"), null);
            com.filenet.api.security.User user;
            Iterator it = users.iterator();
            while (it.hasNext())
            {
            user = (com.filenet.api.security.User)it.next();
            System.out.println("distinguishedname =" +user.get_DistinguishedName());
            System.out.println("shortname =" + user.get_ShortName());
            System.out.println("name=" + user.get_Name());
            System.out.println("displayname =" + user.get_DisplayName());
            }
           
            //retrieve group names
            String pattern1="groupName";
            GroupSet groups = realm.findGroups(pattern1,PrincipalSearchType.PREFIX_MATCH,PrincipalSearchAttribute.SHORT_NAME,PrincipalSearchSortType.NONE,Integer.valueOf("50"), null);
            com.filenet.api.security.Group group;
            Iterator groupIt= groups.iterator();
            while (groupIt.hasNext())
            {
            group=(com.filenet.api.security.Group)groupIt.next();
            System.out.println("name=" + group.get_Name());
            System.out.println("Distinguishedname = " + group.get_DistinguishedName());
            System.out.println("shortname =" + group.get_ShortName());
            //System.out.println("Users =" + group.get_Users());
            }
           
            System.out.println("Done");


        }
        catch(Exception e){
            e.printStackTrace();
        }
    }
    public static void main(String[] args) throws IOException {
        getRealm("OSNAME");
    }
}

Sample Java code to set folder permissions (FileNet Content Engine API)

//Sample code to set folder permissions

import java.io.IOException;
import java.util.Iterator;

import javax.security.auth.Subject;

import com.filenet.api.collection.AccessPermissionList;
import com.filenet.api.collection.FolderSet;
import com.filenet.api.constants.AccessLevel;
import com.filenet.api.constants.AccessType;
import com.filenet.api.constants.RefreshMode;
import com.filenet.api.core.Connection;
import com.filenet.api.core.Domain;
import com.filenet.api.core.Factory;
import com.filenet.api.core.ObjectStore;
import com.filenet.api.security.AccessPermission;
import com.filenet.api.util.UserContext;
public class CEUtil {
    private static Connection conn = null;

    public static Connection getCEConn()
    {
        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 setPermissions(String osName) throws IOException{
       
        try{
            Connection conn = getCEConn();
            Domain domain = Factory.Domain.fetchInstance(conn,null, null);
            ObjectStore objStore = Factory.ObjectStore.fetchInstance(domain, osName,null);
            String folder= "/Test";
           
            com.filenet.api.core.Folder folderOj= Factory.Folder.fetchInstance(objStore,folder, null);
            System.out.println("Folder :: "+folderOj.get_Name());
   
            AccessPermission permission = Factory.AccessPermission.createInstance();
            permission.set_GranteeName("User");
            permission.set_AccessType(AccessType.ALLOW);
            permission.set_InheritableDepth(new Integer(-1));
            permission.set_AccessMask(new Integer(AccessLevel.FULL_CONTROL_FOLDER_AS_INT));
           
            AccessPermissionList permissions = folderOj.get_Permissions();
            permissions.add(permission);
            folderOj.set_Permissions(permissions);
            folderOj.save(RefreshMode.REFRESH);   
            System.out.println("Done");
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }
    public static void main(String[] args) throws IOException {
        setPermissions("OSNAME");
    }
}

Sample code to get object permissions (FileNet Content Engine API)

//Sample code to get object permissions

import java.io.IOException;
import java.util.Iterator;
import javax.security.auth.Subject;
import com.filenet.api.collection.AccessPermissionList;
import com.filenet.api.collection.IndependentObjectSet;
import com.filenet.api.core.Connection;
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.security.AccessPermission;
import com.filenet.api.util.UserContext;
public class CEUtil {
    private static Connection conn = null;

    public static Connection getCEConn()
    {
        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 getObjectPermissions(String osName) throws IOException{
       
        try{
            Connection conn = getCEConn();
            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 document=(Document)it.next();
                    AccessPermissionList permissions= document.get_Permissions();
                    Iterator it1 = permissions.iterator();
                    while (it1.hasNext())
                    {
                    AccessPermission permission = (AccessPermission)it1.next();
                    System.out.println("GranteeName="+ permission.get_GranteeName());
                    System.out.println("GranteeType=" + permission.get_GranteeType().toString());
                    System.out.println("PermissionSource=" +permission.get_PermissionSource().toString());
                    //System.out.println("Accesslevel = " + AccessLevel.getInstanceFromInt(permission.get_AccessMask().intValue()).toString());
                    System.out.println("Accesstype =" +permission.get_AccessType().toString());
                    System.out.println("Inheritabledepth=" +permission.get_InheritableDepth());
                    }
                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 {
        getObjectPermissions("OSNAME");
    }
}

Tuesday, 8 November 2016

Java code to demote a version for a document (FileNet Content Engine API)

//Java code to demote a version for a document (FileNet Content Engine API)

import java.io.IOException;
import java.util.Iterator;
import javax.security.auth.Subject;
import com.filenet.api.collection.IndependentObjectSet;
import com.filenet.api.constants.RefreshMode;
import com.filenet.api.constants.VersionStatus;
import com.filenet.api.core.Connection;
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 demoteVersionDocument(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 document=(Document)it.next();
if (document.get_IsCurrentVersion().booleanValue()== false) 
document = (Document)document.get_CurrentVersion();
if ((document.get_VersionStatus().getValue() == VersionStatus.RELEASED_AS_INT) && (document.get_IsReserved().booleanValue() == false))
{
document.demoteVersion();
document.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 {
demoteVersionDocument("OSNAME");
}
}

Java code to promote a version for a document (FileNet Content Engine API)

//Java code to promote a version for a document (FileNet Content Engine API)

import java.io.IOException;
import java.util.Iterator;
import javax.security.auth.Subject;
import com.filenet.api.collection.IndependentObjectSet;
import com.filenet.api.constants.RefreshMode;
import com.filenet.api.constants.VersionStatus;
import com.filenet.api.core.Connection;
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 promoteVersionDocument(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 document=(Document)it.next();
if (document.get_IsCurrentVersion().booleanValue() == false)
document=(Document)document.get_CurrentVersion();
if ((document.get_VersionStatus().getValue() == VersionStatus.IN_PROCESS_AS_INT) &&(document.get_IsReserved().booleanValue() == false))
{
document.promoteVersion();
document.save(RefreshMode.NO_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 {
promoteVersionDocument("OSNAME");
}
}

Java code to Check IN a CE document (FileNet Content Engine API)

//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");
}
}