Tuesday, 10 May 2016

Retrieving all documents and objects in Folder (FileNet CE API)

//Retrieving all documents and objects in Folder (FileNet CE API)

public void FetchCEObjectsInFolder(Connection conn) {  //FileNet CE Connection 

try {
Domain domain = Factory.Domain.fetchInstance(conn, null, null);
ObjectStore objStore = Factory.ObjectStore.fetchInstance(domain,"OSNAME", null);
System.out.println("Object Store ="+ objStore.get_DisplayName() );

String folder= "/Test"; // Folder name

com.filenet.api.core.Folder folderOj= Factory.Folder.fetchInstance(objStore,folder, null);
System.out.println("del"+folderOj.get_Name());

DocumentSet documents = folderOj.get_ContainedDocuments(); //For documents

ReferentialContainmentRelationshipSet refConRelSet= folderOj.get_Containees(); // for objects
Iterator it = documents.iterator(); 
while(it.hasNext())
{

//Retrieving documents
Document retrieveDoc= (Document)it.next();
String name = retrieveDoc.get_Name();
System.out.println("Document Name :: "+ name);

//Retrieving Objects
ReferentialContainmentRelationship retrieveObj=(ReferentialContainmentRelationship)it.next();
IndependentObject containee=retrieveObj.get_Head();
String className= containee.getClassName();
String displayName= retrieveObj.get_Name(); 
System.out.println("Class Name = "+ className);
System.out.println("Display Name = "+ displayName);
}
} catch (Exception e) {
e.printStackTrace();
}
}

Deleting Sub Folders and Root Folder in CE

//Deleting Sub Folders and Root Folder in CE

public void deleteCEFolder(Connection conn) {  //FileNet CE Connection

try {
Domain domain = Factory.Domain.fetchInstance(conn, null, null);
ObjectStore objStore = Factory.ObjectStore.fetchInstance(domain,"OSNAME", null);
System.out.println("Object Store ="+ objStore.get_DisplayName() );

String folder= "/NewFolder";

com.filenet.api.core.Folder folderOj= Factory.Folder.fetchInstance(objStore,folder, null);
System.out.println("del"+folderOj.get_Name());

FolderSet subFolders= folderOj.get_SubFolders();
Iterator it = subFolders.iterator();
while(it.hasNext()){

com.filenet.api.core.Folder subFolder= (com.filenet.api.core.Folder) it.next();

String name = ((com.filenet.api.core.Folder) subFolder).get_FolderName();
System.out.println("Subfolder = "+name);

//1. First Delete sub folders
subFolder.delete();
subFolder.save(RefreshMode.NO_REFRESH);
System.out.println("Subfolder = "+name+" is Deleted");
}


  //2. Delete Root folder

folderOj.delete();
folderOj.save(RefreshMode.REFRESH);
System.out.println("Root Folder "+folderOj + "is Deleted");

} catch (Exception e) {
e.printStackTrace();
}
}

Fetching folders and sub folders in CE

//Fetching folders and sub folders in CE

public void FetchCEFolder(Connection conn) {     //FileNet CE Connection 

try {
Domain domain = Factory.Domain.fetchInstance(conn, null, null);
ObjectStore objStore = Factory.ObjectStore.fetchInstance(domain,"OSNAME", null);
System.out.println("Object Store ="+ objStore.get_DisplayName() );

String folder= "/NewFolder";

// Fetching Parent folder
com.filenet.api.core.Folder folderOj= Factory.Folder.fetchInstance(objStore,folder, null);
System.out.println("del"+folderOj.get_Name());

//Fetching sub folders 
FolderSet subFolders= folderOj.get_SubFolders(); 
Iterator it = subFolders.iterator();
while(it.hasNext()){
com.filenet.api.core.Folder subFolder= (com.filenet.api.core.Folder) it.next(); 
String name = ((com.filenet.api.core.Folder) subFolder).get_FolderName();
System.out.println("Subfolder = "+name);

// Fetching hidden folders
if(subFolder.getProperties().getBooleanValue("IsHiddenContainer"))
System.out.println("Folder "+ name + "is hidden");

}

} catch (Exception e) {
e.printStackTrace();
}
}

Creating folder and sub folder in CE (CE API)

// Creating folder and sub folder in CE (CE API)

