Skip to content

Commit

Permalink
[ALS-5112] Test Visualization issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Gcolon021 committed Oct 5, 2023
1 parent e5e252e commit 0505890
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ public Response queryFormat(QueryRequest queryRequest) {
}

private Map<String, String> processCrossCounts(String entityString) throws com.fasterxml.jackson.core.JsonProcessingException {
Map<String, String> crossCounts = objectMapper.readValue(entityString, new TypeReference<>() {});
Map<String, String> crossCounts = objectMapper.readValue(entityString, new TypeReference<>() {
});

int requestVariance = generateVarianceWithCrossCounts(crossCounts);
crossCounts = obfuscateCrossCounts(crossCounts, requestVariance);
Expand Down Expand Up @@ -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<String, Map<String, Integer>> continuousCrossCounts = objectMapper.readValue(continuousCrossCountResponse, new TypeReference<Map<String, Map<String, Integer>>>() {
});
// if (properties.getVisualizationResourceId() != null) {
// convert continuousCrossCountResponse to a map
Map<String, Map<String, Integer>> continuousCrossCounts = objectMapper.readValue(continuousCrossCountResponse, new TypeReference<Map<String, Map<String, Integer>>>() {
});

// 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<String, Map<String, Object>> binnedContinuousCrossCounts = objectMapper.readValue(binResponse, new TypeReference<Map<String, Map<String, Object>>>() {
});

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<String, Map<String, Object>> binnedContinuousCrossCounts = objectMapper.readValue(binResponse, new TypeReference<Map<String, Map<String, Object>>>() {
});

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<String, Map<String, Integer>> continuousCrossCounts = objectMapper.readValue(continuousCrossCountResponse, new TypeReference<Map<String, Map<String, Integer>>>() {
});

// Convert continuousCrossCounts Map to a map<String, Map<String, Object>>
Map<String, Map<String, Object>> convertedContinuousCrossCount = new HashMap<>();
continuousCrossCounts.forEach((key, value) -> {
Map<String, Object> 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<String, Map<String, Integer>> continuousCrossCounts = objectMapper.readValue(continuousCrossCountResponse, new TypeReference<Map<String, Map<String, Integer>>>() {
// });
//
// // Convert continuousCrossCounts Map to a map<String, Map<String, Object>>
// Map<String, Map<String, Object>> convertedContinuousCrossCount = new HashMap<>();
// continuousCrossCounts.forEach((key, value) -> {
// Map<String, Object> innerMap = new HashMap<>(value);
// convertedContinuousCrossCount.put(key, innerMap);
// });
//
// obfuscatedCrossCount(generatedVariance, convertedContinuousCrossCount);
// return objectMapper.writeValueAsString(convertedContinuousCrossCount);
// }
}

/**
Expand All @@ -598,7 +601,8 @@ protected String processCategoricalCrossCounts(String categoricalEntityString, S
return null;
}

Map<String, String> crossCounts = objectMapper.readValue(crossCountEntityString, new TypeReference<>() {});
Map<String, String> crossCounts = objectMapper.readValue(crossCountEntityString, new TypeReference<>() {
});
int generatedVariance = this.generateVarianceWithCrossCounts(crossCounts);

boolean mustObfuscate = true;
Expand All @@ -607,7 +611,8 @@ protected String processCategoricalCrossCounts(String categoricalEntityString, S
}

// This might break in the object mapper. We need to test this.
Map<String, Map<String, Integer>> categoricalCrossCount = objectMapper.readValue(categoricalEntityString, new TypeReference<>() {});
Map<String, Map<String, Integer>> categoricalCrossCount = objectMapper.readValue(categoricalEntityString, new TypeReference<>() {
});

if (categoricalCrossCount == null) {
return categoricalEntityString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,13 @@ public List<ContinuousData> getContinuousData(Map<String, Map<String, Integer>>
for (Map.Entry<String, Map<String, Integer>> entry : crossCountsMap.entrySet()) {
String title = getChartTitle(entry.getKey());

// LinkedHashMap<String, Integer> 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<String, Integer> binnedData = new LinkedHashMap<>(bucketData(entry.getValue())); // re-binning data should be safe.
LinkedHashMap<String, Integer> 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,
Expand Down

0 comments on commit 0505890

Please sign in to comment.