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

no longer set category job for every element on xml if category was set in config enableCategory #3734

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 @@ -31,6 +31,7 @@

import javax.sql.DataSource;

import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.type.JdbcType;
import org.flowable.batch.service.BatchServiceConfiguration;
Expand Down Expand Up @@ -322,6 +323,7 @@
import org.flowable.variable.service.impl.types.ShortType;
import org.flowable.variable.service.impl.types.StringType;
import org.flowable.variable.service.impl.types.UUIDType;
import org.springframework.util.CollectionUtils;

public class CmmnEngineConfiguration extends AbstractEngineConfiguration implements CmmnEngineConfigurationApi,
ScriptingEngineAwareEngineConfiguration, HasExpressionManagerEngineConfiguration, HasVariableTypes,
Expand Down Expand Up @@ -1725,11 +1727,18 @@ public void configureJobServiceConfiguration() {

this.jobServiceConfiguration.setJobExecutionScope(this.jobExecutionScope);
this.jobServiceConfiguration.setHistoryJobExecutionScope(this.historyJobExecutionScope);

if (enabledJobCategories != null) {
this.jobServiceConfiguration.setEnabledJobCategories(enabledJobCategories);
}

if (StringUtils.isNoneBlank(defaultJobCategory)) {
if (!CollectionUtils.isEmpty(enabledJobCategories)) {
enabledJobCategories.add(defaultJobCategory);
}
this.jobServiceConfiguration.setEnabledJobCategories(List.of(defaultJobCategory));
}

this.jobServiceConfiguration.setConfigurators(jobServiceConfigurators);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
public class JobUtil {

public static JobEntity createJob(CaseInstanceEntity caseInstance, BaseElement baseElement, String jobHandlerType,
CmmnEngineConfiguration cmmnEngineConfiguration) {
CmmnEngineConfiguration cmmnEngineConfiguration) {
JobEntity job = createJob((VariableContainer) caseInstance, baseElement, jobHandlerType, cmmnEngineConfiguration);

job.setScopeId(caseInstance.getId());
Expand Down Expand Up @@ -62,19 +62,23 @@ protected static JobEntity createJob(VariableContainer variableContainer, BaseEl
job.setElementName(((CaseElement) baseElement).getName());
}

List<ExtensionElement> jobCategoryElements = baseElement.getExtensionElements().get("jobCategory");
if (jobCategoryElements != null && jobCategoryElements.size() > 0) {
ExtensionElement jobCategoryElement = jobCategoryElements.get(0);
if (StringUtils.isNotEmpty(jobCategoryElement.getElementText())) {
Expression categoryExpression = cmmnEngineConfiguration.getExpressionManager().createExpression(jobCategoryElement.getElementText());
Object categoryValue = categoryExpression.getValue(variableContainer);
if (categoryValue != null) {
job.setCategory(categoryValue.toString());
if (StringUtils.isEmpty(cmmnEngineConfiguration.getDefaultJobCategory())) {
List<ExtensionElement> jobCategoryElements = baseElement.getExtensionElements().get("jobCategory");
if (jobCategoryElements != null && jobCategoryElements.size() > 0) {
ExtensionElement jobCategoryElement = jobCategoryElements.get(0);
if (StringUtils.isNotEmpty(jobCategoryElement.getElementText())) {
Expression categoryExpression = cmmnEngineConfiguration.getExpressionManager().createExpression(jobCategoryElement.getElementText());
Object categoryValue = categoryExpression.getValue(variableContainer);
if (categoryValue != null) {
job.setCategory(categoryValue.toString());
}
}
}
} else {
String category = cmmnEngineConfiguration.getDefaultJobCategory();
job.setCategory(category);
}


job.setTenantId(variableContainer.getTenantId());

return job;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ public abstract class AbstractEngineConfiguration {
protected boolean useLockForDatabaseSchemaUpdate = false;

protected String xmlEncoding = "UTF-8";
/**
* Default jobCategory for all
*/
protected String defaultJobCategory;

// COMMAND EXECUTORS ///////////////////////////////////////////////

Expand Down Expand Up @@ -268,7 +272,7 @@ public abstract class AbstractEngineConfiguration {
* correct. The {@link AbstractEngineConfiguration#getDatabaseSchemaUpdate()} value will not be used.
*/
protected boolean usingRelationalDatabase = true;

/**
* Flag that can be set to configure whether or not a schema is used. This is useful for custom implementations that do not use relational databases at all.
* Setting {@link #usingRelationalDatabase} to true will automatically imply using a schema.
Expand Down Expand Up @@ -308,12 +312,12 @@ public abstract class AbstractEngineConfiguration {
* will not be used here - since the schema is taken into account already, adding a prefix for the table-check will result in wrong table-names.
*/
protected boolean tablePrefixIsSchema;

/**
* Set to true if the latest version of a definition should be retrieved, ignoring a possible parent deployment id value
*/
protected boolean alwaysLookupLatestDefinitionVersion;

/**
* Set to true if by default lookups should fallback to the default tenant (an empty string by default or a defined tenant value)
*/
Expand Down Expand Up @@ -355,7 +359,7 @@ public abstract class AbstractEngineConfiguration {
protected List<EngineDeployer> customPreDeployers;
protected List<EngineDeployer> customPostDeployers;
protected List<EngineDeployer> deployers;

// CONFIGURATORS ////////////////////////////////////////////////////////////

protected boolean enableConfiguratorServiceLoader = true; // Enabled by default. In certain environments this should be set to false (eg osgi)
Expand Down Expand Up @@ -428,7 +432,7 @@ public static Properties getDefaultDatabaseTypeMappings() {
* Define a max length for storing String variable types in the database. Mainly used for the Oracle NVARCHAR2 limit of 2000 characters
*/
protected int maxLengthStringVariableType = -1;

protected void initEngineConfigurations() {
addEngineConfiguration(getEngineCfgKey(), getEngineScopeType(), this);
}
Expand Down Expand Up @@ -622,7 +626,7 @@ public Collection<? extends CommandInterceptor> getDefaultCommandInterceptors()

if (commandContextFactory != null) {
String engineCfgKey = getEngineCfgKey();
CommandContextInterceptor commandContextInterceptor = new CommandContextInterceptor(commandContextFactory,
CommandContextInterceptor commandContextInterceptor = new CommandContextInterceptor(commandContextFactory,
classLoader, useClassForNameClassLoading, clock, objectMapper);
engineConfigurations.put(engineCfgKey, this);
commandContextInterceptor.setEngineCfgKey(engineCfgKey);
Expand All @@ -645,7 +649,7 @@ public Collection<? extends CommandInterceptor> getDefaultCommandInterceptors()
}

public abstract String getEngineCfgKey();

public abstract String getEngineScopeType();

public List<CommandInterceptor> getAdditionalDefaultCommandInterceptors() {
Expand Down Expand Up @@ -749,7 +753,7 @@ public void initSessionFactories() {
}

addSessionFactory(new GenericManagerFactory(EntityCache.class, EntityCacheImpl.class));

if (isLoggingSessionEnabled()) {
if (!sessionFactories.containsKey(LoggingSession.class)) {
LoggingSessionFactory loggingSessionFactory = new LoggingSessionFactory();
Expand All @@ -758,9 +762,9 @@ public void initSessionFactories() {
sessionFactories.put(LoggingSession.class, loggingSessionFactory);
}
}

commandContextFactory.setSessionFactories(sessionFactories);

} else {
if (usingRelationalDatabase) {
initDbSqlSessionFactoryEntitySettings();
Expand Down Expand Up @@ -802,7 +806,7 @@ protected void defaultInitDbSqlSessionFactoryEntitySettings(List<Class<? extends
if (insertOrder != null) {
for (Class<? extends Entity> clazz : insertOrder) {
dbSqlSessionFactory.getInsertionOrder().add(clazz);

if (isBulkInsertEnabled) {
dbSqlSessionFactory.getBulkInserteableEntityClasses().add(clazz);
}
Expand Down Expand Up @@ -1031,7 +1035,7 @@ public String getMybatisMappingFile() {
}

public abstract InputStream getMyBatisXmlConfigurationStream();

public void initConfigurators() {

allConfigurators = new ArrayList<>();
Expand Down Expand Up @@ -1113,7 +1117,7 @@ public void configuratorsBeforeInit() {
configurator.beforeInit(this);
}
}

public void configuratorsAfterInit() {
for (EngineConfigurator configurator : allConfigurators) {
logger.info("Executing configure() of {} (priority:{})", configurator.getClass(), configurator.getPriority());
Expand Down Expand Up @@ -1199,7 +1203,7 @@ public AbstractEngineConfiguration setCommonSchemaManager(SchemaManager commonSc
this.commonSchemaManager = commonSchemaManager;
return this;
}

public Command<Void> getSchemaManagementCmd() {
return schemaManagementCmd;
}
Expand Down Expand Up @@ -1493,7 +1497,7 @@ public AbstractEngineConfiguration setEventRegistryEventConsumers(Map<String, Ev
this.eventRegistryEventConsumers = eventRegistryEventConsumers;
return this;
}

public void addEventRegistryEventConsumer(String key, EventRegistryEventConsumer eventRegistryEventConsumer) {
if (eventRegistryEventConsumers == null) {
eventRegistryEventConsumers = new HashMap<>();
Expand Down Expand Up @@ -1648,7 +1652,7 @@ public AbstractEngineConfiguration setUsingRelationalDatabase(boolean usingRelat
this.usingRelationalDatabase = usingRelationalDatabase;
return this;
}

public boolean isUsingSchemaMgmt() {
return usingSchemaMgmt;
}
Expand Down Expand Up @@ -1858,7 +1862,7 @@ protected void initTypedEventListeners() {
public boolean isLoggingSessionEnabled() {
return loggingListener != null;
}

public LoggingListener getLoggingListener() {
return loggingListener;
}
Expand Down Expand Up @@ -1994,11 +1998,11 @@ public AbstractEngineConfiguration setCustomPostDeployers(List<EngineDeployer> c
this.customPostDeployers = customPostDeployers;
return this;
}

public boolean isEnableConfiguratorServiceLoader() {
return enableConfiguratorServiceLoader;
}

public AbstractEngineConfiguration setEnableConfiguratorServiceLoader(boolean enableConfiguratorServiceLoader) {
this.enableConfiguratorServiceLoader = enableConfiguratorServiceLoader;
return this;
Expand Down Expand Up @@ -2055,4 +2059,13 @@ public AbstractEngineConfiguration setForceCloseMybatisConnectionPool(boolean fo
public boolean isForceCloseMybatisConnectionPool() {
return forceCloseMybatisConnectionPool;
}

protected AbstractEngineConfiguration setDefaultJobCategory(String defaultJobCategory){
this.defaultJobCategory = defaultJobCategory;
return this;
}

public String getDefaultJobCategory(){
return this.defaultJobCategory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import javax.xml.namespace.QName;

import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.transaction.TransactionFactory;
Expand Down Expand Up @@ -426,6 +427,7 @@
import org.flowable.variable.service.impl.types.ShortType;
import org.flowable.variable.service.impl.types.StringType;
import org.flowable.variable.service.impl.types.UUIDType;
import org.springframework.util.CollectionUtils;

/**
* @author Tom Baeyens
Expand Down Expand Up @@ -1586,6 +1588,13 @@ public void configureJobServiceConfiguration() {
this.jobServiceConfiguration.setEnabledJobCategories(enabledJobCategories);
}

if (StringUtils.isNoneBlank(defaultJobCategory)) {
if (!CollectionUtils.isEmpty(enabledJobCategories)) {
enabledJobCategories.add(defaultJobCategory);
}
this.jobServiceConfiguration.setEnabledJobCategories(List.of(defaultJobCategory));
}

this.jobServiceConfiguration.setConfigurators(jobServiceConfigurators);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,25 @@ public static JobEntity createJob(ExecutionEntity execution, BaseElement baseEle
}
job.setJobHandlerType(jobHandlerType);

List<ExtensionElement> jobCategoryElements = baseElement.getExtensionElements().get("jobCategory");
if (jobCategoryElements != null && jobCategoryElements.size() > 0) {
ExtensionElement jobCategoryElement = jobCategoryElements.get(0);
if (StringUtils.isNotEmpty(jobCategoryElement.getElementText())) {
Expression categoryExpression = processEngineConfiguration.getExpressionManager().createExpression(jobCategoryElement.getElementText());
Object categoryValue = categoryExpression.getValue(execution);
if (categoryValue != null) {
job.setCategory(categoryValue.toString());

if (StringUtils.isEmpty(processEngineConfiguration.getDefaultJobCategory())) {
List<ExtensionElement> jobCategoryElements = baseElement.getExtensionElements().get("jobCategory");
if (jobCategoryElements != null && jobCategoryElements.size() > 0) {
ExtensionElement jobCategoryElement = jobCategoryElements.get(0);
if (StringUtils.isNotEmpty(jobCategoryElement.getElementText())) {
Expression categoryExpression = processEngineConfiguration.getExpressionManager().createExpression(jobCategoryElement.getElementText());
Object categoryValue = categoryExpression.getValue(execution);
if (categoryValue != null) {
job.setCategory(categoryValue.toString());
}
}
}
} else {
String category = processEngineConfiguration.getDefaultJobCategory();
job.setCategory(category);
}


// Inherit tenant id (if applicable)
if (execution.getTenantId() != null) {
job.setTenantId(execution.getTenantId());
Expand Down