public void createCEFolder(Connection conn) {    //FileNet CE Connection 

try {
//fetching Domain
Domain domain = Factory.Domain.fetchInstance(conn, null, null);
//fetching Object Store
ObjectStore objStore = Factory.ObjectStore.fetchInstance(domain,"OSNAME", null);
System.out.println("Object Store ="+ objStore.get_DisplayName() );

//Creating Root folder 
com.filenet.api.core.Folder testFolder= Factory.Folder.createInstance(objStore,null);
com.filenet.api.core.Folder rootFolder= objStore.get_RootFolder(); 
System.out.println(rootFolder);
testFolder.set_Parent(rootFolder);
testFolder.set_FolderName("NewFolder"); //Folder Name
testFolder.save(RefreshMode.REFRESH);

//Creating Sub folder
com.filenet.api.core.Folder subFolder= testFolder.createSubFolder("newSubFolder");
subFolder.save(RefreshMode.REFRESH);

} catch (Exception e) {
e.printStackTrace();
}
}

Retrieve all Object stores in CE


// Retrieve all Object stores in CE

public void FetchOSList(Connection conn) {   //FileNet CE Connection

try {

Domain domain = Factory.Domain.fetchInstance(conn, null, null);
ObjectStoreSet osSet= domain.get_ObjectStores();
ObjectStore store;
Iterator iterator = osSet.iterator();
Iterator<ObjectStore> osIter = iterator;
while (osIter.hasNext()) {
store = (ObjectStore)osIter.next();
 
if((store.getAccessAllowed().intValue() & AccessLevel.USE_OBJECT_STORE.getValue())>0)
System.out.println(store.get_Name());
 
}

} catch (Exception e) {
e.printStackTrace();
}
}

Friday, 11 March 2016

Fetch(or Filter) Meta Data(of Document) from Content Engine and write into CSV file

//Fetch(or Filter) Meta Data(of Document) from Content Engine  and write into CSV file

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;
import java.util.Iterator;
import javax.security.auth.Subject;
import com.csvreader.CsvWriter;
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.property.Properties;
import com.filenet.api.query.SearchSQL;
import com.filenet.api.query.SearchScope;
import com.filenet.api.util.UserContext;

public class CSVReportFromCEDoc{
private static Connection conn = null;
    public static Connection getCEConnection()
    {
        try {
            String ceURI = "http://localhst:9080/wsi/FNCEWS40MTOM/"; //FileNet URL
            String userName ="p8admin"; //User Name
            String password ="filenet"; //Password
            if(conn==null){
            conn = Factory.Connection.getConnection(ceURI); //CE connection
            Subject subject = UserContext.createSubject(conn, userName, password, null); //creating subject
            UserContext uc = UserContext.get(); 
            uc.pushSubject(subject); //push subject
            }

        } catch (Exception e1) {
            e1.printStackTrace();
        }
        System.out.println("CE Connection"+conn);
        return conn;
    }
    public static void getInternalQADocuments() throws IOException{
        String osName="RAKESHOS"; //Object Store name
        try{
            Connection conn = getCEConnection();
            Domain domain = Factory.Domain.fetchInstance(conn,null, null); //fetching domain
            ObjectStore objStore = Factory.ObjectStore.fetchInstance(domain, osName,null); //fetching object store
            SearchScope searchScope = new SearchScope(objStore); // Creating search scope object
            int count=1;
            String sqlStr = "Select * FROM DocClass"; //CE Query
            SearchSQL searchSQL = new SearchSQL(sqlStr);
            System.out.println("Query ::"+sqlStr);
            //fetching Data from Content Engine
            IndependentObjectSet independentObjectSet = searchScope.fetchObjects(searchSQL, new Integer(10), null, new Boolean(true)); 
           
            File file = new File("E:\\Report.csv"); 

            if ( !file.exists() ){
                file.createNewFile();
            }
            // Use FileWriter constructor that specifies open for appending
            CsvWriter csvOutput = new CsvWriter(new FileWriter(file, true), ',');
            //Create Header for CSV
            csvOutput.write("Title");
            csvOutput.write("Doc Type");
            csvOutput.write("Country");
            csvOutput.write("State");
            csvOutput.write("Street");
            csvOutput.write("House No");
            csvOutput.write("Added On");
            csvOutput.write("Modified On");
             csvOutput.endRecord();
            
            String Title=null;
            String DocType=null;
            Date DateCreated=null;
            Date DateLastModified=null;
            String State=null;
            String Country=null;
            String Street=null;
            String HouseNo=null;
            if(!(independentObjectSet.isEmpty())){
                Iterator it=independentObjectSet.iterator();
                while(it.hasNext())    {
                    Document doc=(Document)it.next();
                   
                    //fetching properties from each document
                    Properties documentProperties = doc.getProperties();
                     Title=doc.getProperties().getStringValue("DocumentTitle");
                     System.out.println("Title:::"+Title);
                     DocType=documentProperties.getStringValue("DocType");
                     DateCreated=documentProperties.getDateTimeValue("DateCreated");
                     DateLastModified=documentProperties.getDateTimeValue("DateLastModified");
                     State=documentProperties.getStringValue("State");
                     Country=documentProperties.getStringValue("Country");
                     Street=documentProperties.getStringValue("Street");
                     HouseNo=documentProperties.getStringValue("HouseNo");
                   
                     //inserting into CSV file
                     csvOutput.write(Title);
                     csvOutput.write(DocType);
                     csvOutput.write(Country);
                     csvOutput.write(State);
                     csvOutput.write(Street);
                     csvOutput.write(HouseNo);
                     csvOutput.write(DateCreated.toString());
                     csvOutput.write(DateLastModified.toString());
                     csvOutput.endRecord();
                     count++; 
                     System.out.println("Count:::;"+count);
                    }
                }
            }
        catch(Exception e){
            e.printStackTrace();
        }
    }
    public static void main(String[] args) throws IOException {
        getInternalQADocuments();
    }
}

