Skip to content

Commit 368761e

Browse files
marko-kriskovicivicac
authored andcommitted
3126 - removed comments
1 parent 8806440 commit 368761e

File tree

10 files changed

+21
-128
lines changed

10 files changed

+21
-128
lines changed

server/libs/platform/platform-workflow/platform-workflow-validator/src/main/java/com/bytechef/platform/workflow/validator/ArrayPropertyValidator.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,16 @@ static void validateFromPropertyInfo(
5858
return;
5959
}
6060

61-
// Check for TASK type array
6261
if (isTaskTypeArray(nestedProperties)) {
6362
TaskValidator.validateTaskArray(valueJsonNode, propertyPath, errors);
6463
return;
6564
}
6665

67-
// Check for wrapped definition (array of arrays or array of objects)
6866
if (isWrappedDefinition(nestedProperties)) {
6967
validateWrappedArray(valueJsonNode, nestedProperties, propertyPath, errors, warnings);
7068
return;
7169
}
7270

73-
// Determine validation type based on actual content
7471
if (!valueJsonNode.isEmpty()) {
7572
JsonNode firstElement = valueJsonNode.get(0);
7673
if (firstElement.isObject()) {
@@ -105,13 +102,11 @@ private static void validateObjectArray(
105102
JsonNode arrayJsonNode, List<PropertyInfo> elementProperties,
106103
String propertyPath, StringBuilder errors, StringBuilder warnings) {
107104

108-
// Check if this is a union type object array
109105
if (isUnionTypeObjectArray(elementProperties)) {
110106
validateUnionTypeObjectArray(arrayJsonNode, elementProperties, propertyPath, errors, warnings);
111107
return;
112108
}
113109

114-
// Standard object array validation
115110
JsonNode rootParametersJsonNode = createRootParametersJsonNode(arrayJsonNode, propertyPath);
116111

117112
for (int i = 0; i < arrayJsonNode.size(); i++) {
@@ -159,11 +154,9 @@ private static void validateObjectArrayElement(
159154
return;
160155
}
161156

162-
// Check for extra properties
163157
validateExtraPropertiesInArrayElement(
164158
elementJsonNode, elementProperties, propertyPath, index, rootParametersJsonNode, warnings);
165159

166-
// Validate each defined property
167160
for (PropertyInfo propertyInfo : elementProperties) {
168161
validatePropertyInArrayElement(
169162
elementJsonNode, propertyInfo, elementPath, index, rootParametersJsonNode, errors);
@@ -200,7 +193,7 @@ private static void checkDisplayConditionForExtraProperty(
200193

201194
DisplayConditionEvaluator.DisplayConditionResult result =
202195
DisplayConditionEvaluator.evaluateForArrayElement(
203-
propertyInfo.displayCondition(), index, rootParametersJsonNode, warnings);
196+
propertyInfo.displayCondition(), index, rootParametersJsonNode);
204197

205198
if (!result.shouldShow()) {
206199
StringUtils.appendWithNewline(
@@ -218,10 +211,9 @@ private static void validatePropertyInArrayElement(
218211
String fieldPath = elementPath + "." + fieldName;
219212
boolean isRequired = propertyInfo.required();
220213

221-
// Check display condition
222214
DisplayConditionEvaluator.DisplayConditionResult result =
223215
DisplayConditionEvaluator.evaluateForArrayElement(
224-
propertyInfo.displayCondition(), index, rootParametersJsonNode, new StringBuilder());
216+
propertyInfo.displayCondition(), index, rootParametersJsonNode);
225217

226218
if (result.shouldShow()) {
227219
if (isRequired && !elementJsonNode.has(fieldName)) {
@@ -350,10 +342,8 @@ private static String simplifyConditionForUnionType(String condition, String bas
350342
String escapedArrayName = baseArrayName.replaceAll("\\[", "\\\\[")
351343
.replaceAll("]", "\\\\]");
352344

353-
// Replace patterns like "baseArrayName[index][index]." with ""
354345
String simplified = condition.replaceAll(escapedArrayName + "\\[index]\\[index]\\.", "");
355346

356-
// Also handle single [index]
357347
simplified = simplified.replaceAll(escapedArrayName + "\\[index]\\.", "");
358348

359349
return simplified;

server/libs/platform/platform-workflow/platform-workflow-validator/src/main/java/com/bytechef/platform/workflow/validator/DataPillValidator.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ private static void findDataPillsInNode(
9292
context, allTasksMap, taskDefinition);
9393
}
9494
} else if (jsonNode.isArray()) {
95-
// Check if this array contains TASK type elements that should be skipped
9695
if (isTaskTypeArray(currentPath, taskDefinition)) {
97-
// Skip validation of this array since it contains nested tasks that will be validated separately
9896
return;
9997
}
10098

@@ -127,15 +125,13 @@ private static String getExpectedTypeFromDefinition(
127125
return null;
128126
}
129127

130-
// Split the field path into parts (e.g., "active" or "config.setting")
131128
String[] pathParts = fieldPath.split("\\.");
132129

133130
List<PropertyInfo> currentProperties = taskDefinition;
134131

135132
for (String part : pathParts) {
136133
PropertyInfo foundProperty = null;
137134

138-
// Look for the property in the current level
139135
for (PropertyInfo property : currentProperties) {
140136
if (part.equals(property.name())) {
141137
foundProperty = property;
@@ -144,19 +140,17 @@ private static String getExpectedTypeFromDefinition(
144140
}
145141

146142
if (foundProperty == null) {
147-
return null; // Property is not found in definition
143+
return null;
148144
}
149145

150-
// If this is the last part of the path, return its type
151146
if (part.equals(pathParts[pathParts.length - 1])) {
152147
return foundProperty.type();
153148
}
154149

155-
// If not the last part, navigate deeper into nested properties
156150
if ("OBJECT".equalsIgnoreCase(foundProperty.type()) && foundProperty.nestedProperties() != null) {
157151
currentProperties = foundProperty.nestedProperties();
158152
} else {
159-
return null; // Can't navigate deeper
153+
return null;
160154
}
161155
}
162156

@@ -191,12 +185,10 @@ private static boolean isTaskTypeArray(@Nullable String currentPath, @Nullable L
191185
return false;
192186
}
193187

194-
// Split the path to find the property definition
195188
String[] pathParts = currentPath.split("\\.");
196189
List<PropertyInfo> currentProperties = taskDefinition;
197190

198191
for (String part : pathParts) {
199-
// Remove array indices from the part (e.g., "items[0]" becomes "items")
200192
String propertyName = part.replaceAll("\\[\\d+]", "");
201193

202194
PropertyInfo propertyInfo = null;
@@ -213,7 +205,6 @@ private static boolean isTaskTypeArray(@Nullable String currentPath, @Nullable L
213205
return false;
214206
}
215207

216-
// Check if this is an ARRAY type with TASK nested properties
217208
List<PropertyInfo> propertyInfos = propertyInfo.nestedProperties();
218209
if ("ARRAY".equalsIgnoreCase(propertyInfo.type()) && propertyInfos != null &&
219210
propertyInfos.size() == 1) {
@@ -225,7 +216,6 @@ private static boolean isTaskTypeArray(@Nullable String currentPath, @Nullable L
225216
}
226217
}
227218

228-
// Continue traversing for nested properties
229219
if (propertyInfos != null) {
230220
currentProperties = propertyInfos;
231221
} else {
@@ -244,18 +234,15 @@ private static boolean isTypeCompatible(String expectedType, @Nullable String ac
244234
return true;
245235
}
246236

247-
// Exact match
248237
if (expectedType.equalsIgnoreCase(actualType)) {
249238
return true;
250239
}
251240

252-
// Integer and number types are compatible
253241
if ((expectedType.equalsIgnoreCase("integer") && actualType.equalsIgnoreCase("number")) ||
254242
(expectedType.equalsIgnoreCase("number") && actualType.equalsIgnoreCase("integer"))) {
255243
return true;
256244
}
257245

258-
// Any type can be converted to string
259246
return expectedType.equalsIgnoreCase("string");
260247
}
261248

server/libs/platform/platform-workflow/platform-workflow-validator/src/main/java/com/bytechef/platform/workflow/validator/DisplayConditionEvaluator.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.bytechef.platform.workflow.validator;
1818

1919
import com.fasterxml.jackson.databind.JsonNode;
20+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2021
import javax.annotation.Nullable;
2122
import org.slf4j.Logger;
2223
import org.slf4j.LoggerFactory;
@@ -37,7 +38,7 @@ private DisplayConditionEvaluator() {
3738
* Evaluates a display condition and returns the result along with any validation messages.
3839
*/
3940
static DisplayConditionResult evaluate(
40-
@Nullable String displayCondition, JsonNode parametersJsonNode, StringBuilder warnings) {
41+
@Nullable String displayCondition, JsonNode parametersJsonNode) {
4142

4243
if (displayCondition == null || displayCondition.isEmpty()) {
4344
return DisplayConditionResult.visible();
@@ -47,15 +48,15 @@ static DisplayConditionResult evaluate(
4748
boolean shouldShow = WorkflowUtils.extractAndEvaluateCondition(displayCondition, parametersJsonNode);
4849
return DisplayConditionResult.of(shouldShow, false, null);
4950
} catch (Exception e) {
50-
return handleEvaluationException(e, displayCondition, warnings);
51+
return handleEvaluationException(e);
5152
}
5253
}
5354

5455
/**
5556
* Evaluates display condition for array elements with index placeholder replacement.
5657
*/
5758
static DisplayConditionResult evaluateForArrayElement(
58-
@Nullable String displayCondition, int index, JsonNode rootParametersJsonNode, StringBuilder warnings) {
59+
@Nullable String displayCondition, int index, JsonNode rootParametersJsonNode) {
5960

6061
if (displayCondition == null || displayCondition.isEmpty()) {
6162
return DisplayConditionResult.visible();
@@ -74,8 +75,7 @@ static DisplayConditionResult evaluateForArrayElement(
7475
}
7576
}
7677

77-
private static DisplayConditionResult handleEvaluationException(
78-
Exception e, String displayCondition, StringBuilder warnings) {
78+
private static DisplayConditionResult handleEvaluationException(Exception e) {
7979

8080
String message = e.getMessage();
8181
if (message != null && message.startsWith("Invalid logic for display condition:")) {
@@ -101,7 +101,8 @@ static class DisplayConditionResult {
101101
private final boolean isMalformed;
102102
private final String malformedMessage;
103103

104-
private DisplayConditionResult(boolean shouldShow, boolean isMalformed, String malformedMessage) {
104+
@SuppressFBWarnings("NP")
105+
private DisplayConditionResult(boolean shouldShow, boolean isMalformed, @Nullable String malformedMessage) {
105106
this.shouldShow = shouldShow;
106107
this.isMalformed = isMalformed;
107108
this.malformedMessage = malformedMessage;
@@ -119,7 +120,7 @@ static DisplayConditionResult malformed(String message) {
119120
return new DisplayConditionResult(false, true, message);
120121
}
121122

122-
static DisplayConditionResult of(boolean shouldShow, boolean isMalformed, String malformedMessage) {
123+
static DisplayConditionResult of(boolean shouldShow, boolean isMalformed, @Nullable String malformedMessage) {
123124
return new DisplayConditionResult(shouldShow, isMalformed, malformedMessage);
124125
}
125126

server/libs/platform/platform-workflow/platform-workflow-validator/src/main/java/com/bytechef/platform/workflow/validator/PropertyUtils.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,10 @@ public static PropertyInfo findPropertyByName(@Nullable PropertyInfo parentPrope
6464
return null;
6565
}
6666

67-
// Check if the parent property itself matches the name
6867
if (targetName.equals(parentProperty.name())) {
6968
return parentProperty;
7069
}
7170

72-
// Search in nested properties
7371
for (PropertyInfo nested : parentProperty.nestedProperties()) {
7472
if (targetName.equals(nested.name())) {
7573
return nested;
@@ -101,17 +99,14 @@ private static boolean checkPropertyExistsRecursive(PropertyInfo outputInfo, Str
10199

102100
String currentProperty = propertyPath[0];
103101

104-
// Handle array access like "items[0]"
105102
if (currentProperty.contains("[") && currentProperty.endsWith("]")) {
106103
return checkArrayPropertyExists(outputInfo, currentProperty, propertyPath);
107104
}
108105

109-
// Check if the current property matches the main property
110106
if (currentProperty.equals(outputInfo.name())) {
111107
return checkCurrentPropertyExists(outputInfo, propertyPath);
112108
}
113109

114-
// Check nested properties if they exist
115110
return checkNestedPropertyExists(outputInfo, currentProperty, propertyPath);
116111
}
117112

@@ -120,7 +115,6 @@ private static boolean checkArrayPropertyExists(
120115

121116
String arrayName = currentProperty.substring(0, currentProperty.indexOf('['));
122117

123-
// Check if the array property exists
124118
List<PropertyInfo> propertyInfos = outputInfo.nestedProperties();
125119

126120
boolean anyMatch = propertyInfos != null &&
@@ -129,7 +123,6 @@ private static boolean checkArrayPropertyExists(
129123
.anyMatch(prop -> arrayName.equals(prop.name()));
130124

131125
if (arrayName.equals(outputInfo.name()) || anyMatch) {
132-
// Find the array property
133126
PropertyInfo arrayPropertyInfo = findArrayProperty(outputInfo, arrayName);
134127

135128
if (arrayPropertyInfo != null && "ARRAY".equals(arrayPropertyInfo.type())) {
@@ -221,17 +214,14 @@ private static String getPropertyTypeRecursive(PropertyInfo outputInfo, String[]
221214

222215
String currentProperty = propertyPath[0];
223216

224-
// Handle array access like "items[0]"
225217
if (currentProperty.contains("[") && currentProperty.endsWith("]")) {
226218
return getArrayPropertyType(outputInfo, currentProperty, propertyPath);
227219
}
228220

229-
// Check if the current property matches the main property
230221
if (currentProperty.equals(outputInfo.name())) {
231222
return getCurrentPropertyType(outputInfo, propertyPath);
232223
}
233224

234-
// Check nested properties if they exist
235225
return getNestedPropertyType(outputInfo, currentProperty, propertyPath);
236226
}
237227

0 commit comments

Comments
 (0)