Search in sources :

Example 1 with JsonInputFile

use of com.homeaway.datapullclient.input.JsonInputFile 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;
}
Also used : JsonInputFile(com.homeaway.datapullclient.input.JsonInputFile) AmazonS3(com.amazonaws.services.s3.AmazonS3) InvalidPointedJsonException(com.homeaway.datapullclient.exception.InvalidPointedJsonException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessingException(com.homeaway.datapullclient.exception.ProcessingException)

Aggregations

AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InvalidPointedJsonException (com.homeaway.datapullclient.exception.InvalidPointedJsonException)1 ProcessingException (com.homeaway.datapullclient.exception.ProcessingException)1 JsonInputFile (com.homeaway.datapullclient.input.JsonInputFile)1 IOException (java.io.IOException)1