Thursday, March 15, 2012

Filtering a subscription trigger

So you want to filter out your subscription trigger so it only triggers on certain events.   There's a filter field in the subscription trigger, but it's just a free-form field.  The documentation isn't clear.

Update - found an easier way.
(%myField%=="myvalue")

Complex filters can look like this:

(%textMessageMonitorEvent/textMessageEnvelope/processType%=="VehicleReady" && %textMessageMonitorEvent/textMessageTrackingInfo/monitorStatus%=="DONE" && %textMessageMonitorEvent/textMessageTrackingInfo/deliveryStatus%<>"SUCCESS")

The below also works, but is harder to read and you have to include the document in the clause.  The above just needs the field path.

%myDoc/myField% L_EQUALS myvalue

Note that there are no quotes on the right operand even though it is a string value!

Also, you need to use the "name" operators like L_EQUALS to have the filter operate on the broker, rather than passing it to the Integration Server and then filtering it (which causes more network traffic and IS CPU usage).

Here are the possible comparators I found in the Developer's handbook.

L_EQUALS
L_NOT_EQUALS
L_LESS_THAN
L_LESS_OR_EQUAL
L_GREATER_THAN
L_GREATER_THAN
L_GREATER_OR_EQUAL
L_GREATER_OR_EQUAL

