Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetaure fds 829 component requirements #2625

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/schematic/api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ target/
*secrets*
synapse_config.yaml
schematic_service_account_creds.json
private_localhost_certificate.crt
private_localhost.key

#schematic downloaded files
manifests
Expand Down
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_requirement_array.py
schematic_api/models/component_requirement_graph.py
schematic_api/models/component_requirement_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
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def generate_google_sheet_manifests(
manifest_title=None,
data_type_array=None,
display_label_type=None,
asset_view_id=None,
use_strict_validation=None,
asset_view_id=None,
generate_all_manifests=None,
): # noqa: E501
"""Generates a list of google sheet links
Expand All @@ -37,10 +37,10 @@ def generate_google_sheet_manifests(
:type data_type_array: List[str]
:param display_label_type: The type of label to display
:type display_label_type: str
:param asset_view_id: ID of view listing all project data assets. E.g. for Synapse this would be the Synapse ID of the fileview listing all data assets for a given project
:type asset_view_id: str
:param use_strict_validation: If true, users are blocked from entering incorrect values. If false, users will get a warning when using incorrect values.
:type use_strict_validation: bool
:param asset_view_id: ID of view listing all project data assets. E.g. for Synapse this would be the Synapse ID of the fileview listing all data assets for a given project
:type asset_view_id: str
:param generate_all_manifests: If true, a manifest for all components will be generated, datasetIds will be ignored. If false, manifests for each id in datasetIds will be generated.
:type generate_all_manifests: bool

Expand All @@ -53,7 +53,7 @@ def generate_google_sheet_manifests(
manifest_title,
data_type_array,
display_label_type,
asset_view_id,
use_strict_validation,
asset_view_id,
generate_all_manifests,
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
handle_exceptions,
get_access_token,
download_schema_file_as_jsonld,
InvalidValueError,
)


Expand All @@ -22,10 +21,10 @@ def generate_google_sheet_manifests(
dataset_id_array: list[str] | None,
manifest_title: str | None,
data_type_array: list[str] | None,
display_label_type: DisplayLabelType = "class_label",
asset_view_id: str | None = None,
use_strict_validation: bool = True,
generate_all_manifests: bool = False,
display_label_type: DisplayLabelType,
use_strict_validation: bool,
asset_view_id: str | None,
generate_all_manifests: bool,
) -> tuple[GoogleSheetLinks | BasicError, int]:
"""Generates a list of links to manifests in google sheet form

Expand Down Expand Up @@ -57,38 +56,9 @@ def generate_google_sheet_manifests(
"""

if generate_all_manifests:
if dataset_id_array:
raise InvalidValueError(
"When generate_all_manifests is True dataset_id_array must be None",
{"dataset_id_array": dataset_id_array},
)
if data_type_array:
raise InvalidValueError(
"When generate_all_manifests is True data_type_array must be None",
{"data_type_array": data_type_array},
)
data_type_array = ["all manifests"]

else:
if not data_type_array:
raise InvalidValueError(
(
"When generate_all_manifests is False data_type_array must be a list with "
"at least one item"
),
{"data_type_array": data_type_array},
)
if dataset_id_array and len(dataset_id_array) != len(data_type_array):
raise InvalidValueError(
(
"When generate_all_manifests is False data_type_array and dataset_id_array "
"must both lists with the same length"
),
{
"data_type_array": data_type_array,
"dataset_id_array": dataset_id_array,
},
)
if not data_type_array:
data_type_array = []

access_token = get_access_token()
if asset_view_id:
Expand Down
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_requirement_array import (
ComponentRequirementArray,
) # noqa: E501
from schematic_api.models.component_requirement_graph import (
ComponentRequirementGraph,
) # 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[ComponentRequirementArray, Tuple[ComponentRequirementArray, int], Tuple[ComponentRequirementArray, 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[ComponentRequirementGraph, Tuple[ComponentRequirementGraph, int], Tuple[ComponentRequirementGraph, 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_requirement_subgraph import (
ComponentRequirementSubgraph,
)
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,72 @@ 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[ComponentRequirementSubgraph], 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[ComponentRequirementGrpah, 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 = [ComponentRequirementSubgraph(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_requirement_array import ComponentRequirementArray
from schematic_api.models.component_requirement_graph import ComponentRequirementGraph
from schematic_api.models.component_requirement_subgraph import ComponentRequirementSubgraph
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 ComponentRequirementArray(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
"""ComponentRequirementArray - a model defined in OpenAPI

:param component_requirements_list: The component_requirements_list of this ComponentRequirementArray. # 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) -> 'ComponentRequirementArray':
"""Returns the dict as a model

:param dikt: A dict.
:type: dict
:return: The ComponentRequirementArray of this ComponentRequirementArray. # noqa: E501
:rtype: ComponentRequirementArray
"""
return util.deserialize_model(dikt, cls)

@property
def component_requirements_list(self):
"""Gets the component_requirements_list of this ComponentRequirementArray.


:return: The component_requirements_list of this ComponentRequirementArray.
: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 ComponentRequirementArray.


:param component_requirements_list: The component_requirements_list of this ComponentRequirementArray.
:type component_requirements_list: List[str]
"""

self._component_requirements_list = component_requirements_list
Loading
Loading