Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make file adapter respect flags #684

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading