def _map_xml_item_to_ckan_dataset_dict(root, elem):

    try:
        organization = config['organization']
        orga = ckanapiutils.get_organization_id_from_name(organization)
    except ckanapi.NotFound:
        print("Organization " + organization +
              " not found, please check config")

    dataset_metadata = {}
    dataset_metadata['type'] = config['package_type']

    dataset_metadata['maintainer'] = config['importer_name']
    dataset_metadata['maintainer_email'] = config['importer_email']

    dataset_metadata['owner_org'] = orga['id']
    dataset_metadata['title'] = elem.find('title').text
    dataset_metadata['name'] = elem.find('wp:post_name', root.nsmap).text
    dataset_metadata['name'] = script_utils._prepare_string_for_ckan_name(
        dataset_metadata['name'])
    dataset_metadata['state'] = 'active'
    dataset_metadata['notes'] = elem.find('content:encoded', root.nsmap).text

    if (elem.find('wp:post_date', root.nsmap) is not None):
        dataset_metadata['odm_date_uploaded'] = elem.find(
            'wp:post_date', root.nsmap).text

    return dataset_metadata
def _map_xml_item_to_ckan_dataset_dict(root, elem):

  try:
    organization = config['organization']
    orga = ckanapiutils.get_organization_id_from_name(organization)
  except ckanapi.NotFound:
    print("Organization " + organization + " not found, please check config")

  dataset_metadata = {}
  dataset_metadata['type'] = config['package_type']

  dataset_metadata['maintainer'] = config['importer_name']
  dataset_metadata['maintainer_email'] = config['importer_email']

  dataset_metadata['owner_org'] = orga['id']
  dataset_metadata['title'] = elem.find('title').text
  dataset_metadata['name'] = elem.find('wp:post_name', root.nsmap).text
  dataset_metadata['name'] = script_utils._prepare_string_for_ckan_name(dataset_metadata['name'])
  dataset_metadata['state'] = 'active'
  dataset_metadata['notes'] = elem.find('content:encoded', root.nsmap).text

  if (elem.find('wp:post_date', root.nsmap) is not None):
    dataset_metadata['odm_date_uploaded'] = elem.find('wp:post_date', root.nsmap).text

  return dataset_metadata
def _map_geoserver_feature_to_ckan_dataset(feature_namespace,feature_name,feature_title,taxonomy_tags,config):

  # First, extract the information from the layer (Title, Abstract, Tags)
  params_dict = {}

  # Specify the package_type
  params_dict['type'] = config.package_type

  params_dict['maintainer'] = config.IMPORTER_NAME
  params_dict['maintainer_email'] = config.IMPORTER_EMAIL

  # The dataset id will be set when we find or create it
  params_dict['state'] = 'active'

  # Extract title (Mandatory)
  params_dict['title'] = feature_title

  # Extract name (Mandatory, lowcase and without characters except _-')
  params_dict['name'] = script_utils._prepare_string_for_ckan_name(feature_name)

  # Notes / Description / Abstract
  params_dict['notes'] = 'Imported Geoserver Layer: '+params_dict['title'] + '.'

  params_dict['taxonomy'] = []
  category_name = script_utils._prepare_string_for_ckan_tag_name(feature_namespace)
  category_name =  script_utils._str_capitalize_underscore_replaced_with_space(category_name)
  if (category_name in taxonomy_tags):
    params_dict['taxonomy'].append(category_name)

  return params_dict
예제 #4
0
def _map_record_to_ckan_dataset_dict(record, config):

    # First, extract the information from the layer (Title, Abstract, Tags)
    params_dict = {}
    params_dict['id'] = ''
    params_dict['state'] = 'active'

    # Specify the package_type
    params_dict['type'] = config.package_type

    params_dict['maintainer'] = config.IMPORTER_NAME
    params_dict['maintainer_email'] = config.IMPORTER_EMAIL

    try:

        if record.title():
            params_dict['title'] = record.title()

        if (record.title()) and (record.title() != ''):
            params_dict['name'] = script_utils._prepare_string_for_ckan_name(
                str(
                    uuid.uuid5(uuid.NAMESPACE_DNS,
                               record.title().encode('utf-8'))))
        elif record.isbn() and (record.isbn() != ''):
            params_dict['name'] = script_utils._prepare_string_for_ckan_name(
                record.isbn())
        else:
            return None

        if (not record.title()) or (record.title() == ''):
            params_dict['title'] = params_dict['name']

    except UnicodeEncodeError as e:
        if (config.DEBUG):
            traceback.print_exc()

    # Summary
    if record['520']:
        params_dict['notes'] = unicode(record['520'].value())

    return params_dict
def _map_record_to_ckan_dataset_dict(record,config):

  # First, extract the information from the layer (Title, Abstract, Tags)
  params_dict = {}
  params_dict['id'] = ''
  params_dict['state'] = 'active'

  # Specify the package_type
  params_dict['type'] = config.package_type

  params_dict['maintainer'] = config.IMPORTER_NAME
  params_dict['maintainer_email'] = config.IMPORTER_EMAIL

  try:

    if record.title():
      params_dict['title'] = record.title()

    if (record.title()) and (record.title() != ''):
      params_dict['name'] = script_utils._prepare_string_for_ckan_name(str(uuid.uuid5(uuid.NAMESPACE_DNS, record.title().encode('utf-8'))))
    elif record.isbn() and (record.isbn() != ''):
      params_dict['name'] = script_utils._prepare_string_for_ckan_name(record.isbn())
    else:
      return None

    if (not record.title()) or (record.title() == ''):
      params_dict['title'] = params_dict['name']

  except UnicodeEncodeError as e:
    if (config.DEBUG):
      traceback.print_exc()

  # Summary
  if record['520']:
    params_dict['notes'] = unicode(record['520'].value())

  return params_dict
def _map_geoserver_feature_to_ckan_dataset(feature_namespace, feature_name,
                                           feature_title, taxonomy_tags,
                                           config):

    # First, extract the information from the layer (Title, Abstract, Tags)
    params_dict = {}

    # Specify the package_type
    params_dict['type'] = config.package_type

    params_dict['maintainer'] = config.IMPORTER_NAME
    params_dict['maintainer_email'] = config.IMPORTER_EMAIL

    # The dataset id will be set when we find or create it
    params_dict['state'] = 'active'

    # Extract title (Mandatory)
    params_dict['title'] = feature_title

    # Extract name (Mandatory, lowcase and without characters except _-')
    params_dict['name'] = script_utils._prepare_string_for_ckan_name(
        feature_name)

    # Notes / Description / Abstract
    params_dict[
        'notes'] = 'Imported Geoserver Layer: ' + params_dict['title'] + '.'

    params_dict['taxonomy'] = []
    category_name = script_utils._prepare_string_for_ckan_tag_name(
        feature_namespace)
    category_name = script_utils._str_capitalize_underscore_replaced_with_space(
        category_name)
    if (config.DEBUG):
        print(category_name)
    if (category_name in taxonomy_tags):
        params_dict['taxonomy'].append(category_name)

    return params_dict