Skip to content

Commit a9f49aa

Browse files
committed
Apply spotless in branch
1 parent dc37256 commit a9f49aa

File tree

16 files changed

+270
-262
lines changed

16 files changed

+270
-262
lines changed

hivemq-edge/src/main/java/com/hivemq/protocols/northbound/NorthboundTagConsumer.java

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -91,26 +91,34 @@ public void accept(final @NotNull List<DataPoint> dataPoints) {
9191
final List<DataPoint> jsonDataPoints =
9292
dataPoints.stream().filter(DataPoint::treatTagValueAsJson).toList();
9393

94-
final var preparedJsonDataPoints = jsonDataPoints.stream().map(jsonDataPoint -> {
95-
try {
96-
final var jsonMap=objectMapper.readValue((String)jsonDataPoint.getTagValue(), typeRef);
97-
if (jsonMap.size() > 1 && jsonMap.containsKey("value")) {
98-
return new DataPointImpl(jsonDataPoint.getTagName(), jsonMap);
99-
} else if (jsonMap.containsKey("value")) {
100-
return new DataPointImpl(jsonDataPoint.getTagName(), jsonMap.get("value"), true);
101-
} else {
102-
log.error("No value received for tag '{}'. This indicates a broken tag on the OPC UA side.", jsonDataPoint.getTagName());
103-
return null;
104-
}
105-
} catch (final JsonProcessingException e) {
106-
if(log.isDebugEnabled()) {
107-
log.debug("Unable to parse JSON for tag '{}': {}", jsonDataPoint.getTagName(), jsonDataPoint.getTagValue() );
108-
} else {
109-
log.error("Unable to parse JSON for tag '{}'", jsonDataPoint.getTagName());
110-
}
111-
return null;
112-
}
113-
}).filter(Objects::nonNull).toList();
94+
final var preparedJsonDataPoints = jsonDataPoints.stream()
95+
.map(jsonDataPoint -> {
96+
try {
97+
final var jsonMap = objectMapper.readValue((String) jsonDataPoint.getTagValue(), typeRef);
98+
if (jsonMap.size() > 1 && jsonMap.containsKey("value")) {
99+
return new DataPointImpl(jsonDataPoint.getTagName(), jsonMap);
100+
} else if (jsonMap.containsKey("value")) {
101+
return new DataPointImpl(jsonDataPoint.getTagName(), jsonMap.get("value"), true);
102+
} else {
103+
log.error(
104+
"No value received for tag '{}'. This indicates a broken tag on the OPC UA side.",
105+
jsonDataPoint.getTagName());
106+
return null;
107+
}
108+
} catch (final JsonProcessingException e) {
109+
if (log.isDebugEnabled()) {
110+
log.debug(
111+
"Unable to parse JSON for tag '{}': {}",
112+
jsonDataPoint.getTagName(),
113+
jsonDataPoint.getTagValue());
114+
} else {
115+
log.error("Unable to parse JSON for tag '{}'", jsonDataPoint.getTagName());
116+
}
117+
return null;
118+
}
119+
})
120+
.filter(Objects::nonNull)
121+
.toList();
114122

115123
final var dataPointsCopied = new ArrayList<>(dataPoints);
116124
dataPointsCopied.removeAll(jsonDataPoints);

modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/OpcUaProtocolAdapter.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -608,28 +608,33 @@ public void createTagSchema(
608608
return;
609609
}
610610
conn.client()
611-
.ifPresentOrElse(client -> {
612-
@SuppressWarnings("unused")
613-
final var unused = new JsonSchemaGenerator(client, config.isIncludeMetadata())
614-
.createMqttPayloadJsonSchema(tag)
615-
.whenComplete((result, throwable) -> {
616-
if (throwable == null) {
617-
result.ifPresentOrElse(schema -> {
618-
log.debug("Schema inferred for tag='{}'", tagName);
619-
output.finish(schema);
620-
}, () -> {
621-
log.error("No schema inferred for tag='{}'", tagName);
622-
output.fail("No schema inferred for tag='" + tagName + "'");
611+
.ifPresentOrElse(
612+
client -> {
613+
@SuppressWarnings("unused")
614+
final var unused = new JsonSchemaGenerator(client, config.isIncludeMetadata())
615+
.createMqttPayloadJsonSchema(tag)
616+
.whenComplete((result, throwable) -> {
617+
if (throwable == null) {
618+
result.ifPresentOrElse(
619+
schema -> {
620+
log.debug("Schema inferred for tag='{}'", tagName);
621+
output.finish(schema);
622+
},
623+
() -> {
624+
log.error("No schema inferred for tag='{}'", tagName);
625+
output.fail("No schema inferred for tag='" + tagName + "'");
626+
});
627+
} else {
628+
log.error(
629+
"Exception while creating tag schema for '{}'", tagName, throwable);
630+
output.fail(throwable, null);
631+
}
623632
});
624-
} else {
625-
log.error("Exception while creating tag schema for '{}'", tagName, throwable);
626-
output.fail(throwable, null);
627-
}
628-
});
629-
}, () -> {
630-
log.error("Discovery failed: Client not connected or not initialized");
631-
output.fail("Discovery failed: Client not connected or not initialized");
632-
});
633+
},
634+
() -> {
635+
log.error("Discovery failed: Client not connected or not initialized");
636+
output.fail("Discovery failed: Client not connected or not initialized");
637+
});
633638
}
634639

635640
@Override

modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/config/BidirectionalOpcUaSpecificAdapterConfig.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ public BidirectionalOpcUaSpecificAdapterConfig(
3434
@JsonProperty("security") final @Nullable Security security,
3535
@JsonProperty("connectionOptions") final @Nullable ConnectionOptions connectionOptions,
3636
@JsonProperty("includeMetadata") final @Nullable Boolean includeMetadata) {
37-
super(uri, overrideUri, applicationUri, auth, tls, opcuaToMqttConfig, security, connectionOptions, includeMetadata);
37+
super(
38+
uri,
39+
overrideUri,
40+
applicationUri,
41+
auth,
42+
tls,
43+
opcuaToMqttConfig,
44+
security,
45+
connectionOptions,
46+
includeMetadata);
3847
}
3948
}

modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/config/OpcUaSpecificAdapterConfig.java

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ public class OpcUaSpecificAdapterConfig implements ProtocolSpecificAdapterConfig
100100
private final @NotNull ConnectionOptions connectionOptions;
101101

102102
@JsonProperty("includeMetadata")
103-
@ModuleConfigField(title = "Include Metadata",
104-
description = "Include OPC UA metadata (timestamps, status code) in JSON output and schema",
105-
defaultValue = "false")
103+
@ModuleConfigField(
104+
title = "Include Metadata",
105+
description = "Include OPC UA metadata (timestamps, status code) in JSON output and schema",
106+
defaultValue = "false")
106107
private final boolean includeMetadata;
107108

108109
@JsonCreator
@@ -167,16 +168,16 @@ public boolean isIncludeMetadata() {
167168
public boolean equals(final Object o) {
168169
if (this == o) return true;
169170
if (!(o instanceof OpcUaSpecificAdapterConfig that)) return false;
170-
return getOverrideUri().equals(that.getOverrideUri()) &&
171-
includeMetadata == that.includeMetadata &&
172-
Objects.equals(id, that.id) &&
173-
Objects.equals(getUri(), that.getUri()) &&
174-
Objects.equals(getApplicationUri(), that.getApplicationUri()) &&
175-
Objects.equals(getAuth(), that.getAuth()) &&
176-
Objects.equals(getTls(), that.getTls()) &&
177-
Objects.equals(getSecurity(), that.getSecurity()) &&
178-
Objects.equals(getOpcuaToMqttConfig(), that.getOpcuaToMqttConfig()) &&
179-
Objects.equals(connectionOptions, that.connectionOptions);
171+
return getOverrideUri().equals(that.getOverrideUri())
172+
&& includeMetadata == that.includeMetadata
173+
&& Objects.equals(id, that.id)
174+
&& Objects.equals(getUri(), that.getUri())
175+
&& Objects.equals(getApplicationUri(), that.getApplicationUri())
176+
&& Objects.equals(getAuth(), that.getAuth())
177+
&& Objects.equals(getTls(), that.getTls())
178+
&& Objects.equals(getSecurity(), that.getSecurity())
179+
&& Objects.equals(getOpcuaToMqttConfig(), that.getOpcuaToMqttConfig())
180+
&& Objects.equals(connectionOptions, that.connectionOptions);
180181
}
181182

182183
@Override
@@ -196,30 +197,29 @@ public int hashCode() {
196197

197198
@Override
198199
public String toString() {
199-
return "OpcUaSpecificAdapterConfig{" +
200-
"id='" +
201-
id +
202-
'\'' +
203-
", uri='" +
204-
uri +
205-
'\'' +
206-
", overrideUri=" +
207-
overrideUri +
208-
", applicationUri='" +
209-
applicationUri +
210-
'\'' +
211-
", auth=" +
212-
auth +
213-
", tls=" +
214-
tls +
215-
", security=" +
216-
security +
217-
", opcuaToMqttConfig=" +
218-
opcuaToMqttConfig +
219-
", connectionOptions=" +
220-
connectionOptions +
221-
", includeMetadata=" +
222-
includeMetadata +
223-
'}';
200+
return "OpcUaSpecificAdapterConfig{" + "id='"
201+
+ id
202+
+ '\''
203+
+ ", uri='"
204+
+ uri
205+
+ '\''
206+
+ ", overrideUri="
207+
+ overrideUri
208+
+ ", applicationUri='"
209+
+ applicationUri
210+
+ '\''
211+
+ ", auth="
212+
+ auth
213+
+ ", tls="
214+
+ tls
215+
+ ", security="
216+
+ security
217+
+ ", opcuaToMqttConfig="
218+
+ opcuaToMqttConfig
219+
+ ", connectionOptions="
220+
+ connectionOptions
221+
+ ", includeMetadata="
222+
+ includeMetadata
223+
+ '}';
224224
}
225225
}

modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/listeners/OpcUaSubscriptionLifecycleHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,8 @@ public void onDataReceived(
325325

326326
private @NotNull String extractPayload(final @NotNull OpcUaClient client, final @NotNull DataValue value)
327327
throws UaException {
328-
final ByteBuffer byteBuffer = OpcUaToJsonConverter.convertPayload(client.getDynamicEncodingContext(),
329-
value,
330-
config.isIncludeMetadata());
328+
final ByteBuffer byteBuffer = OpcUaToJsonConverter.convertPayload(
329+
client.getDynamicEncodingContext(), value, config.isIncludeMetadata());
331330
final byte[] buffer = new byte[byteBuffer.remaining()];
332331
byteBuffer.get(buffer);
333332
return new String(buffer, StandardCharsets.UTF_8);

modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/northbound/OpcUaToJsonConverter.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ public class OpcUaToJsonConverter {
6565
private static final @NotNull Base64.Encoder BASE_64 = Base64.getEncoder();
6666

6767
public static @NotNull ByteBuffer convertPayload(
68-
final @NotNull EncodingContext serializationContext,
69-
final @NotNull DataValue dataValue) {
68+
final @NotNull EncodingContext serializationContext, final @NotNull DataValue dataValue) {
7069
return convertPayload(serializationContext, dataValue, false);
7170
}
7271

@@ -82,30 +81,38 @@ public class OpcUaToJsonConverter {
8281
if (includeMetadata) {
8382
jsonObject.add("statusCode", convertStatusCode(dataValue.getStatusCode()));
8483
if (dataValue.getSourceTime() != null) {
85-
jsonObject.add("sourceTime",
86-
new JsonPrimitive(DateTimeFormatter.ISO_INSTANT.format(dataValue.getSourceTime().getJavaInstant())));
84+
jsonObject.add(
85+
"sourceTime",
86+
new JsonPrimitive(DateTimeFormatter.ISO_INSTANT.format(
87+
dataValue.getSourceTime().getJavaInstant())));
8788
} else {
8889
jsonObject.add("sourceTime", JsonNull.INSTANCE);
8990
}
9091
if (dataValue.getSourcePicoseconds() != null) {
91-
jsonObject.add("sourcePicoseconds", new JsonPrimitive(dataValue.getSourcePicoseconds().intValue()));
92+
jsonObject.add(
93+
"sourcePicoseconds",
94+
new JsonPrimitive(dataValue.getSourcePicoseconds().intValue()));
9295
} else {
9396
jsonObject.add("sourcePicoseconds", JsonNull.INSTANCE);
9497
}
9598
if (dataValue.getServerTime() != null) {
96-
jsonObject.add("serverTime",
97-
new JsonPrimitive(DateTimeFormatter.ISO_INSTANT.format(dataValue.getServerTime().getJavaInstant())));
99+
jsonObject.add(
100+
"serverTime",
101+
new JsonPrimitive(DateTimeFormatter.ISO_INSTANT.format(
102+
dataValue.getServerTime().getJavaInstant())));
98103
} else {
99104
jsonObject.add("serverTime", JsonNull.INSTANCE);
100105
}
101106
if (dataValue.getServerPicoseconds() != null) {
102-
jsonObject.add("serverPicoseconds", new JsonPrimitive(dataValue.getServerPicoseconds().intValue()));
107+
jsonObject.add(
108+
"serverPicoseconds",
109+
new JsonPrimitive(dataValue.getServerPicoseconds().intValue()));
103110
} else {
104111
jsonObject.add("serverPicoseconds", JsonNull.INSTANCE);
105112
}
106113
}
107114

108-
if(value != null) {
115+
if (value != null) {
109116
jsonObject.add("value", convertValue(value, serializationContext));
110117
} else {
111118
jsonObject.add("value", JsonNull.INSTANCE);

modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/southbound/BuiltinJsonSchema.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ public class BuiltinJsonSchema {
120120
* These properties are marked as readOnly and are not required.
121121
*/
122122
static void addReadOnlyMetadataProperties(
123-
final @NotNull ObjectNode propertiesNode,
124-
final @NotNull ObjectMapper objectMapper) {
123+
final @NotNull ObjectNode propertiesNode, final @NotNull ObjectMapper objectMapper) {
125124
// sourceTimestamp - DateTime as ISO 8601 string
126125
final ObjectNode sourceTimestamp = objectMapper.createObjectNode();
127126
sourceTimestamp.put(TYPE, STRING_DATA_TYPE);
@@ -321,8 +320,7 @@ static void populatePropertiesForBuiltinType(
321320
}
322321

323322
static @NotNull JsonNode createJsonSchemaForArrayType(
324-
final @NotNull OpcUaDataType builtinDataType,
325-
final @NotNull UInteger @NotNull [] dimensions) {
323+
final @NotNull OpcUaDataType builtinDataType, final @NotNull UInteger @NotNull [] dimensions) {
326324
return createJsonSchemaForArrayType(builtinDataType, dimensions, false);
327325
}
328326

@@ -356,8 +354,7 @@ static void populatePropertiesForBuiltinType(
356354
}
357355

358356
static @Nullable JsonNode createJsonSchemaForBuiltInType(
359-
final @NotNull OpcUaDataType builtinDataType,
360-
final boolean includeMetadata) {
357+
final @NotNull OpcUaDataType builtinDataType, final boolean includeMetadata) {
361358
if (!includeMetadata) {
362359
return BUILT_IN_TYPES.get(builtinDataType);
363360
}

modules/hivemq-edge-module-opcua/src/main/java/com/hivemq/edge/adapters/opcua/southbound/JsonSchemaGenerator.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,19 @@ public JsonSchemaGenerator(final @NotNull OpcUaClient client, final boolean incl
7171
final String nodeId = tag.getDefinition().getNode();
7272
final var jsonSchemaGenerator = new JsonSchemaGenerator(client, includeMetadata);
7373
final var parsed = NodeId.parse(nodeId);
74-
return jsonSchemaGenerator.collectTypeInfo(parsed).thenApply(info -> {
75-
if (info.arrayDimensions() != null && info.arrayDimensions().length > 0) {
76-
return createJsonSchemaForArrayType(info.dataType(), info.arrayDimensions, includeMetadata);
77-
} else if (info.nestedFields() == null || info.nestedFields().isEmpty()) {
78-
return createJsonSchemaForBuiltInType(info.dataType(), includeMetadata);
79-
} else {
80-
return jsonSchemaGenerator.jsonSchemaFromNodeId(info);
81-
}
82-
}).thenApply(Optional::of);
74+
return jsonSchemaGenerator
75+
.collectTypeInfo(parsed)
76+
.thenApply(info -> {
77+
if (info.arrayDimensions() != null && info.arrayDimensions().length > 0) {
78+
return createJsonSchemaForArrayType(info.dataType(), info.arrayDimensions, includeMetadata);
79+
} else if (info.nestedFields() == null
80+
|| info.nestedFields().isEmpty()) {
81+
return createJsonSchemaForBuiltInType(info.dataType(), includeMetadata);
82+
} else {
83+
return jsonSchemaGenerator.jsonSchemaFromNodeId(info);
84+
}
85+
})
86+
.thenApply(Optional::of);
8387
}
8488

8589
private @NotNull CompletableFuture<FieldInformation> collectTypeInfo(final @NotNull NodeId destinationNodeId) {

0 commit comments

Comments
 (0)