Skip to content

Commit

Permalink
make file adapter respect flags
Browse files Browse the repository at this point in the history
  • Loading branch information
DC2-DanielKrueger committed Dec 10, 2024
1 parent e97e990 commit 3322a37
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hivemq.adapter.sdk.api.config.PollingContext;
import com.hivemq.adapter.sdk.api.data.DataPoint;
import com.hivemq.adapter.sdk.api.data.JsonPayloadCreator;
import com.hivemq.adapter.sdk.api.data.ProtocolAdapterDataSample;
import com.hivemq.edge.adapters.file.FilePollingProtocolAdapter;
import com.hivemq.edge.adapters.file.config.FileToMqttMapping;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -37,18 +37,22 @@ public class FileJsonPayloadCreator implements JsonPayloadCreator {
@Override
public @NotNull List<byte[]> convertToJson(
final @NotNull ProtocolAdapterDataSample sample, final @NotNull ObjectMapper objectMapper) {
List<byte[]> payloads = new ArrayList<>();
for (DataPoint dataPoint : sample.getDataPoints()) {
final List<byte[]> payloads = new ArrayList<>();
for (final DataPoint dataPoint : sample.getDataPoints()) {
try {
FileDataPoint fileDataPoint = (FileDataPoint) dataPoint;
final FilePayload value = new FilePayload(System.currentTimeMillis(),
sample.getPollingContext().getUserProperties(),

final PollingContext pollingContext = sample.getPollingContext();

final FileDataPoint fileDataPoint = (FileDataPoint) dataPoint;
final FilePayload value = new FilePayload(pollingContext.getUserProperties(),
dataPoint.getTagValue(),
dataPoint.getTagName(),
fileDataPoint.getTag().getDefinition().getContentType());
fileDataPoint.getTag().getDefinition().getContentType(),
pollingContext.getIncludeTagNames() ? dataPoint.getTagName() : null,
pollingContext.getIncludeTimestamp() ? System.currentTimeMillis() : null);


payloads.add(objectMapper.writeValueAsBytes(value));
} catch (JsonProcessingException e) {
} catch (final JsonProcessingException e) {
LOG.warn("Unable to create payload for data data point '{}'. Skipping this data point.", dataPoint);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,29 @@
@SuppressWarnings({"FieldCanBeLocal", "unused"})
public class FilePayload {

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonProperty("timestamp")
private final @NotNull Long timestamp;
private final @Nullable Long timestamp;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
private final @Nullable List<MqttUserProperty> userProperties;

@JsonProperty("value")
private final @NotNull Object value;

@JsonProperty("tagName")
private final @NotNull String tagName;

@JsonProperty("contentType")
private final @NotNull String contentType;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonProperty("tagName")
private final @Nullable String tagName;

public FilePayload(
final @NotNull Long timestamp, final @NotNull List<MqttUserProperty> userProperties,
final @NotNull Object value, final @NotNull String tagName, final @NotNull ContentType contentType) {
final @NotNull List<MqttUserProperty> userProperties,
final @NotNull Object value,
final @NotNull ContentType contentType,
final @Nullable String tagName,
final @Nullable Long timestamp) {
this.timestamp = timestamp;
this.userProperties = userProperties;
this.value = value;
Expand Down

0 comments on commit 3322a37

Please sign in to comment.