Commit 2598908e authored by j.hoerdt's avatar j.hoerdt
Browse files

start implementing handle api

parent cbe06eeb
......@@ -42,7 +42,7 @@ class Sensor {
}
private String register_new_pid(Record rec) throws Exception {
String response_body = request_to_registry("POST", Main.prefix_for_new_pids, rec);
String response_body = request_to_registry("POST", "21.11138/USER01", rec);
return new Gson().fromJson(response_body, JsonObject.class).get("epic-pid").getAsString();
}
......@@ -51,45 +51,67 @@ class Sensor {
}
private String request_to_registry(String method, String target_uri, Record rec) throws Exception {
JsonArray body = new JsonArray();
var body = new JsonObject();
body.add("values", new JsonArray());
{
var admin_data = new JsonObject();
var admin_data_value = new JsonObject();
admin_data_value.addProperty("index", "300");
admin_data_value.addProperty("handle", "21.11138/USER01");
admin_data_value.addProperty("permissions", "110011111111");
admin_data.addProperty("format", "admin");
admin_data.add("value", admin_data_value);
add_attribute(body, "100", "HS_ADMIN", admin_data);
}
add_attribute(body,
"1",
"21.T11148/eb3c713572f681e6c4c3",
"[{\"AlternateIdentifier\":{\"AlternateIdentifierValue\":\"" + properties.get("sensor_id") + "\",\"alternateIdentifierType\":\"sensor_id\"}}]"
new JsonPrimitive("[{\"AlternateIdentifier\":{\"AlternateIdentifierValue\":\"" + properties.get("sensor_id") + "\",\"alternateIdentifierType\":\"sensor_id\"}}]")
);
add_attribute(body,
"2",
"21.T11148/22c62082a4d2d9ae2602",
"[{\"dateType\":\"Commissioned\", \"date\":\"" + rec.get("min(all_measurements.first_msg)").asLocalDate().toString() + "\"},{\"dateType\":\"last message\", \"date\":\"" + rec.get("max(all_measurements.last_msg)").asLocalDate().toString() + "\"}]"
new JsonPrimitive("[{\"dateType\":\"Commissioned\", \"date\":\"" + rec.get("min(all_measurements.first_msg)").asLocalDate().toString() + "\"},{\"dateType\":\"last message\", \"date\":\"" + rec.get("max(all_measurements.last_msg)").asLocalDate().toString() + "\"}]")
);
add_attribute(body,
"3",
"21.T11148/709a23220f2c3d64d1e1",
'\"' + rec.get("sensor_type").asString() + '\"'
new JsonPrimitive('\"' + rec.get("sensor_type").asString() + '\"')
);
add_attribute(body,
"4",
"21.T11148/68c2cc7f0ceaa3e499ec",
"{\"Model\":{\"modelName\":\"" + rec.get("sensor_type").asString() + "\"}}"
new JsonPrimitive("{\"Model\":{\"modelName\":\"" + rec.get("sensor_type").asString() + "\"}}")
);
add_attribute(body,
"5",
"21.T11148/9a15a4735d4bda329d80",
"\"https://sensor.community\""
new JsonPrimitive("\"https://sensor.community\"")
);
add_attribute(body,
"6",
"21.T11148/4eaec4bc0f1df68ab2a7",
"{\"Owners\":[{\"Owner\":{\"ownerName\":\"SensorCommunity\",\"ownerContact\":\"contact@open-forecast.eu\"}}]}"
new JsonPrimitive("{\"Owners\":[{\"Owner\":{\"ownerName\":\"SensorCommunity\",\"ownerContact\":\"contact@open-forecast.eu\"}}]}")
);
add_attribute(body,
"7",
"21.T11148/1f3e82ddf0697a497432",
"{\"Manufacturers\":[{\"Manufacturer\":{\"manufacturerName\":\""+ rec.get("manufacturer").asString() +"\"}}]}"
new JsonPrimitive("{\"Manufacturers\":[{\"Manufacturer\":{\"manufacturerName\":\""+ rec.get("manufacturer").asString() +"\"}}]}")
);
if (!rec.get("description").isNull()) {
add_attribute(body,
"8",
"21.T11148/55f8ebc805e65b5b71dd",
"\""+ rec.get("description") +"\""
new JsonPrimitive("\""+ rec.get("description") +"\"")
);
}
if (!rec.get("s.pid").isNull()) {
add_attribute(body,
"9",
"21.T11148/8eb858ee0b12e8e463a5",
"{\"identifier-general-with-type\":{\"identifierValue\":\""+ rec.get("s.pid") +"\", \"identifierType\":\"Handle\"}}"
new JsonPrimitive("{\"identifier-general-with-type\":{\"identifierValue\":\""+ rec.get("s.pid") +"\", \"identifierType\":\"Handle\"}}")
);
}
// add_attribute(body,
......@@ -123,11 +145,12 @@ class Sensor {
}
}
private void add_attribute(JsonArray body, String registered_type, String parsed_data) {
private void add_attribute(JsonObject body, String index, String type, JsonElement data) {
JsonObject obj = new JsonObject();
obj.addProperty("type", registered_type);
obj.addProperty("parsed_data", parsed_data);
body.add(obj);
obj.addProperty("index", index);
obj.addProperty("type", type);
obj.add("data", data);
body.getAsJsonArray("values").add(obj);
}
private Query get_creation_query() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment