Monday, 17 November 2014

Send sample Mail ( Java Code )

//Sending Mail

import java.util.*; 
import javax.mail.*; 
import javax.mail.internet.*; 
 
public class SendEmail 

 public static void main(String [] args){ 
      String to = "abcd@gmail.com";//change accordingly 
      String from = "sample@gmail.com";//change accordingly 
      String host = "localhost";//or IP address 
 
     //Get the session object 
      Properties properties = System.getProperties(); 
      properties.setProperty("mail.smtp.host", host); 
      Session session = Session.getDefaultInstance(properties); 
 
     //compose the message 
      try{ 
         MimeMessage message = new MimeMessage(session); 
         message.setFrom(new InternetAddress(from)); 
         message.addRecipient(Message.RecipientType.TO,new InternetAddress(to)); 
         message.setSubject("Ping"); 
         message.setText("Hello, Happy Birthday to u  "); 
 
         // Send message 
         Transport.send(message); 
         System.out.println("message sent successfully...."); 
 
      }catch (MessagingException mex) {mex.printStackTrace();} 
   } 
}

Friday, 14 November 2014

Get and Put properties on Document(CE API)

//Put Multiple Properties on multiple Documents

                ObjectStore objectstore =//Get Object Store
                logger.info("Object Store Name :: "+objectstore.get_DisplayName());
                SearchScope search=new SearchScope(objectstore);
                String value = "abcd"
                String sql1= "Select * from DocumentClass where DocumentTitle = "+value;
                SearchSQL searchSQL=new SearchSQL(sql1);
                DocumentSet documents=(DocumentSet)search.fetchObjects(searchSQL, Integer.getInteger("50"), null, Boolean.valueOf(true));
                Document doc;
                Iterator it=documents.iterator();
                while(it.hasNext())
                {
                    doc=(Document)it.next();
                    doc.getProperties().putValue("Name", abc);
                    doc.getProperties().putValue("number", 123);
                    doc.getProperties().putValue("Salary", 200);
                    doc.save(RefreshMode.REFRESH);

                }


//

Searching and Deleting documents(CE API)

//Searching and Deleting documents(CE API)

             SearchScope search=new SearchScope(objectstore);
                String value = abc;
                String sql1= "Select * from DocClass where DocumentTitle = "+ Value;
                SearchSQL searchSQL=new SearchSQL(sql1);
                DocumentSet documents=(DocumentSet)search.fetchObjects(searchSQL, Integer.getInteger("50"), null, Boolean.valueOf(true));
                Document doc;
                Iterator it=documents.iterator();
                while(it.hasNext())
                {
                    doc=(Document)it.next();
                    logger.info("document name::"+doc.get_Name());
                    logger.info("deleting the document now:::");
                    doc.delete();
                    doc.save(RefreshMode.REFRESH);
                   
                }

Thursday, 13 November 2014

IBM Case Manager API (fetch P8Connection, Domain, Target Obbject Store)

//Establish ICM Connection

public static Connection getICMConnection(String uri,String userID,String password){
      
        try{
            //uri = "http://localhost:9080/wsi/FNCEWS40MTOM/";
            P8ConnectionCache connCache = new SimpleP8ConnectionCache();
            conn = connCache.getP8Connection(uri);
            log.info("ICM Connection: "+conn);
          
            Subject subject =   UserContext.createSubject(conn, userID, password, "FileNetP8WSI");
            uc = UserContext.get();
            uc.pushSubject(subject);
          
            origLocale = uc.getLocale();
            uc.setLocale(origLocale);
            origCmctx = CaseMgmtContext.set(new CaseMgmtContext(new SimpleVWSessionCache(), connCache));
        }catch(Exception ex){
            ex.printStackTrace();
            log.error("[ICMManager]getICMConnection():Exception found is :"+ex.getMessage());
        }
      
      
        return conn;
    }



//Domain References

public static DomainReference getDomainReference(Connection conn){
       
       
        try{
            Domain domain=Factory.Domain.fetchInstance(conn, null, null);
            log.info("[ICMManager]getDomainreference():Domain Name: "+domain.get_Name());
           
            domainReference=new DomainReference(domain);
        }catch(Exception ex){
            ex.printStackTrace();
            log.error("[ICMManager]getDomainreference():Exception found: "+ex,ex);
        }
        return domainReference;
       
    }


//Get Target Object Store

