-
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.
- Loading branch information
1 parent
e853930
commit 47c5ebf
Showing
25 changed files
with
870 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
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, | ||
) |
104 changes: 104 additions & 0 deletions
104
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,104 @@ | ||
"""Manifest generation functions""" | ||
# pylint: disable=too-many-arguments | ||
|
||
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_google_sheet_manifests( | ||
schema_url: str, | ||
asset_view_id: str, | ||
add_annotations: bool, | ||
dataset_id_array: list[str] | None, | ||
manifest_title: str, | ||
node_label_array: list[str] | None, | ||
use_strict_validation: bool, | ||
generate_all_manifests: bool, | ||
) -> tuple[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 (list[str] | None): 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 (list[str] | None): 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[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: 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
64 changes: 64 additions & 0 deletions
64
apps/schematic/api/schematic_api/models/google_sheet_links.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,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 GoogleSheetLinks(Model): | ||
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
Do not edit the class manually. | ||
""" | ||
|
||
def __init__(self, links=None): # noqa: E501 | ||
"""GoogleSheetLinks - a model defined in OpenAPI | ||
:param links: The links of this GoogleSheetLinks. # noqa: E501 | ||
:type links: List[str] | ||
""" | ||
self.openapi_types = { | ||
'links': List[str] | ||
} | ||
|
||
self.attribute_map = { | ||
'links': 'links' | ||
} | ||
|
||
self._links = links | ||
|
||
@classmethod | ||
def from_dict(cls, dikt) -> 'GoogleSheetLinks': | ||
"""Returns the dict as a model | ||
:param dikt: A dict. | ||
:type: dict | ||
:return: The GoogleSheetLinks of this GoogleSheetLinks. # noqa: E501 | ||
:rtype: GoogleSheetLinks | ||
""" | ||
return util.deserialize_model(dikt, cls) | ||
|
||
@property | ||
def links(self): | ||
"""Gets the links of this GoogleSheetLinks. | ||
:return: The links of this GoogleSheetLinks. | ||
:rtype: List[str] | ||
""" | ||
return self._links | ||
|
||
@links.setter | ||
def links(self, links): | ||
"""Sets the links of this GoogleSheetLinks. | ||
:param links: The links of this GoogleSheetLinks. | ||
:type links: List[str] | ||
""" | ||
|
||
self._links = links |
Oops, something went wrong.