Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync main branch with Apache main branch #87

Merged
merged 7 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Apache KIE
Copyright 2023 The Apache Software Foundation
Copyright 2023-2024 The Apache Software Foundation

This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,21 @@
public interface BusinessCalendar {

/**
* Calculates given time expression into duration in milliseconds based on calendar configuration.
*
* Returns the difference, in milliseconds, between the <b>business date</b> that matches the given
* <code>timeExpression</code>, and the current time.
* See {@link #calculateBusinessTimeAsDate} for <b>business date</b> calculation
*
* @param timeExpression time expression that is supported by business calendar implementation.
* @return duration expressed in milliseconds
*/
public long calculateBusinessTimeAsDuration(String timeExpression);
long calculateBusinessTimeAsDuration(String timeExpression);

/**
* Calculates given time expression into target date based on calendar configuration.
* Returns the first <code>Date</code> that matches the given <code>timeExpression</code> and falls
* into the business calendar working hours.
*
* @param timeExpression time expression that is supported by business calendar implementation.
* @return date when given time expression will match in the future
*/
public Date calculateBusinessTimeAsDate(String timeExpression);
Date calculateBusinessTimeAsDate(String timeExpression);
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.jbpm.process.core.timer;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Objects;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.jbpm.process.core.constants.CalendarConstants.BUSINESS_CALENDAR_PATH;

public class CalendarBeanFactory {

private static final Logger logger = LoggerFactory.getLogger(CalendarBeanFactory.class);

public static CalendarBean createCalendarBean() {
URL resource = Thread.currentThread().getContextClassLoader().getResource(BUSINESS_CALENDAR_PATH);
if (Objects.nonNull(resource)) {
logger.debug("URL resource: {}", resource);
Properties calendarConfiguration = new Properties();
try (InputStream is = resource.openStream()) {
calendarConfiguration.load(is);
return new CalendarBean(calendarConfiguration);
} catch (IOException e) {
String errorMessage = "Error while loading properties for business calendar";
logger.error(errorMessage, e);
throw new RuntimeException(errorMessage, e);
} catch (IllegalArgumentException e) {
String errorMessage = "Error while populating properties for business calendar";
logger.error(errorMessage, e);
throw e;
}
} else {
String errorMessage = String.format("Missing %s", BUSINESS_CALENDAR_PATH);
logger.error(errorMessage);
throw new RuntimeException(errorMessage);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,10 @@ public void configureTimers() {
}

public TimerInstance configureSLATimer(String slaDueDateExpression) {
return configureSLATimer(slaDueDateExpression, null);
}

public TimerInstance configureSLATimer(String slaDueDateExpression, String nodeInstanceId) {
// setup SLA if provided
slaDueDateExpression = resolveVariable(slaDueDateExpression).toString();
if (slaDueDateExpression == null || slaDueDateExpression.trim().isEmpty()) {
Expand All @@ -583,7 +587,7 @@ public TimerInstance configureSLATimer(String slaDueDateExpression) {

TimerInstance timerInstance = createDurationTimer(duration);
if (useTimerSLATracking()) {
registerTimer(timerInstance);
registerTimer(timerInstance, nodeInstanceId);
}
return timerInstance;
}
Expand All @@ -598,13 +602,18 @@ private TimerInstance createDurationTimer(long duration) {
}

private TimerInstance registerTimer(TimerInstance timerInstance) {
return registerTimer(timerInstance, null);
}

private TimerInstance registerTimer(TimerInstance timerInstance, String nodeInstanceId) {
ProcessInstanceJobDescription description =
ProcessInstanceJobDescription.newProcessInstanceJobDescriptionBuilder()
.id(timerInstance.getId())
.timerId(timerInstance.getTimerId())
.expirationTime(DurationExpirationTime.after(timerInstance.getDelay()))
.processInstanceId(getStringId())
.processId(getProcessId())
.nodeInstanceId(nodeInstanceId)
.build();
JobsService jobsService = InternalProcessRuntime.asKogitoProcessRuntime(getKnowledgeRuntime().getProcessRuntime()).getJobsService();
jobsService.scheduleJob(description);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void internalTrigger(final KogitoNodeInstance from, String type) {
protected void configureSla() {
String slaDueDateExpression = (String) getNode().getMetaData().get("customSLADueDate");
if (slaDueDateExpression != null) {
TimerInstance timer = ((WorkflowProcessInstanceImpl) getProcessInstance()).configureSLATimer(slaDueDateExpression);
TimerInstance timer = ((WorkflowProcessInstanceImpl) getProcessInstance()).configureSLATimer(slaDueDateExpression, this.getId());
if (timer != null) {
this.slaTimerId = timer.getId();
this.slaDueDate = new Date(System.currentTimeMillis() + timer.getDelay());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void internalTrigger(KogitoNodeInstance from, String type) {
protected void configureSla() {
String slaDueDateExpression = (String) getNode().getMetaData().get("customSLADueDate");
if (slaDueDateExpression != null) {
TimerInstance timer = ((WorkflowProcessInstanceImpl) getProcessInstance()).configureSLATimer(slaDueDateExpression);
TimerInstance timer = ((WorkflowProcessInstanceImpl) getProcessInstance()).configureSLATimer(slaDueDateExpression, this.getId());
if (timer != null) {
this.slaTimerId = timer.getId();
this.slaDueDate = new Date(System.currentTimeMillis() + timer.getDelay());
Expand Down
Loading
Loading