コード例 #1
0
ファイル: TestOaiClient.py プロジェクト: bodleian/datafinder
    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
コード例 #2
0
ファイル: TestOaiClient.py プロジェクト: bodleian/datafinder
    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