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

business-calendar #3686

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.jbpm.process.core.timer;
package org.kie.kogito.calendar;

import java.util.Date;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.kie.kogito.KogitoConfig;
import org.kie.kogito.auth.IdentityProvider;
import org.kie.kogito.calendar.BusinessCalendar;
import org.kie.kogito.jobs.JobsService;
import org.kie.kogito.signal.SignalManagerHub;
import org.kie.kogito.uow.UnitOfWorkManager;
Expand All @@ -38,4 +39,6 @@ public interface ProcessConfig extends KogitoConfig {
ProcessVersionResolver versionResolver();

IdentityProvider identityProvider();

BusinessCalendar getBusinessCalendar();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.jbpm.process.core.constants;

public class CalendarConstants {
public static final String BUSINESS_CALENDAR_PATH = "calendar.properties";
public static final String BUSINESS_CALENDAR_ENVIRONMENT_KEY = "jbpm.business.calendar";
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@
import java.util.regex.Matcher;

import org.jbpm.util.PatternConstants;
import org.kie.kogito.calendar.BusinessCalendar;
Abhitocode marked this conversation as resolved.
Show resolved Hide resolved
import org.kie.kogito.timer.SessionClock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

/**
* Default implementation of BusinessCalendar interface that is configured with properties.
* Following are supported properties:
Expand Down Expand Up @@ -72,7 +75,7 @@ public class BusinessCalendarImpl implements BusinessCalendar {

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

private Properties businessCalendarConfiguration;
private final Properties businessCalendarConfiguration;

private static final long HOUR_IN_MILLIS = 60 * 60 * 1000;

Expand Down Expand Up @@ -103,38 +106,26 @@ public class BusinessCalendarImpl implements BusinessCalendar {
public static final String WEEKEND_DAYS = "business.weekend.days";
public static final String TIMEZONE = "business.cal.timezone";

private static final String DEFAULT_PROPERTIES_NAME = "/jbpm.business.calendar.properties";

public BusinessCalendarImpl() {
Abhitocode marked this conversation as resolved.
Show resolved Hide resolved
String propertiesLocation = System.getProperty("jbpm.business.calendar.properties");

if (propertiesLocation == null) {
propertiesLocation = DEFAULT_PROPERTIES_NAME;
}
businessCalendarConfiguration = new Properties();

InputStream in = this.getClass().getResourceAsStream(propertiesLocation);
if (in != null) {

try {
businessCalendarConfiguration.load(in);
} catch (IOException e) {
logger.error("Error while loading properties for business calendar", e);

}
}
init();

this(null);
}

public BusinessCalendarImpl(Properties configuration) {
this.businessCalendarConfiguration = configuration;
init();
this(configuration, null);
}

public BusinessCalendarImpl(Properties configuration, SessionClock clock) {
this.businessCalendarConfiguration = configuration;
this.clock = clock;
if (configuration == null) {
businessCalendarConfiguration = new Properties();
try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(BUSINESS_CALENDAR_PATH)) {
businessCalendarConfiguration.load(is);
} catch (IOException e) {
logger.error("Error while loading properties for business calendar", e);
}
} else {
this.businessCalendarConfiguration = configuration;
}
init();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;

import org.drools.core.common.EndOperationListener;
import org.drools.core.common.InternalAgenda;
Expand Down Expand Up @@ -53,11 +54,15 @@
import org.kie.api.runtime.rule.ViewChangedEventListener;
import org.kie.api.time.SessionClock;
import org.kie.kogito.Application;
import org.kie.kogito.calendar.BusinessCalendar;
import org.kie.kogito.internal.process.event.KogitoProcessEventSupport;
import org.kie.kogito.internal.process.runtime.KogitoProcessInstance;
import org.kie.kogito.internal.process.runtime.KogitoProcessRuntime;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemManager;
import org.kie.kogito.jobs.JobsService;
import org.kie.kogito.process.ProcessConfig;

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

/**
* A severely limited implementation of the WorkingMemory interface.
Expand All @@ -72,6 +77,10 @@ class DummyKnowledgeRuntime implements InternalKnowledgeRuntime, KogitoProcessRu
this.processRuntime = processRuntime;
this.environment = new EnvironmentImpl();
// register codegen-based node instances factories
BusinessCalendar calendar = processRuntime.getApplication().config().get(ProcessConfig.class).getBusinessCalendar();
Abhitocode marked this conversation as resolved.
Show resolved Hide resolved
if (Objects.nonNull(calendar)) {
environment.set(BUSINESS_CALENDAR_ENVIRONMENT_KEY, calendar);
}
environment.set("NodeInstanceFactoryRegistry", new CodegenNodeInstanceFactoryRegistry());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.drools.core.phreak.PropagationEntry;
import org.jbpm.process.core.event.EventFilter;
import org.jbpm.process.core.event.EventTypeFilter;
import org.jbpm.process.core.timer.BusinessCalendar;
import org.jbpm.process.core.timer.DateTimeUtils;
import org.jbpm.process.core.timer.Timer;
import org.jbpm.ruleflow.core.RuleFlowProcess;
Expand All @@ -52,6 +51,7 @@
import org.kie.internal.process.CorrelationKey;
import org.kie.internal.runtime.StatefulKnowledgeSession;
import org.kie.kogito.Application;
import org.kie.kogito.calendar.BusinessCalendar;
import org.kie.kogito.internal.process.runtime.KogitoProcessInstance;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemManager;
import org.kie.kogito.jobs.DurationExpirationTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.drools.core.time.impl.ThreadSafeTrackableTimeJobFactoryManager;
import org.jbpm.process.core.event.EventFilter;
import org.jbpm.process.core.event.EventTypeFilter;
import org.jbpm.process.core.timer.BusinessCalendar;
import org.jbpm.process.core.timer.DateTimeUtils;
import org.jbpm.process.core.timer.Timer;
import org.jbpm.process.instance.event.DefaultSignalManagerFactory;
Expand Down Expand Up @@ -64,6 +63,7 @@
import org.kie.internal.process.CorrelationKey;
import org.kie.internal.runtime.StatefulKnowledgeSession;
import org.kie.kogito.Application;
import org.kie.kogito.calendar.BusinessCalendar;
import org.kie.kogito.internal.process.runtime.KogitoProcessInstance;
import org.kie.kogito.internal.process.runtime.KogitoProcessRuntime;
import org.kie.kogito.jobs.DurationExpirationTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.jbpm.process.core.ContextResolver;
import org.jbpm.process.core.context.variable.Variable;
import org.jbpm.process.core.context.variable.VariableScope;
import org.jbpm.process.core.timer.BusinessCalendar;
import org.jbpm.process.core.timer.DateTimeUtils;
import org.jbpm.process.core.timer.Timer;
import org.jbpm.process.instance.ContextInstance;
Expand Down Expand Up @@ -81,6 +80,7 @@
import org.kie.api.definition.process.WorkflowElementIdentifier;
import org.kie.api.runtime.rule.AgendaFilter;
import org.kie.internal.process.CorrelationKey;
import org.kie.kogito.calendar.BusinessCalendar;
import org.kie.kogito.internal.process.event.KogitoEventListener;
import org.kie.kogito.internal.process.runtime.KogitoNodeInstance;
import org.kie.kogito.internal.process.runtime.KogitoNodeInstanceContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.drools.core.common.InternalAgenda;
import org.drools.core.common.ReteEvaluator;
import org.drools.core.rule.consequence.InternalMatch;
import org.jbpm.process.core.timer.BusinessCalendar;
import org.jbpm.process.core.timer.DateTimeUtils;
import org.jbpm.process.core.timer.Timer;
import org.jbpm.process.instance.InternalProcessRuntime;
Expand All @@ -44,6 +43,7 @@
import org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl;
import org.kie.api.event.rule.MatchCreatedEvent;
import org.kie.api.runtime.KieRuntime;
import org.kie.kogito.calendar.BusinessCalendar;
import org.kie.kogito.internal.process.event.KogitoEventListener;
import org.kie.kogito.internal.process.runtime.KogitoNodeInstance;
import org.kie.kogito.internal.process.runtime.KogitoProcessContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.kie.api.event.process.ProcessEventListener;
import org.kie.kogito.Addons;
import org.kie.kogito.auth.IdentityProvider;
import org.kie.kogito.calendar.BusinessCalendar;
import org.kie.kogito.event.EventPublisher;
import org.kie.kogito.jobs.JobsService;
import org.kie.kogito.process.ProcessConfig;
Expand All @@ -51,6 +52,7 @@ public abstract class AbstractProcessConfig implements ProcessConfig {
private final JobsService jobsService;
private final ProcessVersionResolver versionResolver;
private final IdentityProvider identityProvider;
private final BusinessCalendar businessCalendar;

protected AbstractProcessConfig(
Iterable<WorkItemHandlerConfig> workItemHandlerConfig,
Abhitocode marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -62,7 +64,8 @@ protected AbstractProcessConfig(
String kogitoService,
Iterable<UnitOfWorkEventListener> unitOfWorkListeners,
Iterable<ProcessVersionResolver> versionResolver,
Iterable<IdentityProvider> identityProvider) {
Iterable<IdentityProvider> identityProvider,
Abhitocode marked this conversation as resolved.
Show resolved Hide resolved
Iterable<BusinessCalendar> businessCalendar) {

this.workItemHandlerConfig = mergeWorkItemHandler(workItemHandlerConfig, DefaultWorkItemHandlerConfig::new);
this.processEventListenerConfig = merge(processEventListenerConfigs, processEventListeners);
Expand All @@ -72,6 +75,7 @@ protected AbstractProcessConfig(
this.jobsService = orDefault(jobsService, () -> null);
this.versionResolver = orDefault(versionResolver, () -> null);
this.identityProvider = orDefault(identityProvider, NoOpIdentityProvider::new);
this.businessCalendar = orDefault(businessCalendar, () -> null);

eventPublishers.forEach(publisher -> unitOfWorkManager().eventManager().addPublisher(publisher));
unitOfWorkListeners.forEach(listener -> unitOfWorkManager().register(listener));
Expand Down Expand Up @@ -124,6 +128,11 @@ public IdentityProvider identityProvider() {
return identityProvider;
}

@Override
public BusinessCalendar getBusinessCalendar() {
return this.businessCalendar;
}

public org.kie.kogito.Addons addons() {
return Addons.EMTPY;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.kie.kogito.process.impl;

import org.kie.kogito.auth.IdentityProvider;
import org.kie.kogito.calendar.BusinessCalendar;
import org.kie.kogito.jobs.JobsService;
import org.kie.kogito.process.ProcessConfig;
import org.kie.kogito.process.ProcessEventListenerConfig;
Expand All @@ -41,12 +42,13 @@ public class StaticProcessConfig implements ProcessConfig {
private final ProcessVersionResolver versionResolver;

private final IdentityProvider identityProvider;
private final BusinessCalendar businessCalendar;

public StaticProcessConfig(
WorkItemHandlerConfig workItemHandlerConfig,
ProcessEventListenerConfig processEventListenerConfig,
UnitOfWorkManager unitOfWorkManager) {
this(workItemHandlerConfig, processEventListenerConfig, unitOfWorkManager, null, null, new NoOpIdentityProvider());
this(workItemHandlerConfig, processEventListenerConfig, unitOfWorkManager, null, null, new NoOpIdentityProvider(), null);
}

public StaticProcessConfig(
Expand All @@ -55,14 +57,16 @@ public StaticProcessConfig(
UnitOfWorkManager unitOfWorkManager,
JobsService jobsService,
ProcessVersionResolver versionResolver,
IdentityProvider identityProvider) {
IdentityProvider identityProvider,
BusinessCalendar calendar) {
this.unitOfWorkManager = unitOfWorkManager;
this.workItemHandlerConfig = workItemHandlerConfig;
this.processEventListenerConfig = processEventListenerConfig;
this.signalManager = new DefaultSignalManagerHub();
this.jobsService = jobsService;
this.versionResolver = versionResolver;
this.identityProvider = identityProvider;
this.businessCalendar = calendar;
}

public StaticProcessConfig() {
Expand All @@ -71,7 +75,8 @@ public StaticProcessConfig() {
new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()),
null,
null,
new NoOpIdentityProvider());
new NoOpIdentityProvider(),
null);
}

@Override
Expand Down Expand Up @@ -108,4 +113,9 @@ public ProcessVersionResolver versionResolver() {
public IdentityProvider identityProvider() {
return identityProvider;
}

@Override
public BusinessCalendar getBusinessCalendar() {
return this.businessCalendar;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
import org.kie.kogito.internal.process.runtime.KogitoProcessRuntime;
import org.slf4j.LoggerFactory;

import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class RuleFlowProcessInstanceTest extends AbstractBaseTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class AbstractProcessConfigTest {
private static class MockProcessConfig extends AbstractProcessConfig {
protected MockProcessConfig(Iterable<WorkItemHandlerConfig> workItemHandlerConfig) {
super(workItemHandlerConfig, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(),
Collections.emptyList(), null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
Collections.emptyList(), null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
}
}

Expand Down
Loading