# Path: ckanext/dcatapit/dcat/const.py
# THEME_BASE_URI = 'http://publications.europa.eu/resource/authority/data-theme/'
# 
# Path: ckanext/dcatapit/schema.py
# FIELD_THEMES_AGGREGATE = 'themes_aggregate'


import json
import logging
import os
from configparser import SafeConfigParser as ConfigParser
from ckan.lib.base import config
from ckan.model import Session
from ckan.model.group import Group, Member
from ckan.plugins import toolkit
from ckanext.dcatapit.dcat.const import THEME_BASE_URI
from ckanext.dcatapit.schema import FIELD_THEMES_AGGREGATE
        return
    return list(set(new_themes))


def map_nonconformant_groups(harvest_object):
    """
    Adds themes to fetched data
    """
    themes_data = _load_mapping_data()
    if not themes_data:
        return

    data = json.loads(harvest_object.content)
    _groups = data.get('groups')
    if not _groups:
        return

    groups = [g['name'] for g in _groups]
    groups.extend([g['display_name'] for g in _groups if 'display_name' in g])

    new_themes = _get_new_themes(groups, themes_data, add_existing=False)
    if not new_themes:
        return

    # ensure themes are upper-case, otherwise will be discarded by validators


    extra = data.get('extras') or []

    aggr = themes_to_aggr_json(new_themes)

# Path: ckanext/dcatapit/dcat/const.py
# THEME_BASE_URI = 'http://publications.europa.eu/resource/authority/data-theme/'
# 
# Path: ckanext/dcatapit/schema.py
# FIELD_THEMES_AGGREGATE = 'themes_aggregate'


# Path: ckanext/dcatapit/mapping.py
import json
import logging
import os
from configparser import SafeConfigParser as ConfigParser
from ckan.lib.base import config
from ckan.model import Session
from ckan.model.group import Group, Member
from ckan.plugins import toolkit
from ckanext.dcatapit.dcat.const import THEME_BASE_URI
from ckanext.dcatapit.schema import FIELD_THEMES_AGGREGATE

        return
    return list(set(new_themes))


def map_nonconformant_groups(harvest_object):
    """
    Adds themes to fetched data
    """
    themes_data = _load_mapping_data()
    if not themes_data:
        return

    data = json.loads(harvest_object.content)
    _groups = data.get('groups')
    if not _groups:
        return

    groups = [g['name'] for g in _groups]
    groups.extend([g['display_name'] for g in _groups if 'display_name' in g])

    new_themes = _get_new_themes(groups, themes_data, add_existing=False)
    if not new_themes:
        return

    # ensure themes are upper-case, otherwise will be discarded by validators


    extra = data.get('extras') or []

    aggr = themes_to_aggr_json(new_themes)

    _set_extra(extra, FIELD_THEMES_AGGREGATE, aggr)