Skip to content

Commit

Permalink
[incubator-kie-issues#1497] Using the getSerializableNodeInstances in…
Browse files Browse the repository at this point in the history
…side ProtobufProcessInstanceWriter
  • Loading branch information
Gabriele-Cardosi committed Oct 8, 2024
1 parent 30cf1bd commit 7685790
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,8 @@
*/
package org.jbpm.workflow.instance.node;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.stream.*;

import org.jbpm.process.core.ContextContainer;
import org.jbpm.process.core.context.variable.VariableScope;
Expand All @@ -48,7 +42,7 @@
import org.jbpm.workflow.instance.impl.NodeInstanceImpl;
import org.jbpm.workflow.instance.impl.NodeInstanceResolverFactory;
import org.kie.api.definition.process.Connection;
import org.kie.kogito.internal.process.runtime.KogitoNodeInstance;
import org.kie.kogito.internal.process.runtime.*;
import org.mvel2.integration.VariableResolver;
import org.mvel2.integration.impl.SimpleValueResolver;

Expand All @@ -58,6 +52,8 @@
public class ForEachNodeInstance extends CompositeContextNodeInstance {

private static final long serialVersionUID = 510L;
private static final List<Class<? extends org.kie.api.runtime.process.NodeInstance>> NOT_SERIALIZABLE_CLASSES = Arrays.asList(ForEachJoinNodeInstance.class); // using Arrays.asList to allow multiple exclusions

public static final String TEMP_OUTPUT_VAR = "foreach_output";

private int totalInstances;
Expand Down Expand Up @@ -131,6 +127,11 @@ public ContextContainer getContextContainer() {
return getForEachNode().getCompositeNode();
}

@Override
public Collection<org.kie.api.runtime.process.NodeInstance> getSerializableNodeInstances() {
return getNodeInstances().stream().filter(this::isSerializable).collect(Collectors.toUnmodifiableList());
}

private boolean isSequential() {
return getForEachNode().isSequential() || hasAsyncInstances;
}
Expand Down Expand Up @@ -350,6 +351,10 @@ public int getLevelForNode(String uniqueID) {
return 1;
}

private boolean isSerializable(org.kie.api.runtime.process.NodeInstance toCheck) {
return !NOT_SERIALIZABLE_CLASSES.contains(toCheck.getClass());
}

private class ForEachNodeInstanceResolverFactory extends NodeInstanceResolverFactory {

private static final long serialVersionUID = -8856846610671009685L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public FieldDescriptor getContextField(GeneratedMessageV3.Builder<?> builder) {
}

private <T extends NodeInstanceContainer & ContextInstanceContainer & ContextableInstance> WorkflowContext buildWorkflowContext(T nodeInstance) {
List<NodeInstance> nodeInstances = new ArrayList<>(nodeInstance.getNodeInstances());
List<NodeInstance> nodeInstances = new ArrayList<>(nodeInstance.getSerializableNodeInstances());
List<ContextInstance> exclusiveGroupInstances = nodeInstance.getContextInstances(ExclusiveGroup.EXCLUSIVE_GROUP);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) nodeInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
List<Map.Entry<String, Object>> variables = (variableScopeInstance != null) ? new ArrayList<>(variableScopeInstance.getVariables().entrySet()) : Collections.emptyList();
Expand Down

0 comments on commit 7685790

Please sign in to comment.