You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by sa...@apache.org on 2016/10/31 09:30:11 UTC
[3/7] incubator-taverna-mobile git commit: clear codebase
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/b93d871c/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
deleted file mode 100644
index 9835c04..0000000
--- a/app/src/main/java/org/apache/taverna/mobile/fragments/workflowdetails/WorkflowdetailFragment.java
+++ /dev/null
@@ -1,811 +0,0 @@
-package org.apache.taverna.mobile.fragments.workflowdetails;
-/**
- * Apache Taverna Mobile
- * Copyright 2015 The Apache Software Foundation
- *
- * This product includes software developed at
- * The Apache Software Foundation (http://www.apache.org/).
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import com.dropbox.client2.DropboxAPI;
-import com.dropbox.client2.ProgressListener;
-import com.dropbox.client2.android.AndroidAuthSession;
-import com.dropbox.client2.exception.DropboxException;
-import com.dropbox.client2.session.AppKeyPair;
-
-import org.apache.taverna.mobile.R;
-import org.apache.taverna.mobile.activities.DashboardMainActivity;
-import org.apache.taverna.mobile.adapters.WorkflowAdapter;
-import org.apache.taverna.mobile.tavernamobile.TavernaPlayerAPI;
-import org.apache.taverna.mobile.tavernamobile.User;
-import org.apache.taverna.mobile.tavernamobile.Workflow;
-import org.apache.taverna.mobile.utils.DetailsLoader;
-import org.apache.taverna.mobile.utils.RunTask;
-import org.apache.taverna.mobile.utils.WorkflowDB;
-import org.apache.taverna.mobile.utils.WorkflowDownloadManager;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.DownloadManager;
-import android.app.LoaderManager;
-import android.app.ProgressDialog;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Loader;
-import android.content.SharedPreferences;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.net.Uri;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.preference.PreferenceManager;
-import android.support.v4.app.Fragment;
-import android.util.Base64;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.animation.Animation;
-import android.view.animation.AnimationUtils;
-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 java.io.BufferedReader;
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-
-/**
- * Created by Larry Akah on 6/9/15.
- */
-public class WorkflowdetailFragment extends Fragment implements View.OnClickListener,
- LoaderManager.LoaderCallbacks<Workflow> {
- /**
- * The fragment argument representing the section number for this
- * fragment.
- */
- private static final String TAG = "WorkflowdetailFragment";
- private static final String ARG_SECTION_NUMBER = "section_number";
- private static final String BOX_APP_KEY = "doicbvkfyzligh2";
- private static final String BOX_APP_SECRET = "3uuuw36mm7jkflc";
- public static String mWorkfloId = "";
- public static Context cont;
- static View rootView;
- static Animation zoomin;
- static Animation zoomout;
- static Workflow currentWorkflow = null;
- private static ProgressDialog progressDialog;
- private static String download_url;
- public String workflow_uri;
- public AlertDialog runDialog;
- public AlertDialog.Builder alertDialogBuilder;
- public boolean isZoomIn;
- SharedPreferences sharedPreferences;
- private boolean mLoadState = false;
- private boolean mDropupload = false;
- private DownloadManager downloadManager;
- private long wid;
-
- private DropboxAPI<AndroidAuthSession> mDBApi;
-
- public WorkflowdetailFragment() {
- }
-
- /**
- * Returns a new instance of this fragment for the given section
- * number.
- */
- public static WorkflowdetailFragment newInstance(int sectionNumber) {
- WorkflowdetailFragment fragment = new WorkflowdetailFragment();
- Bundle args = new Bundle();
- args.putInt(ARG_SECTION_NUMBER, sectionNumber);
- fragment.setArguments(args);
- return fragment;
- }
-
-
- public static void setWorkflowDetails(final Workflow wk) {
- currentWorkflow = wk;
- final TextView author = (TextView) rootView.findViewById(R.id.wkf_author_text);
- //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);
- //mWorkfloId = wk.getWorkflowTitle();
- ((Activity) cont).runOnUiThread(new Runnable() {
- @Override
- public void run() {
- //load necessary widgets
-
- //set widget data
- //Use android resources to insert text into placeholder
- Resources resources = cont.getResources();
- User uploader = wk.getUploader();
- //String uploaderText = String.format(resources.getString(R.string
- // .workflow_author), uploader != null ? uploader.getName():"Unknown");
- author.setText((uploader != null) ? uploader.getName() : "Unknown");
- title.setText(wk.getWorkflowTitle());
- if (wk.getWorkflowDescription() != null) {
- desc.setText(wk.getWorkflowDescription());
- } else {
- //desc.setVisibility(View.INVISIBLE); //Not sure I trust this! Needs
- // investigating.
- }
- String createdAtText = String.format(resources.getString(R.string.created), wk
- .getWorkflowDatecreated());
- createdat.setText(createdAtText);
- //updated.setText("Workflow Description");
- String typeText = String.format(resources.getString(R.string.workflow_type_text),
- wk.getWorkflowType());
- type.setText(typeText);
-
- //preview.setImageURI(Uri.parse(wk.getWorkflowPreview()));
- new LoadImageThread(preview, wk.getWorkflowPreview()).execute();
- download_url = wk.getWorkflowRemoteUrl();
- zoomin.setAnimationListener(new Animation.AnimationListener() {
-
- @Override
- public void onAnimationStart(Animation arg0) {
- // TODO Auto-generated method stub
- preview.startAnimation(zoomout);
- }
-
- @Override
- public void onAnimationRepeat(Animation arg0) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void onAnimationEnd(Animation arg0) {
- preview.startAnimation(zoomout);
-
- }
- });
- zoomout.setAnimationListener(new Animation.AnimationListener() {
-
- @Override
- public void onAnimationStart(Animation arg0) {
- // TODO Auto-generated method stub
- preview.startAnimation(zoomin);
- }
-
- @Override
- public void onAnimationRepeat(Animation arg0) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void onAnimationEnd(Animation arg0) {
- preview.startAnimation(zoomin);
-
- }
- });
- progressDialog.dismiss();
- }
- });
- // preview.setOnClickListener(WorkflowdetailFragment.getInstance());
- }
-
- public static void setProgressDialog(Context context) {
- WorkflowdetailFragment.progressDialog = new ProgressDialog(context);
- }
-
- public static void setRootView(View rootView) {
- WorkflowdetailFragment.rootView = rootView;
- }
-
- public static void setCont(Context cont) {
- WorkflowdetailFragment.cont = cont;
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
- savedInstanceState) {
-
- AppKeyPair appKeys = new AppKeyPair(BOX_APP_KEY, BOX_APP_SECRET);
- AndroidAuthSession session = new AndroidAuthSession(appKeys);
- mDBApi = new DropboxAPI<AndroidAuthSession>(session);
- // long workflowid = getActivity().getIntent().getLongExtra("workflowid", 0);
- setRootView(inflater.inflate(R.layout.fragment_workflow_detail,
- container, false));
- setProgressDialog(getActivity());
- progressDialog.setMessage(getActivity().getResources().getString(R.string.loading));
- progressDialog.setCancelable(false);
- // mWorkfloId = workflowid;
- zoomin = AnimationUtils.loadAnimation(getActivity(), R.anim.zoomin);
- zoomout = AnimationUtils.loadAnimation(getActivity(), R.anim.zoomout);
-
- isZoomIn = false;
- sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
- wid = getActivity().getIntent().getLongExtra("wid", 0);
- Button createRun = (Button) rootView.findViewById(R.id.run_wk);
- createRun.setOnClickListener(this);
- Button download = (Button) rootView.findViewById(R.id.download_wk);
- download.setOnClickListener(this);
- Button mark_workflow = (Button) rootView.findViewById(R.id.mark_wk);
- mark_workflow.setOnClickListener(this);
- final String favs = sharedPreferences.getString(WorkflowAdapter.FAVORITE_LIST_DB, "");
- String[] ids = favs.split(",");
- if (ids.length > 0) {
- for (String id : ids) {
- if (id.equalsIgnoreCase("" + wid)) {
- mark_workflow.setBackgroundResource(R.drawable
- .abc_list_selector_disabled_holo_light);
- break;
- }
- }
- }
- rootView.findViewById(R.id.saveToDropboxButton).setOnClickListener(this);
- rootView.findViewById(R.id.saveToGoogleDriveButton).setOnClickListener(this);
- (rootView.findViewById(R.id.wkf_image)).setOnLongClickListener(new View
- .OnLongClickListener() {
- @Override
- public boolean onLongClick(View view) {
- view.setAnimation(zoomin);
- return true;
- }
- });
- downloadManager = (DownloadManager) getActivity().getSystemService(Context
- .DOWNLOAD_SERVICE);
- return rootView;
- }
-
- /**
- * Called when a fragment is first attached to its activity.
- * {@link #onCreate(android.os.Bundle)} will be called after this.
- */
- //@Override
- //public void onAttach(Activity activity) {
- // super.onAttach(activity);
- // cont = getActivity();
- //}
- @Override
- public void onAttach(Context context) {
- super.onAttach(context);
- setCont(getActivity());
- }
-
- @Override
- public void onClick(View view) {
- switch (view.getId()) {
- case R.id.run_wk:
- if (((TextView) rootView.findViewById(R.id.wtype)).getText().toString().contains
- ("Taverna 2")) {
- new WorkflowProcessTask(getActivity()).execute(download_url);
- } else {
- Toast.makeText(getActivity(), "Sorry! Only Taverna 2 workflows can be run.",
- Toast.LENGTH_LONG).show();
- }
- break;
- case R.id.download_wk:
- // start the android Download manager to start downloading a remote workflow file
- WorkflowDownloadManager dmgr = new WorkflowDownloadManager(getActivity(),
- downloadManager);
- try {
- dmgr.downloadWorkflow(new File(PreferenceManager.getDefaultSharedPreferences
- (getActivity()).getString(
- DashboardMainActivity.APP_DIRECTORY_NAME, "/")),
- download_url);
- } catch (Exception e) {
- Log.e(TAG, "onClick: ", e);
- }
-
- break;
- case R.id.mark_wk:
-
- ArrayList<Object> mfav = new ArrayList<Object>();
- String favs = sharedPreferences.getString(WorkflowAdapter.FAVORITE_LIST_DB, "");
- //save current workflow as favorite
- mfav.add(currentWorkflow.getId());
- mfav.add(currentWorkflow.getWorkflowAuthor());
- mfav.add(currentWorkflow.getWorkflowTitle());
- mfav.add(currentWorkflow.getWorkflowDescription());
- mfav.add(SimpleDateFormat.getDateTimeInstance().format(new Date()).toString());
- mfav.add(currentWorkflow.getWorkflowDetailsUrl());
- mfav.add(((TextView) rootView.findViewById(R.id.wkf_author)).getText());
- int result = new WorkflowDB(getActivity(), WorkflowAdapter
- .WORKFLOW_FAVORITE_KEY).insert(mfav);
- if (result > 0) {
- sharedPreferences.edit().putString(WorkflowAdapter.FAVORITE_LIST_DB, favs +
- wid + ",").apply();
- Toast.makeText(getActivity(), "Workflow marked as favorite", Toast
- .LENGTH_SHORT).show();
- view.setBackgroundResource(R.drawable.abc_list_selector_disabled_holo_light);
-
- } else if (result == -1) {
- Toast.makeText(getActivity(), "Sorry! This workflow has already been marked " +
- "as a favourite", Toast.LENGTH_SHORT).show();
- } else {
- Toast.makeText(getActivity(), "Error!, please try again", Toast.LENGTH_SHORT)
- .show();
- }
- break;
- case R.id.saveToDropboxButton:
- String authToken = PreferenceManager.getDefaultSharedPreferences(getActivity())
- .getString("dropboxauth", "");
- if (authToken.isEmpty()) {
- mDBApi.getSession().startOAuth2Authentication(getActivity());
- } else {
- mDBApi.getSession().setOAuth2AccessToken(authToken);
- new WorkflowDriveUpload().execute(download_url);
- }
- break;
- case R.id.saveToGoogleDriveButton:
- break;
- }
- }
-
- /**
- * Called when the fragment is visible to the user and actively running.
- * This is generally
- * tied to {@link android.app.Activity#onResume() Activity.onResume} of the containing
- * Activity's lifecycle.
- */
- @Override
- public void onResume() {
- super.onResume();
- if (!mLoadState)
- workflow_uri = getActivity().getIntent().getStringExtra("uri");
-
- getActivity().getLoaderManager().initLoader(1, null, this).forceLoad();
-
- if (mDBApi.getSession().authenticationSuccessful() && !mDropupload) {
- try {
- // Required to complete auth, sets the access token on the session
- mDBApi.getSession().finishAuthentication();
- String accessToken = mDBApi.getSession().getOAuth2AccessToken();
- PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().putString
- ("dropboxauth", accessToken).commit();
- new WorkflowDriveUpload().execute(download_url);
- } catch (IllegalStateException e) {
- Log.i("DbAuthLog", "Error authenticating", e);
- }
- }
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mLoadState = true;
- }
-
- @Override
- public Loader<Workflow> onCreateLoader(int i, Bundle bundle) {
- progressDialog.show();
- return new DetailsLoader(getActivity(),
- DetailsLoader.LoadType.TYPE_WORKFLOW_DETAIL,
- workflow_uri);
- }
-
- @Override
- public void onLoadFinished(Loader<Workflow> workflowLoader, Workflow workflow) {
-
- }
-
- @Override
- public void onLoaderReset(Loader<Workflow> workflowLoader) {
- workflowLoader.reset();
- }
-
- //create and return a new TextView
- public TextView createTextView(Context mcontext, String placeholder) {
- TextView tv = new TextView(mcontext);
- tv.setText(placeholder);
- tv.setMinLines(2);
-
- return tv;
- }
-
- //create and return a new EdiText view
- public EditText createEditText(Context ctx, int i) {
- EditText edt;
- edt = new EditText(ctx);
- edt.setHint("Enter Value");
- edt.setMinLines(1);
- edt.setId(i);
- return edt;
- }
-
- private static class LoadImageThread extends AsyncTask<String, Void, Bitmap> {
- ImageView imageView;
- String src;
-
- public LoadImageThread(ImageView image, String source) {
- imageView = image;
- src = source;
- }
-
- @Override
- protected Bitmap doInBackground(String... strings) {
- Bitmap myBitmap = null;
- try {
- URL url = new URL(src);
- HttpURLConnection connection = null;
- connection = (HttpURLConnection) url.openConnection();
- connection.setDoInput(true);
- connection.connect();
- InputStream input = connection.getInputStream();
- myBitmap = BitmapFactory.decodeStream(input);
-// imageView.setImageBitmap(myBitmap);
- } catch (IOException e) {
- Log.e(TAG, "doInBackground: ", e);
- }
- return myBitmap;
- }
-
- @Override
- protected void onPostExecute(Bitmap bitmap) {
- imageView.setImageBitmap(bitmap);
- }
- }
-
- //fetch and compute the framework on which the run inputs are to be built and entered
- private class WorkflowRunTask extends AsyncTask<String, Void, String> {
-
- TavernaPlayerAPI tavernaPlayerAPI = new TavernaPlayerAPI();
- private Context context;
-
- private WorkflowRunTask(Context context) {
- this.context = context;
- }
-
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- progressDialog.setMessage(this.context.getResources().getString(R.string.fetchrun));
- progressDialog.show();
- }
-
- @Override
- protected String doInBackground(String... params) {
- StringBuffer sb = new StringBuffer();
- try {
-
- URL workflowurl = new URL(new TavernaPlayerAPI(this.context)
- .mPlayerRunFrameworkUrl + params[0]);
- HttpURLConnection connection = (HttpURLConnection) workflowurl.openConnection();
- String userpass = tavernaPlayerAPI.getPlayerUserName(this.context) + ":" +
- tavernaPlayerAPI.getPlayerUserPassword(this.context);
- String basicAuth = "Basic " + Base64.encodeToString(userpass.getBytes(Charset
- .forName("UTF-8")), Base64
- .DEFAULT);
-
- connection.setRequestProperty("Authorization", basicAuth);
- connection.setRequestProperty("Accept", "application/json");
- connection.setRequestMethod("GET");
- // connection.setDoInput(true);
- // connection.setDoOutput(true);
- connection.connect(); //send request
- Log.i("RESPONSE Code", "" + connection.getResponseCode());
- Log.i("RESPONSE Messsage", "" + connection.getResponseMessage());
- Log.i("Authorization ", "" + connection.getRequestProperty("Authorization"));
-
- InputStream dis = connection.getInputStream();
- BufferedReader br = new BufferedReader(new InputStreamReader(dis, "UTF-8"));
-
- String jsonData = "";
- while ((jsonData = br.readLine()) != null) {
- sb.append(jsonData);
- }
- dis.close();
- br.close();
- return sb.toString();
-
- } catch (IOException ex) {
- Log.e(TAG, "doInBackground: ", ex);
- }
- return sb.toString();
- }
-
- @Override
- protected void onPostExecute(String result) {
- //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
- JSONObject mjson = json.getJSONObject("run"); //main framework response json
- String name = mjson.getString("name"); //a name that can be configured or edited
- // for the new run to be created
- ll.addView(createTextView(ctx, name));
- final JSONArray attr_array = mjson.getJSONArray("inputs_attributes");
- for (int i = 0; i < attr_array.length(); i++) {
- JSONObject obj = attr_array.getJSONObject(i);
- ll.addView(createTextView(ctx, obj.getString("name")));
- ll.addView(createEditText(ctx, i));
- }
-
- alertDialogBuilder = new AlertDialog.Builder(ctx);
- alertDialogBuilder.setView(sv);
- // alertDialogBuilder.setMessage(result);
- alertDialogBuilder.setIcon(ctx.getResources().getDrawable(R.mipmap.ic_launcher));
- alertDialogBuilder.setTitle("New Workflow Run");
- alertDialogBuilder.setPositiveButton("Execute", new DialogInterface
- .OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- int n = attr_array.length();
- for (int j = 0; j < n; j++) {
- try {
- EditText inputText = (EditText) ll.findViewById(j);
- String value = inputText.getText().toString(); //get input entry
- // entered by the user
- JSONObject jojb = attr_array.getJSONObject(j); //get the input
- // attributes provided by the skeleton
- jojb.put("value", value); //replace value field in object with
- // the entry provided by the user
- attr_array.put(j, jojb); //replace the input entry with the new
- // name/input json object
-
- } catch (JSONException e) {
- Log.e(TAG, "onClick: ", e);
- }
-
- }
- try {
- json.put("inputs_attributes", attr_array);
- Log.i("RUN FRAMEWORK", json.toString(2));
- //start a run task to execute the run.
- new RunTask(ctx).execute(json.toString());
- } catch (JSONException e) {
- Log.e(TAG, "onClick: ", e);
- } catch (Exception ex) {
- Log.e(TAG, "onClick: ", ex);
- }
-
- }
- });
- alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface
- .OnClickListener() {
-
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- dialogInterface.dismiss();
- }
- });
-
- runDialog = alertDialogBuilder.create();
-
- } catch (JSONException e) {
- Log.e(TAG, "onPostExecute: ", e);
- }
- progressDialog.dismiss();
-
- runDialog.show();
- }
- }
-
- /**
- * Send request for the execution of a run on a Taverna server through the Taverna player using
- * the Player API
- * This process passes through several steps,\n
- * 1- Downloading and caching a local version of the workflow whose run we need \n
- * 2- uploading the workflow through the portal to register it so a run can be generated from
- * it. The request requires some authentication
- * 3- Retrieving the results and extracting data required to create a run (the workflow_id) as
- * provided by the results
- * 4- Posting a run request to the player so that a new run can be created and started
- * 5- retrieving a run framework so that users can know what types of input is expected for a
- * successful run
- * 6- retrieving and displaying run results
- */
- private class WorkflowProcessTask extends AsyncTask<String, Void, String> {
-
- private Context context;
-
- private WorkflowProcessTask(Context context) {
- this.context = context;
- }
-
- @Override
- protected void onPreExecute() {
- progressDialog.setMessage("Uploading Workflow ... ");
- progressDialog.show();
- }
-
- @Override
- protected String doInBackground(String... params) {
- StringBuffer sb = new StringBuffer(53);
- try {
- //prepare connection requests
- URL workflowurl = new URL(params[0]); //the resource xml file representing the
- // workflow to be uploaded to the player
- String playerurl = new TavernaPlayerAPI(this.context).mPlayerBaseUrl +
- "workflows.json";
- TavernaPlayerAPI tavernaPlayerAPI = new TavernaPlayerAPI();
-
- URL posturl = new URL(playerurl);
- HttpURLConnection connection = (HttpURLConnection) posturl.openConnection();
- HttpURLConnection wconn = (HttpURLConnection) workflowurl.openConnection();
- wconn.setRequestMethod("GET");
- wconn.setDoOutput(true);
- wconn.setRequestProperty("Accept", "application/xml");
- wconn.connect();
-
- String user = tavernaPlayerAPI.getPlayerUserName(this.context) + ":" +
- tavernaPlayerAPI.getPlayerUserPassword(this.context);
- String basicAuth = "Basic " + Base64.encodeToString(user.getBytes(Charset.forName
- ("UTF-8")), Base64
- .DEFAULT);
- //read the file from remote resource and encode the stream with a base64 algorithm
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(wconn
- .getInputStream(), "UTF-8"));
- String str = "";
- while ((str = bufferedReader.readLine()) != null) {
- 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();
-
- String data = "{\"document\":\"data:application/octet-stream;base64," +
- 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);
- Log.d(TAG, "BODY=>" + post);
- connection.setRequestMethod("POST");
- connection.setRequestProperty("Authorization", basicAuth);
- connection.setRequestProperty("Accept", "*/*");
- connection.setRequestProperty("Content-Type", "application/json");
- connection.setRequestProperty("Content-Encoding", "UTF-8");
- connection.setUseCaches(false);
- connection.setDoOutput(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, "UTF-8"));
- while ((str = br.readLine()) != null) {
- sb.append(str);
- }
- connection.disconnect();
- } catch (IOException e) {
- Log.e(TAG, "doInBackground: ", e);
- 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) {
- progressDialog.dismiss();
- s = s.substring(1, s.length());
- try {
- JSONObject workflowJson = new JSONObject(s);
- new WorkflowRunTask(getActivity()).execute(workflowJson.getString("id"));
-
- } catch (JSONException e) {
- Log.e(TAG, "onPostExecute: ", e);
- }
-
- }
- }
-
- /**
- * Upload workflow from myexperiment to DropBox
- */
- private class WorkflowDriveUpload extends AsyncTask<String, Void, String> {
- @Override
- protected void onPreExecute() {
- Toast.makeText(getActivity(), "Saving workflow to dropBox", Toast.LENGTH_LONG).show();
- }
-
- @Override
- protected String doInBackground(String... files) {
- // File file = new File(files[0]);
- HttpURLConnection mconn;
- // FileInputStream inputStream = null;
- DropboxAPI.Entry response = null;
- DropboxAPI.Entry metaDataEntry = null;
- try {
- mconn = (HttpURLConnection) new URL(files[0]).openConnection();
- mconn.setRequestMethod("GET");
- mconn.connect();
-
- // inputStream = new FileInputStream(file);
-
- response = mDBApi.putFile("/" + Uri.parse(files[0]).getLastPathSegment(), mconn
- .getInputStream(),
- mconn.getContentLength(), null, new ProgressListener() {
- @Override
- public void onProgress(long l, long l2) {
- if (l == l2) {
- Toast.makeText(getActivity(), "Upload complete", Toast
- .LENGTH_LONG).show();
- }
- }
- });
-
- Log.i("DbExampleLog", "The uploaded file's rev is: " + response.rev);
- // metaDataEntry = mDBApi.metadata("/"+Uri.parse(files[0]).getLastPathSegment(),
- // 1, null, false, null);
- } catch (FileNotFoundException e) {
- Log.e(TAG, "doInBackground: ", e);
- } catch (DropboxException e) {
- Log.e(TAG, "doInBackground: ", e);
- } catch (MalformedURLException e) {
- Log.e(TAG, "doInBackground: ", e);
- } catch (IOException e) {
- Log.e(TAG, "doInBackground: ", e);
- }
-
- return response.rev;
- }
-
- @Override
- protected void onPostExecute(String s) {
- if (null != s) {
- Toast.makeText(getActivity(), "File Saved to dropbox. Reference: " + s, Toast
- .LENGTH_LONG).show();
- mDropupload = true;
- } else {
- Toast.makeText(getActivity(), "Failed to save to dropbox " + s, Toast
- .LENGTH_LONG).show();
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/b93d871c/app/src/main/java/org/apache/taverna/mobile/tavernamobile/Runs.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/tavernamobile/Runs.java b/app/src/main/java/org/apache/taverna/mobile/tavernamobile/Runs.java
deleted file mode 100644
index 56df291..0000000
--- a/app/src/main/java/org/apache/taverna/mobile/tavernamobile/Runs.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
-* Apache Taverna Mobile
-* Copyright 2015 The Apache Software Foundation
-
-* This product includes software developed at
-* The Apache Software Foundation (http://www.apache.org/).
-
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements. See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership. The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-* KIND, either express or implied. See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
-
-package org.apache.taverna.mobile.tavernamobile;
-
-/**
- * Created by Larry Akah on 6/13/15.
- * Workflow runs for a given workflow
- */
-public class Runs {
- private long run_id;
- private long run_workflow_id;
- private String run_name;
- private String run_started_date;
- private String run_ended_date;
- private String state;
- private String run_author;
-
- public Runs(String run_name, String run_started_date, String run_ended_date, String state) {
- this.run_name = run_name;
- this.run_started_date = run_started_date;
- this.run_ended_date = run_ended_date;
- this.state = state;
- }
-
- ;
-
- public long getRunId() {
- return run_id;
- }
-
- public void setrunId(long run_id) {
- this.run_id = run_id;
- }
-
- public long getRunWorkflowId() {
- return run_workflow_id;
- }
-
- public void setRunWorkflowId(long run_workflow_id) {
- this.run_workflow_id = run_workflow_id;
- }
-
- public RunState getState() {
- if (state.equalsIgnoreCase("finished")) {
- return RunState.FINISHED;
- } else if (state.equalsIgnoreCase("failed")) {
- return RunState.FAILED;
- } else {
- return RunState.RUNNING;
- }
- }
-
- public void setState(String state) {
- this.state = state;
- }
-
- public String getRunName() {
- return run_name;
- }
-
- public void setRunName(String run_name) {
- this.run_name = run_name;
- }
-
- public String getRunStartedDate() {
- return run_started_date;
- }
-
- public void setRunStartedDate(String run_started_date) {
- this.run_started_date = run_started_date;
- }
-
- public String getRunAuthor() {
- return run_author;
- }
-
- public void setRunAuthor(String run_author) {
- this.run_author = run_author;
- }
-
- public String getRunEndedDate() {
- return run_ended_date;
- }
-
- public void setRunEndedDate(String run_ended_date) {
- this.run_ended_date = run_ended_date;
- }
-
- public static enum RunState { FAILED, FINISHED, RUNNING }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/b93d871c/app/src/main/java/org/apache/taverna/mobile/tavernamobile/TavernaPlayerAPI.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/tavernamobile/TavernaPlayerAPI.java b/app/src/main/java/org/apache/taverna/mobile/tavernamobile/TavernaPlayerAPI.java
deleted file mode 100644
index 6e6bcc1..0000000
--- a/app/src/main/java/org/apache/taverna/mobile/tavernamobile/TavernaPlayerAPI.java
+++ /dev/null
@@ -1,107 +0,0 @@
-package org.apache.taverna.mobile.tavernamobile;
-/**
- * Apache Taverna Mobile
- * Copyright 2015 The Apache Software Foundation
- *
- * This product includes software developed at
- * The Apache Software Foundation (http://www.apache.org/).
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import android.content.Context;
-import android.preference.PreferenceManager;
-
-import java.net.PasswordAuthentication;
-
-/**
- * Created by Larry Akah on 6/13/15.
- */
-public class TavernaPlayerAPI {
-
- public static String mPlayerBaseUrl = "http://heater.cs.man.ac.uk:3000/";
- public static String mServerBaseUrl = "http://heater.cs.man.ac.uk:8090/taverna-2.5.4/";
- public static String mPlayerWorkFlowUrl = mPlayerBaseUrl + "workflows/";
- public static String mPlayerRunUrl = mPlayerBaseUrl + "runs/";
- public static String mPlayerRunFrameworkUrl = mPlayerRunUrl + "new?workflow_id=";
- //returns a json 'framework' used for creating runs for the given workflow
-
- public TavernaPlayerAPI(Context context) {
- String server = PreferenceManager.getDefaultSharedPreferences(context).getString
- ("pref_server_url", "/");
- String player = PreferenceManager.getDefaultSharedPreferences(context).getString
- ("pref_player_url", "/");
- String user = PreferenceManager.getDefaultSharedPreferences(context).getString
- ("pref_player_url", "/");
- String password = PreferenceManager.getDefaultSharedPreferences(context).getString
- ("pref_player_url", "/");
- mPlayerBaseUrl = player;
- mServerBaseUrl = server;
- mPlayerWorkFlowUrl = mPlayerBaseUrl + "workflows/";
- mPlayerRunUrl = mPlayerBaseUrl + "runs/";
- mPlayerRunFrameworkUrl = mPlayerRunUrl + "new?workflow_id=";
- }
-
- public TavernaPlayerAPI() {
-
- }
-
- public static String getplayerBaseUrl() {
- return mPlayerBaseUrl;
- }
-
- public static String getserverBaseUrl() {
- return mServerBaseUrl;
- }
-
- public static String getplayerWorkflowUrl() {
- return mPlayerWorkFlowUrl;
- }
-
- public static String getplayerRunUrl(Context ctx) {
- return mPlayerRunUrl;
- }
-
- public static String getplayerRunFrameworkUrl(Context ctx) {
- return mPlayerRunFrameworkUrl;
- }
-
- public String getPlayerUserName(Context c) {
- return PreferenceManager.getDefaultSharedPreferences(c).getString("pref_user", "default");
- }
-
- public String getPlayerUserPassword(Context c) {
- return PreferenceManager.getDefaultSharedPreferences(c).getString("pref_password",
- "default");
- }
-
- public static class Authenticator extends java.net.Authenticator {
- private String username, password;
-
- public Authenticator(String username, String password) {
- super();
- this.username = username;
- this.password = password;
- }
-
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(this.username, this.password.toCharArray());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/b93d871c/app/src/main/java/org/apache/taverna/mobile/tavernamobile/User.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/tavernamobile/User.java b/app/src/main/java/org/apache/taverna/mobile/tavernamobile/User.java
deleted file mode 100644
index 4c30739..0000000
--- a/app/src/main/java/org/apache/taverna/mobile/tavernamobile/User.java
+++ /dev/null
@@ -1,171 +0,0 @@
-package org.apache.taverna.mobile.tavernamobile;
-/**
- * Apache Taverna Mobile
- * Copyright 2015 The Apache Software Foundation
- *
- * This product includes software developed at
- * The Apache Software Foundation (http://www.apache.org/).
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.taverna.mobile.adapters.WorkflowAdapter;
-import org.simpleframework.xml.Element;
-
-import android.graphics.Bitmap;
-
-import java.util.List;
-
-/**
- * Created by root on 6/18/15.
- */
-public class User {
-
- private static final long serialVersionUID = 3467195671046297377L;
- @Element(required = false)
- protected String id;
- @Element(name = "created-at", required = false)
- protected String created_at;
- @Element(required = false)
- protected String name;
- @Element(required = false)
- protected String description;
- @Element(required = false)
- protected String email;
- @Element(required = false)
- protected Bitmap avatar;
- @Element(required = false)
- protected String city;
- @Element(required = false)
- protected String country;
- @Element(required = false)
- protected String website;
- protected String details_uri;
- protected List<Workflow> user_workflows; //a list of workflows owned by this user
- private String avatar_url;
- private String row_id; //identifies the row to which this user is being loaded in, in the
- // workflow listview
- private WorkflowAdapter.ViewHolder userViewHolder;
-
- public User(String rid, WorkflowAdapter.ViewHolder vh) {
- super();
- row_id = rid;
- this.userViewHolder = vh;
- }
-
- public WorkflowAdapter.ViewHolder getUserViewHolder() {
- return userViewHolder;
- }
-
- public void setUserViewHolder(WorkflowAdapter.ViewHolder userViewHolder) {
- this.userViewHolder = userViewHolder;
- }
-
- public String getRowId() {
- return this.row_id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getCreatedAt() {
- return created_at;
- }
-
- public void setCreatedAt(String created_at) {
- this.created_at = created_at;
- }
-
- public String getDetailsUri() {
- return this.details_uri;
- }
-
- public void setDetailsUri(String details_uri) {
- this.details_uri = details_uri;
- }
-
- public String getAvatarUrl() {
- return this.avatar_url;
- }
-
- public void setAvatarUrl(String avatar_url) {
- this.avatar_url = avatar_url;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public String getEmail() {
- return email;
- }
-
- public void setEmail(String email) {
- this.email = email;
- }
-
- public Bitmap getAvatar() {
- return avatar;
- }
-
- public void setAvatar(Bitmap avatar) {
- this.avatar = avatar;
- }
-
- public String getCity() {
- return city;
- }
-
- public void setCity(String city) {
- this.city = city;
- }
-
- public String getCountry() {
- return country;
- }
-
- public void setCountry(String country) {
- this.country = country;
- }
-
- public String getWebsite() {
- return website;
- }
-
- public void setWebsite(String website) {
- this.website = website;
- }
-
- @Override
- public String toString() {
- return "This is the user object";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/b93d871c/app/src/main/java/org/apache/taverna/mobile/tavernamobile/Workflow.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/tavernamobile/Workflow.java b/app/src/main/java/org/apache/taverna/mobile/tavernamobile/Workflow.java
deleted file mode 100644
index be92a9c..0000000
--- a/app/src/main/java/org/apache/taverna/mobile/tavernamobile/Workflow.java
+++ /dev/null
@@ -1,361 +0,0 @@
-package org.apache.taverna.mobile.tavernamobile;
-/**
- * Apache Taverna Mobile
- * Copyright 2015 The Apache Software Foundation
- *
- * This product includes software developed at
- * The Apache Software Foundation (http://www.apache.org/).
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.taverna.mobile.R;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Created by root on 6/8/15.
- */
-public class Workflow {
- private Context context;
- private User uploader;
- private String workflow_author;
- private String workflow_title;
- private String workflow_description, about, policy;
- private String workflow_datecreated, workflow_datemodified;
- private Bitmap workflow_author_bitmap;
- private WorkflowComponent workflowComponent;
- private String workflow_remote_url; //provides a link to download the workflow. Equivalent to
- // content-uri in the xml form
- private String workflow_web_url; //a string containing the workflow resource that can be
- // loaded in browser
- private String workflow_details_url; //used to refer to the details of the workflow
- private List<Runs> workflow_runs;
- private int workflow_input;
- private long id;
- private String workflow_uploader; //indicate the user who uploaded the workflow
- private String workflow_Type; //describes whether it is a type 1 or 2 workflow
- private String workflow_preview; //a url to a preview image of the workflow
- private String workflow_thumb_big; //a url to a full scale image of the workflow. I Will
- // usually an SVG because the it is available for most of the workflows
- private String workflow_licence_type; //describes a type of licensing for the workflow
- private String workflow_content_type; //specifies a content type for the workflow;
- private List<String> workflow_tags; //provides a list of string tags that could be used to
- // index the workflow for searches
- private String workflow_versions; //a list of version for the workflow uploaded over time
- private List<String> workflow_credits; //key contributors to the workflow
-
- public Workflow() {
- }
-
- ;
-
- public Workflow(Context context) {
- this.context = context;
- this.workflow_runs = new ArrayList<Runs>();
- }
-
- public Workflow(String author, String description, long id, String url) {
- this.workflow_author = author;
- this.workflow_author_bitmap = null; //BitmapFactory.decodeResource(getResources(), R
- // .drawable.ic_userprofile);
- this.workflow_description = description;
- this.workflow_input = 1;
- this.id = id;
- this.workflow_remote_url = url;
- this.workflow_runs = new ArrayList<Runs>();
- }
-
- public Workflow(Context ctx, String title, String author, String description, long id, String
- url) {
- this.context = ctx;
- this.workflow_author = author;
- this.workflow_author_bitmap = BitmapFactory.decodeResource(this.context.getResources(), R
- .drawable.ic_userprofile);
- this.workflow_description = description;
- this.workflow_title = title;
- this.workflow_input = 1;
- this.id = id;
- this.workflow_remote_url = url;
- this.workflow_runs = new ArrayList<Runs>();
- }
-
- public long getId() {
- return this.id;
- }
-
- public void setId(long id) {
- this.id = id;
- }
-
- public String getWorkflowDatecreated() {
- return this.workflow_datecreated;
- }
-
- public void setWorkflowDatecreated(String workflow_datecreated) {
- this.workflow_datecreated = workflow_datecreated;
- }
-
- public String getWorkflowRemoteUrl() {
- return this.workflow_remote_url;
- }
-
- public void setWorkflowRemoteUrl(String workflow_remote_url) {
- this.workflow_remote_url = workflow_remote_url;
- }
-
- public String getWorkflowDetailsUrl() {
- return this.workflow_details_url;
- }
-
- public void setWorkflowDetailsUrl(String workflow_details_url) {
- this.workflow_details_url = workflow_details_url;
- }
-
- public User getUploader() {
- return this.uploader;
- }
-
- public void setUploader(User uploader) {
- this.uploader = uploader;
- }
-
- public String getPolicy() {
- return this.policy;
- }
-
- public void setPolicy(String policy) {
- this.policy = policy;
- }
-
- public String getAbout() {
- return this.about;
- }
-
- public void setAbout(String about) {
- this.about = about;
- }
-
- public String getWorkflowDatemodified() {
- return this.workflow_datemodified;
- }
-
- public void setWorkflowDatemodified(String workflow_datemodified) {
- this.workflow_datemodified = workflow_datemodified;
- }
-
- public List<Runs> getWorkflowRuns() {
- return this.workflow_runs;
- }
-
- public void setWorkflowRuns(List<Runs> workflow_runs) {
- this.workflow_runs = workflow_runs;
- }
-
- public void addWorkflowRun(Runs runs) { //adds a run to this workflow
- this.workflow_runs.add(runs);
- }
-
- public int getWorkflowInput() {
- return this.workflow_input;
- }
-
- public void setWorkflowInput(int workflow_input) {
- this.workflow_input = workflow_input;
- }
-
- public WorkflowInputType getInputType() {
- return WorkflowInputType.TYPE_INT;
- }
-
- public String getWorkflowAuthor() {
- return this.workflow_author;
- }
-
- public void setWorkflowAuthor(String workflow_author) {
- this.workflow_author = workflow_author;
- }
-
- public String getWorkflowDescription() {
- return this.workflow_description;
- }
-
- public void setWorkflowDescription(String workflow_description) {
- this.workflow_description = workflow_description;
- }
-
- public String getWorkflowTitle() {
- return this.workflow_title;
- }
-
- public void setWorkflowTitle(String workflow_title) {
- this.workflow_title = workflow_title;
- }
-
- public Bitmap getWorkflowAuthorBitmap() {
- return this.workflow_author_bitmap;
- }
-
- public void setWorkflowAuthorBitmap(Bitmap workflow_author_bitmap) {
- this.workflow_author_bitmap = workflow_author_bitmap;
- }
-
- public WorkflowComponent getWorkflowComponent() {
- return this.workflowComponent;
- }
-
- public void setWorkflowComponent(WorkflowComponent workflowComponent) {
- this.workflowComponent = workflowComponent;
- }
-
- public String getWorkflowWebUrl() {
- return workflow_web_url;
- }
-
- public void setWorkflowWebUrl(String workflow_web_url) {
- this.workflow_web_url = workflow_web_url;
- }
-
- public String getWorkflowUploader() {
- return workflow_uploader;
- }
-
- public void setWorkflowUploader(String workflow_uploader) {
- this.workflow_uploader = workflow_uploader;
- }
-
- public String getWorkflowType() {
- return workflow_Type;
- }
-
- public void setWorkflowType(String workflow_Type) {
- this.workflow_Type = workflow_Type;
- }
-
- public String getWorkflowPreview() {
- return workflow_preview;
- }
-
- public void setWorkflowPreview(String workflow_preview) {
- this.workflow_preview = workflow_preview;
- }
-
- public String getWorkflowThumbBig() {
- return workflow_thumb_big;
- }
-
- public void setWorkflowThumbBig(String workflow_thumb_big) {
- this.workflow_thumb_big = workflow_thumb_big;
- }
-
- public String getWorkflowLicenceType() {
- return workflow_licence_type;
- }
-
- public void setWorkflowLicenceType(String workflow_licence_type) {
- this.workflow_licence_type = workflow_licence_type;
- }
-
- public String getWorkflowContentType() {
- return workflow_content_type;
- }
-
- public void setWorkflowContentType(String workflow_content_type) {
- this.workflow_content_type = workflow_content_type;
- }
-
- public List<String> getWorkflowTags() {
- return workflow_tags;
- }
-
- public void setWorkflowTags(List<String> workflow_tags) {
- this.workflow_tags = workflow_tags;
- }
-
- public String getWorkflowVersions() {
- return workflow_versions;
- }
-
- public void setWorkflowVersions(String workflow_versions) {
- this.workflow_versions = workflow_versions;
- }
-
- public List<String> getWorkflowCredits() {
- return workflow_credits;
- }
-
- public void setWorkflowCredits(List<String> workflow_credits) {
- this.workflow_credits = workflow_credits;
- }
-
- @Override
- public String toString() {
- return this.workflow_title;
- }
-
- public static enum WorkflowInputType { TYPE_INT, TYPE_STRING, TYPE_OBJECT }
-}
-/* Use the sample code if it becomes necessary to pass this objects amongst activities
-/ simple class that just has one member property as an example
-public class Workflow implements Parcelable {
- private int mData;
-
- */
-/* everything below here is for implementing Parcelable *//*
-
-
- // 99.9% of the time you can just ignore this
- public int describeContents() {
- return 0;
- }
-
- // write your object's data to the passed-in Parcel
- public void writeToParcel(Parcel out, int flags) {
- out.writeInt(mData);
- }
-
-// this is used to regenerate your object. All Parcelables must have a CREATOR that implements
-these two methods
-public static final Parcelable.Creator<Workflow> CREATOR = new Parcelable.Creator<Workflow>() {
- public Workflow createFromParcel(Parcel in) {
- return new Workflow(in);
- }
-
- public Workflow[] newArray(int size) {
- return new Workflow[size];
- }
-};
-
- // example constructor that takes a Parcel and gives you an object populated with it's values
- private Workflow(Parcel in) {
- mData = in.readInt();
- }
-}
-
-//application in intents. Sending object to another activity
- Intent it = new Intent();
- it.putExtra("parsedWorkflow", myWorkflow);
-//retrieve object
- Workflow mWorkflow = (Workflow) getIntent().getParcelableExtra("parsedWorkflow");
-
- */
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/b93d871c/app/src/main/java/org/apache/taverna/mobile/tavernamobile/WorkflowComponent.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/tavernamobile/WorkflowComponent.java b/app/src/main/java/org/apache/taverna/mobile/tavernamobile/WorkflowComponent.java
deleted file mode 100644
index 514824a..0000000
--- a/app/src/main/java/org/apache/taverna/mobile/tavernamobile/WorkflowComponent.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package org.apache.taverna.mobile.tavernamobile;
-/**
- * Apache Taverna Mobile
- * Copyright 2015 The Apache Software Foundation
- *
- * This product includes software developed at
- * The Apache Software Foundation (http://www.apache.org/).
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * Created by Larry Akah on 6/8/15.
- * the component elements that make up a workflow's dataflow (e.g. Taverna has sources, sinks,
- * processors, links and coordinations)
- */
-public class WorkflowComponent {
-
- public WorkflowComponent() {
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/b93d871c/app/src/main/java/org/apache/taverna/mobile/utils/AvatarLoader.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/utils/AvatarLoader.java b/app/src/main/java/org/apache/taverna/mobile/utils/AvatarLoader.java
deleted file mode 100644
index 984f41b..0000000
--- a/app/src/main/java/org/apache/taverna/mobile/utils/AvatarLoader.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package org.apache.taverna.mobile.utils;
-/**
- * Apache Taverna Mobile
- * Copyright 2015 The Apache Software Foundation
- *
- * This product includes software developed at
- * The Apache Software Foundation (http://www.apache.org/).
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import com.thebuzzmedia.sjxp.rule.IRule;
-
-import org.apache.taverna.mobile.adapters.WorkflowAdapter;
-import org.apache.taverna.mobile.tavernamobile.User;
-import org.apache.taverna.mobile.utils.xmlparsers.AvatarXMLParser;
-import org.apache.taverna.mobile.utils.xmlparsers.MyExperimentXmlParserRules;
-
-import android.os.AsyncTask;
-import android.util.Log;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-/**
- * initiates a process to fetch and parse uploader information so as to retrieve the id, name and
- * avatar link
- * Created by Larry AKah on 6/29/15.
- */
-public class AvatarLoader extends AsyncTask<String, Void, Void> {
- private static final String TAG = "AvatarLoader";
- WorkflowAdapter.ViewHolder vh;
-
- public AvatarLoader(WorkflowAdapter.ViewHolder userViewHolder) {
- this.vh = userViewHolder;
- }
-
- @Override
- protected Void doInBackground(String... strings) {
- URL url = null;
- HttpURLConnection connection = null;
- try {
-
- url = new URL(strings[0]);
- connection = (HttpURLConnection) url.openConnection();
- connection.setDoInput(true);
- connection.connect();
- InputStream input = connection.getInputStream();
- IRule avatarRule = new MyExperimentXmlParserRules.AuthorRule(IRule.Type.ATTRIBUTE,
- "/user/avatar", "resource", "uri", "id");
- IRule avatarName = new MyExperimentXmlParserRules.AuthorRule(IRule.Type.CHARACTER,
- "/user/name");
- AvatarXMLParser avatarXMLParser = new AvatarXMLParser(new IRule[]{avatarRule,
- avatarName});
-
- avatarXMLParser.parse(input, new User(strings[1], this.vh));
-
- } catch (MalformedURLException e) {
- Log.e(TAG, "doInBackground: ", e);
- } catch (IOException e) {
- Log.e(TAG, "doInBackground: ", e);
- }
-
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/b93d871c/app/src/main/java/org/apache/taverna/mobile/utils/DBUtility.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/utils/DBUtility.java b/app/src/main/java/org/apache/taverna/mobile/utils/DBUtility.java
deleted file mode 100644
index df7b990..0000000
--- a/app/src/main/java/org/apache/taverna/mobile/utils/DBUtility.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package org.apache.taverna.mobile.utils;
-/**
- * Apache Taverna Mobile
- * Copyright 2015 The Apache Software Foundation
- *
- * This product includes software developed at
- * The Apache Software Foundation (http://www.apache.org/).
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.json.JSONArray;
-import org.json.JSONException;
-
-import java.util.ArrayList;
-
-/**
- * This class contains all utility functions used by our database for basic functionality not
- * directly related to the core
- * functionality of it but that aids a core functionality to carryout its function efficiently.
- * This class is designed to be a singleton class
- *
- * @author Larry Akah
- */
-public class DBUtility {
-
- /**
- * Returns a new JSONArray of new key values to be stored ommitting the identified entry to be
- * removed
- */
- public static JSONArray removeKey(JSONArray keys, String removeid) throws JSONException {
- ArrayList<String> mkeys = new ArrayList<String>();
- if (keys != null) {
- for (int i = 0; i < keys.length(); i++) {
- mkeys.add(keys.getString(i));
- }
- mkeys.remove(removeid);
- JSONArray nkeyArray = new JSONArray();
- for (String newkey : mkeys) {
- nkeyArray.put(newkey);
- }
- return nkeyArray; //returns the new keys to save under the db;
-
- } else {
- return keys; //returns a null value indicating nothin to remove due to no keys available
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/b93d871c/app/src/main/java/org/apache/taverna/mobile/utils/DetailsLoader.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/utils/DetailsLoader.java b/app/src/main/java/org/apache/taverna/mobile/utils/DetailsLoader.java
deleted file mode 100644
index cec8748..0000000
--- a/app/src/main/java/org/apache/taverna/mobile/utils/DetailsLoader.java
+++ /dev/null
@@ -1,280 +0,0 @@
-package org.apache.taverna.mobile.utils;
-/**
- * Apache Taverna Mobile
- * Copyright 2015 The Apache Software Foundation
- *
- * This product includes software developed at
- * The Apache Software Foundation (http://www.apache.org/).
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import com.thebuzzmedia.sjxp.rule.IRule;
-
-import org.apache.taverna.mobile.tavernamobile.Runs;
-import org.apache.taverna.mobile.tavernamobile.TavernaPlayerAPI;
-import org.apache.taverna.mobile.tavernamobile.Workflow;
-import org.apache.taverna.mobile.utils.xmlparsers.MyExperimentXmlParserRules;
-import org.apache.taverna.mobile.utils.xmlparsers.WorkflowDetailParser;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import android.content.AsyncTaskLoader;
-import android.content.Context;
-import android.util.Base64;
-import android.util.Log;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.Authenticator;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.nio.charset.Charset;
-
-/**
- * Loads workflow details from the myexperiment API and presents them on the UI .The class is
- * generic and can be used to load the
- * different details sections of the app.
- * Created by Larry Akah on 6/14/15.
- */
-public class DetailsLoader extends AsyncTaskLoader<Workflow> {
-
- private static final String TAG = "DetailsLoader";
- private LoadType lt;
- private String uri;
- private Workflow workflow;
- private Context context;
-
- public DetailsLoader(Context context, LoadType LoadType, String dataParam) {
- super(context);
- this.context = context;
- this.lt = LoadType;
- uri = dataParam;
- this.workflow = new Workflow();
- }
-
- @Override
- public Workflow loadInBackground() {
- HttpURLConnection connection = null;
- InputStream dis = null;
- //start a network request to fetch user's workflow details
- try {
- Log.i("LOADER STARTED", "loading data");
- //for password protected urls use the user's credentials
- Authenticator.setDefault(new TavernaPlayerAPI.Authenticator("taverna", "taverna"));
- TavernaPlayerAPI tavernaPlayerAPI = new TavernaPlayerAPI();
- URL workflowurl;
-
- switch (this.lt) {
- case TYPE_WORKFLOW_DETAIL:
- workflowurl = new URL(uri);
- connection = (HttpURLConnection) workflowurl.openConnection();
- connection.setRequestProperty("Accept", "application/json");
- connection.setRequestMethod("GET");
- connection.connect(); //send request
-
- Log.i("Workflow Response Code", "" + connection.getResponseCode());
- Log.i("Workflow Response msg", "" + connection.getResponseMessage());
- dis = connection.getInputStream();
- break;
- case TYPE_RUN_HISTORY:
- workflowurl = new URL(new TavernaPlayerAPI(this.context).mPlayerRunUrl);
- connection = (HttpURLConnection) workflowurl.openConnection();
- String userpass = tavernaPlayerAPI.getPlayerUserName(this.context) + ":" +
- tavernaPlayerAPI.getPlayerUserPassword(this.context);
- String basicAuth = "Basic " + Base64.encodeToString(userpass.getBytes(Charset
- .forName("UTF-8")),
- Base64.DEFAULT);
-
- connection.setRequestProperty("Authorization", basicAuth);
- connection.setRequestProperty("Accept", "application/json");
- connection.setRequestMethod("GET");
- connection.connect(); //send request
- Log.i("RESPONSE CODE", "" + connection.getResponseCode());
- Log.i("RESPONSE Messsage. Run", "" + connection.getResponseMessage());
- dis = connection.getInputStream();
- break;
- case TYPE_POLICY:
- workflowurl = new URL(new TavernaPlayerAPI(this.context).mServerBaseUrl);
- break;
- default:
- workflowurl = new URL(new TavernaPlayerAPI(this.context).mPlayerWorkFlowUrl);
- break;
- }
-
- switch (this.lt) {
- case TYPE_WORKFLOW_DETAIL: {
- //make rules and apply the parser
- IRule workfl = new MyExperimentXmlParserRules.WorkflowDetailRule(IRule.Type
- .ATTRIBUTE,
- "/workflow", "uri", "resource", "id", "version");
- IRule title = new MyExperimentXmlParserRules.TitleRule(IRule.Type.CHARACTER,
- "/workflow/title");
- IRule description = new MyExperimentXmlParserRules.DescriptionRule(IRule.Type
- .CHARACTER, "/workflow/description");
- IRule type = new MyExperimentXmlParserRules.TypeRule(IRule.Type.CHARACTER,
- "/workflow/type");
- IRule attrType = new MyExperimentXmlParserRules.TypeRule(IRule.Type
- .ATTRIBUTE, "/workflow/type", "resource", "uri", "id");
- IRule uploader = new MyExperimentXmlParserRules.UploaderRule(IRule.Type
- .CHARACTER, "/workflow/uploader");
- IRule attrUploader = new MyExperimentXmlParserRules.UploaderRule(IRule.Type
- .ATTRIBUTE, "/workflow/uploader", "resource", "uri", "id");
- IRule date = new MyExperimentXmlParserRules.DateRule(IRule.Type.CHARACTER,
- "/workflow/created-at");
- IRule preview = new MyExperimentXmlParserRules.PreviewRule(IRule.Type
- .CHARACTER, "/workflow/preview");
- IRule licetype = new MyExperimentXmlParserRules.LicenceTypeRule(IRule.Type
- .CHARACTER, "/workflow/licence-type");
- IRule attrlicetype = new MyExperimentXmlParserRules.LicenceTypeRule(IRule
- .Type.ATTRIBUTE, "/workflow/licence-type", "resource", "uri", "id");
- IRule contenturi = new MyExperimentXmlParserRules.ContentUriRule(IRule.Type
- .CHARACTER, "/workflow/content-uri");
- IRule contentType = new MyExperimentXmlParserRules.ContentTypeRule(IRule.Type
- .CHARACTER, "/workflow/content-type");
- IRule tags = new MyExperimentXmlParserRules.TagsRule(IRule.Type.CHARACTER,
- "/workflow/tags/tag");
- IRule attrTags = new MyExperimentXmlParserRules.TagsRule(IRule.Type
- .ATTRIBUTE, "/workflow/tags/tag", "resource", "uri", "id");
-
- WorkflowDetailParser parser = new WorkflowDetailParser(new IRule[]{workfl,
- title, description, type,
- attrlicetype, attrType, uploader, attrUploader, date, preview,
- licetype, contenturi, contentType, tags, attrTags});
- // Log.e(TAG, sb.toString());
- parser.parse(dis, this.workflow);
- }
- dis.close();
- //br.close();
- return workflow;
- case TYPE_RUN_HISTORY: {
- Log.e(TAG, "Downloading run history");
- BufferedReader br = new BufferedReader(new InputStreamReader(dis, "UTF-8"));
- StringBuffer sb = new StringBuffer();
- String jsonData = "";
- while ((jsonData = br.readLine()) != null) {
- sb.append(jsonData);
- }
- workflow = new Workflow(this.context);
- JSONArray jsonArray = new JSONArray(sb.toString());
- Log.i("RUN JSON ", jsonArray.toString(2));
- for (int j = 0; j < jsonArray.length(); j++) {
- JSONObject jsonObject = jsonArray.getJSONObject(j);
- long id = jsonObject.getLong("id");
- long workflow_id = jsonObject.getLong("workflow_id");
- String name = jsonObject.getString("name");
- String started = jsonObject.getString("start_time");
- String ended = jsonObject.getString("finish_time");
- String state = jsonObject.getString("state");
- JSONObject userobj = jsonObject.getJSONObject("user");
- String username = userobj.getString("name");
- StringBuffer nm = new StringBuffer(), ur = new StringBuffer();
- for (String n : name.toLowerCase().split(" ")) {
- nm.append(n);
- }
- for (String p : uri.toLowerCase().split(" ")) {
- ur.append(p);
- }
- if (nm.toString().equals(ur.toString())) {
- Runs mrun = new Runs(name, started, ended, state);
- mrun.setrunId(id);
- mrun.setRunWorkflowId(workflow_id);
- mrun.setRunAuthor(username);
-
- workflow.addWorkflowRun(mrun);
- }
- }
- }
- return workflow;
- case TYPE_POLICY: {
-
- }
- return workflow;
- default:
- BufferedReader br = new BufferedReader(new InputStreamReader(dis, "UTF-8"));
- StringBuffer sb = new StringBuffer();
- String jsonData = "";
- while ((jsonData = br.readLine()) != null) {
- sb.append(jsonData);
- }
- dis.close();
- br.close();
- return workflow;
- }
-
- } catch (MalformedURLException e) {
- Log.e(TAG, "loadInBackground: ", e);
- } catch (IOException e) {
- Log.e(TAG, "loadInBackground: ", e);
- } catch (JSONException e) {
- Log.e(TAG, "loadInBackground: ", e);
- }
- return workflow;
- }
-
- @Override
- public boolean isStarted() {
- return super.isStarted();
- }
-
- @Override
- protected void onStartLoading() {
- /* if(workflow != null){
- deliverResult(workflow);
- }else{
- forceLoad();
- }*/
- forceLoad();
- Log.i("Loading State", "loading started");
- }
-
- @Override
- protected void onStopLoading() {
- Log.i("Loading detailComponent", "loading stopped");
- }
-
- @Override
- public void deliverResult(Workflow data) {
- if (isStarted()) {
- super.deliverResult(data);
- }
- }
-
- public static enum LoadType {
- TYPE_WORKFLOW_DETAIL, TYPE_RUN_HISTORY, TYPE_POLICY,
- TYPE_ABOUT_WORKFLOW
- }
-}
-/**
- * JSONObject js = new JSONObject(sb.toString());
- * Log.i("JSON ", js.toString(2));
- * String created_at = js.getString("created_at");
- * String updated_at = js.getString("updated_at");
- * JSONObject user = js.getJSONObject("user");
- * workflow = new Workflow(this.context, js.getString("title"),
- * user.getString("name"),
- * js.getString("description"),
- * js.getInt("id"),
- * js.getString("url"));
- * workflow.setWorkflowDatecreated(created_at);
- * workflow.setWorkflowDatemodified(updated_at);
- **/
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/b93d871c/app/src/main/java/org/apache/taverna/mobile/utils/HttpUtil.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/utils/HttpUtil.java b/app/src/main/java/org/apache/taverna/mobile/utils/HttpUtil.java
deleted file mode 100644
index 0be41a3..0000000
--- a/app/src/main/java/org/apache/taverna/mobile/utils/HttpUtil.java
+++ /dev/null
@@ -1,108 +0,0 @@
-package org.apache.taverna.mobile.utils;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.auth.BasicScheme;
-import org.apache.http.impl.client.AbstractHttpClient;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.util.EntityUtils;
-import org.apache.taverna.mobile.tavernamobile.User;
-
-import android.util.Log;
-
-import java.io.IOException;
-import java.net.CookieStore;
-import java.net.HttpURLConnection;
-/**
- * Apache Taverna Mobile
- * Copyright 2015 The Apache Software Foundation
- *
- * This product includes software developed at
- * The Apache Software Foundation (http://www.apache.org/).
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * Created by Larry Akah on 6/18/15.
- */
-public class HttpUtil {
- private static final String TAG = "HttpUtil";
-
- public <T> Object doPostAuthenticate() {
- User muser = new User("", null);
-
- return muser;
- }
-
- public <T> Object doGetRequestResponse(String uri, Class<T> classType, String username,
- String password) {
- Object dataObject = null;
-
- HttpClient httpClient = new DefaultHttpClient();
- HttpGet httpGet = new HttpGet(uri);
- HttpResponse httpResponse = null;
- try {
- ((AbstractHttpClient) httpClient).setCookieStore((org.apache.http.client.CookieStore)
- CookieStore.class.newInstance());
- httpGet.addHeader(BasicScheme.authenticate(new UsernamePasswordCredentials(username,
- password), "UTF-8", false));
- httpResponse = httpClient.execute(httpGet);
-
- if (isSuccess(httpResponse, HttpURLConnection.HTTP_OK)) {
- HttpEntity entity = httpResponse.getEntity();
- if (entity != null) {
- String responseString = EntityUtils.toString(entity);
- dataObject = this.deSerialize(classType, responseString);
- }
- }
- } catch (InstantiationException e) {
- Log.e(TAG, "doGetRequestResponse: ", e);
- return e.getMessage();
- } catch (IllegalAccessException e) {
- Log.e(TAG, "doGetRequestResponse: ", e);
- return e.getMessage();
- } catch (ClientProtocolException e) {
- Log.e(TAG, "doGetRequestResponse: ", e);
- return e.getMessage();
- } catch (IOException e) {
- Log.e(TAG, "doGetRequestResponse: ", e);
- return e.getMessage();
- }
-
- return dataObject;
-
- }
-
- //de-serializes xml data to target class
- private <T> Object deSerialize(Class<T> classType, String responseString) {
- //TODO deserialize data and return the appropriate object
- // ObjectInputStream ori = new ObjectInputStream(new DataInputStream(responseString)) ;
-
- return null;
- }
-
- private boolean isSuccess(HttpResponse httpResponse, int httpOk) {
-
- return httpResponse.getStatusLine().getStatusCode() == httpOk;
- }
-}