You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2020/06/16 16:46:31 UTC

[airavata-django-portal] branch AIRAVATA-3285--Interactive-output-view-providers updated: AIRAVATA-3285 Add _meta query parameter for passing type information to backend

This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch AIRAVATA-3285--Interactive-output-view-providers
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git


The following commit(s) were added to refs/heads/AIRAVATA-3285--Interactive-output-view-providers by this push:
     new 4a719ae  AIRAVATA-3285 Add _meta query parameter for passing type information to backend
4a719ae is described below

commit 4a719ae94e5b9c1ce1047a180f444175227bd26f
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Tue Jun 16 12:46:16 2020 -0400

    AIRAVATA-3285 Add _meta query parameter for passing type information to backend
---
 django_airavata/apps/api/output_views.py           | 30 ++++++++++++++--------
 .../output-displays/OutputViewDataLoader.js        | 10 ++++++++
 2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/django_airavata/apps/api/output_views.py b/django_airavata/apps/api/output_views.py
index 9489350..ef227f6 100644
--- a/django_airavata/apps/api/output_views.py
+++ b/django_airavata/apps/api/output_views.py
@@ -258,18 +258,28 @@ def _infer_interactive_param_type(param):
 def _convert_params_to_type(output_view_provider, params):
     method_sig = inspect.signature(output_view_provider.generate_data)
     method_params = method_sig.parameters
+    # Special query parameter _meta holds type information for interactive
+    # parameters (will only be present if there are interactive parameters)
+    meta = json.loads(params.pop("_meta", "{}"))
     for k, v in params.items():
+        meta_type = meta[k]['type'] if k in meta else None
+        default_value = None
         if (k in method_params and
             method_params[k].default is not inspect.Parameter.empty and
                 method_params[k].default is not None):
-            # TODO: handle lists?
-            # Handle boolean and numeric values, converting from string
-            if isinstance(method_params[k].default, bool):
-                params[k] = v == "true"
-            elif isinstance(method_params[k].default, float):
-                params[k] = float(v)
-            elif isinstance(method_params[k].default, int):
-                params[k] = int(v)
-            else:
-                params[k] = v
+            default_value = method_params[k].default
+        # TODO: handle lists?
+        # Handle boolean and numeric values, converting from string
+        if meta_type == 'boolean' or isinstance(default_value, bool):
+            params[k] = v == "true"
+        elif meta_type == 'float' or isinstance(default_value, float):
+            params[k] = float(v)
+        elif meta_type == 'integer' or isinstance(default_value, int):
+            params[k] = int(v)
+        elif meta_type == 'string' or isinstance(default_value, str):
+            params[k] = v
+        else:
+            logger.warning(
+                f"Unrecognized type for parameter {k}: "
+                f"meta_type={meta_type}, default_value={default_value}")
     return params
diff --git a/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/experiment/output-displays/OutputViewDataLoader.js b/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/experiment/output-displays/OutputViewDataLoader.js
index 62a4be7..9391a5b 100644
--- a/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/experiment/output-displays/OutputViewDataLoader.js
+++ b/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/experiment/output-displays/OutputViewDataLoader.js
@@ -26,11 +26,21 @@ export default class OutputViewDataLoader {
 
   createInteractiveParams() {
     const params = {};
+    const meta = {};
     if (this.data && this.data.interactive) {
       this.data.interactive.forEach(p => {
         params[p.name] = p.value;
+        meta[p.name] = {
+          type: p.type
+        };
       });
     }
+    if (Object.keys(meta).length > 0) {
+      // Special _meta query parameter holds type information, which is needed
+      // when the type of a parameter can't be inferred when it is missing a
+      // default value
+      params._meta = JSON.stringify(meta);
+    }
     return params;
   }
 }