Esempio n. 1
0
    def _get_by_pid(self, pid, sysmeta=None, mn_client=None, cn_client=None):
        """ Return DataObject
        """
        if pid is None:
            raise Exception("Missing pid")

        fname = utils.get_object_by_pid(pid, resolve=True, mn_client=mn_client, cn_client=cn_client)
        if fname:
            meta = sysmeta
            if not meta:
                meta = utils.get_sysmeta_by_pid(pid, True)
            url = utils.create_get_url_for_pid(mn_client.base_url, pid)
            return DataObject(pid, False, fname, url, meta, meta.formatId, None)
        else:
            return None
Esempio n. 2
0
    def scimeta_add(self, pid, file_name=None, format_id=None, **kwargs):
        """ Add a scimeta object.
        """
        if not pid:
            raise Exception("Missing the pid")
        # if (self.scimeta and not
        #                       cli_util.confirm('Do you wish to delete the existing science metadata object?')):
        #   return
        else:
            self.scimeta = None

        if not file_name:
            new_meta = utils.get_sysmeta_by_pid(pid, True)
            if not new_meta:
                raise Exception("Couldn't find scimeta in DataONE, and there was no file specified.")
            if not self._is_metadata_format(new_meta.formatId):
                raise Exception('"%s" is not an allowable science metadata type.' % new_meta.formatId)
            new_pid = new_meta.identifier.value()
            if new_pid != pid:
                pid = new_pid

            self.scimeta = self._get_by_pid(pid, new_meta)
            authMN = new_meta.authoritativeMemberNode
            if authMN:
                baseURL = utils.get_baseUrl(authMN.value())
                if baseURL:
                    self.scimeta.url = utils.create_get_url_for_pid(baseURL, pid)

        else:
            complex_path = utils.create_complex_path(file_name)
            if not os.path.exists(complex_path.path):
                raise Exception("%s: file not found" % complex_path.path)
            if not format_id:
                format_id = complex_path.formatId
            if not format_id and configuration.check("format"):
                format_id = configuration.format
            if not format_id:
                raise Exception("The object format could not be determined and was not defined.")
            if not self._is_metadata_format(format_id):
                raise Exception('"%s" is not an allowable science metadata type.' % new_meta.formatId)
                return
            #
            sysmeta = utils.create_sysmeta_from_path(pid, complex_path.path, format_id=format_id, **kwargs)
            self.scimeta = DataObject(pid, True, complex_path.path, None, sysmeta, format_id)
        scidata_list = self._find_scidata(self.scimeta)
        if scidata_list:
            for scidata in scidata_list:
                self.scidata_add(scidata.pid, scidata.fname)
Esempio n. 3
0
    def scidata_add(self, pid, file_name=None, format_id=None, **kwargs):
        """ Add a science data object to the list.
        """
        if not pid:
            raise Exception("Missing the pid")

        if file_name:
            # if utils.get_sysmeta_by_pid(pid):
            #   if not cli_util.confirm('That pid (%s) already exists in DataONE.  Continue?' % pid):
            #     return
            #   raise Exception("The identifer (%s) already exists in DataONE." % pid)

            complex_path = utils.create_complex_path(file_name)
            if not format_id:
                format_id = complex_path.formatId
            if not format_id and configuration.check("format"):
                format_id = configuration.format
            if not format_id:
                raise Exception("The object format could not be determined and was not defined.")
            meta = utils.create_sysmeta_from_path(pid, complex_path.path, format_id=format_id, **kwargs)
            self.scidata_dict[pid] = DataObject(pid, True, complex_path.path, None, meta, format_id)

        else:
            sysmeta = utils.get_sysmeta_by_pid(pid, True)
            if not sysmeta:
                raise Exception("The identifier (%s) was not found in DataONE." % pid)
            else:
                pid = sysmeta.identifier.value()
                # if pid in self.scidata_dict:
                #   if not cli_util.confirm('That science data object (%s) is already in the package.  Replace?' % pid):
                #     return
                # Get the scidata object.
                scidata = self._get_by_pid(pid, sysmeta)
                authMN = sysmeta.authoritativeMemberNode
                if authMN:
                    baseURL = utils.get_baseUrl(authMN.value())
                    if baseURL:
                        scidata.url = utils.create_get_url_for_pid(baseURL, pid)
                self.scidata_dict[pid] = scidata
Esempio n. 4
0
    def _generate_resmap(self, mn_client_base_url):
        """ Create a package.
        """
        # Create the aggregation
        foresite.utils.namespaces["cito"] = Namespace("http://purl.org/spar/cito/")
        aggr = foresite.Aggregation(self.pid)
        aggr._dcterms.title = "Simple aggregation of science metadata and data."

        # Create a reference to the science metadata
        uri_scimeta = URIRef(self.scimeta.url)
        res_scimeta = foresite.AggregatedResource(uri_scimeta)
        res_scimeta._dcterms.identifier = self.scimeta.pid
        res_scimeta._dcterms.description = "Science metadata object."

        # Create references to the science data
        resource_list = []
        for scidata in self.scidata_dict.values():
            uri_scidata = URIRef(scidata.url)
            res_scidata = foresite.AggregatedResource(uri_scidata)
            res_scidata._dcterms.identifier = scidata.pid
            res_scidata._dcterms.description = "Science data object"
            res_scidata._cito.isDocumentedBy = uri_scimeta
            res_scimeta._cito.documents = uri_scidata
            resource_list.append(res_scidata)

        # Add all the resources.
        aggr.add_resource(res_scimeta)
        for resource in resource_list:
            aggr.add_resource(resource)

        # Create the resource map
        resmap_url = utils.create_get_url_for_pid(mn_client_base_url, format(self.pid))
        self.resmap = foresite.ResourceMap(resmap_url)
        self.resmap._dcterms.identifier = self.pid
        self.resmap.set_aggregation(aggr)
        return self.resmap