public static ObjectStoreReference getTargetOSReference(DomainReference domRef,String osName){
       
        try{
            targetObjectStoreReference=new ObjectStoreReference(domRef, osName);
            log.info("[ICMManager]getTargetOSReference():Target Object Store Reference: "+targetObjectStoreReference.toString());
        }catch(Exception ex){
            ex.printStackTrace();
            log.error("[ICMManager]getTargetOSReference():Exception found: "+ex,ex);
        }
        return targetObjectStoreReference;
       
    }


//Close ICM Connection

public static void closeICMObjects(){
        CaseMgmtContext.set(origCmctx);
        uc.setLocale(origLocale);
        uc.popSubject();
        targetObjectStoreReference=null;
        domainReference=null;
        conn=null;
       
    }















Search Work Item in Roaster (PE API)

//Search Work Item in Roaster


public static VWWorkObject getVWWorkObject(VWSession peSession,String rosterName){
      VWWorkObject vwwObj=null;
      try{
     
     
          VWRoster roster=peSession.getRoster(rosterName);
          int queryFlags=VWRoster.QUERY_NO_OPTIONS;
          String abc = "abc";
          String filter="Property_Name ="+abc;

          //Change filter based on requirement

       
          VWRosterQuery query=roster.createQuery(null, null, null, queryFlags, filter, null, VWFetchType.FETCH_TYPE_WORKOBJECT);
          log.info("Total records for Work ITem: "+query.fetchCount());
         
          while(query.hasNext()){
              vwwObj=(VWWorkObject) query.next(); 
          }
         
      }catch(VWException vwe){
          log.error("Exception found at PEManager.getVWWorkObject():"+vwe,vwe);
          vwe.printStackTrace();
      }catch(Exception vwe){
          log.error("Exception found at PEManager.getVWWorkObject():"+vwe,vwe);
          vwe.printStackTrace();
      }
     
      return vwwObj;
  }

Java Program for Oracle DB Connection

//Java Program for Oracle DB Connection

//Establish Connection


public static Connection getConnection(String dbURL,String dbUser,String dbPassword)
    {   
        Connection oracleConnection = null;
       
        try
        {
           
           
            Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
           
   
            String connURL   = "dbURL";           
            String connUName = "dbUser";
            String connPwd   = "dbPassword";
           
           
            oracleConnection = DriverManager.getConnection(connURL, connUName, connPwd);
            if(oracleConnection!=null)
            { 
                log.info("Oracle Connection made successfully.");               
            }
            else
            {
                log.info("Oracle Connection not made successfully.");
            }
           
        } // End TRY
        catch(Exception e)
        {           
            log.error("Exception ---> " +e.getMessage());
            e.printStackTrace();
        } // End CATCH
       
        log.debug("EXIT");
        /* Return Statement */
        return oracleConnection;
    } // End METHOD: getConnection()
   
  
    public static Connection getConnection(String dataSourceName){
        log.info("Enter [OracleConnect]getConnection()");
        log.info("Data Source Name is: "+dataSourceName);
       
        Connection dbConnection=null;
        try{
           
            InitialContext ctx = new InitialContext();
            Object objRef = ctx.lookup(dataSourceName);
            DataSource dataSource = (DataSource)objRef;
            dbConnection = dataSource.getConnection();
        }catch(SQLException ex){
            log.error("Exceptio found at [OracleConnect]getConnection():"+ex);
        }catch(NamingException ex){
            log.error("Exceptio found at [OracleConnect]getConnection():"+ex);
        }catch(Exception ex){
            log.error("Exceptio found at [OracleConnect]getConnection():"+ex);
        }
        return dbConnection;
    }



// Close Connection

