Skip to content

Commit

Permalink
Fix tenant-id determination
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanpelikan committed Mar 14, 2024
1 parent fa67cb8 commit 3668f31
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import io.camunda.zeebe.model.bpmn.instance.zeebe.ZeebeFormDefinition;
import io.camunda.zeebe.model.bpmn.instance.zeebe.ZeebeLoopCharacteristics;
import io.camunda.zeebe.model.bpmn.instance.zeebe.ZeebeTaskDefinition;
import io.vanillabp.camunda8.Camunda8VanillaBpProperties;
import io.vanillabp.camunda8.deployment.Camunda8DeploymentAdapter;
import io.vanillabp.camunda8.deployment.DeployedBpmn;
import io.vanillabp.camunda8.service.Camunda8ProcessService;
import io.vanillabp.camunda8.wiring.Camunda8Connectable.Type;
import io.vanillabp.camunda8.wiring.parameters.Camunda8MethodParameterFactory;
Expand All @@ -31,6 +33,8 @@
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Stream;
Expand All @@ -48,31 +52,31 @@ public class Camunda8TaskWiring extends TaskWiringBase<Camunda8Connectable, Camu

private final Camunda8UserTaskHandler userTaskHandler;

private final String applicationName;

private ZeebeClient client;

private List<JobWorkerBuilderStep3> workers = new LinkedList<>();

private Set<String> userTaskTenantIds = new HashSet<>();

private final Camunda8VanillaBpProperties camunda8Properties;

public Camunda8TaskWiring(
final SpringDataUtil springDataUtil,
final ApplicationContext applicationContext,
final SpringBeanUtil springBeanUtil,
final String applicationName,
final String workerId,
final Camunda8VanillaBpProperties camunda8Properties,
final Camunda8UserTaskHandler userTaskHandler,
final ObjectProvider<Camunda8TaskHandler> taskHandlers,
final Collection<Camunda8ProcessService<?>> connectableServices) {

super(applicationContext, springBeanUtil, new Camunda8MethodParameterFactory());
this.workerId = workerId;
this.applicationName = applicationName;
this.springDataUtil = springDataUtil;
this.taskHandlers = taskHandlers;
this.userTaskHandler = userTaskHandler;
this.connectableServices = connectableServices;
this.camunda8Properties = camunda8Properties;

}

Expand All @@ -85,7 +89,7 @@ protected Class<WorkflowTask> getAnnotationType() {

/**
* Called by
* {@link Camunda8DeploymentAdapter#processBpmnModel(BpmnModelInstanceImpl)} to
* {@link Camunda8DeploymentAdapter#processBpmnModel(String, Map, DeployedBpmn, BpmnModelInstanceImpl, boolean)} to
* ensure client is available before using wire-methods.
*/
@Override
Expand All @@ -107,7 +111,7 @@ public void openWorkers() {
.handler(userTaskHandler)
.timeout(Integer.MAX_VALUE) // user-tasks are not fetched more than once
.name(workerId)
.tenantIds(userTaskTenantIds.stream().toList()));
.tenantIds(userTaskTenantIds.stream().filter(Objects::nonNull).toList()));
}

workers
Expand Down Expand Up @@ -219,6 +223,7 @@ protected void connectToBpms(
final var repository = processService.getWorkflowAggregateRepository();
final var idPropertyName = getWorkflowAggregateIdPropertyName(
processService.getWorkflowAggregateClass());
final var tenantId = camunda8Properties.getTenantId(workflowModuleId);

final var taskHandler = taskHandlers.getObject(
springDataUtil,
Expand All @@ -232,7 +237,6 @@ protected void connectToBpms(

if (connectable.getType() == Type.USERTASK) {

final var tenantId = workflowModuleId == null ? applicationName : workflowModuleId;
userTaskHandler.addTaskHandler(
tenantId,
connectable.getBpmnProcessId(),
Expand All @@ -245,7 +249,6 @@ protected void connectToBpms(

final var variablesToFetch = getVariablesToFetch(idPropertyName, parameters);

final var tenantId = workflowModuleId == null ? applicationName : workflowModuleId;
final var worker = client
.newWorker()
.jobType(connectable.getTaskDefinition())
Expand Down

0 comments on commit 3668f31

Please sign in to comment.