Java code to get last modified date of files from directory

//Java code to get last modified date of files from directory

import java.io.File;
import java.io.FilenameFilter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.activation.MimetypesFileTypeMap;

public class FilterFilesFromFolder {
    
   
    public static <lang> void main(String a[]){
        File file = new File("E:/sample/");
     
        //filtering txt from folder
        FilenameFilter textFilter = new FilenameFilter()
        {
            public boolean accept(File dir, String name) {
                String lowercaseName = name.toLowerCase();
                if (lowercaseName.endsWith(".txt")) {
                    return true;
                } else {
                    return false;
                }
            }
        };
       
        File[] files = file.listFiles(textFilter);
       
        long min = 0;
        String mimeType;
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
        Date d = new Date();
        System.out.println("System Date :"+ sdf.format(d));
        for(File f: files){
            System.out.println("File Name ="+f.getName());
            System.out.println("Date Last Madified ="+ sdf.format(f.lastModified()));
            mimeType = new MimetypesFileTypeMap().getContentType(f);
            System.out.println("MIME Type ="+ new MimetypesFileTypeMap().getContentType(f));
           
            //getting last one hour modified files
            try
            {
                 long cd = d.getTime();
                 long lmd = f.lastModified();
                 long diff= cd-lmd;
                 System.out.println("Diff ="+diff);
                min = diff/(60 * 1000);
                 System.out.println("Diff in Min = "+min);
            }
            catch(Exception e)
            {
                System.out.println("Error in Date Diffrence = " + e);
            }
            if (min <= 60)
            {
            System.out.println("send mail");   
            }
        }
    }
}

Monday, 21 December 2015

Creating a new Object Store in FileNet 5.1

//Creating a new Object Store in FileNet 5.1

3 main steps required for creating a new object store
  1. Create a new Data Base
  2. Create XA and Non-XA Data Sources in WebSphere
  3. Create a new Object Store using FileNet Enterprise Manager Administration Tool 
1. Create a new Data Base (Here i am creating a database in SQL Server)






2. Create XA and Non-XA Data Sources in WebSphere

(Non-XA Data Source)
2.1 Log-on to WebSphere console and navigate to Data Sources as shown below and Click on New

  


2.2 Enter Data source name and JNDI name and click on Next

2.3 Select Non-XA data source as shown below and click on NEXT 


2.4 Enter Database Name, Port number, Server Name and Click on Next

2.5 Select "Component-managed Authentication alias" (for Authentication) and click on Next and Finish it.
2.6 Test the connection.

(XA Data Source)

 2.7 Log-on to WebSphere console and navigate to Data Sources as shown below and Click on New
 
 
2.8 Enter Data source name and JNDI name and click on Next

2.9 Select XA data source as shown below and click on NEXT

2.10 Select "Component-managed Authentication alias" (for Authentication) and click on Next and Finish it.
   
2.11 Test the two (XA and Non XA Data Sources).


3. Create a new Object Store using FileNet Enterprise Manager Administration Tool  

3.1 Log on to FileNet Enterprise Manager Administration Tool (FEM)

3.2 Right click on Object Stores and click on New Object Store

3.3 Click on Next

3.4 Enter Display Name*, Symbolic Name* and Description and click on Next

 3.5 Enter JNDI Data Source Name, JNDI XA Data Source Name (Same as you created in 2 Step) and Click on Next

3.5  Create a new empty folder in Windows (or Linux)(For File Storage Area) (Here Folder Name : RAKESHOS)

 
3.6 Select File Storage Area and click on Next.

3.7 Browse... the Root Directory of Folder  (Here I am selecting RAKESHOS folder) and Click on Next



 3.8 Enter Storage Area Details as shown below and Click on Next

3.9 Add user(s) or (and) groups that should have administrative access to the object store and Click on Next

 3.10 Add user(s) or (and) groups that should have basic, non-administrative access to the object store

3.11 Select AddOns to install(Minimal AddOns mandatory) and Click on Next. Select the AddOns based on your requirement (for example Case Manager Target object store or Design object store or (and) Workplace/XT AddOns)  (Hare i am selecting Workplace/XT and Case Manager Target Object store related AddOns) .



