Beispiel #1
0
    def init_app(self, app):
        """Flask application initialization."""
        self.init_config(app)
        app.extensions['b2share-records'] = self
        self._register_signals(app)
        app.cli.add_command(b2records)
        register_triggers(app)
        register_error_handlers(app)

        app.logger.info("Creating enpoints...")

        # Register records API blueprints
        endpoints = app.config['B2SHARE_RECORDS_REST_ENDPOINTS']
        #for i in endpoints:
        #    app.logger.info("- Creating enpoint: {}".format(i))

        app.register_blueprint(create_blueprint(endpoints))

        @app.before_first_request
        def extend_default_endpoint_prefixes():
            """Fix the endpoint prefixes as ."""

            endpoint_prefixes = utils.build_default_endpoint_prefixes(
                endpoints)
            #app.logger.info("- Fixing endpoint: {}".format(endpoint_prefixes))

            current_records_rest = app.extensions['invenio-records-rest']
            current_records_rest.default_endpoint_prefixes.update(
                endpoint_prefixes)

        before_record_index.connect(indexer_receiver, sender=app)
        app.url_map.converters['pid'] = PIDConverter
Beispiel #2
0
 def register_signals(self):
     """Register signals."""
     file_uploaded.connect(file_uploaded_listener)
     file_processed.connect(file_processed_listener)
     file_deleted.connect(file_deleted_listener)
     after_record_delete.connect(record_deleted_listener)
     before_record_index.connect(index_file_content)
Beispiel #3
0
    def init_app(self, app):
        """Flask application initialization."""
        self.init_config(app)
        self.create_resources()
        self.init_views(app)

        app.extensions['sonar'] = self

        if app.config['SONAR_APP_ENABLE_CORS']:
            from flask_cors import CORS
            CORS(app)

        Bootstrap(app)
        Wiki(app)

        app.context_processor(utility_processor)

        # Connect to signal sent when a user is created in Flask-Security.
        user_registered.connect(user_registered_handler, weak=False)

        # Connect to signal sent when a file is uploaded or deleted
        file_uploaded.connect(file_uploaded_listener, weak=False)
        file_deleted.connect(file_deleted_listener, weak=False)

        # Add user's full name before record index
        before_record_index.connect(add_full_name, weak=False)
Beispiel #4
0
 def register_signals(app):
     """Register Zenodo Deposit signals."""
     before_record_index.connect(indexer_receiver, sender=app, weak=False)
     post_action.connect(datacite_register_after_publish, sender=app,
                         weak=False)
     post_action.connect(index_versioned_record_siblings, sender=app,
                         weak=False)
 def register_signals(self, app):
     """Register the signals."""
     before_record_index.connect(inject_provisional_community)
     if app.config['COMMUNITIES_OAI_ENABLED']:
         listen(Community, 'after_insert', create_oaipmh_set)
         listen(Community, 'after_delete', destroy_oaipmh_set)
     inclusion_request_created.connect(new_request)
Beispiel #6
0
    def init_app(self, app):
        """Flask application initialization."""
        self.init_config(app)
        app.extensions['invenio-pidrelations'] = _InvenioPIDRelationsState(app)

        # Register indexers the default indexer if necessary
        if app.config.get('PIDRELATIONS_REGISTER_DEFAULT_INDEXER'):
            before_record_index.connect(index_relations, sender=app)
Beispiel #7
0
def update_authors_recid(record_id, uuid, profile_recid):
    """Update author profile for a given signature.

    The method receives UUIDs representing record and signature
    respectively together with an author profile recid.
    The new recid will be placed in the signature with the given
    UUID.

    :param record_id:
        A string representing UUID of a given record.

        Example:
            record_id = "a5afb151-8f75-4e91-8dc1-05e7e8e8c0b8"

    :param uuid:
        A string representing UUID of a given signature.

        Example:
            uuid = "c2f432bd-2f52-4c16-ac66-096f168c762f"

    :param profile_recid:
        A string representing author profile recid, that
        updated signature should point to.

        Example:
            profile_recid = "1"
    """
    try:
        record = Record.get_record(record_id)
        update_flag = False

        for author in record['authors']:
            if author['uuid'] == uuid:
                author['recid'] = str(profile_recid)
                update_flag = True

        if update_flag:
            # Disconnect the signal on insert of a new record.
            before_record_index.disconnect(append_updated_record_to_queue)

            # Update the record in the database.
            record.commit()
            db.session.commit()

            # Update the record in Elasticsearch.
            indexer = RecordIndexer()
            indexer.index_by_id(record.id)
    except StaleDataError as exc:
        raise update_authors_recid.retry(exc=exc)
    finally:
        # Reconnect the disconnected signal.
        before_record_index.connect(append_updated_record_to_queue)

    # Report.
    logger.info("Updated signature %s with profile %s",
                uuid, profile_recid)
