-
Notifications
You must be signed in to change notification settings - Fork 0
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
#62 MV Link generation from IQS client & API call #65
Changes from all commits
43d0fdf
f34932c
af58a70
82e3d53
b82b4e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ | |
from iqs_jupyter import api_composition | ||
from iqs_client_extension import ApiClientWithOIDC | ||
|
||
import requests | ||
|
||
|
||
def connect( | ||
address=defaults.default_IQS_address, | ||
|
@@ -58,7 +60,6 @@ def connect( | |
|
||
return IQSClient(configuration, use_oidc) | ||
|
||
|
||
class IQSClient: | ||
def __init__( | ||
self, | ||
|
@@ -71,6 +72,13 @@ def __init__( | |
api_composition.decorate_iqs_client(self, root_configuration, ApiClient) | ||
self.jupyter_tools = ext_point.IQSJupyterTools(self) | ||
|
||
# Acquiring Model Viewer base link from host through internal API | ||
req = requests.get(f"http://{root_configuration.host}/internal-api/solution-configuration") | ||
|
||
# Registering MV URL provider, providing links to MV link received from API call above | ||
ext_point.url_providers.append(ext_point.ModelViewerUrlProvider(self, req.json()["modelViewerBaseURL"])) | ||
Comment on lines
+76
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a specific reason why we do not use a generated OpenAPI client in python, instead of manual json parsing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, but then why is this considered internal API, if it is used by clients to prettify their HTML presentation of query results? Does not sound very internal to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (We have a |
||
|
||
|
||
|
||
class IQSConnectorWidget: | ||
def __init__( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,8 +70,6 @@ def _recognize_typed_element_in_compartment_descriptor( | |
ext_point.element_dict_recognizers.append(_recognize_typed_element_in_compartment_descriptor) | ||
|
||
|
||
|
||
|
||
## monkey patch section | ||
|
||
def _monkey_patch_element_in_compartment_descriptor_repr_html(self): | ||
|
@@ -250,7 +248,7 @@ def _monkey_patch_query_execution_response_to_html(self): | |
param_headers = " ".join(["<th>{}</th> ".format(html.escape(param)) for param in pattern_params]) | ||
match_rows = "\n".join([ | ||
"<tr><th>{}</th>{}</tr>\n".format(row_index," ".join([ | ||
" <td>{}</td>".format(_cell_to_html(match_list[row_index][param])) for param in pattern_params | ||
" <td><a href=\"{}\">{}</a></td>".format(_cell_to_html(match_list[row_index][param]).url, _cell_to_html(match_list[row_index][param])) for param in pattern_params | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This link.generating logic should be within Also, what if a given cell is not a model element, and thus has no url? Do we still generate an
Wait, what? Does |
||
])) for row_index in range(len(match_list)) | ||
]) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,16 +31,30 @@ def cell_to_html(cell): | |
else: | ||
return str(cell) | ||
|
||
def dict_to_element(dict_or_attribute_value, url_provider=None): | ||
def dict_to_element(dict_or_attribute_value): | ||
if isinstance(dict_or_attribute_value, dict): | ||
for recognizer in ext_point.element_dict_recognizers: | ||
recognized = recognizer(dict_or_attribute_value) | ||
if recognized: | ||
if url_provider is not None: | ||
recognized.url = url_provider(recognized) | ||
for url_provider in ext_point.url_providers: | ||
if url_provider(dict_or_attribute_value['element']) is not None: # maybe we should set url param to None - else | ||
setattr(recognized, 'url', url_provider(dict_or_attribute_value['element'])) | ||
Comment on lines
+40
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for your comments!
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return recognized | ||
# not recognized as an element, treated as raw dict | ||
# not recognized as an element, treated as raw dict | ||
return dict_or_attribute_value | ||
else: | ||
return dict_or_attribute_value | ||
|
||
# def dict_to_element(dict_or_attribute_value, url_provider=None): | ||
# if isinstance(dict_or_attribute_value, dict): | ||
# for recognizer in ext_point.element_dict_recognizers: | ||
# recognized = recognizer(dict_or_attribute_value) | ||
# if recognized: | ||
# if url_provider is not None: | ||
# recognized.url = url_provider(recognized) | ||
# return recognized | ||
# # not recognized as an element, treated as raw dict | ||
# return dict_or_attribute_value | ||
# else: | ||
# return dict_or_attribute_value | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove commented out older version |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,8 +29,24 @@ def __init__( | |
self._iqs = iqs | ||
|
||
|
||
# connector-specific extensions may add custom ways to convert a dict to an element representation; | ||
# connector-specific extensions may add custom ways to convert a dict to an element representation; | ||
# parse a dict and return the constructed element or None if not the right format | ||
# default is ElementInCompartmentDescriptor | ||
# default is ElementInCompartmentDescriptor | ||
element_dict_recognizers : List[Callable[[dict], Optional[Any]]] = [] | ||
|
||
|
||
url_providers: List[Callable[[Any], Optional[Any]]] = [] | ||
|
||
class ModelViewerUrlProvider: | ||
def __init__(self, iqs, mv_address=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a statically / globally registered url provider; it should not be aware of the address of the Model Viewer instance. (What if we connect to multiple IncQuery Suite deployments with different addresses)? I would have expected |
||
self.mv_address = mv_address | ||
self.iqs = iqs | ||
|
||
def __call__(self, element): | ||
if "compartmentURI" in element and "relativeElementID" in element: | ||
# Creating ModelViewer Link | ||
compURI = element['compartmentURI'] | ||
relElementID = element['relativeElementID'] | ||
return f"{self.mv_address}?compartmentURI={compURI}&elementId={relElementID}" | ||
else: | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see my comments at
query_execution_response_to_html