Skip to content

Commit e803a44

Browse files
ivicacclaude
andcommitted
1057 Improve Map task dispatcher variable properties and output handling
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e8dc555 commit e803a44

1 file changed

Lines changed: 28 additions & 12 deletions

File tree

server/libs/modules/task-dispatchers/map/src/main/java/com/bytechef/task/dispatcher/map/MapTaskDispatcherDefinitionFactory.java

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@
3333
import com.bytechef.definition.BaseOutputDefinition.OutputResponse;
3434
import com.bytechef.platform.util.SchemaUtils;
3535
import com.bytechef.platform.workflow.task.dispatcher.TaskDispatcherDefinitionFactory;
36-
import com.bytechef.platform.workflow.task.dispatcher.definition.Property.ObjectProperty;
3736
import com.bytechef.platform.workflow.task.dispatcher.definition.PropertyFactory;
3837
import com.bytechef.platform.workflow.task.dispatcher.definition.TaskDispatcherDefinition;
3938
import com.bytechef.platform.workflow.task.dispatcher.definition.TaskDispatcherDsl.ModifiableValueProperty;
4039
import com.bytechef.platform.workflow.task.dispatcher.map.MapDataSource;
4140
import java.util.List;
4241
import java.util.Map;
42+
import java.util.Objects;
4343
import java.util.Optional;
44+
import org.slf4j.Logger;
4445
import org.springframework.stereotype.Component;
4546
import tools.jackson.core.type.TypeReference;
4647

@@ -50,6 +51,8 @@
5051
@Component
5152
public 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

Comments
 (0)