Skip to content

Commit

Permalink
Introducing new structure of Spring Boot properties
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanpelikan committed Feb 26, 2024
1 parent 967ef84 commit fca392d
Show file tree
Hide file tree
Showing 9 changed files with 303 additions and 114 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<artifactId>camunda7-adapter</artifactId>

<name>VanillaBP SPI adapter for Camunda 7.x</name>
<version>1.1.3-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
Expand Down
51 changes: 41 additions & 10 deletions spring-boot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,35 @@ For the taxi ride sample we have the BPMN process ID `TaxiRide` and e.g. the mes

*Hint:* If you want to be prepared to upgrade to Camunda 8 then always set this correlation ID as a local variable since this is mandatory on using Camunda 8.

## Using Camunda multi-tenancy

Typically, on operating multiple workflow modules, one wants to avoid name clashes in Camunda (e.g. of event names, etc.).
Therefore, each workflow module is deployed to Camunda as a separate tenant using the workflow module's id as the tenant-id.

This behavior can be adapted.

**If you wish to define a custom tenant-id instead:**

```yaml
vanillabp:
workflow-modules:
ride:
adapters:
camunda7:
tenant-id: taxiride
```

**If you want to disable multi-tenancy:**

```yaml
vanillabp:
workflow-modules:
ride:
adapters:
camunda7:
use-tenants: false
```

## Transaction behavior

Defining the right Camunda 7 transactional behavior can be difficult. We have seen a lot of developers struggling with all the possibilities Camunda 7 provides regarding transactions. The implementation uses one particular best-practice approach and applies this to every BPMN automatically: Every BPMN task/element is a separate transaction.
Expand All @@ -130,22 +159,24 @@ On introducing VanillaBP one might to keep some of the BPMNs unchanged. Therefor

```yaml
vanillabp:
adapters:
camunda7:
use-bpmn-async-definitions: true
workflow-modules:
ride:
adapters:
camunda7:
use-bpmn-async-definitions: true
```

or just for particular process definitions:

```yaml
vanillabp:
adapters:
camunda7:
bpmn-async-definitions:
- workflow-module-id: ABC1
bpmn-process-id: XYZ1
- workflow-module-id: ABC2
bpmn-process-id: XYZ2
workflow-modules:
ride:
workflows:
Ride:
adapters:
camunda7:
bpmn-async-definitions: true
```

## Job-Executor
Expand Down
4 changes: 2 additions & 2 deletions spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.camunda.community.vanillabp</groupId>
<artifactId>camunda7-adapter</artifactId>
<version>1.1.3-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
</parent>

