diff --git a/pic-sure-resources/pic-sure-aggregate-data-sharing-resource/src/main/java/edu/harvard/hms/dbmi/avillach/AggregateDataSharingResourceRS.java b/pic-sure-resources/pic-sure-aggregate-data-sharing-resource/src/main/java/edu/harvard/hms/dbmi/avillach/AggregateDataSharingResourceRS.java index 686af051..31fc5e08 100644 --- a/pic-sure-resources/pic-sure-aggregate-data-sharing-resource/src/main/java/edu/harvard/hms/dbmi/avillach/AggregateDataSharingResourceRS.java +++ b/pic-sure-resources/pic-sure-aggregate-data-sharing-resource/src/main/java/edu/harvard/hms/dbmi/avillach/AggregateDataSharingResourceRS.java @@ -526,39 +526,14 @@ protected String processContinuousCrossCounts(String continuousCrossCountRespons // Handle the case where there is no visualization service UUID if (properties.getVisualizationResourceId() != null) { - // convert continuousCrossCountResponse to a map - Map> continuousCrossCounts = objectMapper.readValue(continuousCrossCountResponse, new TypeReference>>() { - }); + Map> continuousCrossCounts = objectMapper.readValue(continuousCrossCountResponse, new TypeReference<>() {}); + Map> binnedContinuousCrossCounts = getBinnedContinuousCrossCount(queryRequest, continuousCrossCounts); - // Create Query for Visualization /bin/continuous - QueryRequest visualizationBinRequest = new QueryRequest(); - visualizationBinRequest.setResourceUUID(properties.getVisualizationResourceId()); - visualizationBinRequest.setQuery(continuousCrossCounts); - visualizationBinRequest.setResourceCredentials(queryRequest.getResourceCredentials()); + // Log the binned continuous cross counts + logger.info("Binned continuous cross counts: {}", binnedContinuousCrossCounts); - Resource visResource = resourceRepository.getById(visualizationBinRequest.getResourceUUID()); - if (visResource == null) { - throw new ApplicationException("Visualization resource could not be found"); - } - - // call the binning endpoint - HttpResponse httpResponse = getHttpResponse(visualizationBinRequest, visualizationBinRequest.getResourceUUID(), "/bin/continuous", visResource.getResourceRSPath()); - HttpEntity entity = httpResponse.getEntity(); - String binResponse = EntityUtils.toString(entity, "UTF-8"); - - Map> binnedContinuousCrossCounts = objectMapper.readValue(binResponse, new TypeReference>>() { - }); - - // TODO: Return to this code. I would rather not need to keep converting the data back and forth from int to string. - // Convert binnedContinuousCrossCounts Map to a map> - Map> convertedContinuousCrossCount = new HashMap<>(); - binnedContinuousCrossCounts.forEach((key, value) -> { - Map innerMap = new HashMap<>(value); - convertedContinuousCrossCount.put(key, innerMap); - }); - - if (mustObfuscate || doObfuscateData(convertedContinuousCrossCount)) { - obfuscatedCrossCount(generatedVariance, convertedContinuousCrossCount); + if (mustObfuscate || doObfuscateData(binnedContinuousCrossCounts)) { + obfuscatedCrossCount(generatedVariance, binnedContinuousCrossCounts); } return objectMapper.writeValueAsString(binnedContinuousCrossCounts); @@ -568,19 +543,32 @@ protected String processContinuousCrossCounts(String continuousCrossCountRespons return continuousCrossCountResponse; } - Map> continuousCrossCounts = objectMapper.readValue(continuousCrossCountResponse, new TypeReference>>() { - }); + Map> continuousCrossCounts = objectMapper.readValue(continuousCrossCountResponse, new TypeReference<>() {}); - // Convert continuousCrossCounts Map to a map> - Map> convertedContinuousCrossCount = new HashMap<>(); - continuousCrossCounts.forEach((key, value) -> { - Map innerMap = new HashMap<>(value); - convertedContinuousCrossCount.put(key, innerMap); - }); + obfuscatedCrossCount(generatedVariance, continuousCrossCounts); + return objectMapper.writeValueAsString(continuousCrossCounts); + } + } - obfuscatedCrossCount(generatedVariance, convertedContinuousCrossCount); - return objectMapper.writeValueAsString(convertedContinuousCrossCount); + private Map> getBinnedContinuousCrossCount(QueryRequest queryRequest, Map> continuousCrossCounts) throws IOException { + // Create Query for Visualization /bin/continuous + QueryRequest visualizationBinRequest = new QueryRequest(); + visualizationBinRequest.setResourceUUID(properties.getVisualizationResourceId()); + visualizationBinRequest.setQuery(continuousCrossCounts); + visualizationBinRequest.setResourceCredentials(queryRequest.getResourceCredentials()); + + Resource visResource = resourceRepository.getById(visualizationBinRequest.getResourceUUID()); + if (visResource == null) { + throw new ApplicationException("Visualization resource could not be found"); } + + // call the binning endpoint + HttpResponse httpResponse = getHttpResponse(visualizationBinRequest, visualizationBinRequest.getResourceUUID(), "/bin/continuous", visResource.getResourceRSPath()); + HttpEntity entity = httpResponse.getEntity(); + String binResponse = EntityUtils.toString(entity, "UTF-8"); + + return objectMapper.readValue(binResponse, new TypeReference>>() { + }); } /** @@ -634,8 +622,6 @@ private static void processResults(Map> categoricalC } /** - * - * * @param categoricalCrossCount The categorical cross count * @return boolean based on if the categorical cross count needs to be obfuscated */