Skip to content

Commit

Permalink
rectified samples mappigs
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Oct 23, 2023
1 parent 99dbdc8 commit 5c4407a
Show file tree
Hide file tree
Showing 12 changed files with 1,044 additions and 1,309 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 5c4407a

Please sign in to comment.