From 010593139299b9a4e8e03b2aa41f7892602dd4d0 Mon Sep 17 00:00:00 2001 From: Robert Stephan Date: Mon, 23 Sep 2024 18:15:53 +0200 Subject: [PATCH] initialize CamundaProcessEngine via Properties #87 --- .../jspdocportal/common/bpmn/MCRBPMNMgr.java | 38 +++++++++++++++++-- .../jspdocportal-common/mycore.properties | 11 ++++++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/jspdocportal-common-module/src/main/java/org/mycore/jspdocportal/common/bpmn/MCRBPMNMgr.java b/jspdocportal-common-module/src/main/java/org/mycore/jspdocportal/common/bpmn/MCRBPMNMgr.java index c373e077..b36a7f35 100644 --- a/jspdocportal-common-module/src/main/java/org/mycore/jspdocportal/common/bpmn/MCRBPMNMgr.java +++ b/jspdocportal-common-module/src/main/java/org/mycore/jspdocportal/common/bpmn/MCRBPMNMgr.java @@ -3,6 +3,7 @@ import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.util.List; +import java.util.Map; import java.util.Properties; import org.apache.logging.log4j.LogManager; @@ -11,8 +12,10 @@ import org.camunda.bpm.engine.ProcessEngineConfiguration; import org.camunda.bpm.engine.RuntimeService; import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.impl.cfg.StandaloneProcessEngineConfiguration; import org.mycore.common.MCRException; import org.mycore.common.config.MCRConfiguration2; +import org.mycore.jspdocportal.common.bpmn.identity.MCRMyCoReIDMPlugin; import org.mycore.jspdocportal.common.bpmn.workflows.create_object_simple.MCRWorkflowMgr; import jakarta.mail.Authenticator; @@ -54,16 +57,43 @@ public class MCRBPMNMgr { public static final String WF_VAR_DISPLAY_DERIVATELIST = "wfObjectDisplayDerivateList"; - public static final String MCR_BPMN_CONFIG_FILE = "camunda.cfg.xml"; + public static final String WF_PROCESS_ENGINE_PROPERTIES_PREFIX = "MCR.Worflow.ProcessEngine."; private static ProcessEngine processEngine; public static ProcessEngineConfiguration getWorkflowProcessEngineConfiguration() { try { - return ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(MCR_BPMN_CONFIG_FILE); + Map props = MCRConfiguration2.getSubPropertiesMap(WF_PROCESS_ENGINE_PROPERTIES_PREFIX); + StandaloneProcessEngineConfiguration peConf + = (StandaloneProcessEngineConfiguration) ProcessEngineConfiguration + .createStandaloneProcessEngineConfiguration(); + if (props.containsKey("JdbcDriver")) { + peConf.setJdbcDriver(props.get("JdbcDriver")); + } + if (props.containsKey("JdbcUrl")) { + peConf.setJdbcUrl(props.get("JdbcUrl")); + } + if (props.containsKey("JdbcUsername")) { + peConf.setJdbcUsername(props.get("JdbcUsername")); + } + if (props.containsKey("JdbcPassword")) { + peConf.setJdbcPassword(props.get("JdbcPassword")); + } + if (props.containsKey("DatabaseSchema")) { + peConf.setDatabaseSchema(props.get("DatabaseSchema")); + // databaseTablePrefix = databaseSchema + '.' + peConf.setDatabaseTablePrefix(props.get("DatabaseSchema") + "."); + } + + // default values, currently no support to change via MyCoRe properties + peConf.setHistoryTimeToLive("P7D"); + peConf.setDatabaseSchemaUpdate("true"); + peConf.setJobExecutorActivate(false); + peConf.getProcessEnginePlugins().add(new MCRMyCoReIDMPlugin()); + return peConf; } catch (Exception e) { - throw new MCRException("Workflow Engine configuration not found", e); + throw new MCRException("Workflow Engine could not be configured", e); } } @@ -93,7 +123,7 @@ private static MCRWorkflowMgr getWorkflowMgrForMode(String mode) { String prop = ""; try { prop = "MCR.Workflow.WorkflowMgr.Class.create_object_simple." + mode; - mgr = (MCRWorkflowMgr) MCRConfiguration2.getInstanceOf(prop).orElseThrow(); + mgr = MCRConfiguration2.getInstanceOf(MCRWorkflowMgr.class, prop).orElseThrow(); } catch (Exception e) { throw new MCRException("Could not instantiate MCRWorkflowMgr for " + prop, e); } diff --git a/jspdocportal-common-module/src/main/resources/config/jspdocportal-common/mycore.properties b/jspdocportal-common-module/src/main/resources/config/jspdocportal-common/mycore.properties index 766a5fe7..9c9e4c0e 100644 --- a/jspdocportal-common-module/src/main/resources/config/jspdocportal-common/mycore.properties +++ b/jspdocportal-common-module/src/main/resources/config/jspdocportal-common/mycore.properties @@ -43,6 +43,17 @@ MCR.RestAPI.v1.Files.URL.path=file/${mcrid}/${derid}/ MCR.ConfigurationDirectory.template.files=%MCR.ConfigurationDirectory.template.files%,resources/camunda.cfg.xml +### ProcessEngine Sample Configuration (configuration for workflowEngine database) + +#MCR.Worflow.ProcessEngine.JdbcDriver=org.h2.Driver +#MCR.Worflow.ProcessEngine.JdbcUrl=jdbc:h2:file:c:/Users/mcradmin/AppData/Local/MyCoRe/myapp/data/h2/bpm + +#MCR.Worflow.ProcessEngine.JdbcDriver=org.postgresql.Driver +#MCR.Worflow.ProcessEngine.JdbcUrl=jdbc:postgresql://127.0.0.1/mycoredb?currentSchema=myapp_bpm +#MCR.Worflow.ProcessEngine.JdbcUsername=mcradmin +#MCR.Worflow.ProcessEngine.JdbcPassword=*** +#MCR.Worflow.ProcessEngine.DatabaseSchema=myapp_bpm + MCR.Website.ReadAccessVerification=false; MCR.Request.TrustedProxies= MCR.Workflow.WorkflowDirectory=%MCR.datadir%/workspace