<artifactId>camunda7-spring-boot-adapter</artifactId>
Expand All @@ -20,7 +20,7 @@
<dependency>
<groupId>io.vanillabp</groupId>
<artifactId>spring-boot-support</artifactId>
<version>1.0.8-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.camunda.bpm.springboot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.vanillabp.camunda7.deployment.Camunda7DeploymentAdapter;
import io.vanillabp.camunda7.service.Camunda7ProcessService;
import io.vanillabp.camunda7.service.jobs.startprocess.StartProcessJobHandler;
import io.vanillabp.camunda7.wiring.Camunda7AdapterProperties;
import io.vanillabp.camunda7.wiring.Camunda7TaskWiring;
import io.vanillabp.camunda7.wiring.Camunda7TaskWiringPlugin;
import io.vanillabp.camunda7.wiring.Camunda7UserTaskEventHandler;
Expand All @@ -26,6 +25,7 @@
import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
Expand All @@ -38,6 +38,7 @@
@AutoConfigurationPackage(basePackageClasses = Camunda7AdapterConfiguration.class)
@AutoConfigureBefore(CamundaBpmAutoConfiguration.class)
@EnableProcessApplication("org.camunda.bpm.spring.boot.starter.SpringBootProcessApplication")
@EnableConfigurationProperties(Camunda7VanillaBpProperties.class)
public class Camunda7AdapterConfiguration extends AdapterConfigurationBase<Camunda7ProcessService<?>> {

private static final Logger logger = LoggerFactory.getLogger(Camunda7AdapterConfiguration.class);
Expand All @@ -63,6 +64,12 @@ public class Camunda7AdapterConfiguration extends AdapterConfigurationBase<Camun
@Autowired
private ApplicationEventPublisher applicationEventPublisher;

@Autowired
private Camunda7VanillaBpProperties camunda7Properties;

@Autowired
private VanillaBpProperties properties;

@PostConstruct
public void init() {

Expand All @@ -78,22 +85,15 @@ public String getAdapterId() {

}

@Bean
public Camunda7AdapterProperties camunda7AdapterProperties() {

return new Camunda7AdapterProperties();

}

@Bean
public Camunda7DeploymentAdapter camunda7DeploymentAdapter(
final VanillaBpProperties properties,
final SpringProcessApplication processApplication,
final ProcessEngine processEngine,
final Camunda7TaskWiring taskWiring) {

return new Camunda7DeploymentAdapter(
properties,
camunda7Properties,
processApplication,
applicationName,
taskWiring,
Expand Down Expand Up @@ -126,14 +126,12 @@ public Camunda7TaskWiring taskWiring(
@Bean
public TaskWiringBpmnParseListener taskWiringBpmnParseListener(
final Camunda7TaskWiring taskWiring,
final Camunda7UserTaskEventHandler userTaskEventHandler,
final Camunda7AdapterProperties properties) {
final Camunda7UserTaskEventHandler userTaskEventHandler) {

return new TaskWiringBpmnParseListener(
taskWiring,
userTaskEventHandler,
properties.isUseBpmnAsyncDefinitions(),
properties.getBpmnAsyncDefinitions());
camunda7Properties);

}

Expand Down Expand Up @@ -198,10 +196,10 @@ public <DE> Camunda7ProcessService<?> newProcessServiceImplementation(
workflowAggregateIdClass.getSimpleName()));
}
}

final var result = new Camunda7ProcessService<DE>(
applicationEventPublisher,
applicationName,
camunda7Properties,
processEngine,
workflowAggregate ->
!springDataUtil.isPersistedEntity(workflowAggregateClass, workflowAggregate),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package io.vanillabp.camunda7;

import io.vanillabp.springboot.adapter.VanillaBpProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.StringUtils;

import java.util.Map;

@ConfigurationProperties(prefix = VanillaBpProperties.PREFIX, ignoreUnknownFields = true)
public class Camunda7VanillaBpProperties {

private static final boolean DEFAULT_USEBPMNASYNCDEFINITIONS = false;

private static final boolean DEFAULT_USETENANT = true;

private Map<String, WorkflowModuleAdapterProperties> workflowModules = Map.of();

public Map<String, WorkflowModuleAdapterProperties> getWorkflowModules() {
return workflowModules;
}

public void setWorkflowModules(Map<String, WorkflowModuleAdapterProperties> workflowModules) {

this.workflowModules = workflowModules;
workflowModules.forEach((workflowModuleId, properties) -> {
properties.workflowModuleId = workflowModuleId;
});

}

private static final WorkflowModuleAdapterProperties defaultProperties = new WorkflowModuleAdapterProperties();
private static final AdapterConfiguration defaultAdapterProperties = new AdapterConfiguration();

public String getTenantId(
final String workflowModuleId) {

final var configuration = workflowModules
.getOrDefault(workflowModuleId, defaultProperties)
.getAdapters()
.getOrDefault(Camunda7AdapterConfiguration.ADAPTER_ID, defaultAdapterProperties);
if (!configuration.isUseTenants()) {
return null;
}
if (StringUtils.hasText(configuration.getTenantId())) {
return configuration.getTenantId();
}
return workflowModuleId;

}

public boolean useBpmnAsyncDefinitions(
final String workflowModuleId,
final String bpmnProcessId) {

boolean result = DEFAULT_USEBPMNASYNCDEFINITIONS;
final var workflowModule = workflowModules.get(workflowModuleId);
if (workflowModule == null) {
return result;
}
final var workflowModuleAdapter = workflowModule.getAdapters().get(Camunda7AdapterConfiguration.ADAPTER_ID);
if (workflowModuleAdapter != null) {
result = workflowModuleAdapter.isUseBpmnAsyncDefinitions();
}
final var workflow = workflowModule.getWorkflows().get(bpmnProcessId);
if (workflow == null) {
return result;
}
final var workflowAdapter = workflow.getAdapters().get(Camunda7AdapterConfiguration.ADAPTER_ID);
if (workflowAdapter == null) {
return result;
}
return workflowAdapter.isUseBpmnAsyncDefinitions();

}

public static class AdapterConfiguration extends AsyncProperties {

private boolean useTenants = DEFAULT_USETENANT;

private String tenantId;

public boolean isUseTenants() {
return useTenants;
}

public void setUseTenants(boolean useTenants) {
this.useTenants = useTenants;
}

public String getTenantId() {
return tenantId;
}

public void setTenantId(String tenantId) {
this.tenantId = tenantId;
}

}

public static class AsyncProperties {

private boolean useBpmnAsyncDefinitions = DEFAULT_USEBPMNASYNCDEFINITIONS;

public boolean isUseBpmnAsyncDefinitions() {
return useBpmnAsyncDefinitions;
}

public void setUseBpmnAsyncDefinitions(boolean useBpmnAsyncDefinitions) {
this.useBpmnAsyncDefinitions = useBpmnAsyncDefinitions;
}

}

public static class WorkflowModuleAdapterProperties {

String workflowModuleId;

private Map<String, AdapterConfiguration> adapters = Map.of();

private Map<String, WorkflowAdapterProperties> workflows = Map.of();

public Map<String, AdapterConfiguration> getAdapters() {
return adapters;
}

public void setAdapters(Map<String, AdapterConfiguration> adapters) {
this.adapters = adapters;
}

public Map<String, WorkflowAdapterProperties> getWorkflows() { return workflows; }

public void setWorkflows(Map<String, WorkflowAdapterProperties> workflows) {

this.workflows = workflows;
workflows.forEach((bpmnProcessId, properties) -> {
properties.bpmnProcessId = bpmnProcessId;
properties.workflowModule = this;
});

}

}

public static class WorkflowAdapterProperties {

String bpmnProcessId;

WorkflowModuleAdapterProperties workflowModule;

private Map<String, AsyncProperties> adapters = Map.of();

public WorkflowModuleAdapterProperties getWorkflowModule() {
return workflowModule;
}

public String getBpmnProcessId() {
return bpmnProcessId;
}

public Map<String, AsyncProperties> getAdapters() {
return adapters;
}

public void setAdapters(Map<String, AsyncProperties> adapters) {
this.adapters = adapters;
}

}

}
Loading

0 comments on commit fca392d

Please sign in to comment.