def convert_package_extra_to_kind(dataset_schema=None, package_extra_list=[PackageExtra]): if not dataset_schema: dataset_schema = DatasetSchemaDcatApOp("") if not package_extra_list: return kind = KindSchemaDcatApOp(uri_util.create_uri_for_schema(KindSchemaDcatApOp), graph_name=dataset_schema.graph_name) for package_extra in package_extra_list: if package_extra.value: if package_extra.key == CONTACT_NAME: length = str(len(kind.organisationDASHname_vcard)) kind.organisationDASHname_vcard[length] = ResourceValue(package_extra.value) elif package_extra.key == CONTACT_EMAIL: length = str(len(kind.hasEmail_vcard)) kind.hasEmail_vcard[length] = SchemaGeneric(package_extra.value, graph_name=dataset_schema.graph_name) elif package_extra.key == CONTACT_TELEPHONE: telephone_number = re.sub('[^+\/0-9]', '', package_extra.value) if telephone_number != package_extra.value: logging.info(u"Migration: {2} telephone number migrated from {0} to {1}".format(package_extra.value, telephone_number, dataset_schema.uri)) if telephone_number: #remove space telephone_number = telephone_number.replace(' ','') telephone = TelephoneSchemaDcatApOp( "telephone-" + package_extra_list[0].id + str(create_blank_node_replacement_uri()), graph_name=dataset_schema.graph_name) length_value = str(len(telephone.hasValue_vcard)) telephone.hasValue_vcard[length_value] = SchemaGeneric( telephone_number, graph_name=dataset_schema.graph_name) telephone.type_rdf['0'] = NAMESPACE_DCATAPOP.vcard + VOICE telephone.type_rdf['1'] = NAMESPACE_DCATAPOP.vcard + WORK length_telephone = str(len(kind.hasTelephone_vcard)) kind.hasTelephone_vcard[length_telephone] = telephone elif package_extra.key == CONTACT_ADDRESS: # TODO: The address could be parses but the data are not formatted correctly. address = AddressSchemaDcatApOp(uri_util.create_uri_for_schema(AddressSchemaDcatApOp), graph_name=dataset_schema.graph_name) length = str(len(address.streetDASHaddress_vcard)) address.streetDASHaddress_vcard[length] = ResourceValue(package_extra.value, datatype=NAMESPACE_DCATAPOP.vcard + ADDRESS) address.postalDASHcode_vcard = "" address.locality_vcard = "" address.countryDASHname_vcard = "" length_address = str(len(kind.hasAddress_vcard)) kind.hasAddress_vcard[length_address] = address elif package_extra.key == CONTACT_WEBPAGE: document = DocumentSchemaDcatApOp(new_documentation_uri(), graph_name=dataset_schema.graph_name) document.url_schema['0'] = ResourceValue(package_extra.value, datatype=NAMESPACE_DCATAPOP.foaf + DOCUMENT) document.topic_foaf['0'] = SchemaGeneric(dataset_schema.uri) document.title_dcterms['0'] = ResourceValue("title_" + document.uri, lang='en') document.type_dcterms['0'] = SchemaGeneric("default_type_dcterms") length = str(len(kind.homePage_foaf)) kind.homePage_foaf[length] = document return kind
def set_home_page(self, data_dict): try: home_pages = data_dict.get('home_page') if home_pages: for home_page in home_pages.split(" "): if home_page: home_page_length = str(len(self.schema.homepage_foaf)) document = DocumentSchemaDcatApOp( uri_util.create_uri_for_schema( DocumentSchemaDcatApOp)) document.url_schema[str(len( document.url_schema))] = ResourceValue(home_page) # TODO add correct default values for the three properties document.topic_foaf['0'] = SchemaGeneric( "default_topic_foaf") document.title_dcterms['0'] = ResourceValue("title_" + home_page) document.type_dcterms['0'] = SchemaGeneric( "default_type_dcterms") self.schema.homepage_foaf[home_page_length] = document except BaseException as e: log.error("Failed to set home page to catalog {0}".format( self.schema.uri))
def set_landing_page(dataset_schema, package): document_schema = DocumentSchemaDcatApOp(uri_util.create_uri_for_schema(DocumentSchemaDcatApOp), graph_name=dataset_schema.graph_name) document_schema.url_schema['0'] = ResourceValue(package.url) document_schema.topic_foaf['0'] = SchemaGeneric(dataset_schema.uri) document_schema.title_dcterms['0'] = ResourceValue("title_" + package.url, lang='en') document_schema.type_dcterms['0'] = SchemaGeneric("default_type_dcterms") dataset_schema.landingPage_dcat[str(len(dataset_schema.landingPage_dcat))] = document_schema
def convert_temporal_coverage(self, date_from, date_to): from ckanext.ecportal.model.schemas.dcatapop_period_of_time_schema import PeriodOfTimeSchemaDcatApOp from ckanext.ecportal.lib.dataset_util import ResourceValue return_dict = {} period = PeriodOfTimeSchemaDcatApOp( uri=uri_util.create_uri_for_schema(PeriodOfTimeSchemaDcatApOp)) if date_from: period.startDate_schema['0'] = ResourceValue(date_from, datatype=XSD.date) if date_to: period.endDate_schema['0'] = ResourceValue(date_to, datatype=XSD.date) if period.startDate_schema or period.endDate_schema: return_dict['0'] = period return return_dict
def set_doi(self, doi): """ Set a DOI for this catalogue. :param str doi: The DOI to set. """ if doi: update_doi = True catalog = CatalogDcatApOp(self.schema.uri) catalog.get_description_from_ts() for dois in catalog.schema.identifier_adms.values(): if hasattr(dois, 'notation_skos'): if dois.notation_skos.get( "0" ).value_or_uri == controlled_vocabulary_util.DOI_URI: update_doi = False self.schema.identifier_adms['0'] = dois break if update_doi: org = ckan_helper.get_organization({"name": "publ"}) identifier = IdentifierSchemaDcatApOp( uri_util.create_uri_for_schema(IdentifierSchemaDcatApOp)) identifier.notation_skos = { "0": ResourceValue(doi, datatype=controlled_vocabulary_util.DOI_URI) } identifier.issued_dcterms = { "0": ResourceValue( datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S'), datatype=XSD.date) } identifier.schemeAgency_adms = {"0": ResourceValue(org[1])} identifier_adms_length = len(self.schema.identifier_adms) self.schema.identifier_adms[str( identifier_adms_length)] = identifier
def convert_contact_point(self, address, email, name, phone, webpage): from ckanext.ecportal.lib.dataset_util import ResourceValue from ckanext.ecportal.model.schemas.dcatapop_kind_schema import KindSchemaDcatApOp, \ TelephoneSchemaDcatApOp, AddressSchemaDcatApOp, DocumentSchemaDcatApOp, SchemaGeneric return_dict = {} kind_schema = KindSchemaDcatApOp( uri_util.create_uri_for_schema(KindSchemaDcatApOp)) # Address if address: address_schema = AddressSchemaDcatApOp( uri_util.create_uri_for_schema(AddressSchemaDcatApOp)) address_schema.streetDASHaddress_vcard = { '0': ResourceValue(address) } kind_schema.hasAddress_vcard = {'0': address_schema} # Email if email: kind_schema.hasEmail_vcard = {'0': SchemaGeneric(email)} pass # name if name: length = str(len(kind_schema.organisationDASHname_vcard)) kind_schema.organisationDASHname_vcard = { length: ResourceValue(name) } # names = name.split(" ") # for name in names: # length = str(len(kind_schema.organisationDASHname_vcard)) # kind_schema.organisationDASHname_vcard = {length: ResourceValue(name)} # phone if phone: phone_schema = TelephoneSchemaDcatApOp( uri_util.create_uri_for_schema(TelephoneSchemaDcatApOp)) phone_schema.hasValue_vcard = {'0': SchemaGeneric(phone)} kind_schema.hasTelephone_vcard = {'0': phone_schema} # Webpage if webpage: webpage_schema = DocumentSchemaDcatApOp( uri_util.create_uri_for_schema(DocumentSchemaDcatApOp)) # TODO, must add default values otherwise the validation will be failed webpage_schema.topic_foaf['0'] = SchemaGeneric( "default_topic_foaf") webpage_schema.title_dcterms['0'] = ResourceValue( "title_default_values", lang='en') webpage_schema.type_dcterms['0'] = SchemaGeneric( "default_type_dcterms") webpage_schema.url_schema = {'0': ResourceValue(webpage)} kind_schema.homePage_foaf = {'0': webpage_schema} if kind_schema: return {'0': kind_schema} else: return return_dict