How can a business calendar be used on an individual timer by timer basis in BPM Suite 6?

Solution Unverified - Updated -

Environment

Red Hat JBoss BPM Suite (BPMS) 6.x

Issue

  • We have several timers in our processes, and one of them needs to use business hours for its calculations. We're having a hard time finding good documentation for configuring this behavior.

  • Is it possible to configure a business calendar for a single timer? The docs and code seem to imply that a business calendar is configured for the entire ksession and is used across all timers within that ksession.

  • The requirement is to have some timers be timed exactly and others be timed based on business hours. Is this possible? Perhaps I need to implement a custom BussinesCalendar class where the timer syntax can be expanded with a "business" keyword?

Resolution

It is not possible to set BusinessCalendar for a specific timer. However, there is another approach which can be used to invoke the business calendar directly to calculate the absolute time, store it in a process variable and use the variable to configure the Time Date field on the timer. The logic executed before hand:

    public static void initializeTraderTaskExpiration(ProcessContext kcontext) {
        Properties config = (Properties) kcontext.getVariable(procVariables.workflowSettings.toString());
        Properties businessCalendarProperties =
                (Properties) kcontext.getVariable(procVariables.businessCalendarProperties.toString());
        String expirationExpr = config.getProperty(TRADER_EXPIRATION_EXPR_VAR_NAME);
        if(expirationExpr == null || Objects.equals(expirationExpr, "")) {
            throw new RuntimeException("Missing " + TRADER_EXPIRATION_EXPR_VAR_NAME + " variable");
        }
        BusinessCalendar businessCalendar = new BusinessCalendarImpl(businessCalendarProperties);
        Date expirationDate = businessCalendar.calculateBusinessTimeAsDate(expirationExpr);
        String expirationDateRaw = ISODateTimeFormat.dateTimeNoMillis().print(expirationDate.toInstant().toEpochMilli());
        kcontext.setVariable(procVariables.traderTaskExpirationDate.toString(), expirationDateRaw);
    }

Then:
1. The traderTaskExpirationDate is referenced in the Time Date field using #{...} syntax;
2. Do not configure the business calendar globally;
3. Load a properties file with the necessary business.cal.* properties in a process variable (mostly to prevent loading this file repeatedly during a process' lifetime).

This allows us to keep the normal timer behavior but also pull in the business calendar logic on a timer by timer basis.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments