def updateLocalRecordRelations(self, jobItems): oidIdentifierMap = HashMap() for jobItem in jobItems: oidIdentifierMap.put(jobItem.get("oid"),jobItem.get("required_identifiers")[0].get("identifier")) for jobItem in jobItems: type = jobItem.get("type"); targetSystem = self.systemConfig.getString(None, "curation", "supported-types", type); if targetSystem == "redbox": oid = jobItem.get("oid") digitalObject = StorageUtils.getDigitalObject(self.services.getStorage(), oid) tfPackagePid = self.getPackageData(digitalObject) metadataJsonPayload = digitalObject.getPayload(tfPackagePid) metadataJsonInstream = metadataJsonPayload.open() metadataJson = JsonSimple(metadataJsonInstream) metadataJsonPayload.close() relationships = metadataJson.getArray("relationships") if relationships is not None: for relationship in relationships: system = relationship.get("system") if system != "redbox" or system != None: url = self.systemConfig.getString("can't find it", "curation","external-system-urls","get-oid-for-identifier",system) client = BasicHttpClient(url+ "&identifier="+relationship.get("identifier")) get = GetMethod(url+ "&identifier="+relationship.get("identifier")) client.executeMethod(get) if get.getStatusCode() == 200: response = JsonSimple(get.getResponseBodyAsString()) relationship.put("curatedPid",oidIdentifierMap.get(response.getString(None,"oid"))) relationship.put("isCurated",True) #Now update the relationship on Mint's side break istream = ByteArrayInputStream(String(metadataJson.toString(True)).getBytes()) StorageUtils.createOrUpdatePayload(digitalObject,tfPackagePid,istream)
def notifyExternalRelationship(self, relationship,pid,system,identifier): try: url = self.systemConfig.getString(None, "curation","external-system-urls","notify-curation",system) self.writer.println(url+ "&relationship=isCollectedBy&curatedPid="+pid+"&identifier="+relationship.get("identifier")+"&system="+self.systemConfig.getString(None,"system")+"&sourceIdentifier="+identifier) client = BasicHttpClient(url+ "&relationship=isCollectedBy&curatedPid="+pid+"&identifier="+relationship.get("identifier")+"&system="+self.systemConfig.getString(None,"system")+"&sourceIdentifier="+identifier) get = GetMethod(url+ "&relationship=isCollectedBy&curatedPid="+pid+"&identifier="+relationship.get("identifier")+"&system="+self.systemConfig.getString(None,"system")+"&sourceIdentifier="+identifier) client.executeMethod(get) status = get.getStatusCode() if status != 200: text = get.getStatusText() self.log.error(String.format("Error accessing ReDBox: %s %s",status, text)); return None; except Exception, ex: return None;
def notifyExternalRelationship(self,relationship,pid,system,identifier): try: url = self.systemConfig.getString(None, "curation","external-system-urls","notify-curation",system) url = "http://localhost:9001/default/api/notifyCuration.script?apiKey=1412412412241" completeUrl = url+ "&relationship=isCollectorOf&curatedPid="+pid+"&identifier="+relationship.get("identifier")+"&system="+self.systemConfig.getString("redbox","system")+"&sourceIdentifier="+identifier self.writer.println("the completeUrl: "+ completeUrl) client = BasicHttpClient(completeUrl) get = GetMethod(completeUrl) client.executeMethod(get) status = get.getStatusCode() if status != 200: text = get.getStatusText() self.log.error(String.format("Error accessing Mint",status, text)); return None; except Exception, ex: return None;
def queryJobStatus(self, curationJob): relations = ArrayList() get = None try: url = self.systemConfig.getString(None, "curation","curation-manager-url") client = BasicHttpClient(url + "/job/"+ curationJob.getCurationJobId()) get = GetMethod(url+ "/job/"+ curationJob.getCurationJobId()) client.executeMethod(get) status = get.getStatusCode() if status != 200: text = get.getStatusText() self.log.error(String.format("Error accessing Curation Manager, status code '%d' returned with message: %s",status, text)); return None; except Exception, ex: return None;
def queryJobStatus(self, curationJob): relations = ArrayList() get = None try: url = self.systemConfig.getString(None, "curation", "curation-manager-url") client = BasicHttpClient(url + "/job/" + curationJob.getCurationJobId()) get = GetMethod(url + "/job/" + curationJob.getCurationJobId()) client.executeMethod(get) status = get.getStatusCode() if status != 200: text = get.getStatusText() self.log.error( String.format( "Error accessing Curation Manager, status code '%d' returned with message: %s", status, text)) return None except Exception, ex: return None
def notifyExternalRelationship(self, relationship, pid, system, identifier): try: url = self.systemConfig.getString(None, "curation", "external-system-urls", "notify-curation", system) url = "http://localhost:9001/default/api/notifyCuration.script?apiKey=1412412412241" completeUrl = url + "&relationship=isCollectorOf&curatedPid=" + pid + "&identifier=" + relationship.get( "identifier") + "&system=" + self.systemConfig.getString( "redbox", "system") + "&sourceIdentifier=" + identifier self.writer.println("the completeUrl: " + completeUrl) client = BasicHttpClient(completeUrl) get = GetMethod(completeUrl) client.executeMethod(get) status = get.getStatusCode() if status != 200: text = get.getStatusText() self.log.error( String.format("Error accessing Mint", status, text)) return None except Exception, ex: return None