Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
* one or more contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright ownership.
* Licensed under the Camunda License 1.0. You may not use this file
* except in compliance with the Camunda License 1.0.
*/
package io.camunda.operate.webapp.zeebe.operation.process.modify;
import io.camunda.operate.entities.FlowNodeState;
import io.camunda.operate.exceptions.OperateRuntimeException;
import io.camunda.operate.webapp.reader.FlowNodeInstanceReader;
import io.camunda.operate.webapp.rest.dto.operation.ModifyProcessInstanceRequestDto.Modification;
import io.camunda.zeebe.client.api.command.ModifyProcessInstanceCommandStep1;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
@Component
public class MoveTokenHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(MoveTokenHandler.class);
private final FlowNodeInstanceReader flowNodeInstanceReader;
public MoveTokenHandler(final FlowNodeInstanceReader flowNodeInstanceReader) {
this.flowNodeInstanceReader = flowNodeInstanceReader;
}
public ModifyProcessInstanceCommandStep1.ModifyProcessInstanceCommandStep2 moveToken(
final ModifyProcessInstanceCommandStep1 currentStep,
final Long processInstanceKey,
final Modification modification) {
final int newTokensCount = calculateNewTokensCount(modification, processInstanceKey);
if (newTokensCount > 0) {
final ModifyProcessInstanceCommandStep1.ModifyProcessInstanceCommandStep3 nextStep =
activateNewNodes(currentStep, modification, newTokensCount);
moveGlobalVariables(nextStep, modification);
return cancelTokensOnOriginalNodes(nextStep, processInstanceKey, modification);
} else {
LOGGER.info(
"Skipping MOVE_TOKEN processing for flowNode {} and process instance {} since newTokensCount is {}",
modification.getFromFlowNodeId(),
processInstanceKey,
newTokensCount);
return null;
}
}
private ModifyProcessInstanceCommandStep1.ModifyProcessInstanceCommandStep3 activateNewNodes(
final ModifyProcessInstanceCommandStep1 currentStep,
final Modification modification,
final int newTokensCount) {
final String toFlowNodeId = modification.getToFlowNodeId();
// flowNodeId => List of variables (Map)
// flowNodeId => [ { "key": "value" }, {"key for another flowNode with the same id": "value"} ]
final Map>> variablesToMoveByFlownodeId =
modification.variablesForAddToken() == null
? new HashMap<>()
: modification.variablesForAddToken();
// Create flowNodes with variables
final Queue