private boolean isKnownRelation ( JSONArray relations , JsonObject newRelation ) { // Does it have an OID? Highest priority. Avoids infinite loops // between ReDBox collections pointing at each other, so strict if ( newRelation . containsKey ( "oid" ) ) { for ( Object relation : relations ) { JsonObject json = ( JsonObject ) relation ; String knownOid = ( String ) json . get ( "oid" ) ; String newOid = ( String ) newRelation . get ( "oid" ) ; // Do they match? if ( knownOid . equals ( newOid ) ) { log . debug ( "Known ReDBox linkage '{}'" , knownOid ) ; return true ; } } return false ; } // Mint records we are less strict about and happy // to allow multiple links in differing fields. for ( Object relation : relations ) { JsonObject json = ( JsonObject ) relation ; if ( json . containsKey ( "identifier" ) ) { String knownId = ( String ) json . get ( "identifier" ) ; String knownField = ( String ) json . get ( "field" ) ; String newId = ( String ) newRelation . get ( "identifier" ) ; String newField = ( String ) newRelation . get ( "field" ) ; // And does the ID match? if ( knownId . equals ( newId ) && knownField . equals ( newField ) ) { return true ; } } } // No match found return false ; }
Test whether the field provided is already a known relationship