From e7de8449e4554c60bb97135b4104484c4be415aa Mon Sep 17 00:00:00 2001 From: Nhat Anh Date: Thu, 14 Sep 2023 14:43:52 +0700 Subject: [PATCH 1/3] no longer set category job for every element on xml if category was set on config --- .../cmmn/engine/impl/util/JobUtil.java | 23 +++++++++++------- .../flowable/engine/impl/util/JobUtil.java | 24 ++++++++++++------- 2 files changed, 30 insertions(+), 17 deletions(-) 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..0cdf6bd23aa 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 @@ -26,6 +26,7 @@ import org.flowable.common.engine.api.variable.VariableContainer; import org.flowable.job.service.JobService; import org.flowable.job.service.impl.persistence.entity.JobEntity; +import org.springframework.util.CollectionUtils; /** * @author Filip Hrisafov @@ -62,19 +63,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(CollectionUtils.isEmpty(cmmnEngineConfiguration.getEnabledJobCategories())){ + 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.getEnabledJobCategories().get(0); + job.setCategory(category); } - job.setTenantId(variableContainer.getTenantId()); return job; 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..c6fd87bb23a 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 @@ -23,6 +23,7 @@ import org.flowable.engine.impl.persistence.entity.ExecutionEntity; import org.flowable.job.service.JobService; import org.flowable.job.service.impl.persistence.entity.JobEntity; +import org.springframework.util.CollectionUtils; /** * @author Filip Hrisafov @@ -45,18 +46,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(CollectionUtils.isEmpty(processEngineConfiguration.getEnabledJobCategories())){ + 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.getEnabledJobCategories().get(0); + job.setCategory(category); } + // Inherit tenant id (if applicable) if (execution.getTenantId() != null) { job.setTenantId(execution.getTenantId()); From a8579eeeb8a978a826119df908396d96d0eedab4 Mon Sep 17 00:00:00 2001 From: Nhat Anh Date: Thu, 14 Sep 2023 15:42:12 +0700 Subject: [PATCH 2/3] reformat code --- .../main/java/org/flowable/cmmn/engine/impl/util/JobUtil.java | 4 ++-- .../src/main/java/org/flowable/engine/impl/util/JobUtil.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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 0cdf6bd23aa..81249339a28 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 @@ -63,7 +63,7 @@ protected static JobEntity createJob(VariableContainer variableContainer, BaseEl job.setElementName(((CaseElement) baseElement).getName()); } - if(CollectionUtils.isEmpty(cmmnEngineConfiguration.getEnabledJobCategories())){ + if (CollectionUtils.isEmpty(cmmnEngineConfiguration.getEnabledJobCategories())) { List jobCategoryElements = baseElement.getExtensionElements().get("jobCategory"); if (jobCategoryElements != null && jobCategoryElements.size() > 0) { ExtensionElement jobCategoryElement = jobCategoryElements.get(0); @@ -75,7 +75,7 @@ protected static JobEntity createJob(VariableContainer variableContainer, BaseEl } } } - }else{ + } else { String category = cmmnEngineConfiguration.getEnabledJobCategories().get(0); job.setCategory(category); } 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 c6fd87bb23a..18732f52cf1 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 @@ -47,7 +47,7 @@ public static JobEntity createJob(ExecutionEntity execution, BaseElement baseEle job.setJobHandlerType(jobHandlerType); - if(CollectionUtils.isEmpty(processEngineConfiguration.getEnabledJobCategories())){ + if (CollectionUtils.isEmpty(processEngineConfiguration.getEnabledJobCategories())) { List jobCategoryElements = baseElement.getExtensionElements().get("jobCategory"); if (jobCategoryElements != null && jobCategoryElements.size() > 0) { ExtensionElement jobCategoryElement = jobCategoryElements.get(0); @@ -59,7 +59,7 @@ public static JobEntity createJob(ExecutionEntity execution, BaseElement baseEle } } } - }else{ + } else { String category = processEngineConfiguration.getEnabledJobCategories().get(0); job.setCategory(category); } From b9ec2d75a68206ffedca1c5c13e5e1f841dc8980 Mon Sep 17 00:00:00 2001 From: Nhat Anh Date: Thu, 14 Sep 2023 17:46:23 +0700 Subject: [PATCH 3/3] provider new config property: defaultJobCategory --- .../cmmn/engine/CmmnEngineConfiguration.java | 11 +++- .../cmmn/engine/impl/util/JobUtil.java | 7 ++- .../impl/AbstractEngineConfiguration.java | 51 ++++++++++++------- .../cfg/ProcessEngineConfigurationImpl.java | 9 ++++ .../flowable/engine/impl/util/JobUtil.java | 5 +- 5 files changed, 56 insertions(+), 27 deletions(-) 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 81249339a28..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 @@ -26,7 +26,6 @@ import org.flowable.common.engine.api.variable.VariableContainer; import org.flowable.job.service.JobService; import org.flowable.job.service.impl.persistence.entity.JobEntity; -import org.springframework.util.CollectionUtils; /** * @author Filip Hrisafov @@ -34,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()); @@ -63,7 +62,7 @@ protected static JobEntity createJob(VariableContainer variableContainer, BaseEl job.setElementName(((CaseElement) baseElement).getName()); } - if (CollectionUtils.isEmpty(cmmnEngineConfiguration.getEnabledJobCategories())) { + if (StringUtils.isEmpty(cmmnEngineConfiguration.getDefaultJobCategory())) { List jobCategoryElements = baseElement.getExtensionElements().get("jobCategory"); if (jobCategoryElements != null && jobCategoryElements.size() > 0) { ExtensionElement jobCategoryElement = jobCategoryElements.get(0); @@ -76,7 +75,7 @@ protected static JobEntity createJob(VariableContainer variableContainer, BaseEl } } } else { - String category = cmmnEngineConfiguration.getEnabledJobCategories().get(0); + String category = cmmnEngineConfiguration.getDefaultJobCategory(); job.setCategory(category); } 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 18732f52cf1..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 @@ -23,7 +23,6 @@ import org.flowable.engine.impl.persistence.entity.ExecutionEntity; import org.flowable.job.service.JobService; import org.flowable.job.service.impl.persistence.entity.JobEntity; -import org.springframework.util.CollectionUtils; /** * @author Filip Hrisafov @@ -47,7 +46,7 @@ public static JobEntity createJob(ExecutionEntity execution, BaseElement baseEle job.setJobHandlerType(jobHandlerType); - if (CollectionUtils.isEmpty(processEngineConfiguration.getEnabledJobCategories())) { + if (StringUtils.isEmpty(processEngineConfiguration.getDefaultJobCategory())) { List jobCategoryElements = baseElement.getExtensionElements().get("jobCategory"); if (jobCategoryElements != null && jobCategoryElements.size() > 0) { ExtensionElement jobCategoryElement = jobCategoryElements.get(0); @@ -60,7 +59,7 @@ public static JobEntity createJob(ExecutionEntity execution, BaseElement baseEle } } } else { - String category = processEngineConfiguration.getEnabledJobCategories().get(0); + String category = processEngineConfiguration.getDefaultJobCategory(); job.setCategory(category); }