You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by ia...@apache.org on 2015/07/13 14:54:32 UTC

[14/34] incubator-taverna-mobile git commit: implementing workflow run over the taverna player

implementing workflow run over the taverna player


Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/commit/6e202551
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/tree/6e202551
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/diff/6e202551

Branch: refs/heads/master
Commit: 6e202551a1cf5231fc5d2e0b1e725df69bf01ae8
Parents: 57164b1
Author: larrytech7 <la...@gmail.com>
Authored: Wed Jul 8 15:19:02 2015 +0100
Committer: larrytech7 <la...@gmail.com>
Committed: Wed Jul 8 15:19:02 2015 +0100

----------------------------------------------------------------------
 .../taverna/mobile/activities/RunResult.java    |  67 ++++++++++++++++
 .../workflowdetails/WorkflowdetailFragment.java |  79 ++++++++++++-------
 app/src/main/res/layout/activity_run_result.xml |   4 +
 app/src/main/res/layout/fragment_run_result.xml |  12 +++
 app/src/main/res/menu/run_result.xml            |   7 ++
 simple-xml-2.7.1/simple-xml-2.7.1.iml           |  16 ----
 simple-xml-2.7.1/simple-xml-2.7.1.jar           | Bin 427590 -> 0 bytes
 7 files changed, 142 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/6e202551/app/src/main/java/org/apache/taverna/mobile/activities/RunResult.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/activities/RunResult.java b/app/src/main/java/org/apache/taverna/mobile/activities/RunResult.java
