src/main/java/au/org/dcw/twitter/ingest/ui/TweetSanitiserUI.java
private String sanitiseJSON(final String tweetJSON, Map<String, Object> fieldsToKeep) {
        try {
            JsonNode root = JSON.readValue(tweetJSON, JsonNode.class);

            stripFields(root, fieldsToKeep);

            /* As of 2017-09-27, Twitter is progressively rolling out 280 character tweets,
             * referred to as "extended tweets", and "text" is replaced by "full_text". I am
             * using Twitter4J in extended mode, but as a courtesy to those still running on
             * standard mode, my "sanitised" objects will have "full_text" copied to "text", if
             * there is no content there already.
             *
             * TODO think of the myriad ways in which the full_text will be hidden and how to extract it
             * - full_text
             * - extended_tweet.full_text
             * - retweeted_status.extended_tweet.full_text
             * - retweeted_status.full_text
             */
            if (root.has("full_text")) {
                ((ObjectNode) root).set("text", root.get("full_text").deepCopy());
            }
            if (root.hasNonNull("truncated") &&
                root.get("truncated").asBoolean(false) &&
                has(root, "extended_tweet.full_text")) {
                ((ObjectNode) root).set("text", get(root, "extended_tweet.full_text").deepCopy());
            }
            // not quite right: missing "RT @originalPoster "
            if (root.hasNonNull("retweeted_status") && has(root, "retweeted_status.full_text")) {
                ((ObjectNode) root).set("text", get(root, "retweeted_status.full_text").deepCopy());
            }
            if (root.hasNonNull("retweeted_status") && has(root, "retweeted_status.extended_tweet.full_text")) {
                ((ObjectNode) root).set("text", get(root, "retweeted_status.extended_tweet.full_text").deepCopy());
            }

            return JSON.writeValueAsString(root);

        } catch (IOException e) {
            e.printStackTrace();
            StringWriter sw = new StringWriter();
            PrintWriter stacktrace = new PrintWriter(sw);
            e.printStackTrace(stacktrace);
            return "{\"error\":\"" + e.getMessage() + "\",\"stacktrace\":\"" + sw.toString() + "\"}";
        }
    }
/**
     * Strips sensitive elements from the Tweet's raw JSON.
     *
     * @param tweetJSON The Tweet's raw JSON.
     * @param fieldsToKeep Keep the fields in this nested map.
     * @return The desensitised JSON.
     */
Strips sensitive elements from the Tweet's raw JSON.
@param tweetJSON The Tweet's raw JSON.
@param fieldsToKeep Keep the fields in this nested map.
@return The desensitised JSON.
Strips sensitive elements from the Tweet ' s raw JSON . @param tweetJSON The Tweet ' s raw JSON . @param fieldsToKeep Keep the fields in this nested map . @return The desensitised JSON .
private String sanitiseJSON(final String tweetJSON, Map<String, Object> fieldsToKeep) {
        try {
            JsonNode root = JSON.readValue(tweetJSON, JsonNode.class);
            stripFields(root, fieldsToKeep);
            /* As of 2017-09-27, Twitter is progressively rolling out 280 character tweets,
             * referred to as "extended tweets", and "text" is replaced by "full_text". I am
             * using Twitter4J in extended mode, but as a courtesy to those still running on
             * standard mode, my "sanitised" objects will have "full_text" copied to "text", if
             * there is no content there already.
             *
             * TODO think of the myriad ways in which the full_text will be hidden and how to extract it
             * - full_text
             * - extended_tweet.full_text
             * - retweeted_status.extended_tweet.full_text
             * - retweeted_status.full_text
             */
            if (root.has("full_text")) {
                ((ObjectNode) root).set("text", root.get("full_text").deepCopy());
            }
            if (root.hasNonNull("truncated") &&
                root.get("truncated").asBoolean(false) &&
                has(root, "extended_tweet.full_text")) {
                ((ObjectNode) root).set("text", get(root, "extended_tweet.full_text").deepCopy());
            }
            if (root.hasNonNull("retweeted_status") && has(root, "retweeted_status.full_text")) {
                ((ObjectNode) root).set("text", get(root, "retweeted_status.full_text").deepCopy());
            }
            if (root.hasNonNull("retweeted_status") && has(root, "retweeted_status.extended_tweet.full_text")) {
                ((ObjectNode) root).set("text", get(root, "retweeted_status.extended_tweet.full_text").deepCopy());
            }
            return JSON.writeValueAsString(root);
        } catch (IOException e) {
            e.printStackTrace();
            StringWriter sw = new StringWriter();
            PrintWriter stacktrace = new PrintWriter(sw);
            e.printStackTrace(stacktrace);
            return "{\"error\":\"" + e.getMessage() + "\",\"stacktrace\":\"" + sw.toString() + "\"}";
        }
    }
private String sanitiseJSON ( final String tweetJSON , Map < String , Object > fieldsToKeep ) { try { JsonNode root = JSON . readValue ( tweetJSON , JsonNode . class ) ; stripFields ( root , fieldsToKeep ) ; /* As of 2017-09-27, Twitter is progressively rolling out 280 character tweets,
             * referred to as "extended tweets", and "text" is replaced by "full_text". I am
             * using Twitter4J in extended mode, but as a courtesy to those still running on
             * standard mode, my "sanitised" objects will have "full_text" copied to "text", if
             * there is no content there already.
             *
             * TODO think of the myriad ways in which the full_text will be hidden and how to extract it
             * - full_text
             * - extended_tweet.full_text
             * - retweeted_status.extended_tweet.full_text
             * - retweeted_status.full_text
             */ if ( root . has ( "full_text" ) ) { ( ( ObjectNode ) root ) . set ( "text" , root . get ( "full_text" ) . deepCopy ( ) ) ; } if ( root . hasNonNull ( "truncated" ) && root . get ( "truncated" ) . asBoolean ( false ) && has ( root , "extended_tweet.full_text" ) ) { ( ( ObjectNode ) root ) . set ( "text" , get ( root , "extended_tweet.full_text" ) . deepCopy ( ) ) ; } if ( root . hasNonNull ( "retweeted_status" ) && has ( root , "retweeted_status.full_text" ) ) { ( ( ObjectNode ) root ) . set ( "text" , get ( root , "retweeted_status.full_text" ) . deepCopy ( ) ) ; } if ( root . hasNonNull ( "retweeted_status" ) && has ( root , "retweeted_status.extended_tweet.full_text" ) ) { ( ( ObjectNode ) root ) . set ( "text" , get ( root , "retweeted_status.extended_tweet.full_text" ) . deepCopy ( ) ) ; } return JSON . writeValueAsString ( root ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; StringWriter sw = new StringWriter ( ) ; PrintWriter stacktrace = new PrintWriter ( sw ) ; e . printStackTrace ( stacktrace ) ; return "{\"error\":\"" + e . getMessage ( ) + "\",\"stacktrace\":\"" + sw . toString ( ) + "\"}" ; } }
Strips sensitive elements from the Tweet's raw JSON.
Strips sensitive elements from the Tweet ' s raw JSON .
// not quite right: missing "RT @originalPoster "