11 comments:

  1. Kevin,
    I'm was searching for Developer info when I found your blog. Do you know if there is a way to set Developer so that the items in the Results pane are collapsed by default instead of expanded?
    Thanks,
    Charles

    ReplyDelete
  2. will also work for UM?

    ReplyDelete
  3. // pipeline
    IDataCursor pipelineCursor = pipeline.getCursor();
    String startDateTime = IDataUtil.getString( pipelineCursor, "startDateTime" );
    String endDateTime = IDataUtil.getString( pipelineCursor, "endDateTime" );
    String startDateFormat = IDataUtil.getString( pipelineCursor, "startDateFormat" );
    String endDateFormat = IDataUtil.getString( pipelineCursor, "endDateFormat" );
    pipelineCursor.destroy();
    Boolean includeEndDateFlag = (Boolean) IDataUtil.get( pipelineCursor, "includeEndDateFlag" );
    try {
    SimpleDateFormat sdf = new SimpleDateFormat(startDateFormat);
    Date sdt = sdf.parse(startDateTime);
    SimpleDateFormat edf = new SimpleDateFormat(endDateFormat);
    Date edt = edf.parse(endDateTime);;
    long timediff=0;
    if(includeEndDateFlag){
    SimpleDateFormat newendsdf = new SimpleDateFormat(endDateFormat);
    Calendar c = Calendar.getInstance();
    c.setTime(sdf.parse(endDateTime));
    c.add(Calendar.DATE, 1); // number of days to add
    endDateTime = newendsdf.format(c.getTime());
    edt = edf.parse(endDateTime);
    timediff = edt.getTime() - sdt.getTime();
    }
    else{
    timediff = edt.getTime() - sdt.getTime();
    }
    String displayTimeSec = Long.toString(timediff / 1000);
    String displayTimeMin = Long.toString(timediff / 60000);
    String displayTimeHr = Long.toString(timediff / 3600000);
    String displayTimeDay = Long.toString(timediff / 86400000);
    pipelineCursor.last();
    pipelineCursor.insertAfter("dateDifferenceSec", displayTimeSec);
    pipelineCursor.insertAfter("dateDifferenceMin", displayTimeMin);
    pipelineCursor.insertAfter("dateDifferenceHr", displayTimeHr);
    pipelineCursor.insertAfter("dateDifferenceDay", displayTimeDay);
    pipelineCursor.destroy();
    } catch (ParseException e) {
    IDataUtil.put(pipelineCursor, "errorMessage", e.toString());
    }
    pipelineCursor.destroy();

    ReplyDelete
  4. IDataCursor pipelineCursor = pipeline.getCursor();
    String startDateTime = IDataUtil.getString( pipelineCursor, "startDateTime" );
    String endDateTime = IDataUtil.getString( pipelineCursor, "endDateTime" );
    String startDateFormat = IDataUtil.getString( pipelineCursor, "startDateFormat" );
    String endDateFormat = IDataUtil.getString( pipelineCursor, "endDateFormat" );
    pipelineCursor.destroy();
    Date startDate;
    try {
    startDate = parseDate(startDateTime, startDateFormat);
    Date endDate = parseDate(endDateTime, endDateFormat);
    if (startDate.after(endDate)){
    Date temp = startDate;
    startDate = endDate;
    endDate = temp;
    }
    Map interval = getInterval(startDate, endDate,null);

    IDataUtil.put( pipelineCursor, "dateDifferenceSec", ((Long)interval.get(ChronoUnit.SECONDS)).toString() );
    IDataUtil.put( pipelineCursor, "dateDifferenceMin", ((Long)interval.get(ChronoUnit.MINUTES)).toString() );
    IDataUtil.put( pipelineCursor, "dateDifferenceHr", ((Long)interval.get(ChronoUnit.HOURS)).toString());
    IDataUtil.put( pipelineCursor, "dateDifferenceDay", ((Long)interval.get(ChronoUnit.DAYS)).toString());
    pipelineCursor.destroy();
    } catch (ParseException e) {
    IDataUtil.put( pipelineCursor, "errorMessage", e.toString());
    }

    Shared source code

    private static Date parseDate(String dateStr, String dateFormat) throws ServiceException, ParseException{
    SimpleDateFormat simpleDateFormat = null;
    simpleDateFormat = new SimpleDateFormat(dateFormat);
    simpleDateFormat.setLenient(false);
    Date d = simpleDateFormat.parse(dateStr);
    return d;
    }
    private static Map getInterval(Date startDate, Date endDate, ZoneId zoneId)
    {
    ZoneId zId = zoneId == null ? ZoneId.systemDefault() : zoneId;
    ZonedDateTime start = ZonedDateTime.ofInstant(startDate.toInstant(), zId);
    ZonedDateTime end = ZonedDateTime.ofInstant(endDate.toInstant(), zId);

    Map result = new LinkedHashMap();
    result.put(ChronoUnit.SECONDS, Long.valueOf(ChronoUnit.SECONDS.between(start, end)));
    result.put(ChronoUnit.MINUTES, Long.valueOf(ChronoUnit.MINUTES.between(start, end)));
    result.put(ChronoUnit.HOURS, Long.valueOf(ChronoUnit.HOURS.between(start, end)));
    result.put(ChronoUnit.DAYS, Long.valueOf(ChronoUnit.DAYS.between(start, end)));

    return result;
    }

    ReplyDelete
  5. var modalDialog = CAF.model("#{caf:cid('htmlInputText11')}");
    if(modalDialog.getValue()===""){
    }
    else{
    CAF.model('#{activePageBean.clientIds['modalDialog']}').show();
    }

    ReplyDelete
  6. pipeline
    IDataCursor pipelineCursor = pipeline.getCursor();

    List uniqueCustomers=new ArrayList();
    List filteredList=new ArrayList();

    IData temp=null;
    IDataCursor tempCursor=null;
    // inResultSet
    IData[] inResultSet = IDataUtil.getIDataArray( pipelineCursor, "inResultSet" );
    if ( inResultSet != null){
    for ( int i = 0; i < inResultSet.length; i++ ){
    IDataCursor inResultSetCursor = inResultSet[i].getCursor();
    String customerNumber = IDataUtil.getString( inResultSetCursor, "customerNumber" );
    String LPN = IDataUtil.getString( inResultSetCursor, "LPN" );
    String item = IDataUtil.getString( inResultSetCursor, "item" );
    String itemNo = IDataUtil.getString( inResultSetCursor, "itemNo" );
    String itemDescription = IDataUtil.getString( inResultSetCursor, "itemDescription" );
    String quantity = IDataUtil.getString( inResultSetCursor, "quantity" );
    String status = IDataUtil.getString( inResultSetCursor, "status" );
    String stopNo = IDataUtil.getString( inResultSetCursor, "stopNo" );
    inResultSetCursor.destroy();

    if(!uniqueCustomers.contains(customerNumber)){
    uniqueCustomers.add(customerNumber);

    temp=IDataFactory.create();
    tempCursor=temp.getCursor();

    IDataUtil.put( tempCursor, "customerNumber", customerNumber );
    IDataUtil.put( tempCursor, "LPN", LPN );
    IDataUtil.put( tempCursor, "item", item );
    IDataUtil.put( tempCursor, "itemNo", itemNo );
    IDataUtil.put( tempCursor, "itemDescription", itemDescription );
    IDataUtil.put( tempCursor, "quantity", quantity );
    IDataUtil.put( tempCursor, "status", status );
    IDataUtil.put( tempCursor, "stopNo", stopNo );
    tempCursor.destroy();
    filteredList.add(temp);
    }
    }
    }
    pipelineCursor.destroy();
    IDataUtil.put( pipelineCursor, "filteredResultSet", filteredList.toArray(new IData[filteredList.size()]) );
    pipelineCursor.destroy();

    ReplyDelete
  7. / pipeline
    IDataCursor pipelineCursor = pipeline.getCursor();

    List uniqueCustomers=new ArrayList();
    List uniqueId=new ArrayList();
    List filteredList=new ArrayList();

    IData temp=null;
    IDataCursor tempCursor=null;
    // inResultSet
    IData[] inResultSet = IDataUtil.getIDataArray( pipelineCursor, "inResultSet" );
    if ( inResultSet != null){
    for ( int i = 0; i < inResultSet.length; i++ ){
    IDataCursor inResultSetCursor = inResultSet[i].getCursor();
    String customerNumber = IDataUtil.getString( inResultSetCursor, "customerNumber" );
    String LPN = IDataUtil.getString( inResultSetCursor, "LPN" );
    String item = IDataUtil.getString( inResultSetCursor, "item" );
    String itemNo = IDataUtil.getString( inResultSetCursor, "itemNo" );
    String itemDescription = IDataUtil.getString( inResultSetCursor, "itemDescription" );
    String quantity = IDataUtil.getString( inResultSetCursor, "quantity" );
    String status = IDataUtil.getString( inResultSetCursor, "status" );
    String stopNo = IDataUtil.getString( inResultSetCursor, "stopNo" );
    inResultSetCursor.destroy();

    if(!uniqueCustomers.contains(customerNumber)){
    uniqueCustomers.add(customerNumber);
    uniqueId.add(customerNumber+"_"+stopNo);
    temp=IDataFactory.create();
    tempCursor=temp.getCursor();

    IDataUtil.put( tempCursor, "customerNumber", customerNumber );
    IDataUtil.put( tempCursor, "LPN", LPN );
    IDataUtil.put( tempCursor, "item", item );
    IDataUtil.put( tempCursor, "itemNo", itemNo );
    IDataUtil.put( tempCursor, "itemDescription", itemDescription );
    IDataUtil.put( tempCursor, "quantity", quantity );
    IDataUtil.put( tempCursor, "status", status );
    IDataUtil.put( tempCursor, "stopNo", stopNo );
    tempCursor.destroy();
    filteredList.add(temp);
    }
    else{
    if(uniqueId.contains(customerNumber+"_"+stopNo)){
    temp=IDataFactory.create();
    tempCursor=temp.getCursor();

    IDataUtil.put( tempCursor, "customerNumber", customerNumber );
    IDataUtil.put( tempCursor, "LPN", LPN );
    IDataUtil.put( tempCursor, "item", item );
    IDataUtil.put( tempCursor, "itemNo", itemNo );
    IDataUtil.put( tempCursor, "itemDescription", itemDescription );
    IDataUtil.put( tempCursor, "quantity", quantity );
    IDataUtil.put( tempCursor, "status", status );
    IDataUtil.put( tempCursor, "stopNo", stopNo );
    tempCursor.destroy();
    filteredList.add(temp);
    }
    }
    }
    }
    pipelineCursor.destroy();
    IDataUtil.put( pipelineCursor, "filteredResultSet", filteredList.toArray(new IData[filteredList.size()]) );
    pipelineCursor.destroy();

    ReplyDelete
  8. // pipeline
    IDataCursor pipelineCursor = pipeline.getCursor();
    // routeList
    IData[] routeList = IDataUtil.getIDataArray( pipelineCursor, "routeList" );
    //Calculate date difference in days
    String startDate = IDataUtil.getString( pipelineCursor, "startDate" );
    String endDate = IDataUtil.getString( pipelineCursor, "endDate" );
    String status = IDataUtil.getString( pipelineCursor, "status" );
    String user = IDataUtil.getString( pipelineCursor, "user" );
    pipelineCursor.destroy();
    String dateFormat="yyyy-MM-dd";
    // input
    IData input = IDataFactory.create();
    IDataCursor inputCursor = input.getCursor();
    IDataUtil.put( inputCursor, "startDate", startDate );
    IDataUtil.put( inputCursor, "endDate", endDate );
    IDataUtil.put( inputCursor, "startDatePattern", dateFormat );
    IDataUtil.put( inputCursor, "endDatePattern", dateFormat );
    inputCursor.destroy();
    // output
    IData output = IDataFactory.create();
    try{
    output = Service.doInvoke( "pub.date", "calculateDateDifference", input );
    }catch( Exception e){}
    IDataCursor outputCursor = output.getCursor();
    String dateDifferenceDays = IDataUtil.getString( outputCursor, "dateDifferenceDays" );
    outputCursor.destroy();

    int numOfDays= Integer.valueOf(dateDifferenceDays);

    List outDocList=new ArrayList();
    IData tempDoc=null;
    IDataCursor tempDocCursor=null;
    String deliveryDate=startDate;

    for (int i = 0; i < numOfDays; i++) {
    // input
    input = IDataFactory.create();
    inputCursor = input.getCursor();
    IDataUtil.put( inputCursor, "startDate", deliveryDate );
    IDataUtil.put( inputCursor, "startDatePattern", dateFormat );
    IDataUtil.put( inputCursor, "endDatePattern", dateFormat );
    IDataUtil.put( inputCursor, "addDays", "1" );
    inputCursor.destroy();

    // output
    output = IDataFactory.create();
    try{
    output = Service.doInvoke( "pub.date", "incrementDate", input );
    }catch( Exception e){}
    outputCursor = output.getCursor();
    deliveryDate= IDataUtil.getString( outputCursor, "endDate" );
    outputCursor.destroy();


    for (int j = 0; j < routeList.length; j++) {
    tempDoc=IDataFactory.create();
    tempDocCursor=tempDoc.getCursor();

    IData tempDoc1=routeList[j];
    IDataCursor tempDoc1Cursor=tempDoc1.getCursor();

    String route=IDataUtil.getString(tempDoc1Cursor, "routes");
    tempDoc1Cursor.destroy();

    IDataUtil.put(tempDocCursor,"routeNumber",route);
    IDataUtil.put( tempDocCursor, "deliveryDate", deliveryDate );
    IDataUtil.put( tempDocCursor, "status", status);
    IDataUtil.put( tempDocCursor, "user", user );
    tempDocCursor.destroy();

    outDocList.add(tempDoc);
    }
    }
    // pipeline
    IDataUtil.put(pipelineCursor, "outDocList", outDocList.toArray(new IData[outDocList.size()]));
    pipelineCursor.destroy();

    ReplyDelete
  9. Get a single value from config

    // pipeline
    IDataCursor pipelineCursor = pipeline.getCursor();
    String packageName = IDataUtil.getString( pipelineCursor, "packageName" );
    String propertyFileName = IDataUtil.getString( pipelineCursor, "propertyFileName" );
    String propertyName = IDataUtil.getString( pipelineCursor, "propertyName" );
    pipelineCursor.destroy();

    if(propertyFileName==null || propertyFileName==""){
    propertyFileName=getPackagePropertyFileName(packageName);
    }
    else{
    propertyFileName=getPackageConfigDir(packageName)+File.separator + propertyFileName + ".properties";
    }

    try (InputStream inStream = new FileInputStream(propertyFileName)) {
    Properties prop=new Properties();
    prop.load(inStream);
    IDataUtil.put( pipelineCursor, "propertyValue",prop.getProperty(propertyName));
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    ServerAPI.logError(e);
    } catch (IOException e) {
    e.printStackTrace();
    ServerAPI.logError(e);
    }

    ReplyDelete
  10. Get all values from config

    // pipeline
    IDataCursor pipelineCursor = pipeline.getCursor();
    String packageName = IDataUtil.getString( pipelineCursor, "packageName" );
    String propertyFileName = IDataUtil.getString( pipelineCursor, "propertyFileName" );
    pipelineCursor.destroy();

    if(propertyFileName==null || propertyFileName==""){
    propertyFileName=getPackagePropertyFileName(packageName);
    }
    else{
    propertyFileName=getPackageConfigDir(packageName)+File.separator + propertyFileName + ".properties";
    }

    try (InputStream inStream = new FileInputStream(propertyFileName)) {
    Properties prop=new Properties();
    prop.load(inStream);

    IData tempDoc=IDataFactory.create();
    IDataCursor tempDocCursor=tempDoc.getCursor();

    Set Object keys= prop.keySet();

    for (Object k: keys) {
    IDataUtil.put(tempDocCursor, (String) k, prop.getProperty((String)k));
    }
    tempDocCursor.destroy();
    IDataUtil.put(pipelineCursor, "propertyValues", tempDoc);
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    ServerAPI.logError(e);
    } catch (IOException e) {
    e.printStackTrace();
    ServerAPI.logError(e);
    }
    pipelineCursor.destroy();

    ReplyDelete
    Replies
    1. // pipeline
      IDataCursor pipelineCursor = pipeline.getCursor();
      List outList=new ArrayList();
      IData temp=null;
      IDataCursor tempCurosor=null;

      // actions
      IData[] actions = IDataUtil.getIDataArray( pipelineCursor, "actions" );
      if ( actions != null){
      for ( int i_1 = 0; i_1 < actions.length; i_1++ ){
      IDataCursor actionsCursor = actions[i_1].getCursor();
      String key = IDataUtil.getString( actionsCursor, "key" );
      actionsCursor.destroy();
      }
      }

      // items
      IData[] items = IDataUtil.getIDataArray( pipelineCursor, "items" );
      if ( items != null){
      for ( int i_2 = 0; i_2 < items.length; i_2++ ){
      IDataCursor itemsCursor = items[i_2].getCursor();
      String ITEMS = IDataUtil.getString( itemsCursor, "ITEMS" );
      itemsCursor.destroy();
      }
      }

      // inFGInv
      IData[] inFGInv = IDataUtil.getIDataArray( pipelineCursor, "inFGInv" );
      if ( inFGInv != null){
      for ( int i = 0; i < inFGInv.length; i++ ){
      IDataCursor inFGInvCursor = inFGInv[i].getCursor();
      String INV_LOG_SYSID = IDataUtil.getString( inFGInvCursor, "INV_LOG_SYSID" );
      String QTY_TO = IDataUtil.getString( inFGInvCursor, "QTY_TO" );
      String ITEM_FROM = IDataUtil.getString( inFGInvCursor, "ITEM_FROM" );
      String LOT_FROM = IDataUtil.getString( inFGInvCursor, "LOT_FROM" );
      String BUILDING_NAME = IDataUtil.getString( inFGInvCursor, "BUILDING_NAME" );
      String ACTION = IDataUtil.getString( inFGInvCursor, "ACTION" );
      String QTY_FROM = IDataUtil.getString( inFGInvCursor, "QTY_FROM" );
      String ITEM_TO = IDataUtil.getString( inFGInvCursor, "ITEM_TO" );
      String LOT_TO = IDataUtil.getString( inFGInvCursor, "LOT_TO" );
      String SAVANNA_TIMESTAMP = IDataUtil.getString( inFGInvCursor, "SAVANNA_TIMESTAMP" );
      String LOCATION_FROM = IDataUtil.getString( inFGInvCursor, "LOCATION_FROM" );
      String LOCATION_TO = IDataUtil.getString( inFGInvCursor, "LOCATION_TO" );
      String SCRAP_REASON = IDataUtil.getString( inFGInvCursor, "SCRAP_REASON" );
      String SCRAP_EXPLANATION = IDataUtil.getString( inFGInvCursor, "SCRAP_EXPLANATION" );
      String LOT_EXPIRATION_DATE = IDataUtil.getString( inFGInvCursor, "LOT_EXPIRATION_DATE" );
      String REASON_CODE_ID = IDataUtil.getString( inFGInvCursor, "REASON_CODE_ID" );
      String EBS_TRANSACTION = IDataUtil.getString( inFGInvCursor, "EBS_TRANSACTION" );
      String CLIMATE_ZONE = IDataUtil.getString( inFGInvCursor, "CLIMATE_ZONE" );
      inFGInvCursor.destroy();

      //if inFGInv.Action matches any of the keys in 'actions' map it to output doclist -savannaFinInvOutput
      if(checkIfExists(actions, "key", ACTION)){
      outList.add(inFGInv[i]);
      }
      //if inFGInv.Action does not match any of the keys in 'actions'- perform a validation with keys in items i.e
      else{
      //perform a validation with keys in items i.e
      if(checkIfExists(items, "ITEMS", ITEM_FROM)){
      outList.add(inFGInv[i]);
      }
      //if if inFGInv.ITEM_FROM does not match with any of the keys in items , drop that doc and move over.
      else{

      }
      }
      }
      }
      pipelineCursor.destroy();
      IDataUtil.put( pipelineCursor, "savannaFinInvOutput", outList.toArray(new IData[outList.size()]));
      pipelineCursor.destroy();


      // --- <> ---


      private static Boolean checkIfExists(IData[] inList,String key, String matchValue){
      Boolean isExists=false;
      for (int i = 0; i < inList.length; i++) {
      IDataCursor placeHolderCursor=inList[i].getCursor();
      while(placeHolderCursor.next()){
      String tempKey=placeHolderCursor.getKey();
      String tempVal=(String) placeHolderCursor.getValue();

      if(tempKey.equalsIgnoreCase(key)){
      if(tempVal.equalsIgnoreCase(matchValue)){
      isExists=true;
      break;
      }
      }
      }
      }
      return isExists;
      }

      // --- <> ---

      Delete