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
Beispiel #2
0
    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