Skip to content

Commit

Permalink
initialize CamundaProcessEngine via Properties #87
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteph-de committed Sep 23, 2024
1 parent 48fe1f4 commit 0105931
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String, String> 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);
}
}

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0105931

Please sign in to comment.