-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(schematic): move visualization operations endpoints (#2252)
* add new endpoints * added two endpoints * add new endpoints * redid exception handling for new endpoints
- Loading branch information
1 parent
53e48d8
commit c3af47b
Showing
27 changed files
with
1,029 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
apps/schematic/api/schematic_api/controllers/tangled_tree_controller.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import connexion | ||
import six | ||
from typing import Dict | ||
from typing import Tuple | ||
from typing import Union | ||
|
||
from schematic_api.models.basic_error import BasicError # noqa: E501 | ||
from schematic_api import util | ||
from schematic_api.controllers import tangled_tree_controller_impl | ||
|
||
|
||
def get_tangled_tree_layers(schema_url, figure_type=None): # noqa: E501 | ||
"""Get tangled tree node layers to display for a given data model and figure type | ||
Get tangled tree node layers to display for a given data model and figure type # noqa: E501 | ||
:param schema_url: The URL of a schema in jsonld form | ||
:type schema_url: str | ||
:param figure_type: Figure type to generate. | ||
:type figure_type: str | ||
:rtype: Union[str, Tuple[str, int], Tuple[str, int, Dict[str, str]] | ||
""" | ||
return tangled_tree_controller_impl.get_tangled_tree_layers(schema_url, figure_type) | ||
|
||
|
||
def get_tangled_tree_text(schema_url, figure_type=None, text_format=None): # noqa: E501 | ||
"""Get tangled tree plain or higlighted text to display for a given data model, text formatting and figure type | ||
Get tangled tree plain or higlighted text to display for a given data model, text formatting and figure type # noqa: E501 | ||
:param schema_url: The URL of a schema in jsonld form | ||
:type schema_url: str | ||
:param figure_type: Figure type to generate. | ||
:type figure_type: str | ||
:param text_format: Text formatting type. | ||
:type text_format: str | ||
:rtype: Union[object, Tuple[object, int], Tuple[object, int, Dict[str, str]] | ||
""" | ||
return tangled_tree_controller_impl.get_tangled_tree_text( | ||
schema_url, figure_type, text_format | ||
) |
71 changes: 71 additions & 0 deletions
71
apps/schematic/api/schematic_api/controllers/tangled_tree_controller_impl.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"""Tangled tree controllers""" | ||
|
||
from typing import Literal, Union | ||
|
||
from schematic.visualization.tangled_tree import TangledTree # type: ignore | ||
|
||
from schematic_api.models.basic_error import BasicError | ||
from schematic_api.controllers.utils import ( | ||
handle_exceptions, | ||
download_schema_file_as_jsonld, | ||
) | ||
|
||
|
||
@handle_exceptions | ||
def get_tangled_tree_layers( | ||
schema_url: str, figure_type: Literal["component", "dependency"] = "component" | ||
) -> tuple[Union[str, BasicError], int]: | ||
"""Gets layers for a tangled tree visualization. | ||
Args: | ||
schema_url (str): The URL to the schema file | ||
figure_type (Literal["component", "dependency"]): Figure type to generate. | ||
Returns: | ||
tuple[Union[str, BasicError], int]: A tuple | ||
The first item is either the layers or an error object | ||
The second item is the response status | ||
""" | ||
schema_path = download_schema_file_as_jsonld(schema_url) | ||
tangled_tree = TangledTree(schema_path, figure_type) | ||
# Currently TangledTree.get_tangled_tree_layers() returns either an empty list if | ||
# save_file=False or a list of one string if save_file=False. | ||
# The API should output just the string. | ||
# TangledTree.get_tangled_tree_layers() will likely get changed in the future to return | ||
# just a string. | ||
layers_list: list[str] = tangled_tree.get_tangled_tree_layers(save_file=False) | ||
if len(layers_list) == 0: | ||
raise ValueError("TangledTree.get_tangled_tree_layers() returned an empty list") | ||
result: Union[str, BasicError] = layers_list[0] | ||
status = 200 | ||
|
||
return result, status | ||
|
||
|
||
@handle_exceptions | ||
def get_tangled_tree_text( | ||
schema_url: str, | ||
figure_type: Literal["component", "dependency"] = "component", | ||
text_format: Literal["plain", "highlighted"] = "plain", | ||
) -> tuple[Union[str, BasicError], int]: | ||
"""Gets text for a tangled tree visualization. | ||
Args: | ||
schema_url (str): The URL to the schema file | ||
figure_type (Literal["component", "dependency"]): Figure type to generate. | ||
text_format (Literal["plain", "highlighted"]): Determines the type of text | ||
rendering to return | ||
Returns: | ||
tuple[Union[str, BasicError], int]: A tuple | ||
The first item is either the text or an error object | ||
The second item is the response status | ||
""" | ||
schema_path = download_schema_file_as_jsonld(schema_url) | ||
tangled_tree = TangledTree(schema_path, figure_type) | ||
result: Union[str, BasicError] = tangled_tree.get_text_for_tangled_tree( | ||
text_format, save_file=False | ||
) | ||
status = 200 | ||
|
||
return result, status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.