Beispiel #8
0
    def init_app(self, app):
        """Flask application initialization."""
        self.init_config(app)
        app.extensions['sonar_documents'] = self

        # Connect to oaiharvester signal
        oaiharvest_finished.connect(transform_harvested_records, weak=False)

        # Connect to record index signal, to modify record before indexing.
        before_record_index.connect(populate_fulltext_field, weak=False)
Beispiel #9
0
    def init_app(self, app):
        """Flask application initialization."""
        self.init_config(app)
        app.extensions['invenio-explicit-acls'] = AclAPI(app)

        # register signals
        from invenio_explicit_acls.signals import add_acls
        from invenio_indexer.signals import before_record_index

        before_record_index.connect(add_acls)
Beispiel #10
0
    def init_app(self, app):
        """Flask application initialization."""
        self.init_config(app)

        # Register context processors
        app.context_processor(record_communities)
        # Register blueprint
        app.register_blueprint(blueprint)
        before_record_index.connect(indexer_receiver, sender=app)
        app.extensions['zenodo-records'] = self
Beispiel #11
0
    def init_app(self, app):
        """Flask application initialization."""
        self.init_config(app)
        # app.register_blueprint(blueprint)
        app.extensions['invenio-pidrelations'] = _InvenioPIDRelationsState(app)

        # Register indexers if they are required
        if app.config.get('PIDRELATIONS_INDEX_RELATIONS'):
            from invenio_indexer.signals import before_record_index
            before_record_index.connect(index_relations, sender=app)
Beispiel #12
0
 def register_signals(app):
     """Register CDS Deposit signals."""
     # index records after published
     # note: if publish a project -> index also videos
     post_action.connect(index_deposit_after_action,
                         sender=app, weak=False)
     # if it's a project/video, expands informations before index
     before_record_index.connect(
         cdsdeposit_indexer_receiver, sender=app, weak=False)
     # register Datacite after publish record
     post_action.connect(
         datacite_register_after_publish, sender=app, weak=False)
Beispiel #13
0
    def init_app(self, app):
        """Flask application initialization."""
        self.init_config(app)

        # Register context processors
        app.context_processor(record_communities)
        # Register blueprint
        app.register_blueprint(blueprint)
        # Add global record serializer template filter
        app.add_template_filter(serialize_record, 'serialize_record')
        before_record_index.connect(indexer_receiver, sender=app)
        app.extensions['zenodo-records'] = self
Beispiel #14
0
 def register_signals(app):
     """Register Zenodo Deposit signals."""
     before_record_index.connect(indexer_receiver, sender=app, weak=False)
     post_action.connect(datacite_register_after_publish,
                         sender=app,
                         weak=False)
     post_action.connect(index_versioned_record_siblings,
                         sender=app,
                         weak=False)
     post_action.connect(openaire_direct_index_after_publish,
                         sender=app,
                         weak=False)
Beispiel #15
0
def update_authors_recid(record_id, uuid, profile_recid):
    """Update author profile for a given signature.

    The method receives UUIDs representing record and signature
    respectively together with an author profile recid.
    The new recid will be placed in the signature with the given
    UUID.

    :param record_id:
        A string representing UUID of a given record.

        Example:
            record_id = "a5afb151-8f75-4e91-8dc1-05e7e8e8c0b8"

    :param uuid:
        A string representing UUID of a given signature.

        Example:
            uuid = "c2f432bd-2f52-4c16-ac66-096f168c762f"

    :param profile_recid:
        A string representing author profile recid, that
        updated signature should point to.

        Example:
            profile_recid = "1"
    """
    try:
        record = InspireRecord.get_record(record_id)
        update_flag = False

        for author in record['authors']:
            if author['uuid'] == uuid:
                author['recid'] = str(profile_recid)
                update_flag = True

        if update_flag:
            # Disconnect the signal on insert of a new record.
            before_record_index.disconnect(append_updated_record_to_queue)

            # Update the record in the database.
            record.commit()
            db.session.commit()
    except StaleDataError as exc:
        raise update_authors_recid.retry(exc=exc)
    finally:
        # Reconnect the disconnected signal.
        before_record_index.connect(append_updated_record_to_queue)

    # Report.
    logger.info("Updated signature %s with profile %s", uuid, profile_recid)
