drop doc id and use correct path

pull/8/head
Medad Rufus Newman 2022-05-07 18:31:33 +01:00
rodzic 0a40f59aeb
commit 8946430b97
2 zmienionych plików z 10 dodań i 32 usunięć

Wyświetl plik

@ -109,12 +109,10 @@ public final class AmateurSondehubUploader {
// encode sentence as raw bytes
byte[] bytes = sentence.getBytes(StandardCharsets.US_ASCII);
// determine docId
String docId = createDocId(bytes);
for (HabReceiver receiver : receivers) {
// create Json
HabitatPayloadTelemetryDoc doc = new HabitatPayloadTelemetryDoc(instant, bytes);
PayloadTelemetryDoc doc = new payloadTelemetryDoc(instant, bytes);
doc.addCallSign(receiver.getCallsign());
String json = doc.format();
@ -127,17 +125,16 @@ public final class AmateurSondehubUploader {
* Performs the actual payload telemetry upload as a REST-like call towards
* amateurSondehub.
*
* @param docId the document id
* @param json the JSON payload
*/
private void uploadPayloadTelemetry(String docId, String json) {
LOG.info("Upload payload telemetry doc {}: {}", docId, json);
private void uploadPayloadTelemetry(String json) {
LOG.info("Upload payload telemetry: {}", json);
try {
Response<String> response = restClient.updateListener(docId, json).execute();
Response<String> response = restClient.updateListener(json).execute();
if (response.isSuccessful()) {
LOG.info("Result payload telemetry doc {}: {}", docId, response.body());
LOG.info("Result payload telemetry: {}", response.body());
} else {
LOG.warn("Result payload telemetry doc {}: {}", docId, response.message());
LOG.warn("Result payload telemetry: {}", response.message());
}
} catch (IOException e) {
LOG.warn("Caught IOException: {}", e.getMessage());
@ -145,17 +142,4 @@ public final class AmateurSondehubUploader {
LOG.error("Caught Exception: {}", e);
}
}
/**
* Creates the document id from the raw payload telemetry sentence.
*
* @param bytes the raw sentence
* @return the document id
*/
private String createDocId(byte[] bytes) {
byte[] base64 = base64Encoder.encode(bytes);
byte[] hash = sha256.digest(base64);
return DatatypeConverter.printHexBinary(hash).toLowerCase(Locale.ROOT);
}
}

Wyświetl plik

@ -3,20 +3,14 @@ package nl.sikken.bertrik.hab.amateurSondehub;
import nl.sikken.bertrik.hab.UploadResult;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.PUT;
import retrofit2.http.Path;
import retrofit2.http.Query;
/**
* Interface definition for payload telemetry and listener telemetry towards AmateurSondehub.
* Interface definition for payload telemetry and listener telemetry towards
* AmateurSondehub.
*/
public interface IAmateurSondehubRestApi {
@PUT("/habitat/_design/payload_telemetry/_update/add_listener/{doc_id}")
Call<String> updateListener(@Path("doc_id") String docId, @Body String json);
@PUT("/habitat/{doc_id}")
Call<UploadResult> uploadDocument(@Path("doc_id") String docId, @Body String document);
@PUT("/amateur/telemetry")
Call<UploadResult> uploadDocument(@Body String document);
}