Complex Event Example

Below is a sample code for a complex event. It will look for any given file name at any given location. If file is found, then it will trigger the associated transaction. It will also set the file path in context so, if “eventContextEnabled=true” for the source activity in the process flow then that file will be processed in transaction.

 

import com.adeptia.indigo.TransactionExecutor;
import com.adeptia.indigo.event.EventUtils;
import com.adeptia.indigo.event.mailtrigger.MessageDigest;
import com.adeptia.indigo.logging.Logger;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import java.io.File;
import com.adeptia.indigo.event.PatternMatch;
 
 
// code variables
 
 
// Name or pattern of the file to match
         String filename = "S*.txt";
         // Location where to look for the files
         String baseLocation = "C:/Source";
         PatternMatch patternMatch = new PatternMatch();
         File file = new File(baseLocation);
         File[] fileList = file.listFiles();
         // List to contain files which matches the pattern
         List tempFileList = new ArrayList();
         boolean fileFound = false;
         for(int i = 0; i<fileList.length; i++){
             Map hashMap = new HashMap();
        Map eventContextMap = new HashMap();
         File temp = fileList[i];
         if (temp.getName().equals(filename)
                 || patternMatch.isMatch(temp.getName(), filename)) {
             fileFound = true;
             // add file path and event id to map
             hashMap.put(EventUtils.FILEPATH, temp.getAbsolutePath());
            hashMap.put("EventID","ComplexEvent:192168001192138691163386400009");
            // setting up values in the context variables. Repeat the below line for each variable.
            eventContextMap.put(EventUtils.EVENTCONTEXTVAR, hashMap);
            // define the process flow to be triggered.
             String processFlowId = "192168001083138624061603700001";
           
            // e.g. String processFlowId = "192168000003132845505680300001";
             TransactionExecutor.executeTransactionWithTransID(eventContextMap, processFlowId, subject, false);
         }
    }
         if (!fileFound) {
             // If no file matches then it will return from here
             System.out.println("No matching files found");
             return;
         }

        

 

Have more questions? Submit a request

0 Comments

Article is closed for comments.