# oarepo\_oaipmh\_harvester.transformers.oai\_import

## `oarepo_oaipmh_harvester.transformers.oai_import`

`oai-import` transformer - converts harvested XML with the target model's import.

The transformer takes the single child of the OAI `<metadata>` element and looks up an import of the target model whose `oai_name` equals `(namespace, local name)` of that element (imports are added to models with `oarepo_model` `AddMetadataImport`). The import's deserializer gets the element itself (`deserialize_xml`) if it supports it, otherwise its string serialization (`deserialize`). Deleted OAI records pass through with `record = None`.

Datastream configuration: `oai-import{model:"<model name>"}`.

If the deserializer raises (e.g. a marshmallow `ValidationError`), the record fails - the error is stored on its harvest record and the harvest goes on. See [Readers, transformers and writers](<https://oarepo.github.io/oarepo-oaipmh-harvester/readers-transformers-writers.html#using-oai-import>) for an example.

### `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. |
