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 @@ -93,10 +93,9 @@ protected Optional<DataField> transformDataField(String fieldId, Case useCase) {
}
Set mapValues = optValues.get();
Map<String, I18nString> options = this.getFieldOptions(multichoiceMap, netField);
List<Map.Entry<String, I18nString>> values = new ArrayList<>();
List<Map.Entry<String, Collection<String>>> values = new ArrayList<>();
for (String key : (Set<String>) mapValues) {
I18nString selectedValue = options.get(key);
values.add(new AbstractMap.SimpleEntry<>(key, selectedValue != null ? selectedValue : new I18nString("")));
values.add(new AbstractMap.SimpleEntry<>(key, I18nStringUtils.collectTranslations(options.get(key))));
}
Comment on lines +96 to 99
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, let's look at the file and the complete method context
cat -n application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticCaseMappingService.java | sed -n '80,110p'

Repository: netgrif/application-engine

Length of output: 2089


🏁 Script executed:

# Search for I18nStringUtils.collectTranslations implementation
find . -type f -name "*.java" | xargs grep -l "I18nStringUtils" | head -5

Repository: netgrif/application-engine

Length of output: 292


🏁 Script executed:

# Look for the I18nStringUtils class definition
fd -type f -name "I18nStringUtils.java"

Repository: netgrif/application-engine

Length of output: 240


🏁 Script executed:

# Read the I18nStringUtils file to see the collectTranslations implementation
cat -n nae-object-library/src/main/java/com/netgrif/application/engine/objects/elastic/domain/I18nStringUtils.java

Repository: netgrif/application-engine

Length of output: 786


🏁 Script executed:

# Search for getFieldOptions implementation
rg -nA10 "getFieldOptions" application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticCaseMappingService.java

Repository: netgrif/application-engine

Length of output: 1830


🏁 Script executed:

# Search for tests related to transformMultichoiceMapField
fd -type f -name "*.java" | xargs grep -l "transformMultichoiceMapField\|ElasticCaseMappingService" | grep -i test

Repository: netgrif/application-engine

Length of output: 240


🏁 Script executed:

# Search for tests of ElasticCaseMappingService
find . -type f -name "*.java" -path "*/test/*" | xargs grep -l "ElasticCaseMappingService" 2>/dev/null | head -3

Repository: netgrif/application-engine

Length of output: 52


🏁 Script executed:

# Search for any validation or warnings about missing keys
rg -n "mapValues|options\.get" application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticCaseMappingService.java -B2 -A2

Repository: netgrif/application-engine

Length of output: 1025


🏁 Script executed:

# Check if there's any logging or warning in the surrounding code
rg -n "logger|log\.|warn|error" application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticCaseMappingService.java | head -20

Repository: netgrif/application-engine

Length of output: 1771


🏁 Script executed:

# Check the git history of this specific method to understand its evolution
git log --oneline -n 20 -- application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticCaseMappingService.java

Repository: netgrif/application-engine

Length of output: 150


Inconsistent error handling: missing options keys are silently converted to empty translations.

The code at line 98 does not validate that all keys from mapValues exist in the options map. While I18nStringUtils.collectTranslations(null) handles null gracefully by returning an empty list, this pattern is inconsistent with the error handling established elsewhere in this class. Other methods (e.g., lines 163, 180, 194) log errors when encountering data inconsistencies. Consider either adding validation to ensure all keys are present in the options map, or logging a warning when options.get(key) returns null to make data issues visible during debugging.

🤖 Prompt for AI Agents
In
application-engine/src/main/java/com/netgrif/application/engine/elastic/service/ElasticCaseMappingService.java
around lines 96-99, the code blindly calls options.get(key) and passes the
result to I18nStringUtils.collectTranslations, silently producing empty
translations for missing keys; change this to first check
options.containsKey(key) and if the key is missing log a warning (including the
missing key and identifying context such as the parent map or document id), then
either continue with an explicit empty translation list or handle it
consistently with the class’s error strategy (throw or collect an error),
ensuring missing keys are visible in logs rather than silently ignored.

