Skip to content

oarepo_oaipmh_harvester.oai_harvester.api

oarepo_oaipmh_harvester.oai_harvester.api

Record API level classes for OAI-PMH Harvester.

HarvesterDumper

Bases: SearchDumper

Search dumper with configured extensions.

Source code in oarepo_oaipmh_harvester/oai_harvester/api.py
class HarvesterDumper(SearchDumper):
    """Search dumper with configured extensions."""

    def __init__(
        self,
    ) -> None:
        """Initialize the dumper."""
        super().__init__(
            extensions=[
                IndexedAtDumperExt(),
            ],
            model_fields={
                "id": ("uuid", str),
            },
        )

__init__() -> None

Initialize the dumper.

Source code in oarepo_oaipmh_harvester/oai_harvester/api.py
def __init__(
    self,
) -> None:
    """Initialize the dumper."""
    super().__init__(
        extensions=[
            IndexedAtDumperExt(),
        ],
        model_fields={
            "id": ("uuid", str),
        },
    )

OAIHarvesterAggregate

Bases: BaseAggregate

An aggregate of information about an OAI-PMH harvester.

Source code in oarepo_oaipmh_harvester/oai_harvester/api.py
class OAIHarvesterAggregate(BaseAggregate):
    """An aggregate of information about an OAI-PMH harvester."""

    model: OAIHarvesterAggregateModel  # ty: ignore[invalid-attribute-override] monkeytype

    model_cls = OAIHarvesterAggregateModel  # ty: ignore[invalid-assignment] monkeytype
    """The model class for the request."""

    dumper = HarvesterDumper()
    """Search dumper with configured extensions."""

    index = IndexField(
        "oai-harvester-oai-harvester-v1.0.0",
    )
    """The search engine index to use."""

    id = ModelField("id", dump_type=str)
    """The ID of the harvester."""

    base_url = ModelField("base_url", dump_type=str)
    """The base URL of the OAI-PMH service."""

    name = ModelField("name", dump_type=str)
    """The name of the harvester."""

    comment = ModelField("comment", dump_type=str)
    """Comment."""

    metadata_prefix = ModelField("metadata_prefix", dump_type=str)
    """The metadata prefix to harvest."""

    setspec = ModelField("setspec", dump_type=str)
    """The set specifications to harvest."""

    loader = ModelField("loader", dump_type=str)
    """The definition of the loader."""

    transformers = ModelField("transformers", dump_type=list)
    """The list of transformers."""

    writers = ModelField("writers", dump_type=list)
    """The list of writers."""

    harvest_managers = ModelField("harvest_managers", dump_type=list)
    """The list of harvest managers. Each item is a dict with 'user' key with user ID."""

    @classmethod
    @override
    def create(
        cls,
        data: dict,
        id_: UUID | None = None,
        **kwargs: Any,
    ) -> OAIHarvesterAggregate:
        """Create a new OAI harvester and store it in the database."""
        with db.session.begin_nested():
            record = OAIHarvester(**data)
            db.session.add(record)
            return cls.from_model(record)

    @override
    def delete(self, force: bool = False) -> OAIHarvesterAggregate:
        """Delete the harvester."""
        if self.model is None:
            raise MissingModelError

        with db.session.begin_nested():
            if self.send_signals:
                before_record_delete.send(
                    _current_app_object(),
                    record=self,
                )

            # Run pre delete extensions
            for e in self._extensions:
                e.pre_delete(self, force=True)

            # the only change from super is the model.model_obj instead of model
            db.session.delete(self.model.model_obj)

        if self.send_signals:
            after_record_delete.send(
                _current_app_object(),
                record=self,
            )

        # Run post delete extensions
        for e in self._extensions:
            e.post_delete(self, force=True)

        return self

    @classmethod
    def get_record(cls, id_: UUID | str, with_deleted: bool = False) -> OAIHarvesterAggregate:  # noqa: ARG003 interface compatibility
        """Get the harvester via the specified ID (harvesters are never soft deleted)."""
        with db.session.no_autoflush:
            record = OAIHarvester.query.get(str(id_))
            if record is None:
                raise PIDDoesNotExistError(cls.__name__, str(id_))
            return cls.from_model(record)

