Fix bug in transform output schema generator
@@ -25,19 +25,11 @@ import org.streampipes.model.output.TransformOutputStrategy;
import org.streampipes.model.schema.EventProperty;
import org.streampipes.model.schema.EventPropertyPrimitive;
import org.streampipes.model.schema.EventSchema;
-import org.streampipes.model.staticproperty.FreeTextStaticProperty;
-import org.streampipes.model.staticproperty.MappingPropertyUnary;
-import org.streampipes.model.staticproperty.Option;
-import org.streampipes.model.staticproperty.SelectionStaticProperty;
-import org.streampipes.model.staticproperty.StaticProperty;
+import org.streampipes.model.staticproperty.*;
import org.streampipes.model.util.Cloner;
import java.net.URI;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
import java.util.stream.Collectors;
public class TransformOutputSchemaGenerator implements OutputSchemaGenerator<TransformOutputStrategy> {
@@ -45,6 +37,8 @@ public class TransformOutputSchemaGenerator implements OutputSchemaGenerator<Tra
private TransformOutputStrategy strategy;
private DataProcessorInvocation dataProcessorInvocation;
+ protected static final String prefix = "urn:streampipes.org:spi:";
+
public TransformOutputSchemaGenerator(DataProcessorInvocation dataProcessorInvocation, TransformOutputStrategy
strategy) {
this.strategy = strategy;
@@ -55,13 +49,14 @@ public class TransformOutputSchemaGenerator implements OutputSchemaGenerator<Tra
public EventSchema buildFromOneStream(SpDataStream stream) {
// TODO exceptions
Map<String, EventProperty> modifiedEventProperties = new HashMap<>();
- EventSchema outSchema = stream.getEventSchema();
+ EventSchema outSchema = new EventSchema();
+ EventSchema inSchema = stream.getEventSchema();
strategy.getTransformOperations().forEach(to -> {
Optional<MappingPropertyUnary> mappingPropertyOpt = findMappingProperty(to.getMappingPropertyInternalName(),
dataProcessorInvocation.getStaticProperties());
if (mappingPropertyOpt.isPresent()) {
- Optional<EventProperty> eventPropertyOpt = findEventProperty(mappingPropertyOpt.get().getMapsTo(), outSchema
+ Optional<EventProperty> eventPropertyOpt = findEventProperty(mappingPropertyOpt.get().getMapsTo(), inSchema
.getEventProperties());
if (eventPropertyOpt.isPresent()) {
@@ -72,10 +67,15 @@ public class TransformOutputSchemaGenerator implements OutputSchemaGenerator<Tra
}
});
- List<EventProperty> newProperties = outSchema.getEventProperties().stream().map(ep -> modifiedEventProperties
- .getOrDefault(ep
- .getElementId
- (), ep)).collect(Collectors.toList());
+ List<EventProperty> newProperties = inSchema.getEventProperties().stream().map(ep -> {
+ if (modifiedEventProperties.containsKey(ep.getElementId())) {
+ EventProperty newProperty = modifiedEventProperties.get(ep.getElementId());
+ newProperty.setElementId(prefix + UUID.randomUUID().toString());
+ return newProperty;
+ } else {
+ return ep;
+ }
+ }).collect(Collectors.toList());
outSchema.setEventProperties(newProperties);
return outSchema;
@@ -156,9 +156,14 @@ public class TransformOutputSchemaGenerator implements OutputSchemaGenerator<Tra
return eventProperties
.stream()
.filter(ep -> ep.getElementId().equals(mapsTo.toString()))
+ .map(this::cloneEp)
.findFirst();
}
+ private EventProperty cloneEp(EventProperty ep) {
+ return new Cloner().property(ep);
+ }
+
private Optional<MappingPropertyUnary> findMappingProperty(String mappingPropertyInternalName, List<StaticProperty>
staticProperties) {
