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);
}
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;
}
Aggregations