Ejemplo n.º 1
0
 def purge_ckan(self):
     r = make_ckan_api_call("api/action/vocabulary_delete", {'id': self.id})
     if not r['success']:
         raise CKANAPIException({
             "message": "Impossible to purge vocabulary",
             "vocabulary_id": self.id,
             "reason": r['error']['message']
         })
Ejemplo n.º 2
0
 def purge_ckan(self):
     r = make_ckan_api_call("api/action/organization_purge",
                            {'id': self.key})
     if not r['success']:
         raise CKANAPIException({
             "message": "Impossible to purge organization",
             "organization_key": self.key,
             "reason": r['error']['message']
         })
Ejemplo n.º 3
0
    def purge_ckan(cls, id):
        r = make_ckan_api_call("api/action/dataset_purge", {'id': id})

        if not r['success']:
            raise CKANAPIException({
                "message": "Impossible to purge dataset",
                "dataset": id,
                "error": r['error']
            })
Ejemplo n.º 4
0
def purge_dataset(dataset_name_or_id):
    r = make_ckan_api_call("api/action/dataset_purge",
                           {'id': dataset_name_or_id})

    if not r['success']:
        raise CKANAPIException({
            "message": "Impossible to create dataset",
            "dataset": dataset_name_or_id,
            "error": r['error']
        })
Ejemplo n.º 5
0
def create_dataset(dataset, all_organizations):
    params = {
        'title': dataset.title,
        'name': dataset_title_to_name(dataset.title),
        'notes': dataset.description,
        'owner_org':
        all_organizations[dataset.publishing_organization_key].name,
        'url': urljoin("http://www.gbif.org/dataset/", dataset.uuid),

        # Having difficulties adding extras to the dataset.
        # So far, it works IF the extras parameter is not named extras (myextras is good), and a dict
        # (not a list of dicts) is passed. It is, however, not shown in the web interface later...
        #'extras': [{'dataset_type': dataset.dataset_type}]
        'gbif_uuid': dataset.uuid,

        # A Heavy but perfectly working solution: add the field via a plugin like in the tutorial:
        # http://docs.ckan.org/en/latest/extensions/adding-custom-fields.html
        # Then pass the parameter as a first-class one (title, name, ...) (no list of dicts: just a key and value)
        'dataset_type': dataset.dataset_type,
        'administrative_contact': dataset.administrative_contact_full,
        'administrative_contact_name': dataset.administrative_contact_name,
        'metadata_contact': dataset.metadata_contact,
    }

    if dataset.dwca_url:
        params['dwca_url'] = dataset.dwca_url
    if dataset.website:
        params['dataset_website'] = dataset.website

    r = make_ckan_api_call("api/action/package_create", params)

    if not r['success']:
        raise CKANAPIException({
            "message": "Impossible to create dataset",
            "dataset": dataset,
            "error": r['error']
        })
Ejemplo n.º 6
0
 def create_in_ckan(self, all_organizations):
     params = {
         'title': self.title,
         'name': self.id,  # ie the IPT identifier
         'id': self.
         gbif_uuid,  # ie the GBIF uuio becomes the internal CKAN identifier
         'dataset_type': self.dataset_type,
         'notes': self.description,
         'owner_org':
         all_organizations[self.publishing_organization_key].name,
         'url': urljoin("http://www.gbif.org/dataset/", self.gbif_uuid),
         'administrative_contact_full': self.administrative_contact_full,
         'administrative_contact_name': self.administrative_contact_name,
         'metadata_contact_full': self.metadata_contact_full,
         'metadata_contact_name': self.metadata_contact_name,
         'originator_full': self.originator_full,
         'originator_name': self.originator_name,
         'eml_created': self.metadata_created,
         'eml_modified': self.metadata_modified,
         'maintenance_frequency': self.maintenance_frequency,
         'start_datetime': self.start_datetime,
         'end_datetime': self.end_datetime,
         'geo_desc': self.geo_desc,
         #'occurrences': jsonpickle.encode(self.occurrences),
         'occurrence_count': self.occurrence_count,
         'doi': self.doi,
         'doi_gbif': self.doi_gbif,
         'study_extent': self.study_extent,
         'quality_control': self.quality_control
     }
     if self.dwca_url:
         params['dwca_url'] = self.dwca_url
     if self.website:
         params['dataset_website'] = self.website
     geo_json = self.bounds_to_geojson(northbound_lat=self.northbound_lat,
                                       southbound_lat=self.southbound_lat,
                                       eastbound_lon=self.eastbound_lon,
                                       westbound_lon=self.westbound_lon,
                                       geo_desc=self.geo_desc)
     if geo_json is not None:
         params['extras'] = [{
             'key':
             'spatial',
             'value':
             '{"type": "Polygon","coordinates": ' + geo_json + '}'
         }]
     params['tags'] = []
     for keyword in self.keywords:
         keyword = Keyword.create_in_ckan(keyword)
         if keyword is not None and keyword.name is not None and not "".__eq__(
                 keyword.name.strip()):
             if keyword.vocabulary_id is None:
                 params['tags'].append({'name': keyword.name})
             else:
                 params['tags'].append({
                     'name':
                     keyword.name,
                     'vocabulary_id':
                     keyword.vocabulary_id
                 })
     if license is not None:
         params['license_id'] = self.license_id
     if self.method_steps is not None:
         r = ''
         for i in range(len(self.method_steps)):
             r = r + str(i + 1) + '. ' + self.method_steps[i] + '\n'
         if r != '':
             params['method_steps'] = r
     r = make_ckan_api_call("api/action/package_create", params)
     if r is not None:
         if not r['success']:
             raise CKANAPIException({
                 "message": "Impossible to create dataset",
                 "dataset": self,
                 "error": r['error']
             })
     for resource in self.resources:
         Resource.create_in_ckan(resource)