Skip to content

Commit

Permalink
Merge pull request #391 from tausif010/feature/add-unitExternal-id
Browse files Browse the repository at this point in the history
Added support to add the unit external id to TimeseriesMetadata
  • Loading branch information
dsorenes authored Oct 9, 2024
2 parents 0e42e43 + f3516f5 commit f527731
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/timeSeries.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ List<TimeseriesMetadata> upsertTimeseriesList = List.of(TimeseriesMetadata.newBu
.setIsString(false)
.setIsStep(false)
.setDescription("Description")
.setUnit("TestUnits")
.setUnit("TestUnits")
.setUnitExternalId("TestUnitExternalId")
.putMetadata("type", "sdk-data-generator")
.putMetadata("sdk-data-generator", "sdk-data-generator")
.build());
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.cognite</groupId>
<artifactId>cdf-sdk-java</artifactId>
<version>2.3.1</version>
<version>2.3.2</version>
<licenses>
<license>
<name>Apache 2</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ public static TimeseriesMetadata parseTimeseriesMetadata(String json) throws Exc
}
}

if (root.path("unitExternalId").isTextual()) {
builder.setUnitExternalId(root.get("unitExternalId").textValue());
}

return builder.build();
}

Expand Down Expand Up @@ -352,6 +356,10 @@ public static Map<String, Object> toRequestInsertItem(TimeseriesMetadata element
mapBuilder.put("dataSetId", element.getDataSetId());
}

if (element.hasUnitExternalId()) {
mapBuilder.put("unitExternalId", element.getUnitExternalId());
}

return mapBuilder.build();
}

Expand Down Expand Up @@ -399,6 +407,9 @@ public static Map<String, Object> toRequestUpdateItem(TimeseriesMetadata element
if (element.hasDataSetId()) {
updateNodeBuilder.put("dataSetId", ImmutableMap.of("set", element.getDataSetId()));
}
if (element.hasUnitExternalId()) {
updateNodeBuilder.put("unitExternalId", ImmutableMap.of("set", element.getUnitExternalId()));
}
mapBuilder.put("update", updateNodeBuilder.build());
return mapBuilder.build();
}
Expand Down Expand Up @@ -466,6 +477,12 @@ public static Map<String, Object> toRequestReplaceItem(TimeseriesMetadata elemen
updateNodeBuilder.put("dataSetId", ImmutableMap.of("setNull", true));
}

if (element.hasUnitExternalId()) {
updateNodeBuilder.put("unitExternalId", ImmutableMap.of("set", element.getUnitExternalId()));
} else {
updateNodeBuilder.put("unitExternalId", ImmutableMap.of("setNull", true));
}

mapBuilder.put("update", updateNodeBuilder.build());
return mapBuilder.build();
}
Expand Down
1 change: 1 addition & 0 deletions src/main/proto/timeseries.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ message TimeseriesMetadata {
optional int64 last_updated_time = 11;
map<string, string> metadata = 12;
optional int64 data_set_id = 13;
optional string unit_external_id = 14;
}

/*
Expand Down

0 comments on commit f527731

Please sign in to comment.