new file mode 100644
index 0000000..2ae1a53
--- /dev/null
+++ b/app/src/main/java/org/apache/taverna/mobile/activities/RunResult.java
@@ -0,0 +1,67 @@
+package org.apache.taverna.mobile.activities;
+
+import android.support.v7.app.ActionBarActivity;
+import android.support.v7.app.ActionBar;
+import android.support.v4.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.os.Build;
+
+import org.apache.taverna.mobile.R;
+
+public class RunResult extends ActionBarActivity {
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_run_result);
+        if (savedInstanceState == null) {
+            getSupportFragmentManager().beginTransaction()
+                    .add(R.id.container, new PlaceholderFragment())
+                    .commit();
+        }
+    }
+
+
+    @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+        // Inflate the menu; this adds items to the action bar if it is present.
+        getMenuInflater().inflate(R.menu.run_result, menu);
+        return true;
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        // Handle action bar item clicks here. The action bar will
+        // automatically handle clicks on the Home/Up button, so long
+        // as you specify a parent activity in AndroidManifest.xml.
+        int id = item.getItemId();
+
+        //noinspection SimplifiableIfStatement
+        if (id == R.id.action_settings) {
+            return true;
+        }
+
+        return super.onOptionsItemSelected(item);
+    }
+
+    /**
+     * A placeholder fragment containing a simple view.
+     */
+    public static class PlaceholderFragment extends Fragment {
+
+        public PlaceholderFragment() {
+        }
+
+        @Override
+        public View onCreateView(LayoutInflater inflater, ViewGroup container,
+                                 Bundle savedInstanceState) {
+            View rootView = inflater.inflate(R.layout.fragment_run_result, container, false);
+            return rootView;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/6e202551/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowdetailFragment.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowdetailFragment.java b/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowdetailFragment.java
index 68ebf09..8e6419e 100644
--- a/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowdetailFragment.java
+++ b/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowdetailFragment.java
@@ -49,6 +49,7 @@ import android.widget.Button;
 import android.widget.EditText;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
+import android.widget.ScrollView;
 import android.widget.TextView;
 import android.widget.Toast;
 import android.widget.ZoomControls;
@@ -72,11 +73,12 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.nio.charset.CharsetEncoder;
 
 /**
  * Created by Larry Akah on 6/9/15.
  */
-public class WorkflowdetailFragment extends Fragment implements View.OnClickListener, LoaderManager.LoaderCallbacks<Workflow>{
+public class WorkflowdetailFragment extends Fragment implements View.OnClickListener,LoaderManager.LoaderCallbacks<Workflow>{
     /**
      * The fragment argument representing the section number for this
      * fragment.
@@ -106,6 +108,9 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
         fragment.setArguments(args);
         return fragment;
     }
+    public static WorkflowdetailFragment getInstance(){
+        return WorkflowdetailFragment.getInstance();
+    }
 
     public WorkflowdetailFragment() {
     }
@@ -122,8 +127,8 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
         zoomin = AnimationUtils.loadAnimation(getActivity(), R.anim.zoomin);
         zoomout = AnimationUtils.loadAnimation(getActivity(), R.anim.zoomout);
         zoomControls = (ZoomControls) rootView.findViewById(R.id.zoomControls);
-        zoomControls.setOnZoomInClickListener(this);
-        zoomControls.setOnZoomOutClickListener(this);
+        zoomControls.setOnClickListener(this);
+       // zoomControls.setOnZoomOutClickListener(this);
 
         Button createRun = (Button) rootView.findViewById(R.id.run_wk);
         createRun.setOnClickListener(this);
@@ -149,9 +154,10 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
     public void onClick(View view) {
         switch(view.getId()){
             case R.id.run_wk:
-                //TODO implement functionality to issue a run request to the Taverna PLAYER to run the current workflow
-                //new WorkflowRunTask(getActivity()).execute(""+WORKFLO_ID);
-                new WorkflowProcessTask(getActivity()).execute(download_url);
+                if (((TextView)rootView.findViewById(R.id.wtype)).getText().toString().contains("Taverna 2"))
+                    new WorkflowProcessTask(getActivity()).execute(download_url);
+                else
+                    Toast.makeText(getActivity(), "Sorry! only Type 2 workflows can be run as of now.", Toast.LENGTH_LONG).show();
                 break;
             case R.id.download_wk:
                 // start the android Download manager to start downloading a remote workflow file
@@ -169,9 +175,13 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
                 //TODO mark a workflow as important and launch task to store the entry into the local database
                 break;
             case R.id.zoomControls:
+                zoomin.reset();
                 zoomin.startNow();
                 Toast.makeText(getActivity(), "Zooming", Toast.LENGTH_SHORT).show();
                 break;
+            case R.id.wkf_image:
+                view.setAnimation(zoomin);
+                break;
         }
     }
 
@@ -227,18 +237,18 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
     }
 
     public static void setWorkflowDetails(final Workflow wk){
+        final TextView author = (TextView) rootView.findViewById(R.id.wkf_author);
+        final TextView updated = (TextView) rootView.findViewById(R.id.wupdatedat);
+        final TextView type = (TextView) rootView.findViewById(R.id.wtype);
+        final TextView title = (TextView) rootView.findViewById(R.id.wtitle);
+        final TextView desc = (TextView) rootView.findViewById(R.id.wdescription);
+        final TextView createdat = (TextView) rootView.findViewById(R.id.wcreatedat);
+        final ImageView preview = (ImageView) rootView.findViewById(R.id.wkf_image);
 
         ((Activity)cont).runOnUiThread(new Runnable() {
             @Override
             public void run() {
                 //load necessary widgets
-                TextView author = (TextView) rootView.findViewById(R.id.wkf_author);
-                TextView updated = (TextView) rootView.findViewById(R.id.wupdatedat);
-                TextView type = (TextView) rootView.findViewById(R.id.wtype);
-                TextView title = (TextView) rootView.findViewById(R.id.wtitle);
-                TextView desc = (TextView) rootView.findViewById(R.id.wdescription);
-                TextView createdat = (TextView) rootView.findViewById(R.id.wcreatedat);
-                final ImageView preview = (ImageView) rootView.findViewById(R.id.wkf_image);
 
                 //set widget data
                 User uploader = wk.getUploader();
@@ -295,6 +305,7 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
                 progressDialog.dismiss();
             }
         });
+      //  preview.setOnClickListener(WorkflowdetailFragment.getInstance());
     }
 
     private static class LoadImageThread extends AsyncTask<String, Void, Bitmap>{
@@ -405,7 +416,9 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
             //show the skeleton to the user in a dialog box
             final Context ctx = this.context;
             final LinearLayout ll = new LinearLayout(ctx);
+            ScrollView sv = new ScrollView(ctx);
             ll.setOrientation(LinearLayout.VERTICAL);
+            sv.addView(ll);
 
             try {
                 final JSONObject json = new JSONObject(result); //main server response json
@@ -420,10 +433,10 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
                 }
 
                 alertDialogBuilder = new AlertDialog.Builder(ctx);
-                alertDialogBuilder.setView(ll);
+                alertDialogBuilder.setView(sv);
  //               alertDialogBuilder.setMessage(result);
                 alertDialogBuilder.setIcon(ctx.getResources().getDrawable(R.mipmap.ic_launcher));
-                alertDialogBuilder.setTitle("New Run");
+                alertDialogBuilder.setTitle("New Workflow Run");
                 alertDialogBuilder.setPositiveButton("Execute", new DialogInterface.OnClickListener() {
                     @Override
                     public void onClick(DialogInterface dialogInterface, int i) {
@@ -444,7 +457,8 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
                         try {
                             json.put("inputs_attributes", attr_array);
                             Log.i("RUN FRAMEWORK", json.toString(2));
-                            new RunTask(ctx).execute(json.toString());
+                            //start a run task to execute the run.
+                         //   new RunTask(ctx).execute(json.toString());
                         } catch (JSONException e) {
                             e.printStackTrace();
                         }
@@ -518,10 +532,9 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
                     sb.append(str); //in this string builder we have read the workflow( as .t2flow or .xml) workflow from remote resource. Now we need to post that to the player.
                 bufferedReader.close();
                 wconn.disconnect();
-//PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHM6c2N1ZmwgeG1sbnM6cz0iaHR0cDovL29yZy5lbWJsLmViaS5lc2NpZW5jZS94c2N1ZmwvMC4xYWxwaGEiIHZlcnNpb249IjAuMiIgbG9nPSIwIj4KICA8czp3b3JrZmxvd2Rlc2NyaXB0aW9uIGxzaWQ9InVybjpsc2lkOnd3dy5teWdyaWQub3JnLnVrOm9wZXJhdGlvbjpLNlpDRzZJV05TMCIgYXV0aG9yPSIiIHRpdGxlPSIiIC8+CiAgPHM6cHJvY2Vzc29yIG5hbWU9IlN0cmluZ19Db25zdGFudCIgYm9yaW5nPSJ0cnVlIj4KICAgIDxzOnN0cmluZ2NvbnN0YW50Pmh0dHA6Ly93d3cuY3MubWFuLmFjLnVrL35nb2RlcmlzYS9QaG90by5qcGc8L3M6c3RyaW5nY29uc3RhbnQ+CiAgPC9zOnByb2Nlc3Nvcj4KICA8czpwcm9jZXNzb3IgbmFtZT0iR2V0X2ltYWdlX2Zyb21fVVJMIj4KICAgIDxzOmxvY2FsPm9yZy5lbWJsLmViaS5lc2NpZW5jZS5zY3VmbHdvcmtlcnMuamF2YS5XZWJJbWFnZUZldGNoZXI8L3M6bG9jYWw+CiAgPC9zOnByb2Nlc3Nvcj4KICA8czpsaW5rIHNvdXJjZT0iU3RyaW5nX0NvbnN0YW50OnZhbHVlIiBzaW5rPSJHZXRfaW1hZ2VfZnJvbV9VUkw6dXJsIiAvPgogIDxzOmxpbmsgc291cmNlPSJHZXRfaW1hZ2VfZnJvbV9VUkw6aW1hZ2UiIHNpbms9InZpeiIgLz4KICA8czpzaW5rIG5hbWU9InZpeiIgLz4KPC9zOnNjdWZsPgoKCg==
-                       // Base64.encodeToString(sb.toString().getBytes("UTF-8"), Base64.DEFAULT)
+
                 String data = "{\"document\":\"data:application/octet-stream;base64," +
-                        Base64.encodeToString(sb.toString().getBytes("UTF-8"), Base64.URL_SAFE|Base64.NO_WRAP)+"\"}";
+                        Base64.encodeToString(sb.toString().getBytes("UTF-8"), Base64.URL_SAFE|Base64.NO_WRAP).replace('-','+')+"\"}";
                 String post = "{\"workflow\":"+data+"}";
                 //clear sb so that we can use it again to fetch results from this post request
                 sb.delete(0,sb.length()-1);
@@ -529,25 +542,23 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
                 connection.setRequestMethod("POST");
                 connection.setRequestProperty("Authorization", basicAuth);
                 connection.setRequestProperty("Accept", "*/*");
-               // connection.setRequestProperty("Content-Length", "10165");
                 connection.setRequestProperty("Content-Type", "application/json");
                 connection.setRequestProperty("Content-Encoding", "UTF-8");
-                connection.setRequestProperty("Accept-Charset", "UTF-8");
                 connection.setUseCaches (false);
                 connection.setDoOutput(true);
-             //   connection.setDoInput(true);
                 connection.connect(); //send request
 
                 DataOutputStream dos = new DataOutputStream(connection.getOutputStream());
+
                 dos.writeBytes(post);//write post data which is a formatted json data representing body of workflow
 
                 dos.flush();
                 dos.close();
-/*
+
                 InputStream dis = connection.getInputStream();
                 BufferedReader br = new BufferedReader(new InputStreamReader(dis));
                 while ((str = br.readLine())!= null)
-                    sb.append(str);*/
+                    sb.append(str);
                 System.out.println("Post Response Code: "+connection.getResponseCode());
                 System.out.println("Post response message: "+connection.getResponseMessage());
                 connection.disconnect();
@@ -555,17 +566,32 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
                 e.printStackTrace();
                 sb.append("Error reading remote workflow. Please try again later");
             }
+
             return sb.toString();
         }
 
+        /**
+         * Receives a result from the player as a json describing the workflow that has just been uploaded along with key components that
+         * can be used to generate a run from thw workflow. A run is started that would fetch and build a sample UI for a workflow run to be executed
+         * @param s the json result that describes the uploaded workflow
+         */
         @Override
         protected void onPostExecute(String s) {
-            System.out.println(s);
             progressDialog.dismiss();
+            System.out.println(s);
+            s = s.substring(1, s.length());
+            try {
+                JSONObject workflowJson = new JSONObject(s);
+                new WorkflowRunTask(getActivity()).execute(workflowJson.getString("id"));
+
+            } catch (JSONException e) {
+                e.printStackTrace();
+            }
+
         }
     }
     /**
-     * creates a new workflow run from the
+     * creates a new workflow run from the workflow on the player
      */
     private class RunTask extends AsyncTask<String, Void, String>{
 
@@ -617,7 +643,6 @@ public class WorkflowdetailFragment extends Fragment implements View.OnClickList
                 br.close();
                 Log.i("RESPONSE Code", "" + connection.getResponseCode());
                 Log.i("RESPONSE Messsage", "" + connection.getResponseMessage());
-                Log.i("Authorization ", "" + connection.getRequestProperty("Authorization"));
 
                 return sb.toString();
 

http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/6e202551/app/src/main/res/layout/activity_run_result.xml
----------------------------------------------------------------------
diff --git a/app/src/main/res/layout/activity_run_result.xml b/app/src/main/res/layout/activity_run_result.xml
new file mode 100644
index 0000000..027aa67
--- /dev/null
+++ b/app/src/main/res/layout/activity_run_result.xml
@@ -0,0 +1,4 @@
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container"
+    android:layout_width="match_parent" android:layout_height="match_parent"
+    tools:context="org.apache.taverna.mobile.activities.RunResult" tools:ignore="MergeRootFrame" />

http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/6e202551/app/src/main/res/layout/fragment_run_result.xml
----------------------------------------------------------------------
diff --git a/app/src/main/res/layout/fragment_run_result.xml b/app/src/main/res/layout/fragment_run_result.xml
new file mode 100644
index 0000000..ccb985c
--- /dev/null
+++ b/app/src/main/res/layout/fragment_run_result.xml
@@ -0,0 +1,12 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
+    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
+    android:paddingRight="@dimen/activity_horizontal_margin"
+    android:paddingTop="@dimen/activity_vertical_margin"
+    android:paddingBottom="@dimen/activity_vertical_margin"
+    tools:context="org.apache.taverna.mobile.activities.RunResult$PlaceholderFragment">
+
+    <TextView android:text="@string/hello_world" android:layout_width="wrap_content"
+        android:layout_height="wrap_content" />
+
+</RelativeLayout>

http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/6e202551/app/src/main/res/menu/run_result.xml
----------------------------------------------------------------------
diff --git a/app/src/main/res/menu/run_result.xml b/app/src/main/res/menu/run_result.xml
new file mode 100644
index 0000000..35d088f
--- /dev/null
+++ b/app/src/main/res/menu/run_result.xml
@@ -0,0 +1,7 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    tools:context="org.apache.taverna.mobile.activities.RunResult">
+    <item android:id="@+id/action_settings" android:title="@string/action_settings"
+        android:orderInCategory="100" app:showAsAction="never" />
+</menu>

http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/6e202551/simple-xml-2.7.1/simple-xml-2.7.1.iml
----------------------------------------------------------------------
diff --git a/simple-xml-2.7.1/simple-xml-2.7.1.iml b/simple-xml-2.7.1/simple-xml-2.7.1.iml
deleted file mode 100644
index 07735a7..0000000
--- a/simple-xml-2.7.1/simple-xml-2.7.1.iml
+++ /dev/null
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="TavernaMobile2" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
-  <component name="FacetManager">
-    <facet type="android-gradle" name="Android-Gradle">
-      <configuration>
-        <option name="GRADLE_PROJECT_PATH" value=":simple-xml-2.7.1" />
-      </configuration>
-    </facet>
-  </component>
-  <component name="NewModuleRootManager" inherit-compiler-output="true">
-    <exclude-output />
-    <orderEntry type="inheritedJdk" />
-    <orderEntry type="sourceFolder" forTests="false" />
-  </component>
-</module>
-

http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/6e202551/simple-xml-2.7.1/simple-xml-2.7.1.jar
----------------------------------------------------------------------
diff --git a/simple-xml-2.7.1/simple-xml-2.7.1.jar b/simple-xml-2.7.1/simple-xml-2.7.1.jar
deleted file mode 100644
index 913725d..0000000
Binary files a/simple-xml-2.7.1/simple-xml-2.7.1.jar and /dev/null differ