1616
1717package com .bytechef .platform .workflow .validator ;
1818
19+ import com .bytechef .commons .util .CollectionUtils ;
1920import com .bytechef .commons .util .StringUtils ;
2021import com .bytechef .platform .workflow .validator .model .PropertyInfo ;
2122import com .fasterxml .jackson .databind .JsonNode ;
22- import com .fasterxml .jackson .databind .ObjectMapper ;
2323import com .fasterxml .jackson .databind .node .ObjectNode ;
2424import java .util .ArrayList ;
2525import java .util .Iterator ;
@@ -65,11 +65,13 @@ static void validateFromPropertyInfo(
6565
6666 if (isWrappedDefinition (nestedProperties )) {
6767 validateWrappedArray (valueJsonNode , nestedProperties , propertyPath , errors , warnings );
68+
6869 return ;
6970 }
7071
7172 if (!valueJsonNode .isEmpty ()) {
7273 JsonNode firstElement = valueJsonNode .get (0 );
74+
7375 if (firstElement .isObject ()) {
7476 validateObjectArray (valueJsonNode , nestedProperties , propertyPath , errors , warnings );
7577 } else {
@@ -86,6 +88,7 @@ private static void validateUnionTypeArray(
8688
8789 for (int i = 0 ; i < arrayJsonNode .size (); i ++) {
8890 JsonNode valueJsonNode = arrayJsonNode .get (i );
91+
8992 boolean matchesAnyType = allowedTypes .stream ()
9093 .anyMatch (typeInfo -> TypeValidator .isTypeValid (valueJsonNode , typeInfo .type ()));
9194
@@ -104,15 +107,15 @@ private static void validateObjectArray(
104107
105108 if (isUnionTypeObjectArray (elementProperties )) {
106109 validateUnionTypeObjectArray (arrayJsonNode , elementProperties , propertyPath , errors , warnings );
110+
107111 return ;
108112 }
109113
110114 JsonNode rootParametersJsonNode = createRootParametersJsonNode (arrayJsonNode , propertyPath );
111115
112116 for (int i = 0 ; i < arrayJsonNode .size (); i ++) {
113117 validateObjectArrayElement (
114- arrayJsonNode .get (i ), elementProperties , propertyPath , i ,
115- rootParametersJsonNode , errors , warnings );
118+ arrayJsonNode .get (i ), elementProperties , propertyPath , i , rootParametersJsonNode , errors , warnings );
116119 }
117120 }
118121
@@ -129,8 +132,10 @@ private static void validateUnionTypeObjectArray(
129132
130133 if (!elementJsonNode .isObject ()) {
131134 String actualType = JsonUtils .getJsonNodeType (elementJsonNode );
135+
132136 StringUtils .appendWithNewline (
133137 ValidationErrorUtils .typeError (elementPath , "object" , actualType ), errors );
138+
134139 continue ;
135140 }
136141
@@ -141,16 +146,16 @@ private static void validateUnionTypeObjectArray(
141146 }
142147
143148 private static void validateObjectArrayElement (
144- JsonNode elementJsonNode , List <PropertyInfo > elementProperties ,
145- String propertyPath , int index , JsonNode rootParametersJsonNode ,
146- StringBuilder errors , StringBuilder warnings ) {
149+ JsonNode elementJsonNode , List <PropertyInfo > elementProperties , String propertyPath , int index ,
150+ JsonNode rootParametersJsonNode , StringBuilder errors , StringBuilder warnings ) {
147151
148152 String elementPath = propertyPath + "[" + index + "]" ;
149153
150154 if (!elementJsonNode .isObject ()) {
151155 String actualType = JsonUtils .getJsonNodeType (elementJsonNode );
152- StringUtils .appendWithNewline (
153- ValidationErrorUtils .typeError (elementPath , "object" , actualType ), errors );
156+
157+ StringUtils .appendWithNewline (ValidationErrorUtils .typeError (elementPath , "object" , actualType ), errors );
158+
154159 return ;
155160 }
156161
@@ -179,8 +184,9 @@ private static void validateExtraPropertiesInArrayElement(
179184 StringUtils .appendWithNewline (
180185 "Property '" + propertyPath + "[index]." + fieldName + "' is not defined in task definition" ,
181186 warnings );
182- } else if (matchingProperty .displayCondition () != null && !matchingProperty .displayCondition ()
183- .isEmpty ()) {
187+ } else if (matchingProperty .displayCondition () != null &&
188+ !org .apache .commons .lang3 .StringUtils .isEmpty (matchingProperty .displayCondition ())) {
189+
184190 checkDisplayConditionForExtraProperty (
185191 matchingProperty , index , propertyPath , fieldName , rootParametersJsonNode , warnings );
186192 }
@@ -197,8 +203,7 @@ private static void checkDisplayConditionForExtraProperty(
197203
198204 if (!result .shouldShow ()) {
199205 StringUtils .appendWithNewline (
200- "Property '" + propertyPath + "[" + index + "]." + fieldName +
201- "' is not defined in task definition" ,
206+ "Property '" + propertyPath + "[" + index + "]." + fieldName + "' is not defined in task definition" ,
202207 warnings );
203208 }
204209 }
@@ -220,6 +225,7 @@ private static void validatePropertyInArrayElement(
220225 StringUtils .appendWithNewline ("Missing required property: " + fieldPath , errors );
221226 } else if (elementJsonNode .has (fieldName )) {
222227 JsonNode valueJsonNode = elementJsonNode .get (fieldName );
228+
223229 if (!valueJsonNode .isTextual () || !TypeValidator .isDataPillExpression (valueJsonNode .asText ())) {
224230 TypeValidator .validateType (valueJsonNode , propertyInfo .type (), fieldPath , errors );
225231 }
@@ -232,6 +238,7 @@ private static boolean matchesAnyUnionType(
232238
233239 for (PropertyInfo unionType : unionTypes ) {
234240 List <PropertyInfo > schemaProperties = unionType .nestedProperties ();
241+
235242 if (schemaProperties == null || schemaProperties .isEmpty ()) {
236243 continue ;
237244 }
@@ -250,6 +257,7 @@ private static boolean matchesAnyUnionType(
250257 if (!currentWarnings .isEmpty ()) {
251258 warnings .append (currentWarnings );
252259 }
260+
253261 return true ;
254262 }
255263 }
@@ -303,16 +311,15 @@ private static boolean isWrappedDefinition(List<PropertyInfo> nestedProperties)
303311
304312 private static boolean isUnionTypeObjectArray (List <PropertyInfo > elementProperties ) {
305313 return elementProperties .stream ()
306- .allMatch (prop -> "OBJECT" .equalsIgnoreCase (prop .type ()) &&
307- prop .nestedProperties () != null &&
308- !prop .nestedProperties ()
309- .isEmpty ());
314+ .allMatch (prop -> "OBJECT" .equalsIgnoreCase (prop .type ()) && prop .nestedProperties () != null &&
315+ !CollectionUtils .isEmpty (prop .nestedProperties ()));
310316 }
311317
312318 private static JsonNode createRootParametersJsonNode (JsonNode arrayValue , String propertyPath ) {
313- ObjectMapper mapper = new ObjectMapper ();
314- ObjectNode rootNode = mapper . createObjectNode ();
319+ ObjectNode rootNode = com . bytechef . commons . util . JsonUtils . createObjectNode ();
320+
315321 rootNode .set (propertyPath , arrayValue );
322+
316323 return rootNode ;
317324 }
318325
@@ -327,6 +334,7 @@ private static List<PropertyInfo> simplifyDisplayConditionsForUnionType(
327334
328335 if (displayCondition != null && !displayCondition .isEmpty ()) {
329336 String simplifiedCondition = simplifyConditionForUnionType (displayCondition , baseArrayName );
337+
330338 simplified .add (new PropertyInfo (
331339 prop .name (), prop .type (), prop .description (), prop .required (),
332340 prop .expressionEnabled (), simplifiedCondition , prop .nestedProperties ()));
@@ -357,29 +365,35 @@ private static void addUnionTypeError(
357365 String actualType = JsonUtils .getJsonNodeType (valueJsonNode );
358366
359367 StringBuilder expectedTypes = new StringBuilder ();
368+
360369 for (int j = 0 ; j < allowedTypes .size (); j ++) {
361370 if (j > 0 ) {
362371 expectedTypes .append (" or " );
363372 }
364- expectedTypes .append (allowedTypes .get (j )
365- .type ()
366- .toLowerCase ());
373+
374+ PropertyInfo propertyInfo = allowedTypes .get (j );
375+
376+ expectedTypes .append (org .apache .commons .lang3 .StringUtils .lowerCase (propertyInfo .type ()));
367377 }
368378
369379 StringUtils .appendWithNewline (
370380 ValidationErrorUtils .arrayElementError (elementValue , propertyName , expectedTypes .toString (), actualType ),
371381 errors );
372382 }
373383
374- private static void
375- addUnionTypeObjectError (String elementPath , List <PropertyInfo > unionTypes , StringBuilder errors ) {
384+ private static void addUnionTypeObjectError (
385+ String elementPath , List <PropertyInfo > unionTypes , StringBuilder errors ) {
386+
376387 StringBuilder typeNames = new StringBuilder ();
388+
377389 for (int j = 0 ; j < unionTypes .size (); j ++) {
378390 if (j > 0 ) {
379391 typeNames .append (", " );
380392 }
381- typeNames .append (unionTypes .get (j )
382- .name ());
393+
394+ PropertyInfo propertyInfo = unionTypes .get (j );
395+
396+ typeNames .append (propertyInfo .name ());
383397 }
384398
385399 StringUtils .appendWithNewline (
0 commit comments