Sunday, 23 November 2014

Configure Work Queue in FileNet (FileNet Process Engine)

---Configure Work Queue in FileNet (FileNet Process Engine)

A work queue holds work items that can be processed by one of a number of users or by an automated process.

In Process Configuration Console, you create and configure work queues as appropriate for your applications. For each queue, you can specify security for the queue, which determines who can see and process items in the queue, and you can expose data fields and create indexes to facilitate searching for items in the queue.


--Steps to Configure

Steps

//Process Configuration Console
1. Goto Workplace XT --> Tools --> Administration --> Process Configuration Console

2. Select on Connection Point and Click on Connect
 



3. Right Click on Work Queue and click on New..


 4. Enter Queue Name and click on Create




 5. Click on Commit (Save Queue) and Work Queue created Successfully


 
 6. If you want to add users and groups in work Queue, Right click on work queue and go to Properties..
 
 
 
 7. Go to Security tab and add users and groups (add users and groups to Right Side Layout)
 


 8. Commit Changes

 
 

Friday, 21 November 2014

Configure Component Queue in FileNet (FileNet Process Engine)

---Configure Component Queue in FileNet (FileNet Process Engine)

Component queues make it possible to process a workflow step by using an external entity, such as a Java object or Java Message Service (JMS).

By using Process Configuration Console, you configure a component queue with an adapter, either Java or JMS. The Java adapter allows you to expose public methods from a Java class as operations on a queue. The JMS adapter enables you to publish workflow data to a JMS queue, also by using operations. By using Process Designer, the workflow author adds a component step to a map and selects operations for that step from the list of component queues. The workflow author also specifies the appropriate expression for each operation parameter.


--Steps to Configure

Required Tools  

1. Process Configuration Console (PCC) Configuartion
2. Application Engine Process Task Manager (AE PTM) Configuration

Steps

//Process Configuration Console

1. Goto Workplace XT --> Tools --> Administration --> Process Configuration Console

2. Select on Connection Point and Click on Connect  


3.Right Click on Component Queue. and Click on New




4.Enter Queue Name


5. Click on Next


6.  Click on Configure..


7. Select JAR File 
8. Select Main Class File and Click on OK



9. Fill the JAAS Credentials as shown below and Click on OK


10. Right Click on Component, you created and go to Operation


11. Select Required Methods (Functions) and Click on OK






12. Commit Changes 






//Application Engine Process Task Manager (AE PTM)


13. Go to Installed-Path/FileNet/WebClient/Router

Open routercmd (PTM)



 14. Disconnect (Stop) Connection Point (Same as you installed Component Queue)




 15. Go to Required Libraries  tab and add Component JAR and Support JAR and Support file paths.