Beispiel #16
0
    def init_app(self, app):
        """Flask application initialization."""
        self.init_config(app)
        app.extensions['sonar_documents'] = self

        # Connect to oaiharvester signal
        oaiharvest_finished.connect(transform_harvested_records, weak=False)
        oaiharvest_finished.connect(export_json, weak=False)

        # Connect to record index signal, to modify record before indexing.
        before_record_index.connect(enrich_document_data, weak=False)

        # Adds `_oai` property
        before_record_insert.connect(update_oai_property)
        before_record_update.connect(update_oai_property)
Beispiel #17
0
    def register_signals(self):
        """Register signals."""
        before_record_index.connect(enrich_loan_data)
        before_record_index.connect(enrich_document_data)

        item_at_desk.connect(listener_item_at_desk)

        oaiharvest_finished.connect(publish_harvested_records, weak=False)

        apiharvest_part.connect(publish_api_harvested_records, weak=False)

        after_record_insert.connect(mef_person_insert)
        after_record_update.connect(mef_person_update)
        after_record_delete.connect(mef_person_delete)
        after_record_revert.connect(mef_person_revert)
Beispiel #18
0
    def init_config(self, app):
        """Initialize configuration.

        :param app: The Flask application.
        """
        # Use theme's base template if theme is installed
        if 'BASE_TEMPLATE' in app.config:
            app.config.setdefault(
                'WEKO_DEPOSIT_BASE_TEMPLATE',
                app.config['BASE_TEMPLATE'],
            )

        for k in dir(config):
            if k.startswith('WEKO_DEPOSIT_'):
                app.config.setdefault(k, getattr(config, k))
        before_record_index.connect(append_file_content)
Beispiel #19
0
    def register_signals(self):
        """Register signals."""
        from invenio_indexer.signals import before_record_index
        from .loans.listener import enrich_loan_data
        before_record_index.connect(enrich_loan_data)
        from .documents.listener import enrich_document_data
        before_record_index.connect(enrich_document_data)

        from .patrons.listener import listener_item_at_desk
        from .items.signals import item_at_desk
        item_at_desk.connect(listener_item_at_desk)

        from invenio_oaiharvester.signals import oaiharvest_finished
        from .ebooks.receivers import publish_harvested_records
        oaiharvest_finished.connect(publish_harvested_records, weak=False)

        from .apiharvester.signals import apiharvest_part
        from .mef_persons.receivers import publish_api_harvested_records
        apiharvest_part.connect(publish_api_harvested_records, weak=False)
Beispiel #20
0
    def init_app(self, app):
        """Flask application initialization."""
        self.init_config(app)

        # Register context processors
        app.context_processor(record_communities)
        # Register blueprint
        app.register_blueprint(blueprint)
        # Add global record serializer template filter
        app.add_template_filter(serialize_record, 'serialize_record')

        # Register versioning blueprint
        app.register_blueprint(versioning_blueprint)

        self.custom_metadata = CustomMetadataAPI(
            term_types=app.config.get('ZENODO_CUSTOM_METADATA_TERM_TYPES'),
            vocabularies=app.config.get('ZENODO_CUSTOM_METADATA_VOCABULARIES'),
        )

        before_record_index.connect(indexer_receiver, sender=app)
        app.extensions['zenodo-records'] = self
Beispiel #21
0
    def init_app(self, app):
        """Flask application initialization."""
        self.init_config(app)

        # Register context processors
        app.context_processor(record_communities)
        # Register blueprint
        app.register_blueprint(blueprint)
        # Add global record serializer template filter
        app.add_template_filter(serialize_record, 'serialize_record')

        # Register versioning blueprint
        app.register_blueprint(versioning_blueprint)

        self.custom_metadata = CustomMetadataAPI(
            term_types=app.config.get('ZENODO_CUSTOM_METADATA_TERM_TYPES'),
            vocabularies=app.config.get('ZENODO_CUSTOM_METADATA_VOCABULARIES'),
        )

        before_record_index.connect(indexer_receiver, sender=app)
        app.extensions['zenodo-records'] = self
Beispiel #22
0
    def init_app(self, app):
        """Flask application initialization."""
        self.init_config(app)
        app.extensions['b2share-records'] = self
        register_triggers(app)
        register_error_handlers(app)

        # Register records API blueprints
        endpoints = app.config['B2SHARE_RECORDS_REST_ENDPOINTS']
        app.register_blueprint(create_blueprint(endpoints))

        @app.before_first_request
        def extend_default_endpoint_prefixes():
            """Fix the endpoint prefixes as ."""
            endpoint_prefixes = utils.build_default_endpoint_prefixes(
                endpoints)
            current_records_rest = app.extensions['invenio-records-rest']
            current_records_rest.default_endpoint_prefixes.update(
                endpoint_prefixes)

        before_record_index.connect(indexer_receiver, sender=app)
        app.url_map.converters['pid'] = PIDConverter
