Esempio n. 1
0
def index_holdingpen_record(sender, **kwargs):
    """Index a Holding Pen record."""
    from invenio.ext.es import es

    from invenio_records.api import Record
    from invenio_records.signals import before_record_insert

    from .registry import workflows
    from .models import ObjectVersion

    if not sender.workflow:
        # No workflow registered to object yet. Skip indexing
        return

    workflow = workflows.get(sender.workflow.name)
    if not workflow:
        current_app.logger.error(
            "No workflow found for sender: {0}".format(sender.id)
        )
        return

    if not hasattr(sender, 'data'):
        sender.data = sender.get_data()
    if not hasattr(sender, 'extra_data'):
        sender.extra_data = sender.get_extra_data()

    record = Record({})
    record["version"] = ObjectVersion.name_from_version(sender.version)
    record["type"] = sender.data_type
    record["status"] = sender.status
    record["created"] = sender.created.isoformat()
    record["modified"] = sender.modified.isoformat()
    record["uri"] = sender.uri
    record["id_workflow"] = sender.id_workflow
    record["id_user"] = sender.id_user
    record["id_parent"] = sender.id_parent
    record["workflow"] = sender.workflow.name
    try:
        record.update(workflow.get_record(sender))
    except Exception as err:
        current_app.logger.exception(err)

    try:
        record.update(workflow.get_sort_data(sender))
    except Exception as err:
        current_app.logger.exception(err)

    from invenio.modules.jsonalchemy.registry import functions
    list(functions('recordext'))

    toposort_send(before_record_insert, record)

    es.index(
        index=current_app.config.get("WORKFLOWS_HOLDING_PEN_INDEX"),
        doc_type='record',
        body=dict(record),
        id=sender.id
    )
Esempio n. 2
0
    def update_record(
        self,
        original_record: Record,
        new_record_data: dict,
        identity: Identity,
    ) -> Record:
        """Update the metadata of the specified Record with the new data.

        :param original_record: The Record whose metadata should be updated.
        :param new_records_data: The new (partial) metadata to be used.
        :param identity: The identity to be used for checking the update permissions.
        :return: The updated Record.
        :rtype: Record
        """
        original_record.update(new_record_data)
        return original_record.commit()
Esempio n. 3
0
def index_holdingpen_record(sender, **kwargs):
    """Index a Holding Pen record."""
    from invenio_ext.es import es
    from invenio_records.api import Record
    from invenio_records.signals import before_record_index
    from invenio_records.recordext.functions.get_record_collections import (
        get_record_collections,
    )
    from invenio_records.tasks.index import get_record_index

    from invenio_workflows.registry import workflows

    if not sender.workflow:
        # No workflow registered to object yet. Skip indexing
        return

    if sender.version == ObjectVersion.INITIAL:
        # Ignore initial versions
        return

    workflow = workflows.get(sender.workflow.name)
    if not workflow:
        current_app.logger.info(
            "Workflow {0} not found for sender: {1}".format(
                sender.workflow.name, sender.id
            )
        )
        return

    if not hasattr(sender, 'data'):
        sender.data = sender.get_data()
    if not hasattr(sender, 'extra_data'):
        sender.extra_data = sender.get_extra_data()

    record = Record({})
    record["version"] = ObjectVersion.name_from_version(sender.version)
    record["type"] = sender.data_type
    record["status"] = sender.status
    record["created"] = sender.created.isoformat()
    record["modified"] = sender.modified.isoformat()
    record["uri"] = sender.uri
    record["id_workflow"] = sender.id_workflow
    record["id_user"] = sender.id_user
    record["id_parent"] = sender.id_parent
    record["workflow"] = sender.workflow.name
    try:
        record.update(workflow.get_record(sender))
    except Exception as err:
        current_app.logger.exception(err)

    try:
        record.update(workflow.get_sort_data(sender))
    except Exception as err:
        current_app.logger.exception(err)

    # Add collection to get correct mapping
    record["_collections"] = get_record_collections(record)

    # Depends on "_collections" being filled correctly for record
    record_index = get_record_index(record) or current_app.config["SEARCH_ELASTIC_DEFAULT_INDEX"]

    # Trigger any before_record_index receivers
    before_record_index.send(sender.id, json=record, index=record_index)

    if record_index:
        index = current_app.config['WORKFLOWS_HOLDING_PEN_ES_PREFIX'] + record_index
        es.index(
            index=index,
            doc_type=current_app.config["WORKFLOWS_HOLDING_PEN_DOC_TYPE"],
            body=dict(record),
            id=sender.id
        )