Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
import java.nio.file.Path;
import java.util.*;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@Slf4j
Expand All @@ -67,6 +69,8 @@ public class Importer {
public static final String DEFAULT_FIELD_TEMPLATE = "material";
public static final String DEFAULT_FIELD_APPEARANCE = "outline";
public static final String DEFAULT_FIELD_ALIGNMENT = null;
public static final String PLUGIN_STRING_REGEX = "(?<=\\bPlugin\\.)[^.]+";
public static final Pattern PLUGIN_STRING_PATTERN = Pattern.compile(PLUGIN_STRING_REGEX);

@Getter
protected Document document;
Expand Down Expand Up @@ -222,6 +226,7 @@ protected Optional<PetriNet> createPetriNet() throws MissingPetriNetMetaDataExce
resolveCaseEvents(document.getCaseEvents());
evaluateFunctions();
actions.forEach(this::evaluateActions);
net.setPluginDependencies(extractPluginDependencies());

if (document.getCaseName() != null && document.getCaseName().isDynamic()) {
net.setDefaultCaseNameExpression(new Expression(document.getCaseName().getValue()));
Expand Down Expand Up @@ -1343,4 +1348,16 @@ protected Map<String, String> buildTagsMap(List<Tag> tagsList) {
}
return tags;
}

@Transactional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for @Transactional. This annotations have been removed in another task on the pull request.

There is no database interaction in the method

protected Set<String> extractPluginDependencies() {
HashSet<String> plugins = new HashSet<>();
for (Action action: this.actions.values()) {
Matcher matcher = PLUGIN_STRING_PATTERN.matcher(action.getDefinition());
while (matcher.find()) {
plugins.add(matcher.group(0));
}
}
return plugins;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ public abstract class PetriNet extends PetriNetObject {
@Setter
private Map<String, String> tags;

@Getter
@Setter
private Set<String> pluginDependencies;
Comment on lines +137 to +139
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Plugin dependency field looks good; consider defensive copy in copy constructor

The new pluginDependencies field and its initialization in the default constructor are fine and align with the new Importer behavior.

In the copy constructor, though, this.pluginDependencies = petriNet.getPluginDependencies(); reuses the same mutable Set instance, which can lead to surprising shared mutations between the original and the copy, and it does not guard against a null value.

Consider defensively copying and null‑guarding here:

-        this.pluginDependencies = petriNet.getPluginDependencies();
+        Set<String> sourcePlugins = petriNet.getPluginDependencies();
+        this.pluginDependencies = sourcePlugins != null
+                ? new HashSet<>(sourcePlugins)
+                : new HashSet<>();

This keeps the field non‑null and avoids accidental cross‑net coupling via a shared set.

Also applies to: 164-165, 200-200

🤖 Prompt for AI Agents
In
nae-object-library/src/main/java/com/netgrif/application/engine/objects/petrinet/domain/PetriNet.java
around lines 137-139 (and also update similar assignments at 164-165 and 200),
the copy constructor assigns the pluginDependencies reference directly from the
source object, risking shared mutable state and possible NPE; change these
assignments to create a defensive copy and null-guard the source (e.g., if
source.getPluginDependencies() is null, assign a new empty Set, otherwise assign
a new Set constructed from the source) so the copy has its own non-null
collection instance.


public PetriNet() {
this._id = new ObjectId();
this.identifier = "Default";
Expand All @@ -157,6 +161,7 @@ public PetriNet() {
userRefs = new HashMap<>();
functions = new LinkedList<>();
tags = new HashMap<>();
pluginDependencies = new HashSet<>();
}

public PetriNet(PetriNet petriNet) {
Expand Down Expand Up @@ -192,6 +197,7 @@ public PetriNet(PetriNet petriNet) {
this.defaultRoleEnabled = petriNet.isDefaultRoleEnabled();
this.anonymousRoleEnabled = petriNet.isAnonymousRoleEnabled();
this.author = petriNet.getAuthor();
this.pluginDependencies = petriNet.getPluginDependencies();
initializeArcs();
}

Expand Down
Loading