Beispiel #23
0
    def init_app(self, app):
        """Flask application initialization."""
        self.init_config(app)
        app.cli.add_command(b2records)
        app.extensions['b2share-records'] = self
        register_triggers(app)
        register_error_handlers(app)

        # Register records API blueprints
        endpoints = app.config['B2SHARE_RECORDS_REST_ENDPOINTS']
        app.register_blueprint(create_blueprint(endpoints))

        @app.before_first_request
        def extend_default_endpoint_prefixes():
            """Fix the endpoint prefixes as ."""
            endpoint_prefixes = utils.build_default_endpoint_prefixes(endpoints)
            current_records_rest = app.extensions['invenio-records-rest']
            current_records_rest.default_endpoint_prefixes.update(
                endpoint_prefixes
            )

        before_record_index.connect(indexer_receiver, sender=app)
        app.url_map.converters['pid'] = PIDConverter
Beispiel #24
0
def indexer(app, es):
    """Create a record indexer."""
    InvenioIndexer(app)
    before_record_index.connect(record_indexer_receiver, sender=app)
    yield RecordIndexer()
Beispiel #25
0
def indexer(app, es):
    """Create a record indexer."""
    InvenioIndexer(app)
    before_record_index.connect(record_indexer_receiver, sender=app)
    yield RecordIndexer()
Beispiel #26
0
 def init_app(self, app):
     """Flask application initialization."""
     self.init_config(app)
     app.extensions['my-site'] = self
     before_record_index.connect(indexer_receiver, sender=app, weak=False)
Beispiel #27
0
    def register_signals(self):
        """Register signals."""
        before_record_index.connect(enrich_loan_data)
        before_record_index.connect(enrich_document_data)
        before_record_index.connect(enrich_item_data)
        before_record_index.connect(enrich_patron_data)
        before_record_index.connect(enrich_location_data)
        before_record_index.connect(enrich_holding_data)
        before_record_index.connect(enrich_notification_data)

        loan_state_changed.connect(listener_loan_state_changed, weak=False)

        oaiharvest_finished.connect(publish_harvested_records, weak=False)

        apiharvest_part.connect(publish_api_harvested_records, weak=False)

        after_record_insert.connect(mef_person_insert)
        after_record_update.connect(mef_person_update)
        after_record_delete.connect(mef_person_delete)
        after_record_revert.connect(mef_person_revert)
Beispiel #28
0
 def init_app(self, app):
     """Flask application initialization."""
     app.extensions['cd2h-records'] = self
     before_record_index.connect(before_deposit_index_hook,
                                 sender=app,
                                 weak=False)
Beispiel #29
0
    def register_signals(self, app):
        """Register signals."""
        # TODO: use before_record_index.dynamic_connect() if it works
        # example:
        # before_record_index.dynamic_connect(
        #    enrich_patron_data, sender=app, index='patrons-patron-v0.0.1')
        before_record_index.connect(enrich_acq_account_data, sender=app)
        before_record_index.connect(enrich_acq_order_data, sender=app)
        before_record_index.connect(enrich_acq_receipt_data, sender=app)
        before_record_index.connect(enrich_acq_receipt_line_data, sender=app)
        before_record_index.connect(enrich_acq_order_line_data, sender=app)
        before_record_index.connect(enrich_collection_data, sender=app)
        before_record_index.connect(enrich_loan_data, sender=app)
        before_record_index.connect(enrich_document_data, sender=app)
        before_record_index.connect(enrich_contributions_data, sender=app)
        before_record_index.connect(enrich_item_data, sender=app)
        before_record_index.connect(enrich_patron_data, sender=app)
        before_record_index.connect(enrich_location_data, sender=app)
        before_record_index.connect(enrich_holding_data, sender=app)
        before_record_index.connect(enrich_notification_data, sender=app)
        before_record_index.connect(enrich_patron_transaction_event_data,
                                    sender=app)
        before_record_index.connect(enrich_patron_transaction_data, sender=app)
        before_record_index.connect(enrich_ill_request_data, sender=app)
        before_record_index.connect(prepare_template_data, sender=app)

        after_record_insert.connect(create_subscription_patron_transaction)
        after_record_update.connect(create_subscription_patron_transaction)
        after_record_update.connect(update_items_locations_and_types)

        before_record_update.connect(budget_is_active_changed)
        before_record_update.connect(negative_availability_changes)

        loan_state_changed.connect(listener_loan_state_changed, weak=False)

        oaiharvest_finished.connect(publish_harvested_records, weak=False)

        apiharvest_part.connect(publish_api_harvested_records, weak=False)

        # invenio-userprofiles signal
        after_profile_update.connect(update_from_profile)

        # store the username in the session
        user_logged_in.connect(set_user_name)
        user_logged_out.connect(remove_user_name)
        user_loaded_from_cookie.connect(set_user_name)
