From defbc6dc3edc779832cb9de66a2b07211a7b5874 Mon Sep 17 00:00:00 2001 From: redmitry Date: Thu, 1 Feb 2024 16:49:09 +0100 Subject: [PATCH] sprint start --- pom.xml | 2 +- .../engine/BeaconNetworkResponseBuilder.java | 37 ++++++++----------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/pom.xml b/pom.xml index 4eb628d..4b3d9a8 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 es.bsc.inb.ga4gh beacon-network-v2 - 0.0.10 + 0.0.11-SNAPSHOT war diff --git a/src/main/java/es/bsc/inb/ga4gh/beacon/network/engine/BeaconNetworkResponseBuilder.java b/src/main/java/es/bsc/inb/ga4gh/beacon/network/engine/BeaconNetworkResponseBuilder.java index d45939f..984e0c8 100644 --- a/src/main/java/es/bsc/inb/ga4gh/beacon/network/engine/BeaconNetworkResponseBuilder.java +++ b/src/main/java/es/bsc/inb/ga4gh/beacon/network/engine/BeaconNetworkResponseBuilder.java @@ -82,7 +82,7 @@ public Response build( BeaconRequestQuery query, List>> invocations) { - AbstractBeaconResponse aggregated = null; + AbstractBeaconResponse aggregated; final List beacons_responses = getResultsets(invocations); @@ -101,25 +101,19 @@ public Response build( aggregated = response; } else { final BeaconResultsetsResponse response = new BeaconResultsetsResponse(); + final BeaconResultsets resultsets = new BeaconResultsets(); + + response.setResponse(resultsets); response.setMeta(new BeaconResponseMeta()); response.setResponseSummary(new BeaconResponseSummary(false)); - + for (AbstractBeaconResponse beacon_response : beacons_responses) { if (beacon_response instanceof BeaconResultsetsResponse res) { mergeMeta(response, res); mergeResultsets(response, res); mergeSummary(response, res); - } - } - aggregated = response; - } - - if (aggregated instanceof BeaconResultsetsResponse resultsets) { - BeaconResultsets results = resultsets.getResponse(); - - for (AbstractBeaconResponse beacon_response : beacons_responses) { - if (beacon_response instanceof BeaconErrorResponse err) { - BeaconResultset empty = new BeaconResultset(); + } else if (beacon_response instanceof BeaconErrorResponse err) { + final BeaconResultset empty = new BeaconResultset(); empty.setExists(false); BeaconError error = err.getBeaconError(); if (error != null) { @@ -133,16 +127,20 @@ public Response build( empty.setInfo(Json.createObjectBuilder().add("error", b).build()); } - BeaconResponseMeta err_meta = err.getMeta(); + final BeaconResponseMeta err_meta = err.getMeta(); if (err_meta != null) { empty.setBeaconId(err_meta.getBeaconId()); } + + List list = resultsets.getResultSets(); + if (list == null) { + resultsets.setResultSets(list = new ArrayList()); + } - results.getResultSets().add(empty); + list.add(empty); } } - } else { - aggregated = new BeaconErrorResponse(); // todo + aggregated = response; } final BeaconResponseMeta beacon_network_response_meta = this.getMeta(meta, query); @@ -184,9 +182,6 @@ private void mergeResultsets(BeaconResultsetsResponse target, BeaconResultsetsRe : source.getMeta().getBeaconId(); BeaconResultsets target_response = target.getResponse(); - if (target_response == null) { - target.setResponse(target_response = new BeaconResultsets()); - } List target_resultsets = target_response.getResultSets(); if (target_resultsets == null) { @@ -208,7 +203,7 @@ private void mergeResultsets(BeaconResultsetsResponse target, BeaconResultsetsRe // emulate a resultset for boolean or count responses BeaconResultset result_set = new BeaconResultset(); - result_set.setId(beacon_id); + result_set.setBeaconId(beacon_id); result_set.setInfo(source.getInfo()); result_set.setResultsHandovers(source.getBeaconHandovers()); BeaconResponseSummary summary = source.getResponseSummary();