Skip to content

Commit

Permalink
added component requirement endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewelamb committed Apr 10, 2024
1 parent d503473 commit fe30b32
Show file tree
Hide file tree
Showing 16 changed files with 723 additions and 0 deletions.
3 changes: 3 additions & 0 deletions apps/schematic/api/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ schematic_api/models/__init__.py
schematic_api/models/asset_type.py
schematic_api/models/base_model_.py
schematic_api/models/basic_error.py
schematic_api/models/component_requirements_array.py
schematic_api/models/component_requirements_graph.py
schematic_api/models/component_requirements_subgraph.py
schematic_api/models/connected_node_pair.py
schematic_api/models/connected_node_pair_array.py
schematic_api/models/connected_node_pair_page.py
Expand Down
48 changes: 48 additions & 0 deletions apps/schematic/api/schematic_api/controllers/schema_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
from typing import Union

from schematic_api.models.basic_error import BasicError # noqa: E501
from schematic_api.models.component_requirements_array import (
ComponentRequirementsArray,
) # noqa: E501
from schematic_api.models.component_requirements_graph import (
ComponentRequirementsGraph,
) # noqa: E501
from schematic_api.models.connected_node_pair_array import (
ConnectedNodePairArray,
) # noqa: E501
Expand Down Expand Up @@ -42,6 +48,48 @@ def get_component(
)


def get_component_requirements_array(
component_label, schema_url, display_label_type=None
): # noqa: E501
"""Given a source model component (see https://w3id.org/biolink/vocab/category for definnition of component), return all components required by it in array form.
Given a source model component (see https://w3id.org/biolink/vocab/category for definnition of component), return all components required by it in array form. # noqa: E501
:param component_label: The label of a component in a schema
:type component_label: str
:param schema_url: The URL of a schema in jsonld or csv form
:type schema_url: str
:param display_label_type: The type of label to display
:type display_label_type: str
:rtype: Union[ComponentRequirementsArray, Tuple[ComponentRequirementsArray, int], Tuple[ComponentRequirementsArray, int, Dict[str, str]]
"""
return schema_controller_impl.get_component_requirements_array(
component_label, schema_url, display_label_type
)


def get_component_requirements_graph(
component_label, schema_url, display_label_type=None
): # noqa: E501
"""Given a source model component (see https://w3id.org/biolink/vocab/category for definnition of component), return all components required by it in graph form.
Given a source model component (see https://w3id.org/biolink/vocab/category for definnition of component), return all components required by it in graph form. # noqa: E501
:param component_label: The label of a component in a schema
:type component_label: str
:param schema_url: The URL of a schema in jsonld or csv form
:type schema_url: str
:param display_label_type: The type of label to display
:type display_label_type: str
:rtype: Union[ComponentRequirementsGraph, Tuple[ComponentRequirementsGraph, int], Tuple[ComponentRequirementsGraph, int, Dict[str, str]]
"""
return schema_controller_impl.get_component_requirements_graph(
component_label, schema_url, display_label_type
)


def get_connected_node_pair_array(
schema_url, relationship_type, display_label_type=None
): # noqa: E501
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
from schematic.visualization.attributes_explorer import AttributesExplorer # type: ignore
from schematic.utils.schema_utils import get_property_label_from_display_name # type: ignore
from schematic.utils.schema_utils import DisplayLabelType # type: ignore
from schematic.models.metadata import MetadataModel # type: ignore