Beispiel #30
0
 def init_app(self, app):
     """Flask application initialization."""
     self.init_config(app)
     app.register_blueprint(blueprint)
     before_record_index.connect(indexer_receiver, sender=app)
     app.extensions['zenodo-records'] = self
Beispiel #31
0
# Create Flask application
app = Flask(__name__, template_folder='.')
app.config.update(dict(
    TEMPLATES_AUTO_RELOAD=True,
    CELERY_ALWAYS_EAGER=True,
    CELERY_RESULT_BACKEND='cache',
    CELERY_CACHE_BACKEND='memory'))

InvenioDB(app)
InvenioPIDStore(app)
InvenioPIDRelations(app)
app.register_blueprint(versioning_blueprint)
InvenioIndexer(app)
InvenioRecords(app)
InvenioRecordsUI(app)
before_record_index.connect(index_relations, sender=app)

record_resolver = Resolver(
    pid_type='recid', object_type='rec', getter=Record.get_record
)


class SimpleRecordSchema(Schema):
    """Tiny schema for our simple record."""

    recid = fields.Str()
    title = fields.Str()
    body = fields.Str()


@app.route('/')
Beispiel #32
0
 def register_signals(self, app):
     """Register signals."""
     before_record_index.connect(enrich_mef_data, sender=app)
 def init_app(self, app):
     """Flask application initialization."""
     app.register_blueprint(blueprint)
     before_record_index.connect(indexer_receiver, sender=app)
     app.config.setdefault('JSONSCHEMAS_HOST', JSONSCHEMAS_HOST)
     app.extensions['records'] = self
Beispiel #34
0
 def init_app(self, app):
     """Flask application initialization."""
     self.init_config(app)
     app.cli.add_command(openaire)
     before_record_index.connect(indexer_receiver, sender=app)
     app.extensions['invenio-openaire'] = self
Beispiel #35
0
 def register_signals(app):
     """Register Zenodo Deposit signals."""
     oaiharvest_finished.connect(publish_harvested_records, weak=False)
     before_record_index.connect(indexer_receiver, weak=False)
Beispiel #36
0
 def init_app(self, app):
     """Flask application initialization."""
     self.init_config(app)
     app.cli.add_command(openaire)
     before_record_index.connect(indexer_receiver, sender=app)
     app.extensions['invenio-openaire'] = self
Beispiel #37
0
    def register_signals(self, app):
        """Register signals."""
        # TODO: use before_record_index.dynamic_connect() if it works
        # example:
        # before_record_index.dynamic_connect(
        #    enrich_patron_data, sender=app, index='patrons-patron-v0.0.1')
        before_record_index.connect(enrich_collection_data, sender=app)
        before_record_index.connect(enrich_loan_data, sender=app)
        before_record_index.connect(enrich_document_data, sender=app)
        before_record_index.connect(enrich_contributions_data, sender=app)
        before_record_index.connect(enrich_item_data, sender=app)
        before_record_index.connect(enrich_patron_data, sender=app)
        before_record_index.connect(enrich_location_data, sender=app)
        before_record_index.connect(enrich_holding_data, sender=app)
        before_record_index.connect(enrich_notification_data, sender=app)
        before_record_index.connect(enrich_patron_transaction_event_data,
                                    sender=app)
        before_record_index.connect(enrich_patron_transaction_data, sender=app)
        before_record_index.connect(enrich_ill_request_data, sender=app)

        after_record_insert.connect(create_subscription_patron_transaction)
        after_record_update.connect(create_subscription_patron_transaction)

        loan_state_changed.connect(listener_loan_state_changed, weak=False)

        oaiharvest_finished.connect(publish_harvested_records, weak=False)

        apiharvest_part.connect(publish_api_harvested_records, weak=False)

        # invenio-userprofiles signal
        after_profile_update.connect(update_from_profile)
 def init_app(self, app):
     """Flask application initialization."""
     app.register_blueprint(blueprint)
     before_record_index.connect(indexer_receiver, sender=app)
     app.config.setdefault('JSONSCHEMAS_HOST', JSONSCHEMAS_HOST)
     app.extensions['records'] = self