return Optional.of(new com.netgrif.application.engine.adapter.spring.elastic.domain.MapField(values));
}
Expand Down Expand Up @@ -134,8 +133,7 @@ protected Optional<DataField> transformStringCollectionField(com.netgrif.applica
(com.netgrif.application.engine.objects.workflow.domain.DataField enumMap, EnumerationMapField netField) {
Map<String, I18nString> options = this.getFieldOptions(enumMap, netField);
String selectedKey = (String) enumMap.getValue();
I18nString selectedValue = options.get(selectedKey);
return Optional.of(new com.netgrif.application.engine.adapter.spring.elastic.domain.MapField(new AbstractMap.SimpleEntry<>(selectedKey, selectedValue != null ? selectedValue : new I18nString(""))));
return Optional.of(new com.netgrif.application.engine.adapter.spring.elastic.domain.MapField(new AbstractMap.SimpleEntry<>(selectedKey, I18nStringUtils.collectTranslations(options.get(selectedKey)))));
}

private Map<String, I18nString> getFieldOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.netgrif.application.engine.objects.auth.dto;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import lombok.ToString;
Comment on lines +3 to +6
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Remove unused import.

lombok.NonNull is imported but not used in this class.

 import lombok.Data;
 import lombok.EqualsAndHashCode;
-import lombok.NonNull;
 import lombok.ToString;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import lombok.ToString;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
🤖 Prompt for AI Agents
In
nae-object-library/src/main/java/com/netgrif/application/engine/objects/auth/dto/AuthPrincipalDto.java
around lines 3 to 6, the import lombok.NonNull is unused; remove that import
line and keep only the required lombok imports (Data, EqualsAndHashCode,
ToString) so there are no unused imports.


import java.io.Serial;
import java.io.Serializable;

@Data
public class AuthPrincipalDto implements Serializable {

@Serial
private static final long serialVersionUID = 6725518942728316525L;

private String username;

private String realmId;

@ToString.Exclude
@EqualsAndHashCode.Exclude
private String sessionId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public abstract class ElasticCase implements Serializable {

private String authorUsername;

private List<ImmediateField> immediateData;

private Map<String, DataField> dataSet;

private Set<String> taskIds;
Expand Down Expand Up @@ -79,6 +77,8 @@ public abstract class ElasticCase implements Serializable {

private Map<String, String> tags;

private NodeInfo nodeInfo;

public ElasticCase(Case useCase) {
id = useCase.getStringId();
lastModified = Timestamp.valueOf(useCase.getLastModified()).getTime();
Expand All @@ -104,7 +104,6 @@ public ElasticCase(Case useCase) {
tags = new HashMap<>(useCase.getTags());

dataSet = new HashMap<>();
immediateData = useCase.getImmediateData().stream().map(ImmediateField::new).collect(Collectors.toList());
}

public void update(ElasticCase useCase) {
Expand All @@ -123,6 +122,5 @@ public void update(ElasticCase useCase) {
tags = useCase.getTags();

dataSet = useCase.getDataSet();
immediateData = useCase.getImmediateData();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,22 @@
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public abstract class I18nField extends TextField {
public abstract class I18nField extends DataField {

public String[] keyValue;

public Map<String, String> translations;

public I18nField(Set<String> keys, Set<String> values, Map<String, String> translations) {
super(new String[0]);
super(values.toArray(new String[0]));
this.keyValue = keys.toArray(new String[0]);
this.textValue = values.toArray(new String[0]);
this.translations = translations;
}

@Override
public Object getValue() {
if (textValue != null && textValue.length > 0) {
return new I18nString(textValue[0], translations);
if (fulltextValue != null && fulltextValue.length > 0) {
return new I18nString(fulltextValue[0], translations);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.netgrif.application.engine.objects.elastic.domain;

import com.netgrif.application.engine.objects.petrinet.domain.I18nString;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
Expand All @@ -10,26 +9,22 @@
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public abstract class MapField extends TextField {
public abstract class MapField extends DataField {

public String[] keyValue;
public Map<String, I18nString> keyValueTranslations;

public MapField(Map.Entry<String, I18nString> valueTranslationPair) {
this(List.of(valueTranslationPair));
public MapField(Map.Entry<String, Collection<String>> valuePair) {
this(List.of(valuePair));
}

public MapField(List<Map.Entry<String, I18nString>> valueTranslationPairs) {
public MapField(List<Map.Entry<String, Collection<String>>> valuePairs) {
super(new String[0]);
this.keyValue = new String[valueTranslationPairs.size()];
this.keyValue = new String[valuePairs.size()];
List<String> values = new ArrayList<>();
this.keyValueTranslations = new HashMap<>();
for (int i = 0; i < valueTranslationPairs.size(); i++) {
this.keyValue[i] = valueTranslationPairs.get(i).getKey();
values.addAll(I18nStringUtils.collectTranslations(valueTranslationPairs.get(i).getValue()));
this.keyValueTranslations.put(valueTranslationPairs.get(i).getKey(), valueTranslationPairs.get(i).getValue());
for (int i = 0; i < valuePairs.size(); i++) {
keyValue[i] = valuePairs.get(i).getKey();
values.addAll(valuePairs.get(i).getValue());
}
this.textValue = values.toArray(new String[0]);
this.fulltextValue = values.toArray(new String[0]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.netgrif.application.engine.objects.elastic.domain;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;

@Data
@AllArgsConstructor
public class NodeInfo implements Serializable {

@Serial
private static final long serialVersionUID = 7454569786379865L;

private String nodeHost;
private int nodePort;
}
Comment on lines +9 to +18
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add @NoArgsConstructor for deserialization compatibility.

This class is used as a field in ElasticCase, which is serialized to Elasticsearch. Most serialization frameworks (including Jackson, commonly used with Elasticsearch) require a no-argument constructor for deserialization. Without it, you may encounter runtime errors when reading ElasticCase documents from Elasticsearch.

 @Data
 @AllArgsConstructor
+@NoArgsConstructor
 public class NodeInfo implements Serializable {

Also add the import:

import lombok.NoArgsConstructor;
🤖 Prompt for AI Agents
In
nae-object-library/src/main/java/com/netgrif/application/engine/objects/elastic/domain/NodeInfo.java
around lines 9 to 18, the class lacks a no-argument constructor required by
deserializers (e.g., Jackson) — add Lombok's @NoArgsConstructor annotation to
the class and import lombok.NoArgsConstructor so the class has an implicit
no-arg constructor for deserialization while keeping the existing @Data and
@AllArgsConstructor.

Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.netgrif.application.engine.objects.elastic.domain;


import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public abstract class StringCollectionField extends TextField {
public abstract class StringCollectionField extends DataField {

public String[] collectionValue;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.netgrif.application.engine.adapter.spring.elastic.domain;

import com.netgrif.application.engine.objects.petrinet.domain.I18nString;
import lombok.NoArgsConstructor;
import org.springframework.data.elasticsearch.annotations.Field;

import java.util.Collection;
import java.util.List;
import java.util.Map;
Expand All @@ -13,11 +11,11 @@
@NoArgsConstructor
public class MapField extends com.netgrif.application.engine.objects.elastic.domain.MapField {

public MapField(Map.Entry<String, I18nString> valuePair) {
public MapField(Map.Entry<String, Collection<String>> valuePair) {
super(valuePair);
}

public MapField(List<Map.Entry<String, I18nString>> valuePairs) {
public MapField(List<Map.Entry<String, Collection<String>>> valuePairs) {
super(valuePairs);
}

Expand All @@ -31,9 +29,4 @@ public String[] getFulltextValue() {
public String[] getKeyValue() {
return super.getKeyValue();
}

@Field(type = Flattened, index = false)
public Map<String, I18nString> getKeyValueTranslations() {
return super.keyValueTranslations;
}
}
Loading