use of com.homeaway.datapullclient.exception.InvalidPointedJsonException in project datapull by homeaway.
the class DataPullRequestProcessor method extractUserJsonFromS3IfProvided.
public String extractUserJsonFromS3IfProvided(String json, boolean isStart) throws ProcessingException {
List<String> jsonS3PathList = new ArrayList<>();
try {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(json);
while (jsonNode.has("jsoninputfile")) {
JsonNode jsonInputFileNode = jsonNode.path("jsoninputfile");
JsonInputFile jsonInputFile = mapper.treeToValue(jsonInputFileNode, JsonInputFile.class);
String s3path = jsonInputFile.getS3Path();
if (jsonS3PathList.contains(s3path)) {
throw new ProcessingException("JSON is pointing to same JSON.");
}
jsonS3PathList.add(s3path);
AmazonS3 s3Client = config.getS3Client();
String bucketName = s3path.substring(0, s3path.indexOf("/"));
String path = s3path.substring(s3path.indexOf("/") + 1);
json = readFileFromS3(s3Client, bucketName, path);
jsonNode = mapper.readTree(json);
}
} catch (IOException e) {
if (isStart) {
if (jsonS3PathList.size() != 0) {
throw new InvalidPointedJsonException("Invalid input json at path - " + jsonS3PathList.get(jsonS3PathList.size() - 1));
} else {
throw new InvalidPointedJsonException("Invalid input json - " + json);
}
} else {
throw new ProcessingException(e.getMessage());
}
}
return json;
}
Aggregations