Search in sources :

Example 1 with BusinessCalendarImpl

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

the class HumanTaskReassignmentTest 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 2 with BusinessCalendarImpl

use of org.jbpm.process.core.timer.BusinessCalendarImpl 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 3 with BusinessCalendarImpl

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

the class BoundaryEventOnTaskWithCalendarTest method testProcessWithTimeCycleISO.

@Test(timeout = 10000)
public void testProcessWithTimeCycleISO() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("deadline1", 1);
    addProcessEventListener(countDownListener);
    createRuntimeManager("org/jbpm/test/functional/event/BoundaryEventWithCycleCalendar.bpmn2");
    RuntimeEngine runtimeEngine = getRuntimeEngine();
    KieSession ksession = runtimeEngine.getKieSession();
    ksession.getEnvironment().set("jbpm.business.calendar", new BusinessCalendarImpl() {

        @Override
        public long calculateBusinessTimeAsDuration(String timeExpression) {
            timeExpression = adoptISOFormat(timeExpression);
            return TimeUtils.parseTimeString(timeExpression);
        }

        @Override
        public Date calculateBusinessTimeAsDate(String timeExpression) {
            timeExpression = adoptISOFormat(timeExpression);
            return new Date(TimeUtils.parseTimeString(getCurrentTime() + timeExpression));
        }
    });
    HashMap<String, Object> params = new HashMap<String, Object>();
    params.put("date", "R3/PT2S");
    ProcessInstance processInstance = ksession.startProcess("boundaryTimer", params);
    assertNodeTriggered(processInstance.getId(), "Start", "form1");
    countDownListener.waitTillCompleted();
    ProcessInstance pi = ksession.getProcessInstance(processInstance.getId());
    assertNull(pi);
    assertNodeTriggered(processInstance.getId(), "Koniec1");
    assertProcessInstanceCompleted(processInstance.getId());
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) BusinessCalendarImpl(org.jbpm.process.core.timer.BusinessCalendarImpl) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Date(java.util.Date) Test(org.junit.Test)

Example 4 with BusinessCalendarImpl

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

the class BoundaryEventOnTaskWithCalendarTest method testProcess.

@Test(timeout = 10000)
public void testProcess() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("deadline1", 1);
    addProcessEventListener(countDownListener);
    createRuntimeManager("org/jbpm/test/functional/event/BoundaryEventWithCalendar.bpmn2");
    RuntimeEngine runtimeEngine = getRuntimeEngine();
    KieSession ksession = runtimeEngine.getKieSession();
    ksession.getEnvironment().set("jbpm.business.calendar", new BusinessCalendarImpl());
    HashMap<String, Object> params = new HashMap<String, Object>();
    OffsetDateTime plusTwoSeconds = OffsetDateTime.now().plusSeconds(2);
    params.put("date", plusTwoSeconds.toString());
    ProcessInstance processInstance = ksession.startProcess("boundaryTimer", params);
    assertNodeTriggered(processInstance.getId(), "Start", "form1");
    countDownListener.waitTillCompleted();
    ProcessInstance pi = ksession.getProcessInstance(processInstance.getId());
    assertNull(pi);
    assertNodeTriggered(processInstance.getId(), "Koniec1");
    assertProcessInstanceCompleted(processInstance.getId());
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) OffsetDateTime(java.time.OffsetDateTime) BusinessCalendarImpl(org.jbpm.process.core.timer.BusinessCalendarImpl) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Aggregations

BusinessCalendarImpl (org.jbpm.process.core.timer.BusinessCalendarImpl)4 Date (java.util.Date)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Calendar (java.util.Calendar)2 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 BusinessCalendar (org.jbpm.process.core.timer.BusinessCalendar)2 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)2 Test (org.junit.Test)2 KieSession (org.kie.api.runtime.KieSession)2 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)2 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)2 OffsetDateTime (java.time.OffsetDateTime)1