from schematic_api.models.basic_error import BasicError
from schematic_api.models.component_requirements_subgraph import (
ComponentRequirementsSubgraph,
)
from schematic_api.models.node_property_array import NodePropertyArray
from schematic_api.models.validation_rule import ValidationRule
from schematic_api.models.validation_rule_array import ValidationRuleArray
Expand Down Expand Up @@ -62,6 +66,70 @@ def get_component(
return result, status


@handle_exceptions
def get_component_requirements_array(
component_label: str,
schema_url: str,
display_label_type: DisplayLabelType,
) -> tuple[Union[list[str], BasicError], int]:
"""Gets the input components required components
Args:
component_label (str): The label of the component
schema_url (str): The URL of the schema in json form
display_label_type (DisplayLabelType):
The type of label to use as display
Defaults to "class_label"
Returns:
tuple[Union[ComponentRequirementArray, BasicError], int]: A tuple
item 1 is either the required coponents or an error
item 2 is the status
"""
schema_path = download_schema_file_as_jsonld(schema_url)
metadata_model = MetadataModel(
inputMModelLocation=schema_path,
inputMModelLocationType="local",
data_model_labels=display_label_type,
)
result = metadata_model.get_component_requirements(
source_component=component_label, as_graph=False
)
status = 200
return result, status


@handle_exceptions
def get_component_requirements_graph(
component_label: str,
schema_url: str,
display_label_type: DisplayLabelType,
) -> tuple[Union[list[ComponentRequirementsSubgraph], BasicError], int]:
"""Gets the input components required components
Args:
component_label (str): The label of the component
schema_url (str): The URL of the schema in json form
display_label_type (DisplayLabelType):
The type of label to use as display
Defaults to "class_label"
Returns:
tuple[Union[ComponentRequirementsSubgrpah, BasicError], int]: A tuple
item 1 is either the required coponents or an error
item 2 is the status
"""
schema_path = download_schema_file_as_jsonld(schema_url)
metadata_model = MetadataModel(
inputMModelLocation=schema_path,
inputMModelLocationType="local",
data_model_labels=display_label_type,
)
results = metadata_model.get_component_requirements(
source_component=component_label, as_graph=True
)
result = [ComponentRequirementsSubgraph(result[0], result[1]) for result in results]

status = 200
return result, status


def get_connected_node_pairs_from_schematic(
relationship_type: str,
schema_url: str,
Expand Down
3 changes: 3 additions & 0 deletions apps/schematic/api/schematic_api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# import models into model package
from schematic_api.models.asset_type import AssetType
from schematic_api.models.basic_error import BasicError
from schematic_api.models.component_requirements_array import ComponentRequirementsArray
from schematic_api.models.component_requirements_graph import ComponentRequirementsGraph
from schematic_api.models.component_requirements_subgraph import ComponentRequirementsSubgraph
from schematic_api.models.connected_node_pair import ConnectedNodePair
from schematic_api.models.connected_node_pair_array import ConnectedNodePairArray
from schematic_api.models.connected_node_pair_page import ConnectedNodePairPage
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# coding: utf-8

from __future__ import absolute_import
from datetime import date, datetime # noqa: F401

from typing import List, Dict # noqa: F401

from schematic_api.models.base_model_ import Model
from schematic_api import util


class ComponentRequirementsArray(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""

def __init__(self, component_requirements_list=None): # noqa: E501
"""ComponentRequirementsArray - a model defined in OpenAPI
:param component_requirements_list: The component_requirements_list of this ComponentRequirementsArray. # noqa: E501
:type component_requirements_list: List[str]
"""
self.openapi_types = {
'component_requirements_list': List[str]
}

self.attribute_map = {
'component_requirements_list': 'componentRequirementsList'
}

self._component_requirements_list = component_requirements_list

@classmethod
def from_dict(cls, dikt) -> 'ComponentRequirementsArray':
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The ComponentRequirementsArray of this ComponentRequirementsArray. # noqa: E501
:rtype: ComponentRequirementsArray
"""
return util.deserialize_model(dikt, cls)

@property
def component_requirements_list(self):
"""Gets the component_requirements_list of this ComponentRequirementsArray.
:return: The component_requirements_list of this ComponentRequirementsArray.
:rtype: List[str]
"""
return self._component_requirements_list

@component_requirements_list.setter
def component_requirements_list(self, component_requirements_list):
"""Sets the component_requirements_list of this ComponentRequirementsArray.
:param component_requirements_list: The component_requirements_list of this ComponentRequirementsArray.
:type component_requirements_list: List[str]
"""

self._component_requirements_list = component_requirements_list
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# coding: utf-8

from __future__ import absolute_import
from datetime import date, datetime # noqa: F401

from typing import List, Dict # noqa: F401

from schematic_api.models.base_model_ import Model
from schematic_api.models.component_requirements_subgraph import ComponentRequirementsSubgraph
from schematic_api import util

from schematic_api.models.component_requirements_subgraph import ComponentRequirementsSubgraph # noqa: E501

class ComponentRequirementsGraph(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""

def __init__(self, component_requirements_graph=None): # noqa: E501
"""ComponentRequirementsGraph - a model defined in OpenAPI
:param component_requirements_graph: The component_requirements_graph of this ComponentRequirementsGraph. # noqa: E501
:type component_requirements_graph: List[ComponentRequirementsSubgraph]
"""
self.openapi_types = {
'component_requirements_graph': List[ComponentRequirementsSubgraph]
}

self.attribute_map = {
'component_requirements_graph': 'componentRequirementsGraph'
}

self._component_requirements_graph = component_requirements_graph

@classmethod
def from_dict(cls, dikt) -> 'ComponentRequirementsGraph':
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The ComponentRequirementsGraph of this ComponentRequirementsGraph. # noqa: E501
:rtype: ComponentRequirementsGraph
"""
return util.deserialize_model(dikt, cls)

@property
def component_requirements_graph(self):
"""Gets the component_requirements_graph of this ComponentRequirementsGraph.
:return: The component_requirements_graph of this ComponentRequirementsGraph.
:rtype: List[ComponentRequirementsSubgraph]
"""
return self._component_requirements_graph

@component_requirements_graph.setter
def component_requirements_graph(self, component_requirements_graph):
"""Sets the component_requirements_graph of this ComponentRequirementsGraph.
:param component_requirements_graph: The component_requirements_graph of this ComponentRequirementsGraph.
:type component_requirements_graph: List[ComponentRequirementsSubgraph]
"""

self._component_requirements_graph = component_requirements_graph
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# coding: utf-8

from __future__ import absolute_import
from datetime import date, datetime # noqa: F401

from typing import List, Dict # noqa: F401

from schematic_api.models.base_model_ import Model
from schematic_api import util


class ComponentRequirementsSubgraph(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""

def __init__(self, component1=None, component2=None): # noqa: E501
"""ComponentRequirementsSubgraph - a model defined in OpenAPI
:param component1: The component1 of this ComponentRequirementsSubgraph. # noqa: E501
:type component1: str
:param component2: The component2 of this ComponentRequirementsSubgraph. # noqa: E501
:type component2: str
"""
self.openapi_types = {
'component1': str,
'component2': str
}

self.attribute_map = {
'component1': 'component1',
'component2': 'component2'
}

self._component1 = component1
self._component2 = component2

@classmethod
def from_dict(cls, dikt) -> 'ComponentRequirementsSubgraph':
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The ComponentRequirementsSubgraph of this ComponentRequirementsSubgraph. # noqa: E501
:rtype: ComponentRequirementsSubgraph
"""
return util.deserialize_model(dikt, cls)

@property
def component1(self):
"""Gets the component1 of this ComponentRequirementsSubgraph.
The display name of the first component in the graph # noqa: E501
:return: The component1 of this ComponentRequirementsSubgraph.
:rtype: str
"""
return self._component1

@component1.setter
def component1(self, component1):
"""Sets the component1 of this ComponentRequirementsSubgraph.
The display name of the first component in the graph # noqa: E501
:param component1: The component1 of this ComponentRequirementsSubgraph.
:type component1: str
"""
if component1 is None:
raise ValueError("Invalid value for `component1`, must not be `None`") # noqa: E501

self._component1 = component1

@property
def component2(self):
"""Gets the component2 of this ComponentRequirementsSubgraph.
The display name of the second component in the graph # noqa: E501
:return: The component2 of this ComponentRequirementsSubgraph.
:rtype: str
"""
return self._component2

@component2.setter
def component2(self, component2):
"""Sets the component2 of this ComponentRequirementsSubgraph.
The display name of the second component in the graph # noqa: E501
:param component2: The component2 of this ComponentRequirementsSubgraph.
:type component2: str
"""
if component2 is None:
raise ValueError("Invalid value for `component2`, must not be `None`") # noqa: E501

self._component2 = component2
Loading

0 comments on commit fe30b32

Please sign in to comment.