(Note : It allows JAR files and Folder Path only. If you have *.properties files, add it's parent folder only).





  



16. Click on Apply and Start Connection point


**********Component Queue configured Successfully*****************

Thursday, 20 November 2014

Add Case Comments in Case Client (IBM Case Manager API)

//Add Case Comments in Case Client (IBM Case Manager API)

public void addCaseCommentInHistory() throws Exception {
            String caseFolderGUID = //GUID of Case Folder
            String comment = "Hi"
            CaseMgmtContext oldCmc = null;
            log.info("Inside [WorkFlowHoldUnholdServices]addCaseComment():.............");
            ICMManager icmManager=new ICMManager();
            Connection conn=null;
            DomainReference domainRef=null;
            ObjectStoreReference osRef=null;
            Folder folder=null;
            try{
                conn=// Establish Connection

                if(conn!=null){
                    domainRef=ICMManager.getDomainReference(conn);
                    if(domainRef!=null){
                        osRef=ICMManager.getTargetOSReference(domainRef, fnObjectStoreName);
                        if(osRef!=null){
                            // retrieve case folder
                            folder = Factory.Folder.fetchInstance(osRef.getFetchlessCEObject(), caseFolderGUID, null);
                            // retrieve case using GUID
                            Id folderGUID = folder.get_Id();
                            Case cs = Case.getFetchlessInstance(osRef, folderGUID);
                            cs.addCaseComment(CommentContext.CASE, comment);
                            cs.save(RefreshMode.REFRESH, null, ModificationIntent.MODIFY);
                            log.info("History updated in Case");
                           
                        }else{
                            log.info("History Not updated As Target OS Ref is NULL");
                        }
                    }   
                }       
            }catch (Exception e) {
                log.error("addCaseCommentInHistory(String, String) - exception:"+ e,e); //$NON-NLS-1$
                e.printStackTrace();               

            }                    
        }               
             




//for connection please click on below link

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


  

Dispatch Work Item in FileNet Process Engine (Process Engine API)

   
    //Fetch the Work Item
    VWWorkObject vwWorkObj=null;
      try{
          VWRoster roster=peSession.getRoster(rosterName);
          int queryFlags=VWRoster.QUERY_NO_OPTIONS;
          String Name = "abcd";
          String filter="Doc_Name="+Name;//Change Accrordigly (Based on Process Administaration tool fields)
             
          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()){
              vwWorkObj=(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();
      }
     
//Terminate(Dispatch) work Item
try{

if(vwWorkObj!=null){

String Response = "Cancel";
VWStepElement vwStepObj=vwWorkObj.fetchStepElement();
vwStepObj.doLock(true);
vwStepObj.setSelectedResponse(Response);

vwStepObj.doDispatch();
}else{
                           
log.info("VWWorkObject is NULL");
                       
}
                       
}catch(Exception ex){
                           
ex.printStackTrace();
                       
}   

Tuesday, 18 November 2014

Build URL of Document in FileNet (Content Engine API)

//Build URL of Document in FileNet (Content Engine API)



//The below code generates the URL of Document. The URL works on same Browser where you run the code else it asks Credentials

public void opendoc() throws IOException
    {
        String baseP8URL = "http://localhost:9080/WorkplaceXT/";
        String user = //User Name
        String password = //Password
        //String objectStore = //Object Store Name
        String docID = //GUID of Document
        //Get Connection
        //Get Domain
        objectStore = //Get Object Store
        com.filenet.api.core.Document doc=com.filenet.api.core.Factory.Document.fetchInstance(objectStore, docID, null);
        String vsId = doc.get_VersionSeries().get_Id().toString();
       
        // Call WorkplaceXT’s setCredentials servlet to obtain user token
        try {
       
        URL url = new URL(baseP8URL +
        "setCredentials?op=getUserToken&userId="
        + user + "&password=" + password + "&verify=true");
        HttpURLConnection p8con =
        (HttpURLConnection) url.openConnection();
        p8con.setRequestMethod("POST");
        p8con.connect();
        InputStream in = p8con.getInputStream();
        int c = -1;
        String tempUserToken = "";
        while ( (c=in.read()) >= 0) tempUserToken +=
        new Character((char)c).toString();
                String userToken = URLEncoder.encode(tempUserToken, "UTF-8");
                System.out.println("the user token "+userToken);
                String strURL = baseP8URL + "getContent?objectStoreName="
                + "Target" + "&vsId=" + vsId + "&objectType=document&ut=" //
                + userToken + "&impersonate=true";
        System.out.println("ssss"+ strURL);
        }
        catch (Exception e )
        {
            e.printStackTrace();
        }
               
    }

View Content (Attachment) in FileNet Document (Content Engine API)

//View Content (Attachment) in FileNet Document (Content Engine API)


        ceConnection = //Get Connection
        domain = //Get Domain
        objectStore = //Get Object Store
       
        InputStream inputStream=null;
        try
        {
        FileInputStream is=null;
       
        System.out.println("inside fetchdoc Filenet----------------------------");
        ArrayList[] ars=new ArrayList[2];
        SearchScope search=new SearchScope(objectStore);
       
        String sql1= "Select * from [DocClass_Test] where ([DocumentTitle]= '"+DocTitle+"')";
        SearchSQL searchSQL=new SearchSQL(sql1);
        DocumentSet documents=(DocumentSet)search.fetchObjects(searchSQL, Integer.getInteger("50"), null, Boolean.valueOf(true));
        Document doc;
        Iterator it=documents.iterator();
       
        System.out.println("calling FileInputStream");
        while(it.hasNext())
        {
            doc=(Document)it.next();
            ContentElementList contents = doc.get_ContentElements();
              ContentTransfer ct;
              Iterator itContent = contents.iterator();
              while(itContent.hasNext()) {
                  ct = (ContentTransfer)itContent.next();
              inputStream = ct.accessContentStream();
              int bufferLength = 64*1024; // buffer size (64KB)
                byte[] buffer = new byte[bufferLength];
                int read=0;
              
                DataOutputStream out = new DataOutputStream(response.getOutputStream());
                System.out.println("calling while-- check");
                while((read=inputStream.read(buffer))!=-1)
                {
                    out.write(buffer,0,read);                 
                }
               
                out.close();
   
        }     
        }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }

Monday, 17 November 2014

Send Mail with multiple TO address and with Rich HTML Text

//Send Mail with multiple TO address and with Rich HTML Text

                    String from = abc@abcc.com
                  logger.debug("From Address :" +from);
                 
                  String[] to = "abcd@gmail.com,bcda@yahoo.com, xyzaa@gmail.com,vbgjg@hotmail.com";
                  String[] temp_to;
                  String delimeter = ",";
                  temp_to = to.split(delimeter);
                  for(int i =0; i < temp_to.length ; i++){
                      System.out.println(temp_to[i]);
                      System.out.println("");
                      }
                  logger.debug("To Address :"+to);
                  String host = "localhost";
                  logger.debug("SMTP Server IP Address :"+host);

                 
                  try{
                  //Session
                  Properties properties = System.getProperties(); 
                  properties.setProperty("mail.smtp.host", host); 
                  Session session = Session.getDefaultInstance(properties);
                              
                  //logger.info("Session ="+session);
                  logger.debug("Session object is created :"+session);
                 
                 
                  //Mail Part
                  MimeMessage message = new MimeMessage(session);
                  Multipart multipart = new MimeMultipart();
                  message.setFrom(new InternetAddress(from));
                  InternetAddress[] recipientAddress = new InternetAddress[temp_to.length];
                  int counter = 0;
                  for (String recipient : temp_to) {
                      recipientAddress[counter] = new InternetAddress(recipient.trim());
                      counter++;
                  }
                 // message.setRecipients(message.RecipientType.TO, recipientAddress);
                  message.setRecipients(javax.mail.Message.RecipientType.TO, recipientAddress);
                  message.setSubject("Document Uploaded:Need Approval");
                  logger.debug("Subject is created");
                 
                  BodyPart messageBodyPart = new MimeBodyPart();
         
                  String body = "<i>Dear Sir/Madam,</i><br>";
                  body += "<br><br><b>**********************ABCD**********************</b><br>";
                  body += "<br><font color=black>Sample Mail from p8programmer.</font><br>";
                  body += "<br><br><b><font color=red>Details:</font></b><br>";
                  body += "<br><table border=1><tbody>";
                  body += "<tr><td width=150 valign=top class=emailcontent style=padding:8px;>From</td><td width=200 valign=top class=emailcontent style=padding:8px;><b>"+from+"</b></td></tr>";
                  body += "<tr><td width=150 valign=top class=emailcontent style=padding:8px;>To</td><td width=200 valign=top class=emailcontent style=padding:8px;><b>"+to+"</b></td></tr>";
                  body += "</tbody></table><br><br><br>";
                  body += "<tr><td bgcolor=black height=5></td></tr>";
                  body += "<tr> <td style=padding:10px; class=emailcontent><br>Thanks &amp;Regards <br/>";
                  body += "<strong><i><font color=blue>p8programmer</font></i></strong></td>";
                  body += "<br><br></tr>";
                  body += "<td style=padding:10px; class=emailcontent>***************************************************************************************************************<br>";
                
               
                 
                  messageBodyPart.setContent(body,"text/html");
                  multipart.addBodyPart(messageBodyPart);
                 
                                  
                  logger.debug("...Body Part Created...");
                  message.setContent(multipart);
                  Transport.send(message);
                 
                  //logger.info("message sent successfully....");
                  logger.info("......Message sent successfully.....");
                  }
                  catch (MessagingException mex) {
                      mex.printStackTrace();
                      logger.error("Exception occured while sending mail :"+mex);
                  }

Send EMail reminder from Excel spreadsheet (Read TO Address from Excel sheet)

Description:  
Sending automatic mail from java code based on Date of births

1. Read Data from Excel sheet

2. Compare Date of Birth and Current Date
3. Fetch Name and mail Address  based on Date of birth and Current date (If equal)
4. Send mail to particular person (Send Mail with random images) with help of above deatils


Note :

Excel sheet content : (Date Format US English (mm/dd) )




 //Read Excel sheet compare Date of Birth and Current Date

package sample;

import java.io.File;
import java.io.IOException;

import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

import java.util.Calendar;
import java.util.GregorianCalendar;

import java.util.*;


public class ReadExcel {

 
  private String inputFile;
  public ArrayList<String> items = new ArrayList();

 
  public void setInputFile(String inputFile) {
    this.inputFile = inputFile;
  }

  public void read() throws IOException  {
    File inputWorkbook = new File(inputFile);
    Workbook w;
    try {
      w = Workbook.getWorkbook(inputWorkbook);
      // Get the first sheet
      Sheet sheet = w.getSheet(0);
      // Loop over first 10 column and lines

      for (int j = 0; j < sheet.getColumns(); j++) {
        for (int i = 0; i < sheet.getRows(); i++) {
          Cell cell = sheet.getCell(j, i);
          CellType type = cell.getType();
          
               
          if (type == CellType.DATE) {
              if( GetDate().equals(cell.getContents()))
                 
                      {
                 
                  System.out.println("Date Matched");
                 
                  System.out.println("Current Date "+GetDate());
                 
                  Cell a2 = sheet.getCell(j-1,i);
                //  name = a2.getContents();
                  items.add(a2.getContents());
                 
                 
                  Cell a1 = sheet.getCell(j+1,i);
                 // email = a1.getContents();
                  items.add(a1.getContents());
                    
                  System.out.println("Name  :" + a2);
                  System.out.println("Email  :"+ a1);
                     System.out.println("I got a Date " + cell.getContents());                
                 
            }else
            {
                System.out.println("Date not matched with current date");
            }
          }
         
           

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

 String GetDate(){
     int day, month;
     String CurrentDate;
     GregorianCalendar date = new GregorianCalendar();

     day = date.get(Calendar.DAY_OF_MONTH);
     month = date.get(Calendar.MONTH);
     CurrentDate = (month+1)+"/"+day;
 
     System.out.println("Current date is  " +CurrentDate);

    return CurrentDate;
     
  }
  public static void main(String[] args) throws IOException {
    ReadExcel test = new ReadExcel();
   // test.setInputFile("C:/Users/IBM_ADMIN/Documents/sample.xls");
    //test.GetDate();
    test.read();
    Iterator itr= test.items.iterator();
    while(itr.hasNext())
    {
        System.out.println("Name :" + itr.next() + "\n Email :" + itr.next());
 
    }
   
  }

}



//Sending Mail with Random Images 

package sample;

import java.io.IOException;
import java.util.*; 

import javax.mail.*; 
import javax.mail.internet.*; 
import javax.activation.*; 

import sample.ReadExcel;
 
public class SendEmail extends ReadExcel  

 public static void main(String [] args) throws IOException {
   
     
   
      String from = "abcde@gmail.com";//change accordingly
   
      String host = "127.0.0.1";//or IP address 
     
     
 
     //Get the session object 
      Properties properties = System.getProperties(); 
      properties.setProperty("mail.smtp.host", host); 
      Session session = Session.getDefaultInstance(properties); 
   
      String charsetNum = "123456789";
      StringBuffer image=new StringBuffer("images");
      ReadExcel test = new ReadExcel();
      test.setInputFile("C:/Users/IBM_ADMIN/Documents/sample.xls");
      test.GetDate();
      test.read();
      for(Iterator itr = test.items.iterator(); itr.hasNext();)
      {
          String name = (String)itr.next();
          String mail = (String)itr.next();
          String cc= (String) itr.next();
          System.out.println((new StringBuilder("Name :")).append(name).append("\n Email :").append(mail).append("\n CC :").append(cc).toString());
          try
          {
              java.util.Random rand = new java.util.Random(System.currentTimeMillis());

              for (int n = 1; n <2; n++) {
                  int pos = rand.nextInt(charsetNum.length());
                  image.append(charsetNum.charAt(pos));
              }
             
              String randomImageName = image.toString();
              System.out.println("randomImageName- "+randomImageName);
             
             
           
              MimeMessage message = new MimeMessage(session);
              message.setFrom(new InternetAddress(from));
              message.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(mail));
              message.addRecipient(javax.mail.Message.RecipientType.CC, new InternetAddress(cc));
              message.setSubject("Wishing you a Very Happy Birthday -"+name);
             
              MimeMultipart multipart = new MimeMultipart();
              BodyPart messageBodyPart = new MimeBodyPart();
                                        
              String htmlText = "<H2 style=\"font-family:Calibri;color:red;\">Wishing you a Very Happy Birthday.. !!**.."+name+"..**!!</H2>";
              messageBodyPart.setContent(htmlText, "text/html");               
             
              multipart.addBodyPart(messageBodyPart);
            
             
              messageBodyPart = new MimeBodyPart();
              String cntent1 = "<H3 style=\"font-family:Calibri;color:green;\"><br><br>Wishes you for Healthy Long Life...</H3>";
              messageBodyPart.setContent(cntent1,"text/html");
              multipart.addBodyPart(messageBodyPart);
             
              messageBodyPart = new MimeBodyPart();
              String cntent2 = "<H4 style=\"font-family:Calibri;color:red;\"><br><br>From ABC.</H4><br><img src=\"cid:image\"><br><br>" +
                      "PLEASE DO NOT REPLY TO ALL!!!!<br><br><b>AA PMO TEAM</b>";
              messageBodyPart.setContent(cntent2, "text/html");               
              multipart.addBodyPart(messageBodyPart);               
             
              messageBodyPart = new MimeBodyPart();
              javax.activation.DataSource fds1 = new FileDataSource("C:/Users/IBM_ADMIN/Pictures/"+randomImageName+".jpg");
              messageBodyPart.setDataHandler(new DataHandler(fds1));
              messageBodyPart.addHeader("Content-ID", "<image>");
              multipart.addBodyPart(messageBodyPart);
             
             
              message.setContent(multipart);
              Transport.send(message);
              System.out.println("message sent successfully....");
          }   

        catch (MessagingException mex) {mex.printStackTrace();} 
         
   
      }
     
 
     //compose the message 
     
   }