model_cls = OAIHarvesterAggregateModel class-attribute instance-attribute

The model class for the request.

dumper = HarvesterDumper() class-attribute instance-attribute

Search dumper with configured extensions.

index = IndexField('oai-harvester-oai-harvester-v1.0.0') class-attribute instance-attribute

The search engine index to use.

id = ModelField('id', dump_type=str) class-attribute instance-attribute

The ID of the harvester.

base_url = ModelField('base_url', dump_type=str) class-attribute instance-attribute

The base URL of the OAI-PMH service.

name = ModelField('name', dump_type=str) class-attribute instance-attribute

The name of the harvester.

comment = ModelField('comment', dump_type=str) class-attribute instance-attribute

Comment.

metadata_prefix = ModelField('metadata_prefix', dump_type=str) class-attribute instance-attribute

The metadata prefix to harvest.

setspec = ModelField('setspec', dump_type=str) class-attribute instance-attribute

The set specifications to harvest.

loader = ModelField('loader', dump_type=str) class-attribute instance-attribute

The definition of the loader.

transformers = ModelField('transformers', dump_type=list) class-attribute instance-attribute

The list of transformers.

writers = ModelField('writers', dump_type=list) class-attribute instance-attribute

The list of writers.

harvest_managers = ModelField('harvest_managers', dump_type=list) class-attribute instance-attribute

The list of harvest managers. Each item is a dict with 'user' key with user ID.

create(data: dict, id_: UUID | None = None, **kwargs: Any) -> OAIHarvesterAggregate classmethod

Create a new OAI harvester and store it in the database.

Source code in oarepo_oaipmh_harvester/oai_harvester/api.py
@classmethod
@override
def create(
    cls,
    data: dict,
    id_: UUID | None = None,
    **kwargs: Any,
) -> OAIHarvesterAggregate:
    """Create a new OAI harvester and store it in the database."""
    with db.session.begin_nested():
        record = OAIHarvester(**data)
        db.session.add(record)
        return cls.from_model(record)

delete(force: bool = False) -> OAIHarvesterAggregate

Delete the harvester.

Source code in oarepo_oaipmh_harvester/oai_harvester/api.py
@override
def delete(self, force: bool = False) -> OAIHarvesterAggregate:
    """Delete the harvester."""
    if self.model is None:
        raise MissingModelError

    with db.session.begin_nested():
        if self.send_signals:
            before_record_delete.send(
                _current_app_object(),
                record=self,
            )

        # Run pre delete extensions
        for e in self._extensions:
            e.pre_delete(self, force=True)

        # the only change from super is the model.model_obj instead of model
        db.session.delete(self.model.model_obj)

    if self.send_signals:
        after_record_delete.send(
            _current_app_object(),
            record=self,
        )

    # Run post delete extensions
    for e in self._extensions:
        e.post_delete(self, force=True)

    return self

get_record(id_: UUID | str, with_deleted: bool = False) -> OAIHarvesterAggregate classmethod

Get the harvester via the specified ID (harvesters are never soft deleted).

Source code in oarepo_oaipmh_harvester/oai_harvester/api.py
@classmethod
def get_record(cls, id_: UUID | str, with_deleted: bool = False) -> OAIHarvesterAggregate:  # noqa: ARG003 interface compatibility
    """Get the harvester via the specified ID (harvesters are never soft deleted)."""
    with db.session.no_autoflush:
        record = OAIHarvester.query.get(str(id_))
        if record is None:
            raise PIDDoesNotExistError(cls.__name__, str(id_))
        return cls.from_model(record)