diff --git a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/CmmnEngineConfiguration.java b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/CmmnEngineConfiguration.java index e8308fd9ea8..57f0a74cde1 100644 --- a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/CmmnEngineConfiguration.java +++ b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/CmmnEngineConfiguration.java @@ -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; @@ -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, @@ -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); } } diff --git a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/util/JobUtil.java b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/util/JobUtil.java index 75622ee1114..49ebefc7b84 100644 --- a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/util/JobUtil.java +++ b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/util/JobUtil.java @@ -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()); @@ -62,19 +62,23 @@ protected static JobEntity createJob(VariableContainer variableContainer, BaseEl job.setElementName(((CaseElement) baseElement).getName()); } - List 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 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; diff --git a/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/AbstractEngineConfiguration.java b/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/AbstractEngineConfiguration.java index edaf99f67e0..f4fb8d4cc2d 100755 --- a/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/AbstractEngineConfiguration.java +++ b/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/AbstractEngineConfiguration.java @@ -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 /////////////////////////////////////////////// @@ -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. @@ -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) */ @@ -355,7 +359,7 @@ public abstract class AbstractEngineConfiguration { protected List customPreDeployers; protected List customPostDeployers; protected List deployers; - + // CONFIGURATORS //////////////////////////////////////////////////////////// protected boolean enableConfiguratorServiceLoader = true; // Enabled by default. In certain environments this should be set to false (eg osgi) @@ -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); } @@ -622,7 +626,7 @@ public Collection 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); @@ -645,7 +649,7 @@ public Collection getDefaultCommandInterceptors() } public abstract String getEngineCfgKey(); - + public abstract String getEngineScopeType(); public List getAdditionalDefaultCommandInterceptors() { @@ -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(); @@ -758,9 +762,9 @@ public void initSessionFactories() { sessionFactories.put(LoggingSession.class, loggingSessionFactory); } } - + commandContextFactory.setSessionFactories(sessionFactories); - + } else { if (usingRelationalDatabase) { initDbSqlSessionFactoryEntitySettings(); @@ -802,7 +806,7 @@ protected void defaultInitDbSqlSessionFactoryEntitySettings(List clazz : insertOrder) { dbSqlSessionFactory.getInsertionOrder().add(clazz); - + if (isBulkInsertEnabled) { dbSqlSessionFactory.getBulkInserteableEntityClasses().add(clazz); } @@ -1031,7 +1035,7 @@ public String getMybatisMappingFile() { } public abstract InputStream getMyBatisXmlConfigurationStream(); - + public void initConfigurators() { allConfigurators = new ArrayList<>(); @@ -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()); @@ -1199,7 +1203,7 @@ public AbstractEngineConfiguration setCommonSchemaManager(SchemaManager commonSc this.commonSchemaManager = commonSchemaManager; return this; } - + public Command getSchemaManagementCmd() { return schemaManagementCmd; } @@ -1493,7 +1497,7 @@ public AbstractEngineConfiguration setEventRegistryEventConsumers(Map(); @@ -1648,7 +1652,7 @@ public AbstractEngineConfiguration setUsingRelationalDatabase(boolean usingRelat this.usingRelationalDatabase = usingRelationalDatabase; return this; } - + public boolean isUsingSchemaMgmt() { return usingSchemaMgmt; } @@ -1858,7 +1862,7 @@ protected void initTypedEventListeners() { public boolean isLoggingSessionEnabled() { return loggingListener != null; } - + public LoggingListener getLoggingListener() { return loggingListener; } @@ -1994,11 +1998,11 @@ public AbstractEngineConfiguration setCustomPostDeployers(List c this.customPostDeployers = customPostDeployers; return this; } - + public boolean isEnableConfiguratorServiceLoader() { return enableConfiguratorServiceLoader; } - + public AbstractEngineConfiguration setEnableConfiguratorServiceLoader(boolean enableConfiguratorServiceLoader) { this.enableConfiguratorServiceLoader = enableConfiguratorServiceLoader; return this; @@ -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; + } } diff --git a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cfg/ProcessEngineConfigurationImpl.java b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cfg/ProcessEngineConfigurationImpl.java index 3afeee0fd2f..3d8486977af 100755 --- a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cfg/ProcessEngineConfigurationImpl.java +++ b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cfg/ProcessEngineConfigurationImpl.java @@ -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; @@ -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 @@ -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); } } diff --git a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/util/JobUtil.java b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/util/JobUtil.java index e26c0229068..646fa371cf2 100644 --- a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/util/JobUtil.java +++ b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/util/JobUtil.java @@ -45,18 +45,25 @@ public static JobEntity createJob(ExecutionEntity execution, BaseElement baseEle } job.setJobHandlerType(jobHandlerType); - List 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 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());