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 0e2efafc..6cb332ed 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 @@ -431,7 +431,8 @@ public Response queryFormat(QueryRequest queryRequest) { } private Map processCrossCounts(String entityString) throws com.fasterxml.jackson.core.JsonProcessingException { - Map crossCounts = objectMapper.readValue(entityString, new TypeReference<>() {}); + Map crossCounts = objectMapper.readValue(entityString, new TypeReference<>() { + }); int requestVariance = generateVarianceWithCrossCounts(crossCounts); crossCounts = obfuscateCrossCounts(crossCounts, requestVariance); @@ -520,64 +521,66 @@ protected String processContinuousCrossCounts(String continuousCrossCountRespons boolean mustObfuscate = true; + logger.info("Visualization Resource ID: " + properties.getVisualizationResourceId()); + // TODO: Test if there is a visualization service resource id // 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>>() { - }); +// if (properties.getVisualizationResourceId() != null) { + // convert continuousCrossCountResponse to a map + Map> continuousCrossCounts = objectMapper.readValue(continuousCrossCountResponse, new TypeReference>>() { + }); - // Create Query for Visualization /bin/continuous - QueryRequest visualizationBinRequest = new QueryRequest(); - visualizationBinRequest.setResourceUUID(properties.getVisualizationResourceId()); - visualizationBinRequest.setQuery(continuousCrossCounts); - visualizationBinRequest.setResourceCredentials(queryRequest.getResourceCredentials()); + // 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"); - } + 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"); + // 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>>() { - }); - - if (!mustObfuscate) { - // Ensure all inner values are Strings to be consistent in our returned data. - binnedContinuousCrossCounts.forEach( - (key, value) -> value.forEach( - (innerKey, innerValue) -> value.put(innerKey, innerValue.toString()) - ) - ); + Map> binnedContinuousCrossCounts = objectMapper.readValue(binResponse, new TypeReference>>() { + }); - return objectMapper.writeValueAsString(binnedContinuousCrossCounts); - } + if (!mustObfuscate) { + // Ensure all inner values are Strings to be consistent in our returned data. + binnedContinuousCrossCounts.forEach( + (key, value) -> value.forEach( + (innerKey, innerValue) -> value.put(innerKey, innerValue.toString()) + ) + ); - obfuscatedCrossCount(generatedVariance, binnedContinuousCrossCounts); return objectMapper.writeValueAsString(binnedContinuousCrossCounts); - } else { - // If there is no visualization service resource id, we will simply return the continuous cross count response. - - if (!mustObfuscate) { - return continuousCrossCountResponse; - } - - 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, convertedContinuousCrossCount); - return objectMapper.writeValueAsString(convertedContinuousCrossCount); } + + obfuscatedCrossCount(generatedVariance, binnedContinuousCrossCounts); + return objectMapper.writeValueAsString(binnedContinuousCrossCounts); +// } else { +// // If there is no visualization service resource id, we will simply return the continuous cross count response. +// +// if (!mustObfuscate) { +// return continuousCrossCountResponse; +// } +// +// 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, convertedContinuousCrossCount); +// return objectMapper.writeValueAsString(convertedContinuousCrossCount); +// } } /** @@ -598,7 +601,8 @@ protected String processCategoricalCrossCounts(String categoricalEntityString, S return null; } - Map crossCounts = objectMapper.readValue(crossCountEntityString, new TypeReference<>() {}); + Map crossCounts = objectMapper.readValue(crossCountEntityString, new TypeReference<>() { + }); int generatedVariance = this.generateVarianceWithCrossCounts(crossCounts); boolean mustObfuscate = true; @@ -607,7 +611,8 @@ protected String processCategoricalCrossCounts(String categoricalEntityString, S } // This might break in the object mapper. We need to test this. - Map> categoricalCrossCount = objectMapper.readValue(categoricalEntityString, new TypeReference<>() {}); + Map> categoricalCrossCount = objectMapper.readValue(categoricalEntityString, new TypeReference<>() { + }); if (categoricalCrossCount == null) { return categoricalEntityString; diff --git a/pic-sure-resources/pic-sure-visualization-resource/src/main/java/edu/harvard/hms/dbmi/avillach/resource/visualization/VisualizationResource.java b/pic-sure-resources/pic-sure-visualization-resource/src/main/java/edu/harvard/hms/dbmi/avillach/resource/visualization/VisualizationResource.java index 5249ddd8..f67fa19d 100644 --- a/pic-sure-resources/pic-sure-visualization-resource/src/main/java/edu/harvard/hms/dbmi/avillach/resource/visualization/VisualizationResource.java +++ b/pic-sure-resources/pic-sure-visualization-resource/src/main/java/edu/harvard/hms/dbmi/avillach/resource/visualization/VisualizationResource.java @@ -77,6 +77,7 @@ public Response querySync(QueryRequest query) { String requestSource = null; if (requestScopedHeader != null && requestScopedHeader.getHeaders() != null) { requestSource = requestScopedHeader.getHeaders().get("request-source").get(0); + logger.info("resource=visualization /query/sync query=" + query.getQuery().toString() + " request-source=" + requestSource); } return visualizationService.handleQuerySync(query, requestSource); @@ -99,6 +100,6 @@ public Response queryFormat(QueryRequest resultRequest) { @Path("/bin/continuous") public Response generateContinuousBin(QueryRequest continuousData) { logger.info("resource=visualization /bin/continuous query=" + continuousData.getQuery().toString()); - return visualizationService.generateContinuousBin(continuousData); + return visualizationService.generateContinuousBin(continuousData); } } \ No newline at end of file diff --git a/pic-sure-resources/pic-sure-visualization-resource/src/main/java/edu/harvard/hms/dbmi/avillach/resource/visualization/service/DataProcessingService.java b/pic-sure-resources/pic-sure-visualization-resource/src/main/java/edu/harvard/hms/dbmi/avillach/resource/visualization/service/DataProcessingService.java index 4f998800..15c03a1e 100644 --- a/pic-sure-resources/pic-sure-visualization-resource/src/main/java/edu/harvard/hms/dbmi/avillach/resource/visualization/service/DataProcessingService.java +++ b/pic-sure-resources/pic-sure-visualization-resource/src/main/java/edu/harvard/hms/dbmi/avillach/resource/visualization/service/DataProcessingService.java @@ -87,15 +87,13 @@ public List getContinuousData(Map> for (Map.Entry> entry : crossCountsMap.entrySet()) { String title = getChartTitle(entry.getKey()); -// LinkedHashMap binnedData; -// if (!isOpenAccess) { // If not open access we need to bin the data -// binnedData = new LinkedHashMap<>(bucketData(entry.getValue())); -// } else { -// // If it is obfuscated the data is already binned -// binnedData = new LinkedHashMap<>(entry.getValue()); -// } - - LinkedHashMap binnedData = new LinkedHashMap<>(bucketData(entry.getValue())); // re-binning data should be safe. + LinkedHashMap binnedData; + if (!isOpenAccess) { // If not open access we need to bin the data + binnedData = new LinkedHashMap<>(bucketData(entry.getValue())); + } else { + // If it is obfuscated the data is already binned + binnedData = new LinkedHashMap<>(entry.getValue()); + } continuousDataList.add(new ContinuousData( title,