Search in sources :

Example 6 with BusinessCalendar

use of org.jbpm.process.core.timer.BusinessCalendar in project jbpm by kiegroup.

the class BusinessCalendarTest method configureBusinessCalendar.

private void configureBusinessCalendar(boolean businessHour) {
    Properties configuration = new Properties();
    if (businessHour) {
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DATE, -1);
        int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
        configuration.setProperty(BusinessCalendarImpl.START_HOUR, "0");
        configuration.setProperty(BusinessCalendarImpl.END_HOUR, "24");
        configuration.setProperty(BusinessCalendarImpl.HOURS_PER_DAY, "24");
        configuration.setProperty(BusinessCalendarImpl.DAYS_PER_WEEK, "7");
        configuration.setProperty(BusinessCalendarImpl.WEEKEND_DAYS, Integer.toString(dayOfWeek));
    } else {
        Date today = new Date();
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DATE, 1);
        Date tomorrow = c.getTime();
        String dateFormat = "yyyy-MM-dd";
        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
        configuration.setProperty(BusinessCalendarImpl.HOLIDAYS, sdf.format(today) + "," + sdf.format(tomorrow));
        configuration.setProperty(BusinessCalendarImpl.HOLIDAY_DATE_FORMAT, dateFormat);
    }
    BusinessCalendar businessCalendar = new BusinessCalendarImpl(configuration);
    ksession.getEnvironment().set("jbpm.business.calendar", businessCalendar);
}
Also used : Calendar(java.util.Calendar) BusinessCalendar(org.jbpm.process.core.timer.BusinessCalendar) BusinessCalendarImpl(org.jbpm.process.core.timer.BusinessCalendarImpl) BusinessCalendar(org.jbpm.process.core.timer.BusinessCalendar) Properties(java.util.Properties) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 7 with BusinessCalendar

use of org.jbpm.process.core.timer.BusinessCalendar in project jbpm by kiegroup.

the class HumanTaskHandlerHelper method parseDeadlineString.

protected static List<Deadline> parseDeadlineString(String deadlineInfo, List<OrganizationalEntity> businessAdministrators, Environment environment) {
    if (deadlineInfo == null || deadlineInfo.length() == 0) {
        return new ArrayList<Deadline>();
    }
    List<Deadline> deadlines = new ArrayList<Deadline>();
    String[] allComponents = deadlineInfo.split(COMPONENT_SEPARATOR);
    BusinessCalendar businessCalendar = null;
    if (environment != null && environment.get("jbpm.business.calendar") != null) {
        businessCalendar = (BusinessCalendar) environment.get("jbpm.business.calendar");
    }
    for (String component : allComponents) {
        String[] mainComponents = component.split(ELEMENT_SEPARATOR);
        if (mainComponents != null && mainComponents.length == 2) {
            String actionComponent = mainComponents[0].substring(1, mainComponents[0].length() - 1);
            String expireComponents = mainComponents[1].substring(1, mainComponents[1].length() - 1);
            String[] expireElements = expireComponents.split(ATTRIBUTES_ELEMENTS_SEPARATOR);
            Deadline taskDeadline = null;
            for (String expiresAt : expireElements) {
                logger.debug("Expires at is {}", expiresAt);
                taskDeadline = TaskModelProvider.getFactory().newDeadline();
                if (businessCalendar != null) {
                    taskDeadline.setDate(businessCalendar.calculateBusinessTimeAsDate(expiresAt));
                } else {
                    taskDeadline.setDate(new Date(System.currentTimeMillis() + TimeUtils.parseTimeString(expiresAt)));
                }
                logger.debug("Calculated date of execution is {} and current date {}", taskDeadline.getDate(), new Date());
                List<Escalation> escalations = new ArrayList<Escalation>();
                Escalation escalation = TaskModelProvider.getFactory().newEscalation();
                escalations.add(escalation);
                escalation.setName("Default escalation");
                taskDeadline.setEscalations(escalations);
                escalation.setReassignments(parseReassignment(actionComponent));
                escalation.setNotifications(parseNotifications(actionComponent, businessAdministrators));
                deadlines.add(taskDeadline);
            }
        } else {
            logger.warn("Incorrect syntax of deadline property {}", deadlineInfo);
        }
    }
    return deadlines;
}
Also used : Deadline(org.kie.internal.task.api.model.Deadline) Escalation(org.kie.internal.task.api.model.Escalation) ArrayList(java.util.ArrayList) BusinessCalendar(org.jbpm.process.core.timer.BusinessCalendar) Date(java.util.Date)

Aggregations

BusinessCalendar (org.jbpm.process.core.timer.BusinessCalendar)7 Date (java.util.Date)3 TimerInstance (org.jbpm.process.instance.timer.TimerInstance)3 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 Properties (java.util.Properties)2 BusinessCalendarImpl (org.jbpm.process.core.timer.BusinessCalendarImpl)2 HashMap (java.util.HashMap)1 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)1 InternalKnowledgeRuntime (org.drools.core.common.InternalKnowledgeRuntime)1 Timer (org.jbpm.process.core.timer.Timer)1 DefaultSignalManagerFactory (org.jbpm.process.instance.event.DefaultSignalManagerFactory)1 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)1 Test (org.junit.Test)1 KieServices (org.kie.api.KieServices)1 ReleaseId (org.kie.api.builder.ReleaseId)1 KieRuntime (org.kie.api.runtime.KieRuntime)1 KieSession (org.kie.api.runtime.KieSession)1 RegisterableItemsFactory (org.kie.api.runtime.manager.RegisterableItemsFactory)1