3.12 Finish the changes and it will take some time to create a Object Store.




 ....Object Store created successfully...

****************************************************************************************

Friday, 11 December 2015

Java code to Create/Delete user in LDAP

//Java code to Create/Delete user in LDAP

// Establish a LDAP connection

public static LdapContext getInitialLdapContext()
        throws Exception
    {
        LdapContext ctx = null;
        String dnusername = "cn=root,ou=users, o=sample,c=country"; //Admin user name
        String dnpwd = "abcd@123"; //Admin Password
        try
        {
            Control rctls[] = {new PasswordPolicyControl(true)};
            String ldapHostName = bundle.getString("LDAP_IP");
            String ldapHostRMIPort = bundle.getString("LDAP_PORT");
            String providerURL = (new StringBuilder("ldap://")).append(ldapHostName).append(":").append(ldapHostRMIPort).toString();
            System.out.println("URL  =  "+ providerURL);
            Hashtable env = new Hashtable();
            env.put("java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory");
            env.put("java.naming.provider.url", providerURL);
            env.put("java.naming.security.authentication", "simple");
            env.put("java.naming.security.principal", dnusername);
            env.put("java.naming.security.credentials", dnpwd);
            ctx = new InitialLdapContext(env, rctls);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return ctx;
    }
    private static String getUserDN(String username)
    {
        return (new StringBuilder("cn=")).append(username).append(",").append("ou=users, o=sample,c=country").toString();
    }
   
   
    //Create a user
   private static void addUser(String username, String surname,  String titleprop, String mailprop, String employeenumberprop, String mobileprop, String displayNameprop, String password)
       // throws NamingException
    {
        private static DirContext context;
        context = getInitialLdapContext();
        Attributes container = new BasicAttributes();
        Attribute objClasses = new BasicAttribute("objectClass");
        objClasses.add("organizationalPerson");
        objClasses.add("inetOrgPerson");
        objClasses.add("person");
        objClasses.add("top");
        Attribute cn = new BasicAttribute("cn", username);
        Attribute sn = new BasicAttribute("sn", surname);
        Attribute uid = new BasicAttribute("uid", username);
        Attribute title = new BasicAttribute("title", titleprop);
        Attribute mail = new BasicAttribute("mail", mailprop);
        Attribute mobile = new BasicAttribute("mobile", mobileprop);
        Attribute employeeNumber = new BasicAttribute("employeeNumber", employeenumberprop);
        Attribute userPassword = new BasicAttribute("userpassword", password);
        Attribute  displayName = new BasicAttribute("displayName",displayNameprop);
        container.put(objClasses);
        container.put(sn);
        container.put(uid);
        container.put(title);
        container.put(mail);
        container.put(mobile);
        container.put(employeeNumber);
        container.put(countryCode);
        container.put(displayName);

        container.put(userPassword);
       try{
        context.createSubcontext(getUserDN(username), container);
       }
       catch (Exception e) {
        // TODO: handle exception
           log.info(e);
    }
       
       System.out.println((new StringBuilder(String.valueOf(password))).append("- is the Password for user- ").append(username).toString());
       
    }
   
    //Delete a user
    private static void deleteUser(String username)
        throws NamingException
    {
        try
        {
            context.destroySubcontext(getUserDN(username));
            System.out.println((new StringBuilder("User has been deleted successfully - ")).append(username).toString());
        }
        catch(NameNotFoundException namenotfoundexception) {
            log.info(namenotfoundexception);
        }
    }
   

   

Tuesday, 24 November 2015

Connection Points and Isolated Regions

//Connection Points and Isolated regions


Connection Points: Connection points replace the router process used in previous Process Engine releases, connecting the Process Engine API to an associated isolated region. Connection points are defined in the Content Engine API (the PEConnectionPoint and IsolatedRegion classes) and persisted in the Global Configuration Data (GCD) on the Content Engine. Multiple connection points can reference the same isolated region. The set of connection points defined is reflected in the Content Engine's Domain.PEConnectionPoints property. To create and manage connection points, use the IBM Administration Console for Content Platform Engine.

To establish or log on to a Process Engine session a connection point must be specified and the Content Engine host must be accessible.

Isolated regions: An isolated region is a logical subdivision of the workflow system. Isolated regions are often used to separate development, testing, and production environments such that developers and testers can share computing resources while still keeping their disparate activities isolated. An isolated region consists of queues, rosters, and event logs.

An isolated region is identified by one or more connection points. Information that is common to all regions in the workflow system is contained in the workflow system properties.

You can initialize or delete an isolated region. In addition, you can delete the workflow system. Typically, these activities are performed only in a development environment.