Skip to content

Commit

Permalink
Add sample entities, set input and output ports
Browse files Browse the repository at this point in the history
  • Loading branch information
klosr-eccenca committed Jan 24, 2025
1 parent e93da68 commit 9c27a59
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
40 changes: 35 additions & 5 deletions cmem_plugin_irdi/workflow/irdi_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from typing import Sequence # noqa: UP035

import rfc3987
from cmem_plugin_base.dataintegration.context import ExecutionContext
from cmem_plugin_base.dataintegration.context import (
ExecutionContext,
ExecutionReport,
)
from cmem_plugin_base.dataintegration.description import Icon, Plugin, PluginParameter
from cmem_plugin_base.dataintegration.entity import (
Entities,
Expand All @@ -14,7 +17,10 @@
)
from cmem_plugin_base.dataintegration.parameter.graph import GraphParameterType
from cmem_plugin_base.dataintegration.plugins import WorkflowPlugin
from cmem_plugin_base.dataintegration.ports import FixedNumberOfInputs, FixedSchemaPort
from cmem_plugin_base.dataintegration.ports import (
FixedNumberOfInputs,
FixedSchemaPort,
)
from cmem_plugin_base.dataintegration.utils import setup_cmempy_user_access

from cmem_plugin_irdi.components import components
Expand Down Expand Up @@ -48,8 +54,6 @@
name="output_schema_path",
label="Output path / property",
description="Path or property that will connect input values and their generated IRDIs",
default_value="http://purl.org/dc/terms/identifier",
advanced=True,
),
PluginParameter(
name="counted_object",
Expand Down Expand Up @@ -90,7 +94,7 @@ def __init__( # noqa: PLR0913
csi: str,
counted_object: str,
input_schema_path: str,
output_schema_path: str = "http://purl.org/dc/terms/identifier",
output_schema_path: str,
):
self.input_schema_path = input_schema_path
self.graph = graph
Expand Down Expand Up @@ -124,6 +128,23 @@ def __init__( # noqa: PLR0913
)
]
)
# define
else:
self.input_ports = FixedNumberOfInputs(
[
FixedSchemaPort(
schema=EntitySchema(
type_uri="",
paths=[],
)
)
]
)

# define output port
self.output_port = FixedSchemaPort(
schema=EntitySchema(type_uri="", paths=[EntityPath(path=self.output_schema_path)])
)

# construct counter identifier
self.counter = f"{self.icd}-{self.oi}-{self.opi}-{self.opis}-{self.ai}" f"#{self.csi}"
Expand Down Expand Up @@ -158,6 +179,15 @@ def execute(self, inputs: Sequence[Entities], context: ExecutionContext) -> Enti
)
output.append(Entity(uri=uri, values=[[irdi]]))

# write execution report
context.report.update(
ExecutionReport(
entity_count=len(output),
operation_desc="IRDIs created",
sample_entities=Entities(entities=output[:10], schema=schema),
)
)

return Entities(entities=output, schema=schema)

def _get_input_uri(self, entities: Entities) -> list[str]:
Expand Down
1 change: 1 addition & 0 deletions tests/test_irdi_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"csi": "A4",
"counted_object": "urn:object",
"input_schema_path": "",
"output_schema_path": "http://purl.org/dc/terms/identifier",
}

IRDI_PARAMS_INVALID = {"icd": "12345", "opis": "a"}
Expand Down

0 comments on commit 9c27a59

Please sign in to comment.