-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(schematic): add generate manifest endpoint (#2431)
* feat(schematic): integration testing (#2398) * changed authenticication so that only endpoints that need it have it * updated schematic * add patch for access token * schema endpoints no longer mockeed * added tests for handle exceptions * added integration tests * marked synapse tests * added error handling for bad schema urls * fix error message * add workflow for end to end testing * fix some test results * add unit mark * add unit mark * add workflow for testing with secrets * rename file * fix synapse test file when secrets file doesnt exists * fix test workflows * turned synapse ids into secrets in workflow * turned synapse ids into secrets in workflow * Update schematic-api-ci.yml * Update schematic-api-ci.yml * Update schematic-api-ci.yml * Update schematic-api-ci.yml * Update schematic-api-ci.yml * Update schematic-api-ci.yml * Update schematic-api-ci.yml * Update schematic-api-ci.yml * add paging, and split connected noeds into two endpoints * paginated preoject datasets query * paginated preoject datasets query * paginated dataset files endpoint * pagniate project manifests endpoint * paginate get node dependencies * paginate get node dependencies * paginate node properties endpoint * paginate validation rules endpoint * paginate get projects endpoint * update schematic and other packages * remove uneeded type ignores * added generate manifest endpoints * temp commit * delete manifest file * add generate manifest endpoint * fix broken tests
- Loading branch information
1 parent
024cef1
commit 06269d9
Showing
40 changed files
with
1,757 additions
and
892 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,6 @@ | ||
# Do not change the 'definitions' section unless you know what you're doing | ||
definitions: | ||
synapse_config: ".synapseConfig" | ||
service_acct_creds: "schematic_service_account_creds.json" | ||
asset_store: | ||
synapse: | ||
config: '.synapseConfig' | ||
|
||
synapse: | ||
master_fileview: 'syn23643253' | ||
manifest_folder: 'manifests' | ||
manifest_basename: 'synapse_storage_manifest' | ||
service_acct_creds: 'syn25171627' | ||
|
||
manifest: | ||
# if making many manifests, just include name prefix | ||
title: 'example' | ||
# to make all manifests enter only 'all manifests' | ||
data_type: | ||
- 'Biospecimen' | ||
- 'Patient' | ||
|
||
model: | ||
input: | ||
location: 'tests/data/example.model.jsonld' | ||
file_type: 'local' | ||
|
||
style: | ||
google_manifest: | ||
req_bg_color: | ||
red: 0.9215 | ||
green: 0.9725 | ||
blue: 0.9803 | ||
opt_bg_color: | ||
red: 1.0 | ||
green: 1.0 | ||
blue: 0.9019 | ||
master_template_id: '1LYS5qE4nV9jzcYw5sXwCza25slDfRA1CIg3cs-hCdpU' | ||
strict_validation: true | ||
google_sheets: | ||
service_acct_creds: 'schematic_service_account_creds.json' |
55 changes: 55 additions & 0 deletions
55
apps/schematic/api/schematic_api/controllers/manifest_generation_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,55 @@ | ||
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.models.google_sheet_links import GoogleSheetLinks # noqa: E501 | ||
from schematic_api import util | ||
from schematic_api.controllers import manifest_generation_controller_impl | ||
|
||
|
||
def generate_google_sheet_manifests( | ||
schema_url, | ||
asset_view_id, | ||
add_annotations=None, | ||
dataset_id_array=None, | ||
manifest_title=None, | ||
node_label_array=None, | ||
use_strict_validation=None, | ||
generate_all_manifests=None, | ||
): # noqa: E501 | ||
"""Generates a list of google sheet links | ||
Generates a list of google sheet links # noqa: E501 | ||
:param schema_url: The URL of a schema in jsonld form | ||
:type schema_url: 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 add_annotations: If true, annotations are added to the manifest | ||
:type add_annotations: bool | ||
:param dataset_id_array: An array of dataset ids | ||
:type dataset_id_array: List[str] | ||
:param manifest_title: If making one manifest, the title of the manifest If making multiple manifests, the prefix of the title of the manifests | ||
:type manifest_title: str | ||
:param node_label_array: An array of nodel labels | ||
:type node_label_array: List[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 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 | ||
:rtype: Union[GoogleSheetLinks, Tuple[GoogleSheetLinks, int], Tuple[GoogleSheetLinks, int, Dict[str, str]] | ||
""" | ||
return manifest_generation_controller_impl.generate_google_sheet_manifests( | ||
schema_url, | ||
asset_view_id, | ||
add_annotations, | ||
dataset_id_array, | ||
manifest_title, | ||
node_label_array, | ||
use_strict_validation, | ||
generate_all_manifests, | ||
) |
148 changes: 148 additions & 0 deletions
148
apps/schematic/api/schematic_api/controllers/manifest_generation_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,148 @@ | ||
"""Manifest generation functions""" | ||
# pylint: disable=too-many-arguments | ||
|
||
from typing import Union, BinaryIO, Optional | ||
from schematic import CONFIG # type: ignore | ||
from schematic.manifest.generator import ManifestGenerator # type: ignore | ||
|
||
from schematic_api.models.basic_error import BasicError | ||
from schematic_api.models.google_sheet_links import GoogleSheetLinks | ||
from schematic_api.controllers.utils import ( | ||
handle_exceptions, | ||
get_access_token, | ||
download_schema_file_as_jsonld, | ||
InvalidValueError, | ||
) | ||
|
||
|
||
@handle_exceptions | ||
def generate_excel_manifest( | ||
schema_url: str, | ||
asset_view_id: str, | ||
node_label: str, | ||
add_annotations: bool, | ||
manifest_title: str, | ||
dataset_id: Optional[str], | ||
) -> tuple[Union[BinaryIO, BasicError], int]: | ||
"""Generates a manifest in excel form | ||
Args: | ||
schema_url (str): The URL of the schema | ||
dataset_id (Optional[str]): Use this to get the existing manifest in the dataset. | ||
Must be of same type as the node_label | ||
asset_view_id (str): ID of the asset view | ||
node_label (str): The datatype of the manifest to generate | ||
add_annotations (bool): Whether or not annotatiosn get added to the manifest | ||
manifest_title (str): Title of the manifest | ||
Returns: | ||
tuple[Union[BinaryIO, BasicError], int]: A tuple | ||
The first item is either manifest in Excel form or an error object | ||
The second item is the response status | ||
""" | ||
access_token = get_access_token() | ||
CONFIG.load_config("schematic_api/config.yml") | ||
CONFIG.synapse_master_fileview_id = asset_view_id | ||
schema_path = download_schema_file_as_jsonld(schema_url) | ||
manifest = ManifestGenerator.create_single_manifest( | ||
jsonld=schema_path, | ||
output_format="excel", | ||
data_type=node_label, | ||
title=manifest_title, | ||
access_token=access_token, | ||
dataset_id=dataset_id, | ||
use_annotations=add_annotations, | ||
) | ||
result: Union[BinaryIO, BasicError] = manifest | ||
status = 200 | ||
return result, status | ||
|
||
|
||
@handle_exceptions | ||
def generate_google_sheet_manifests( | ||
schema_url: str, | ||
asset_view_id: str, | ||
add_annotations: bool, | ||
dataset_id_array: Optional[list[str]], | ||
manifest_title: str, | ||
node_label_array: Optional[list[str]], | ||
use_strict_validation: bool, | ||
generate_all_manifests: bool, | ||
) -> tuple[Union[GoogleSheetLinks, BasicError], int]: | ||
"""Generates a list of links to manifets in google sheet form | ||
Args: | ||
schema_url (str): The URL of the schema | ||
dataset_id_array (Optional[list[str]]): Use this to get the existing manifests in the | ||
datasets. Must be of same type as the node_label_array, same order, and same length | ||
asset_view_id (str): ID of the asset view | ||
node_label_array (Optional[list[str]]): The datatypes of the manifests to generate | ||
add_annotations (bool): Whether or not annotatiosn get added to the manifest | ||
manifest_title (str): Title of the manifest | ||
use_strict_validation (bool): Whether or not to use google sheet strict validation | ||
generate_all_manifests (bool): Will generate a manifest for all data types | ||
Raises: | ||
ValueError: When generate_all_manifests is true and either dataset_id_array or | ||
node_label_array are provided | ||
ValueError: When generate_all_manifests is false and node_label_array is not provided | ||
ValueError: When generate_all_manifests is false and dataset_id_arrayy is provided, | ||
but it doesn't match the length of node_label_array | ||
Returns: | ||
tuple[Union[GoogleSheetLinks, BasicError], int]: A tuple | ||
The first item is either the google sheet links of the manifests or an error object | ||
The second item is the response status | ||
""" | ||
|
||
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 node_label_array: | ||
raise InvalidValueError( | ||
"When generate_all_manifests is True node_label_array must be None", | ||
{"node_label_array": node_label_array}, | ||
) | ||
node_label_array = ["all_manifests"] | ||
|
||
else: | ||
if not node_label_array: | ||
raise InvalidValueError( | ||
( | ||
"When generate_all_manifests is False node_label_array must be a list with " | ||
"atleast one item" | ||
), | ||
{"node_label_array": node_label_array}, | ||
) | ||
if dataset_id_array and len(dataset_id_array) != len(node_label_array): | ||
raise InvalidValueError( | ||
( | ||
"When generate_all_manifests is False node_label_array and dataset_id_array " | ||
"must both lists with the same length" | ||
), | ||
{ | ||
"node_label_array": node_label_array, | ||
"dataset_id_array": dataset_id_array, | ||
}, | ||
) | ||
|
||
access_token = get_access_token() | ||
CONFIG.load_config("schematic_api/config.yml") | ||
CONFIG.synapse_master_fileview_id = asset_view_id | ||
schema_path = download_schema_file_as_jsonld(schema_url) | ||
links = ManifestGenerator.create_manifests( | ||
jsonld=schema_path, | ||
output_format="google_sheet", | ||
data_types=node_label_array, | ||
title=manifest_title, | ||
access_token=access_token, | ||
dataset_ids=dataset_id_array, | ||
strict=use_strict_validation, | ||
use_annotations=add_annotations, | ||
) | ||
result: Union[GoogleSheetLinks, BasicError] = GoogleSheetLinks(links) | ||
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
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
Oops, something went wrong.