def oai_mungeMetadata(self): host = '192.168.2.216' http_host = 'http://192.168.2.216' user_name = 'admin' password = '******' id="oai:generic-eprints-org:1086" fields=[ ("relation", "/ww1archives/datasets/"+id+"/dc_manifest_file.rdf")] files =[] metadata_content = """<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#' > <rdf:Description rdf:about=""> <rdfs:seeAlso rdf:resource="dc_manifest_file.rdf" /> </rdf:Description> </rdf:RDF>""" #print "METADATA TO BE MUNGED" + metadata_content # print "resource url: /eprints-maths/datasets/"+id+"/manifest.rdf" #(resp, respdata) = datastore.doHTTP_PUT(metadata_content, resource="/sandbox/datasets/TestSubmission/manifest.rdf", expect_type="text/plain") #(reqtype, reqdata) = SparqlQueryTestCase.encode_multipart_formdata(fields, files) putRequest = HTTPRequest(endpointhost=host) putRequest.setRequestUserPass(endpointuser=user_name, endpointpass=password) (resp,respdata) = putRequest.doHTTP_PUT( metadata_content, resource="/ww1archives/datasets/"+id+"/manifest.rdf") # os.remove(self.dc_data_file) #LHobtained = resp.getheader('Content-Location', None) #LHexpected = "%sdatasets/TestSubmission"%self._endpointpath #self.assertEquals(LHobtained, LHexpected, 'Content-Location not correct') return
def oai_createDataset(self, src, silo, identifier, embargoed=False, embargoed_until=False): # Create a new dataset, check response id = self.oai_getDCMetadata(src, identifier, silo) fields = \ [ ("id",id) ] if embargoed != None: if embargoed: fields.append(('embargoed', 'True')) else: fields.append(('embargoed', 'False')) if embargoed_until != None: if embargoed_until == True: fields.append(('embargoed_until', 'True')) elif embargoed_until == False: fields.append(('embargoed_until', 'False')) else: fields.append(('embargoed_until', embargoed_until)) dc_manifest_file = open(self.dc_data_file).read() user_name = 'admin' password = '******' host = 'datafinder-d2v.bodleian.ox.ac.uk' http_host = 'http://datafinder-d2v.bodleian.ox.ac.uk' # Post the harvested oai_dc metadata file to the dataset fields=[] files = [ ("file", "dc_manifest_file.rdf", dc_manifest_file, "application/rdf+xml")] (reqtype, reqdata) = SparqlQueryTestCase.encode_multipart_formdata(fields, files) postRequest = HTTPRequest(endpointhost=host) postRequest.setRequestUserPass(endpointuser=user_name, endpointpass=password) (resp,respdata) = postRequest.doHTTP_POST(reqdata, reqtype, resource="/ADS/datasets/" + id + "/") #Submit the main manifest file which as the see also fields=[] main_manifest_filename = 'manifest.rdf' main_manifest = open(main_manifest_filename).read() #print main_manifest files = [("file", "manifest.rdf", main_manifest, "application/rdf+xml")] (reqtype, reqdata) = SparqlQueryTestCase.encode_multipart_formdata(fields, files) (resp,respdata) = postRequest.doHTTP_POST(reqdata, reqtype, resource="/ADS/datasets/" + id + "/") return
worker_number = "1" worker_section = "worker_solr" rq = Redis() b = BroadcastToRedis("localhost", "silochanges") b.creation(silo_name, item_id) # line = rq.spop("{\"_timestamp\": \"2013-05-16T18:03:24.125059\", \"type\": \"c\", \"id\": \"datafinder_1\", \"silo\": \"DataFinder\"}") # msg = json.loads(line) user_name = "admin" password = "******" datastore = HTTPRequest(endpointhost="10.0.1.154") datastore.setRequestUserPass(endpointuser=user_name, endpointpass=password) (resp, respdata) = datastore.doHTTP_GET(resource="/" + silo_name + "/states/" + item_id) # print str(respdata) json_data = json.loads(respdata) uuid = json_data["state"]["metadata"]["uuid"] (resp, respdata) = datastore.doHTTP_GET(resource="/" + silo_name + "/datasets/" + item_id + "/manifest.rdf") # print respdata text_file = open("sample_redis_manifest.rdf", "w") text_file.write(respdata) text_file.close() graph = rdflib.Graph() try: with open("sample_redis_manifest.rdf", "r") as f: graph.parse(f, base="sample_redis_manifest.rdf")
def oai_createDataset(self, src, silo, identifier, embargoed=None, embargoed_until=None): # Create a new dataset, check response metadata = self.oai_getDCMetadata(src, identifier, silo) id = metadata["identifier"] #id = id.replace('.','-') fields = \ [ ("id",id) # ("source", metadata["source"]), # ("creator", metadata["creator"]), # ("subject", metadata["subject"]), # ("date",metadata["date"]), # ("relation", metadata["relation"]), # ("title", metadata["title"]), # ("type", metadata["type"]) ] if embargoed != None: if embargoed: fields.append(('embargoed', 'True')) else: fields.append(('embargoed', 'False')) if embargoed_until != None: if embargoed_until == True: fields.append(('embargoed_until', 'True')) elif embargoed_until == False: fields.append(('embargoed_until', 'False')) else: fields.append(('embargoed_until', embargoed_until)) dc_manifest_file = open(self.dc_data_file).read() user_name = 'admin' password = '******' host = 'datafinder-d2v' http_host = 'http://datafinder-d2v' # Create a dataset files =[] (reqtype, reqdata) = SparqlQueryTestCase.encode_multipart_formdata(fields, files) postRequest = HTTPRequest(endpointhost=host) postRequest.setRequestUserPass(endpointuser=user_name, endpointpass=password) (resp,respdata) = postRequest.doHTTP_POST( reqdata, reqtype, resource="/ww1archives/datasets/") # Post the harvested oai_dc metadata file to the dataset fields=[] files = \ [ ("file", "dc_manifest_file.rdf", dc_manifest_file, "application/rdf") ] (reqtype, reqdata) = SparqlQueryTestCase.encode_multipart_formdata(fields, files) postRequest = HTTPRequest(endpointhost=host) postRequest.setRequestUserPass(endpointuser=user_name, endpointpass=password) (resp,respdata) = postRequest.doHTTP_POST( reqdata, reqtype, resource="/ww1archives/datasets/"+id) #<rdf:Description rdf:resource="http://example.org/testrdf.zip"> # Add the dc:relation into the main manifest file that related to the oai_dc manifest file fields=[ ("relation", "/ww1archives/datasets/"+id+"/dc_manifest_file.rdf")] files =[] metadata_content = """<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#' > <rdf:Description rdf:about=""> <rdfs:seeAlso rdf:resource="dc_manifest_file.rdf"/> </rdf:Description> </rdf:RDF>""" print "METADATA TO BE MUNGED" + metadata_content print "resource url: /ww1archives/datasets/"+id+"/manifest.rdf" putRequest = HTTPRequest(endpointhost=host) putRequest.setRequestUserPass(endpointuser=user_name, endpointpass=password) (resp,respdata) = putRequest.doHTTP_PUT( metadata_content, resource="/ww1archives/datasets/"+id+"/manifest.rdf") #(reqtype, reqdata) = SparqlQueryTestCase.encode_multipart_formdata(fields, files) # # os.remove(self.dc_data_file) #LHobtained = resp.getheader('Content-Location', None) #LHexpected = "%sdatasets/TestSubmission"%self._endpointpath #self.assertEquals(LHobtained, LHexpected, 'Content-Location not correct') return