private void publishRelations ( JsonSimple response , String oid ) throws TransactionException { log . debug ( "Publishing Children of '{}'" , oid ) ; JsonSimple data = getDataFromStorage ( oid ) ; if ( data == null ) { log . error ( "Error accessing item data! '{}'" , oid ) ; emailObjectLink ( response , oid , "An error occured publishing the related objects for this" + " record. Please check the system logs." ) ; return ; } JSONArray relations = data . writeArray ( "relationships" ) ; for ( Object relation : relations ) { JsonSimple json = new JsonSimple ( ( JsonObject ) relation ) ; String broker = json . getString ( null , "broker" ) ; boolean localRecord = broker . equals ( brokerUrl ) ; String relatedId = json . getString ( null , "identifier" ) ; // We need to find OIDs to match IDs (only for local records) String relatedOid = json . getString ( null , "oid" ) ; if ( relatedOid == null && localRecord ) { String identifier = json . getString ( null , "identifier" ) ; if ( identifier == null ) { log . error ( "NULL identifer provided!" ) ; } relatedOid = idToOid ( identifier ) ; if ( relatedOid == null ) { log . error ( "Cannot resolve identifer: '{}'" , identifier ) ; } } // We only publish downstream relations (ie. we are their authority) boolean authority = json . getBoolean ( false , "authority" ) ; boolean relationPublishRequested = json . getBoolean ( false , "relationPublishedRequested" ) ; if ( authority && ! relationPublishRequested ) { // Is this relationship using a curated ID? boolean isCurated = json . getBoolean ( false , "isCurated" ) ; if ( isCurated ) { log . debug ( " * Publishing '{}'" , relatedId ) ; // It is a local object if ( localRecord ) { createTask ( response , relatedOid , "publish" ) ; // Or remote } else { JsonObject task = createTask ( response , broker , relatedOid , "publish" ) ; // We won't know OIDs for remote systems task . remove ( "oid" ) ; task . put ( "identifier" , relatedId ) ; } log . debug ( " * Writing relationPublishedRequested for '{}'" , relatedId ) ; json . getJsonObject ( ) . put ( "relationPublishedRequested" , true ) ; saveObjectData ( data , oid ) ; } else { log . debug ( " * Ignoring non-curated relationship '{}'" , relatedId ) ; } } } }
Send out requests to all relations to publish