def rdf_resources():
    """
    Return list of resource IDs with RDF records
    :return:
    """
    # FIXME - Need to add in indexlots and artefacts
    return [get_specimen_resource_id()]
Exemple #2
0
    def after_update(self, context, pkg_dict):
        """
        If this is the specimen resource, clear memcached

        NB: Our version of ckan doesn't have the IResource after_update method
        But updating a resource calls IPackageController.after_update
        @param context:
        @param resource:
        @return:
        """
        for resource in pkg_dict.get('resources', []):
            # If this is the specimen resource ID, clear the collection stats
            if 'id' in resource:
                if resource['id'] in [helpers.get_specimen_resource_id(), helpers.get_indexlot_resource_id()]:
                    # Quick and dirty, delete all caches when indexlot or specimens are updated
                    # TODO: Move to invalidate_cache - need to investigate why that isn't working
                    for _cache in cache_managers.values():
                        _cache.clear()
    def datastore_modify_data_dict(self, context, data_dict):
        '''
        This function allows overriding of the data dict before datastore_search gets to it. We use
        this opportunity to:

            - remove any of our custom filter options (has image, lat long only etc) and add info
              to the context so that we can pick them up and handle them in datastore_modify_search.
              This is necessary because we define the actual query the filter options use in the
              elasticsearch-dsl lib's objects and therefore need to modify the actual search object
              prior to it being sent to the elasticsearch server.

            - alter the sort if the resource being searched is one of the EMu ones, this allows us
              to enforce a modified by sort order instead of the default and therefore means we can
              show the last changed EMu data first

        :param context: the context dict
        :param data_dict: the data dict
        :return: the modified data dict
        '''
        # remove our custom filters from the filters dict, we'll add them ourselves in the modify
        # search function below
        if u'filters' in data_dict:
            # figure out which options are available for this resource
            resource_show = p.toolkit.get_action(u'resource_show')
            resource = resource_show(context, {u'id': data_dict[u'resource_id']})
            options = resource_view_get_filter_options(resource)
            # we'll store the filters that need applying on the context to avoid repeating our work
            # in the modify search function below
            context[u'option_filters'] = []
            for option in options:
                if option.name in data_dict[u'filters']:
                    # if the option is in the filters, delete it and add it's filter to the context
                    del data_dict[u'filters'][option.name]
                    context[u'option_filters'].append(option.filter_dsl)

        if u'sort' not in data_dict:
            # by default sort the EMu resources by modified so that the latest records are first
            if data_dict['resource_id'] in {helpers.get_specimen_resource_id(),
                                            helpers.get_artefact_resource_id(),
                                            helpers.get_indexlot_resource_id()}:
                data_dict['sort'] = ['modified desc']

        return data_dict
    def after_update(self, context, pkg_dict):

        """
        If this is the specimen resource, clear memcached

        NB: Our version of ckan doesn't have the IResource after_update method
        But updating a resource calls IPackageController.after_update
        @param context:
        @param resource:
        @return:
        """
        for resource in pkg_dict.get('resources', []):
            # If this is the specimen resource ID, clear the collection stats
            if 'id' in resource:
                if resource['id'] in [helpers.get_specimen_resource_id(), helpers.get_indexlot_resource_id()]:
                    log.info('Clearing caches')
                    # Quick and dirty, delete all caches when indexlot or specimens are updated
                    for _cache in cache_managers.values():
                        _cache.clear()

        # Clear the NGINX proxy cache
        cache_clear_nginx_proxy()
    def datastore_modify_fields(self, resource_id, mapping, fields):
        '''
        This function allows us to modify the field definitions before they are returned as part of
        the datastore_search action. All we do here is just modify the associatedMedia field if it
        exists to ensure it is treated as an array.

        :param resource_id: the resource id
        :param mapping: the original mapping dict returned by elasticsearch from which the field
                        info has been derived
        :param fields: the fields dict itself
        :return: the fields dict
        '''
        # if we're dealing with one of our EMu backed resources and the associatedMedia field is
        # present set its type to array rather than string (the default). This isn't really
        # necessary from recline's point of view as we override the render of this field's data
        # anyway, but for completeness and correctness we'll do the override
        if resource_id in {helpers.get_specimen_resource_id(), helpers.get_artefact_resource_id(),
                           helpers.get_indexlot_resource_id()}:
            for field_def in fields:
                if field_def['id'] == 'associatedMedia':
                    field_def['type'] = 'array'
                    field_def['sortable'] = False
        return fields
 def datastore_is_read_only_resource(self, resource_id):
     # we don't want any of the versioned datastore ingestion and indexing code modifying the
     # collections data as we manage it all through the data importer
     return resource_id in {helpers.get_specimen_resource_id(),
                            helpers.get_artefact_resource_id(),
                            helpers.get_indexlot_resource_id()}