public static void closeConnection(Connection dbConnection) throws SQLException
    {
        try
        {
            if(dbConnection != null)
            {
                dbConnection.close();       
                log.info("Oracle Connection closed.");
            } // End IF
        } // End TRY

Java Program for DB2 Connection

//Establish DB2 Connection

   import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.apache.log4j.Logger;

/*

     *@Rakesh K
 */

public class DB2Connect
{
    public static Logger log=Logger.getLogger(DB2Connect.class);
  
    public static Connection getConnection(String dbURL,String dbUser,String dbPassword)
    {  
        log.debug("ENTER [DB2Connect]getConnection()");
      
        /* Connection Variable */
        Connection db2Connection = null;
      
        try
        {
          
            Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
          
            /* Connection Parameters */
            String connURL   = "dbURL";         
            String connUName = "dbUser";
            String connPwd   = "dbPassword";
          
            log.info("DB2 connection url:"+connURL+", for the User: "+connUName);
            /*
             * String connURL="jdbc:db2://localhost:50000/SAMPLEDB";
             * DB2 Connection URL Pattern
             */
          
            db2Connection = DriverManager.getConnection(connURL, connUName, connPwd);
            if(db2Connection!=null)
            {
                log.info("DB2 Connection made successfully.");
            }
                          
        } // End TRY
        catch(Exception e)
        {  
            log.error("Exception ----> " +e.getMessage());
            log.error("Exception ----> " +e);
            e.printStackTrace();
        } // End CATCH
      
        log.debug("EXIT");
        /* Return Statement */
        return db2Connection;
    } // End METHOD: getConnection()
  
  
    public static void closeConnection(Connection dbConnection) throws SQLException
    {
        try
        {
            if(dbConnection != null)
            {
                dbConnection.close();      
                log.info("DB2 Connection closed.");
            } // End IF
        } // End TRY
      
        catch(SQLException e)
        {
            log.error("Exception ---> " +e.getMessage());
        } // End CATCH
    } // End METHOD: closeConnection()          
}



Get PE Session (Process Engine JAVA API)

Process Engine API

//Get Session

  public static VWSession getPESession()
    {
      String strAppURI1="http://localhost:9080/wsi/FNCEWS40MTOM/";
      System.out.println("[ENTER  PEManager getPESession()]");
      VWSession peSession = null;

      System.setProperty("java.security.auth.login.config","C:\\opt\\jaas.conf.WSI");
    

      try
      {
        peSession = new VWSession();
        peSession.setBootstrapCEURI(strAppURI1);
    
        peSession.logon(username, password, connectionPoint);
        String sn = peSession.getPEServerName();
        System.out.println("++++++++++++++++"+ sn);

        System.out.println("PE session established:"+peSession);
      }
      catch (VWException e) {
          System.out.println("Exception occured while establishing PE session." );
          e.printStackTrace();

      }
      System.out.println("[Exit PEManager getPESession()]");
    return peSession;
  }

//Close VWSession

public static void closePESession(VWSession peSession)
  {
    log.debug("[Enter closePESession]");
    try {
      if (peSession != null)
        peSession.logoff();
    }
    catch (VWException e) {
      log.error(e.getMessage(), e);
    }

    log.debug("[Exit : closePESession]");
  } 


Content Engine JAVA API

Content Engine API's

// Get Connection

    public Connection getCEConnectionHTTP() {
        try{
        String UserName = "p8admin";
        String Password = "p8admin";
        String Url = "http://localhost:9080/wsi/FNCEWS40MTOM/";
        String Stanza = "FileNetP8WSI";
        connection = Factory.Connection.getConnection(Url);
        System.out.println("Connection is established");
        subject = UserContext.createSubject(connection, UserName, Password, Stanza);
        UserContext uc = UserContext.get();
        uc.pushSubject(subject);
        return connection;
        }
        catch (EngineRuntimeException engineRuntimeException) {
            System.out.println("RuntimeException occured while getting the connection = "+ engineRuntimeException.getMessage());
                           
            engineRuntimeException.printStackTrace();
        }
        return connection;
    }


//Get Domain


public Domain getFileNetDomain()
    {
        String domainName = "P8DEVAirtelAfrica";
        Domain domain = null;
        try
        {
        domain = Factory.Domain.fetchInstance(getCEConnectionHTTP(), domainName, null);
        }
        catch (EngineRuntimeException engineRuntimeException) {
            System.out.println("RuntimeException occured while getting the Domain = "+ engineRuntimeException.getMessage());
                           
            engineRuntimeException.printStackTrace();
        }
        return domain;
    }


// Get Object Store

public ObjectStore getObjectStore(Domain domain, String objectStoreName) {
        ObjectStore os = null;
        try {
//            domain = null;
            os = Factory.ObjectStore.fetchInstance(domain, objectStoreName, null);
            System.out.println("ObjectStor Details " + os.get_DisplayName());
        } catch (EngineRuntimeException ere) {
            System.out.println("getObjectStore :" + ere.getExceptionCode().getKey());
            ere.printStackTrace();
        }
        return os;
    }