List < String > getWarnings ( JsonNode root ) { ArrayList < String > warnings = new ArrayList <> ( ) ; if ( root . has ( "warnings" ) ) { JsonNode warningNode = root . path ( "warnings" ) ; Iterator < Map . Entry < String , JsonNode > > moduleIterator = warningNode . fields ( ) ; while ( moduleIterator . hasNext ( ) ) { Map . Entry < String , JsonNode > moduleNode = moduleIterator . next ( ) ; Iterator < JsonNode > moduleOutputIterator = moduleNode . getValue ( ) . elements ( ) ; while ( moduleOutputIterator . hasNext ( ) ) { JsonNode moduleOutputNode = moduleOutputIterator . next ( ) ; if ( moduleOutputNode . isTextual ( ) ) { warnings . add ( "[" + moduleNode . getKey ( ) + "]: " + moduleOutputNode . textValue ( ) ) ; } else if ( moduleOutputNode . isArray ( ) ) { Iterator < JsonNode > messageIterator = moduleOutputNode . elements ( ) ; while ( messageIterator . hasNext ( ) ) { JsonNode messageNode = messageIterator . next ( ) ; warnings . add ( "[" + moduleNode . getKey ( ) + "]: " + messageNode . path ( "html" ) . path ( "*" ) . asText ( messageNode . toString ( ) ) ) ; } } else { warnings . add ( "[" + moduleNode . getKey ( ) + "]: " + "Warning was not understood. Please report this to Wikidata Toolkit. JSON source: " + moduleOutputNode . toString ( ) ) ; } } } } return warnings ; }
Extracts warnings that are returned in an API response .