# oarepo\_oaipmh\_harvester.transformers

## `oarepo_oaipmh_harvester.transformers`

Transformers for OAI-PMH harvested records.

A transformer converts what the harvester's reader yields into the data the writer stores - `{"record": <data for the model's service or None>, "oai_record": <OAI record>}`. This package ships oai-import, which converts the metadata with one of the target model's imports, and skip-if-owned, which skips records written by another harvester.

How to write your own readers and transformers, what they receive and produce and how they report errors is described in [Readers, transformers and writers](<https://oarepo.github.io/oarepo-oaipmh-harvester/readers-transformers-writers.html>).

Modules:

| Name | Description |
| --- | --- |
| `oai_import` | `oai-import` transformer - converts harvested XML with the target model's import. |
| `skip_if_owned` | `skip-if-owned` transformer - lets a fallback harvester give way to other harvesters. |

### `OAIImportTransformer`

Bases: `BaseTransformer`

Transformer for importing OAI-PMH records.

This transformers needs a model name to find the appropriate importer for the metadata format being imported.

#### `__init__(model: str, *_args: Any, **_kwargs: Any) -> None`

Initialize the OAI import transformer.

#### `apply(stream_entry: StreamEntry, *_args: Any, **_kwargs: Any) -> StreamEntry`

Apply the transformation to the entry.

Returns:

| Name | Type | Description |
| --- | --- | --- |
| `StreamEntry` | `StreamEntry` | The transformed entry. |

Raises:

| Type | Description |
| --- | --- |
| `TransformerError` | In case of errors. |

### `SkipIfOwnedTransformer`

Bases: `BaseTransformer`

Mark the entry as filtered if another harvester owns its local record.

#### `__init__(model: str, *_args: Any, harvester_id: str, **_kwargs: Any) -> None`

Initialize the transformer.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `model` | `str` | Name of the target model (`current_runtime.models`). | *required* |
| `harvester_id` | `str` | Harvester the entries belong to (set by the harvest task). | *required* |

#### `apply(stream_entry: StreamEntry, *_args: Any, **_kwargs: Any) -> StreamEntry`

Mark the entry as filtered, with the reason in `entry["skip_reason"]`, if the pid is owned.
