Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Oct 23, 2023
2 parents b0df5ff + 5c4407a commit 3c41c49
Show file tree
Hide file tree
Showing 13 changed files with 1,045 additions and 1,310 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@ public void extractFromSource(ProcessingContext<byte[]> context)
throws ProcessingException {
CustomEventOuter.CustomEvent payloadProtobuf;
try {
payloadProtobuf = CustomEventOuter.CustomEvent
.parseFrom(context.getPayload());
byte[] payload = context.getPayload();
if (payload == null) {
log.info("Preparing new event failed, payload == null");

} else {
log.info("Preparing new event: {}", new String(payload));
}
payloadProtobuf = CustomEventOuter.CustomEvent
.parseFrom(payload);
} catch (InvalidProtocolBufferException e) {
throw new ProcessingException(e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ public void extractFromSource(ProcessingContext<byte[]> context)
TYPE.TEXTUAL,
RepairStrategy.DEFAULT))));

ObjectNode fragment = objectMapper.createObjectNode();
fragment.set("value", new FloatNode(jsonNode.get("temperature").floatValue()));
fragment.set("unit", new TextNode(jsonNode.get("unit").textValue()));
ObjectNode fragmentTemperature = objectMapper.createObjectNode();
ObjectNode fragmentTemperatureSeries = objectMapper.createObjectNode();
fragmentTemperature.set("T", fragmentTemperatureSeries);
fragmentTemperatureSeries.set("value", new FloatNode(jsonNode.get("temperature").floatValue()));
fragmentTemperatureSeries.set("unit", new TextNode(jsonNode.get("unit").textValue()));

postProcessingCache.put("c8y_Fragment_to_remove",
new ArrayList<SubstituteValue>(Arrays.asList(
Expand All @@ -89,7 +91,7 @@ public void extractFromSource(ProcessingContext<byte[]> context)

postProcessingCache.put("c8y_Temperature",
new ArrayList<SubstituteValue>(Arrays.asList(
new SubstituteValue(fragment,
new SubstituteValue(fragmentTemperature,
TYPE.OBJECT,
RepairStrategy.DEFAULT))));

Expand All @@ -104,12 +106,16 @@ public void extractFromSource(ProcessingContext<byte[]> context)
if (jsonNode.get("unexpected") != null) {
// it is important to use RepairStrategy.CREATE_IF_MISSING as the node
// "unexpected" does not yet exists in the target payload
postProcessingCache.put("c8y_Unexpected",
ObjectNode fragmentUnexpected = objectMapper.createObjectNode();
ObjectNode fragmentUnexpectedSeries = objectMapper.createObjectNode();
fragmentUnexpected.set("U", fragmentUnexpectedSeries);
fragmentUnexpectedSeries.set("value", new FloatNode(jsonNode.get("unexpected").floatValue()));
fragmentUnexpectedSeries.set("unit", new TextNode("unknown"));
postProcessingCache.put("c8y_Unexpected",
new ArrayList<SubstituteValue>(
Arrays.asList(new SubstituteValue(
new FloatNode(jsonNode.get("unexpected")
.floatValue()),
TYPE.NUMBER,
fragmentUnexpected,
TYPE.OBJECT,
RepairStrategy.CREATE_IF_MISSING))));
unexpected = jsonNode.get("unexpected").floatValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ private void loadProcessorExtensions() {
Map<?, ?> props = (Map<?, ?>) (extension.get(ExtensionsComponent.PROCESSOR_EXTENSION_TYPE));
String extName = props.get("name").toString();
boolean external = (Boolean) props.get("external");
log.info("Trying to load extension id: {}, name: {}, ", extension.getId().getValue(), extName);
log.info("Trying to load extension id: {}, name: {}", extension.getId().getValue(), extName);

try {
if (external) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public void substituteValueInObject(MappingType type, SubstituteValue sub, Docum
} else if (sub.repairStrategy.equals(RepairStrategy.CREATE_IF_MISSING) ) {
boolean pathIsNested = keys.contains(".") || keys.contains("[") ;
if (pathIsNested) {
throw new JSONException ("Can only crrate new nodes ion the root level!");
throw new JSONException ("Can only create new nodes ion the root level!");
}
jsonObject.put("$", keys, sub.typedValue());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void extractFromSource(ProcessingContext<JsonNode> context)
}

// no substitution for the time property exists, then use the system time
if (!substitutionTimeExists && mapping.targetAPI != API.INVENTORY) {
if (!substitutionTimeExists && mapping.targetAPI != API.INVENTORY && mapping.targetAPI != API.OPERATION) {
List<SubstituteValue> postProcessingCacheEntry = postProcessingCache.getOrDefault(TIME,
new ArrayList<SubstituteValue>());
postProcessingCacheEntry.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ public AbstractExtensibleRepresentation createMEAO(ProcessingContext<?> context)
String payload = context.getCurrentRequest().getRequest();
mqttMessage.setPayload(payload.getBytes());
mqttClient.publish(context.getResolvedPublishTopic(), mqttMessage);
log.info("Published outbound message: {} for mapping: {} ", payload, context.getMapping().name);
log.info("Published outbound message: {} for mapping: {} on topic: {}", payload, context.getMapping().name, context.getResolvedPublishTopic());
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<revision>3.3.0</revision>
<revision>3.3.1-SNAPSHOT</revision>
<c8y.version>1018.0.220</c8y.version>
<lombok.version>1.18.24</lombok.version>
<maven.compiler.source>11</maven.compiler.source>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 3c41c49

Please sign in to comment.