3333import com .bytechef .definition .BaseOutputDefinition .OutputResponse ;
3434import com .bytechef .platform .util .SchemaUtils ;
3535import com .bytechef .platform .workflow .task .dispatcher .TaskDispatcherDefinitionFactory ;
36- import com .bytechef .platform .workflow .task .dispatcher .definition .Property .ObjectProperty ;
3736import com .bytechef .platform .workflow .task .dispatcher .definition .PropertyFactory ;
3837import com .bytechef .platform .workflow .task .dispatcher .definition .TaskDispatcherDefinition ;
3938import com .bytechef .platform .workflow .task .dispatcher .definition .TaskDispatcherDsl .ModifiableValueProperty ;
4039import com .bytechef .platform .workflow .task .dispatcher .map .MapDataSource ;
4140import java .util .List ;
4241import java .util .Map ;
42+ import java .util .Objects ;
4343import java .util .Optional ;
44+ import org .slf4j .Logger ;
4445import org .springframework .stereotype .Component ;
4546import tools .jackson .core .type .TypeReference ;
4647
5051@ Component
5152public class MapTaskDispatcherDefinitionFactory implements TaskDispatcherDefinitionFactory {
5253
54+ private static final Logger logger = org .slf4j .LoggerFactory .getLogger (MapTaskDispatcherDefinitionFactory .class );
55+
5356 private final TaskDispatcherDefinition taskDispatcherDefinition ;
5457
5558 public MapTaskDispatcherDefinitionFactory (Optional <MapDataSource > mapDataSource ) {
@@ -79,7 +82,7 @@ protected static OutputResponse output(Map<String, ?> inputParameters, MapDataSo
7982 long environmentId = MapUtils .getLong (inputParameters , ENVIRONMENT_ID , 0L );
8083
8184 List <Map <String , ?>> iterateeTasks = MapUtils .getList (
82- inputParameters , ITERATEE , new TypeReference <Map < String , ?> >() {}, List .of ());
85+ inputParameters , ITERATEE , new TypeReference <>() {}, List .of ());
8386
8487 if (iterateeTasks .isEmpty ()) {
8588 return null ;
@@ -101,8 +104,7 @@ protected static OutputResponse output(Map<String, ?> inputParameters, MapDataSo
101104 return null ;
102105 }
103106
104- ModifiableValueProperty <?, ?> lastTaskSchema =
105- (ModifiableValueProperty <?, ?>) lastTaskOutput .getOutputSchema ();
107+ ModifiableValueProperty <?, ?> lastTaskSchema = (ModifiableValueProperty <?, ?>) lastTaskOutput .getOutputSchema ();
106108
107109 Object lastTaskSampleOutput = lastTaskOutput .getSampleOutput ();
108110
@@ -114,20 +116,34 @@ protected static OutputResponse output(Map<String, ?> inputParameters, MapDataSo
114116 }
115117
116118 protected static OutputResponse variableProperties (Map <String , ?> inputParameters ) {
117- ObjectProperty variableProperties ;
119+ OutputResponse outputResponse ;
120+ List <?> list = List .of ();
121+
122+ if (MapUtils .containsKey (inputParameters , ITEMS )) {
123+ // TODO Remove once UI suppress executing outputs if previous nodes don't have defined output
124+ try {
125+ list = MapUtils .getList (inputParameters , ITEMS , List .of ());
126+ } catch (Exception e ) {
127+ if (logger .isDebugEnabled ()) {
128+ logger .debug (e .getMessage ());
129+ }
130+ }
131+ }
118132
119- List <?> list = MapUtils .getRequiredList (inputParameters , ITEMS );
133+ boolean allNull = list .isEmpty () || list .stream ()
134+ .allMatch (Objects ::isNull );
120135
121- if (list .isEmpty ()) {
122- variableProperties = object ();
136+ if (allNull ) {
137+ outputResponse = OutputResponse .of (
138+ object ().properties (object (ITEM ), integer (INDEX )), Map .of (ITEM , Map .of (), INDEX , 0 ));
123139 } else {
124- ModifiableValueProperty <?, ?> outputSchema = (ModifiableValueProperty <?, ?>) SchemaUtils .getOutputSchema (
140+ ModifiableValueProperty <?, ?> itemProperty = (ModifiableValueProperty <?, ?>) SchemaUtils .getOutputSchema (
125141 ITEM , list .getFirst (), PropertyFactory .PROPERTY_FACTORY );
126142
127- variableProperties = object ()
128- .properties (outputSchema , integer (INDEX ));
143+ outputResponse = OutputResponse . of (
144+ object () .properties (itemProperty , integer (INDEX )), Map . of ( ITEM , list . getFirst (), INDEX , 0 ));
129145 }
130146
131- return OutputResponse . of ( variableProperties ) ;
147+ return outputResponse ;
132148 }
133149}
0 commit comments