http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/e752e97d/app/src/main/java/org/apache/taverna/mobile/utils/WorkflowLoader.java ---------------------------------------------------------------------- diff --git a/app/src/main/java/org/apache/taverna/mobile/utils/WorkflowLoader.java b/app/src/main/java/org/apache/taverna/mobile/utils/WorkflowLoader.java index d4957de..c98f0f5 100644 --- a/app/src/main/java/org/apache/taverna/mobile/utils/WorkflowLoader.java +++ b/app/src/main/java/org/apache/taverna/mobile/utils/WorkflowLoader.java @@ -2,10 +2,10 @@ 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 @@ -23,10 +23,6 @@ package org.apache.taverna.mobile.utils; * specific language governing permissions and limitations * under the License. */ -import android.content.Context; -import android.os.AsyncTask; -import android.support.v4.widget.SwipeRefreshLayout; -import android.util.Log; import com.thebuzzmedia.sjxp.rule.IRule; @@ -34,6 +30,11 @@ import org.apache.taverna.mobile.tavernamobile.Workflow; import org.apache.taverna.mobile.utils.xmlparsers.MyExperimentXmlParserRules; import org.apache.taverna.mobile.utils.xmlparsers.WorkflowParser; +import android.content.Context; +import android.os.AsyncTask; +import android.support.v4.widget.SwipeRefreshLayout; +import android.util.Log; + import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; @@ -46,7 +47,7 @@ import java.util.List; /** * Created by Larry Akah on 6/13/15. */ -public class WorkflowLoader extends AsyncTask<String, Object, Object>{ //WorkflowLoaderMain { +public class WorkflowLoader extends AsyncTask<String, Object, Object> { //WorkflowLoaderMain { private Context ctx; private List<Workflow> userWorkflows; @@ -68,26 +69,29 @@ public class WorkflowLoader extends AsyncTask<String, Object, Object>{ //Workflo public List<Workflow> doInBackground(String[] pages) { //start a network request to fetch user's workflows - IRule wkflowRule = new MyExperimentXmlParserRules.WorkflowRule(IRule.Type.ATTRIBUTE, "/workflows/workflow", "resource", "uri","id", "version"); - IRule workflowNameRule = new MyExperimentXmlParserRules.WorkflowRule(IRule.Type.CHARACTER, "/workflows/workflow"); + IRule wkflowRule = new MyExperimentXmlParserRules.WorkflowRule(IRule.Type.ATTRIBUTE, + "/workflows/workflow", "resource", "uri", "id", "version"); + IRule workflowNameRule = new MyExperimentXmlParserRules.WorkflowRule(IRule.Type + .CHARACTER, "/workflows/workflow"); WorkflowParser xmlParser = new WorkflowParser(new IRule[]{wkflowRule, workflowNameRule}); try { - URL workflowurl = new URL("http://www.myexperiment.org/workflows.xml?page="+Integer.parseInt((pages[0]))); + URL workflowurl = new URL("http://www.myexperiment.org/workflows.xml?page=" + Integer + .parseInt((pages[0]))); HttpURLConnection connection = (HttpURLConnection) workflowurl.openConnection(); connection.setRequestMethod("GET"); connection.connect(); //send request - Log.i("WorkflowLoader","Loading workflows page = "+pages[0]); + Log.i("WorkflowLoader", "Loading workflows page = " + pages[0]); InputStream dis = connection.getInputStream(); xmlParser.parse(dis, this.userWorkflows); - }catch (MalformedURLException e) { + } catch (MalformedURLException e) { e.printStackTrace(); } catch (ProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); - }catch (Exception ex){ + } catch (Exception ex) { ex.printStackTrace(); } return this.userWorkflows; @@ -96,6 +100,6 @@ public class WorkflowLoader extends AsyncTask<String, Object, Object>{ //Workflo @Override protected void onPostExecute(Object o) { refreshLayout.setRefreshing(false); - System.out.println("Workflow Count: "+this.userWorkflows.size()); + System.out.println("Workflow Count: " + this.userWorkflows.size()); } }
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/e752e97d/app/src/main/java/org/apache/taverna/mobile/utils/WorkflowLoaderMain.java ---------------------------------------------------------------------- diff --git a/app/src/main/java/org/apache/taverna/mobile/utils/WorkflowLoaderMain.java b/app/src/main/java/org/apache/taverna/mobile/utils/WorkflowLoaderMain.java index 41c650d..bb56ec9 100644 --- a/app/src/main/java/org/apache/taverna/mobile/utils/WorkflowLoaderMain.java +++ b/app/src/main/java/org/apache/taverna/mobile/utils/WorkflowLoaderMain.java @@ -2,10 +2,10 @@ 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 @@ -23,11 +23,12 @@ package org.apache.taverna.mobile.utils; * specific language governing permissions and limitations * under the License. */ -import android.content.AsyncTaskLoader; -import android.content.Context; import org.apache.taverna.mobile.tavernamobile.Workflow; +import android.content.AsyncTaskLoader; +import android.content.Context; + import java.util.List; /** http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/e752e97d/app/src/main/java/org/apache/taverna/mobile/utils/WorkflowOpen.java ---------------------------------------------------------------------- diff --git a/app/src/main/java/org/apache/taverna/mobile/utils/WorkflowOpen.java b/app/src/main/java/org/apache/taverna/mobile/utils/WorkflowOpen.java index eae8479..b54124b 100644 --- a/app/src/main/java/org/apache/taverna/mobile/utils/WorkflowOpen.java +++ b/app/src/main/java/org/apache/taverna/mobile/utils/WorkflowOpen.java @@ -4,6 +4,12 @@ package org.apache.taverna.mobile.utils; * Created by Larry Akah on 7/11/15. */ +import org.apache.taverna.mobile.R; +import org.apache.taverna.mobile.tavernamobile.TavernaPlayerAPI; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.Context; @@ -16,12 +22,6 @@ import android.widget.LinearLayout; import android.widget.ScrollView; import android.widget.TextView; -import org.apache.taverna.mobile.R; -import org.apache.taverna.mobile.tavernamobile.TavernaPlayerAPI; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.File; @@ -33,27 +33,27 @@ import java.net.HttpURLConnection; import java.net.URL; /** - *Read the selected xml file from storage and upload to player to generate workflowRun + * Read the selected xml file from storage and upload to player to generate workflowRun */ public class WorkflowOpen extends AsyncTask<String, Void, String> { + TavernaPlayerAPI tavernaPlayerAPI = new TavernaPlayerAPI(); private Context context; private ProgressDialog progressDialog; - TavernaPlayerAPI tavernaPlayerAPI = new TavernaPlayerAPI(); public WorkflowOpen(Context context) { this.context = context; progressDialog = new ProgressDialog(this.context); } - @Override - protected void onPreExecute() { - progressDialog.setMessage("Uploading Workflow ... "); - progressDialog.show(); - } + @Override + protected void onPreExecute() { + + progressDialog.setMessage("Uploading Workflow ... "); + progressDialog.show(); + } /** - * * @param params path to workflow file to upload to player * @return run framework used to create a new workflow run */ @@ -63,13 +63,16 @@ public class WorkflowOpen extends AsyncTask<String, Void, String> { String str = ""; try { - //prepare connection requests - File objectFile = new File(params[0]); //the resource xml file representing the workflow to be uploaded to the player - String playerurl = new TavernaPlayerAPI(this.context).PLAYER_BASE_URL+"workflows.json"; + //prepare connection requests + File objectFile = new File(params[0]); //the resource xml file representing the + // workflow to be uploaded to the player + String playerurl = new TavernaPlayerAPI(this.context).PLAYER_BASE_URL + "workflows" + + ".json"; URL posturl = new URL(playerurl); HttpURLConnection connection = (HttpURLConnection) posturl.openConnection(); - String user = tavernaPlayerAPI.getPlayerUserName(this.context) + ":" + tavernaPlayerAPI.getPlayerUserPassword(this.context); + String user = tavernaPlayerAPI.getPlayerUserName(this.context) + ":" + + tavernaPlayerAPI.getPlayerUserPassword(this.context); String basicAuth = "Basic " + Base64.encodeToString(user.getBytes(), Base64.DEFAULT); //read the file from remote resource and encode the stream with a base64 algorithm @@ -81,41 +84,42 @@ public class WorkflowOpen extends AsyncTask<String, Void, String> { sb.append('\n'); } br.close(); - } - catch (IOException e) { + } catch (IOException e) { e.printStackTrace(); } 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+"}"; + 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); - System.out.println("BODY=>"+post); + sb.delete(0, sb.length() - 1); + System.out.println("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.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.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) + while ((str = br.readLine()) != null) sb.append(str); - System.out.println("Post Response Code: "+connection.getResponseCode()); - System.out.println("Post response message: "+connection.getResponseMessage()); + System.out.println("Post Response Code: " + connection.getResponseCode()); + System.out.println("Post response message: " + connection.getResponseMessage()); connection.disconnect(); - }catch (IOException e){ + } catch (IOException e) { e.printStackTrace(); sb.append("Error reading remote workflow. Please try again later"); } @@ -124,13 +128,16 @@ public class WorkflowOpen extends AsyncTask<String, Void, String> { } /** - * 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 + * 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(); + progressDialog.dismiss(); System.out.println(s); s = s.substring(1, s.length()); try { @@ -144,7 +151,7 @@ public class WorkflowOpen extends AsyncTask<String, Void, String> { } //create and return a new TextView - public TextView createTextView(Context mcontext, String placeholder){ + public TextView createTextView(Context mcontext, String placeholder) { TextView tv = new TextView(mcontext); tv.setText(placeholder); tv.setMinLines(2); @@ -153,7 +160,7 @@ public class WorkflowOpen extends AsyncTask<String, Void, String> { } //create and return a new EdiText view - public EditText createEditText(Context ctx, int i){ + public EditText createEditText(Context ctx, int i) { EditText edt; edt = new EditText(ctx); edt.setHint("Enter Value"); @@ -162,7 +169,7 @@ public class WorkflowOpen extends AsyncTask<String, Void, String> { return edt; } - private class WorkflowRunTask extends AsyncTask<String, Void, String>{ + private class WorkflowRunTask extends AsyncTask<String, Void, String> { private Context context; private AlertDialog.Builder alertDialogBuilder; @@ -184,10 +191,13 @@ public class WorkflowOpen extends AsyncTask<String, Void, String> { StringBuffer sb = new StringBuffer(); try { - URL workflowurl = new URL(new TavernaPlayerAPI(this.context).PLAYER_RUN_FRAMEWORK_URL+params[0]); + URL workflowurl = new URL(new TavernaPlayerAPI(this.context) + .PLAYER_RUN_FRAMEWORK_URL + params[0]); HttpURLConnection connection = (HttpURLConnection) workflowurl.openConnection(); - String userpass = tavernaPlayerAPI.getPlayerUserName(this.context) + ":" + tavernaPlayerAPI.getPlayerUserPassword(this.context); - String basicAuth = "Basic " + Base64.encodeToString(userpass.getBytes(), Base64.DEFAULT); + String userpass = tavernaPlayerAPI.getPlayerUserName(this.context) + ":" + + tavernaPlayerAPI.getPlayerUserPassword(this.context); + String basicAuth = "Basic " + Base64.encodeToString(userpass.getBytes(), Base64 + .DEFAULT); connection.setRequestProperty("Authorization", basicAuth); connection.setRequestProperty("Accept", "application/json"); @@ -208,7 +218,7 @@ public class WorkflowOpen extends AsyncTask<String, Void, String> { br.close(); return sb.toString(); - }catch (IOException ex){ + } catch (IOException ex) { ex.printStackTrace(); } return sb.toString(); @@ -226,10 +236,11 @@ public class WorkflowOpen extends AsyncTask<String, Void, String> { 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 + 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++){ + 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)); @@ -240,17 +251,22 @@ public class WorkflowOpen extends AsyncTask<String, Void, String> { // alertDialogBuilder.setMessage(result); alertDialogBuilder.setIcon(ctx.getResources().getDrawable(R.mipmap.ic_launcher)); alertDialogBuilder.setTitle("New Workflow Run"); - alertDialogBuilder.setPositiveButton("Execute", new DialogInterface.OnClickListener() { + 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++){ + 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 + 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) { e.printStackTrace(); @@ -268,7 +284,8 @@ public class WorkflowOpen extends AsyncTask<String, Void, String> { } }); - alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface + .OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/e752e97d/app/src/main/java/org/apache/taverna/mobile/utils/Workflow_DB.java ---------------------------------------------------------------------- diff --git a/app/src/main/java/org/apache/taverna/mobile/utils/Workflow_DB.java b/app/src/main/java/org/apache/taverna/mobile/utils/Workflow_DB.java deleted file mode 100644 index 0394841..0000000 --- a/app/src/main/java/org/apache/taverna/mobile/utils/Workflow_DB.java +++ /dev/null @@ -1,307 +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 java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import android.content.Context; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; -import android.util.Log; - -/** - * @author Larry Akah - * @version 1.0.0 - * This class is developed as a means to simplify the code base of the initial json_db implementation. - * It aims at using fully the java JSON API available to implement the CRUD functionality of the json_db library. - * This class is much more scalable and light-weight than the first implementation - */ -public class Workflow_DB { - - private String ENTITY_KEY; - private Context context; - private SharedPreferences msharedpreference; - private ArrayList<String> ITEM_IDS; - private final String LIBTAG = getClass().getName(); - private JSONObject DBJSON; - private JSONObject dataobj; //hold all entries for a given ENTITY_KEY - - /** - * Constructor initializes a basic data store environment - * @param ctx a reference to the application's context or sand box - * @param entityKey The main data store key for each entity space/schema - */ - public Workflow_DB(Context ctx, String entityKey){ - context = ctx; - ENTITY_KEY = entityKey; - DBJSON = new JSONObject(); - ITEM_IDS = new ArrayList<String>(); - dataobj = DBJSON; - } - - /** - * Inserts an entity set('row') into the data store - * @param items values for each 'column' in the entity - * @return the same instance for chaining multiple calls to this method. - * @throws org.json.JSONException - */ - public Workflow_DB put(ArrayList<Object> items) throws JSONException{ - - String item_id = this.generateRandomId(); - ITEM_IDS.add(item_id); - JSONArray jarray = new JSONArray(); - for(Object item: items){ - jarray.put(item); - } - dataobj.put(item_id, jarray); - return this; - } - - /** - * Returns all entity entries from the data store. Each item of an entity is accompanied with the key or unique id of the items. - * @author Larry Akah - * @throws org.json.JSONException for errors during construction of a JSON data string. - * @throws NullPointerException for any null accessed variable - */ - public List<ArrayList<Object>> get() throws JSONException , NullPointerException{ - msharedpreference = PreferenceManager.getDefaultSharedPreferences(context); - //read key and get existing data - List<ArrayList<Object>> results = new ArrayList<ArrayList<Object>>(); - JSONObject mainJson = new JSONObject(msharedpreference.getString(ENTITY_KEY, "{"+ENTITY_KEY+":{}}")); - - Log.i(ENTITY_KEY, mainJson.toString(2)); - - JSONArray keysJson = mainJson.getJSONArray("ids"); //retrieve a json array of ids for every entity entry - Log.i(ENTITY_KEY, keysJson.toString(2)); - - if(null != keysJson) - for(int i=0; i<keysJson.length(); i++){ - //for each key, get the associated data - try { - JSONArray resultArray = mainJson.getJSONArray(keysJson.getString(i)); - ArrayList<Object> mlist = new ArrayList<Object>(); - if(null != resultArray) - for(int j=0; j<resultArray.length(); j++){ - mlist.add(resultArray.getString(j)); - - } - mlist.add(keysJson.getString(i)); // adds the entry key as last value of the data returned - results.add(mlist); - } catch (Exception e) { - e.printStackTrace(); - continue; - } - } - return results; - } - - /** - * updates a single item entry of an entity - * @param itemId provides the id of the item to be updated - * @param newItem the new set of data to be used to update the entry - * @return boolean indicating whether the item was successfully updated or not. True means item was updated, false means otherwise. - */ - public boolean update(String itemId, ArrayList<Object> newItem){ - boolean operationSucceeded = false; - - JSONArray jarray = new JSONArray(); - for(Object item: newItem){ - jarray.put(item); - } - try { - dataobj.put(itemId, jarray); //replace the current entry at the given ID. - Log.d(LIBTAG, ""+dataobj.toString(2)); - operationSucceeded = true; - } catch (JSONException e) { - e.printStackTrace(); - operationSucceeded = false; - }finally{ - return operationSucceeded; - } - } - - /** - * Updates all the items of a given entity - * @return the number of items successfully updated. - */ - public int updateAll(List<ArrayList<String>> items){ - return 0; - } - - /** - * Gets an entry of an entity from the data store - * @author Larry Akah - * @param id The id of the item('row') in question to return - * @throws org.json.JSONException for errors during construction of a JSON data string. - * @throws NullPointerException for any null accessed variable - */ - public ArrayList<Object> get(String id) throws JSONException , NullPointerException{ - msharedpreference = PreferenceManager.getDefaultSharedPreferences(context); - //read key and get existing data - ArrayList<Object> results = new ArrayList<Object>(); - JSONObject mainJson = new JSONObject(msharedpreference.getString(ENTITY_KEY, ENTITY_KEY+":{}")); - - Log.i(ENTITY_KEY, mainJson.toString(2)); - - JSONArray keysJson = mainJson.getJSONArray("ids"); //retrieve a json array of ids for every entity entry - Log.i(ENTITY_KEY, keysJson.toString(2)); - - if(null != keysJson) - for(int i=0; i<keysJson.length(); i++){ - //for each key, get the associated data - try { - JSONArray resultArray = mainJson.getJSONArray(keysJson.getString(i)); - if(null != resultArray) - for(int j=0; j<resultArray.length(); j++){ - results.add(resultArray.getString(j)); - } - } catch (Exception e) { - e.printStackTrace(); - continue; - } - } - return results; - } - - /** - * Persists all data by making the data permanent in the preference file on the fileSystem - * Save all id's in a different preference - * @author Larry Akah - * @return true or false indicating whether the save was successful or not - */ - public boolean save(){ - msharedpreference = PreferenceManager.getDefaultSharedPreferences(context); - boolean saved = false; - if(dataobj != null) - try { - saved = saveid(ITEM_IDS); - if(saved) - msharedpreference.edit().putString(ENTITY_KEY, dataobj.toString()).apply(); - return saved; - } catch (JSONException e) { - e.printStackTrace(); - return false; - } - else - return false; - } - - /** - * - * @return the number of entities inserted - */ - public int insert(ArrayList<Object> item){ - long start = System.currentTimeMillis(); - msharedpreference = PreferenceManager.getDefaultSharedPreferences(context); - try { - JSONObject jsonObject = new JSONObject(msharedpreference.getString(ENTITY_KEY, "{"+ENTITY_KEY+":{}}")); //main json db - System.out.println(jsonObject.toString(1)); - - JSONArray jsonArray; - if(jsonObject.has("ids")) - jsonArray = jsonObject.optJSONArray("ids"); - else - jsonArray = new JSONArray(); - - String newItemId = item.get(0).toString(); //use the workflow id as an entity key for the new entity - - //verify if this workflow item has already been marked as favorite - for(int k=0; k<jsonArray.length(); k++){ - if (jsonArray.get(k).toString().equalsIgnoreCase(newItemId)) - return -1; - } - - jsonArray.put(jsonArray.length(),newItemId); //add new entity id - JSONArray newEntity = new JSONArray(); - for(Object entity: item){ - newEntity.put(entity); - } - jsonObject.put("ids", jsonArray); - jsonObject.put(newItemId, newEntity); - msharedpreference.edit().putString(ENTITY_KEY, jsonObject.toString()).commit(); - long end = System.currentTimeMillis(); - System.out.println("Insert benchmark length = "+(end - start)); - return 1; - } catch (JSONException e) { - e.printStackTrace(); - } - return 0; - } - - /** - * save the ids of all entity entries - * @author Larry Akah - * @param ids A list of auto-generated ids that point to each set of entity data in the data store - * @throws org.json.JSONException - */ - private boolean saveid(ArrayList<String> ids) throws JSONException{ - JSONArray jarray = new JSONArray(); - for(Object item: ids){ - jarray.put(item); - } - dataobj.put("ids", jarray); - - return jarray.length() == ids.size()? true:false; - } - - /** - * Removes an item from an entity entry - * @author Larry Akah - * @throws org.json.JSONException - */ - public Workflow_DB delete(String itemID) throws JSONException{ - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); - JSONObject dbjson = new JSONObject(sp.getString(ENTITY_KEY, ENTITY_KEY+":{}")); - - JSONArray currentkeys = dbjson.getJSONArray("ids"); - JSONArray newKeys = DB_Utility.removeKey(currentkeys, itemID); - - dbjson.put("ids", newKeys); - sp.edit().putString(ENTITY_KEY, dbjson.toString()).apply(); - - return this; - } - /** - * Removes all items from an entity - * @author Larry Akah - */ - public int bulkDelete(String entity_key){ - - return 0; - } - - /** - * Generates a random hexadecimal string to be used as ids for identifying each entry of an entity item. Proven to be collision resistant enough accross API KEYS - * @author Larry Akah - */ - private String generateRandomId(){ - return UUID.randomUUID().toString(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/e752e97d/app/src/main/java/org/apache/taverna/mobile/utils/xmlparsers/AvatarXMLParser.java ---------------------------------------------------------------------- diff --git a/app/src/main/java/org/apache/taverna/mobile/utils/xmlparsers/AvatarXMLParser.java b/app/src/main/java/org/apache/taverna/mobile/utils/xmlparsers/AvatarXMLParser.java index 9b74aa1..047b282 100644 --- a/app/src/main/java/org/apache/taverna/mobile/utils/xmlparsers/AvatarXMLParser.java +++ b/app/src/main/java/org/apache/taverna/mobile/utils/xmlparsers/AvatarXMLParser.java @@ -2,10 +2,10 @@ package org.apache.taverna.mobile.utils.xmlparsers; /** * 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 @@ -23,6 +23,7 @@ package org.apache.taverna.mobile.utils.xmlparsers; * specific language governing permissions and limitations * under the License. */ + import com.thebuzzmedia.sjxp.XMLParser; import com.thebuzzmedia.sjxp.XMLParserException; import com.thebuzzmedia.sjxp.rule.IRule; http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/e752e97d/app/src/main/java/org/apache/taverna/mobile/utils/xmlparsers/MyExperimentXmlParserRules.java ---------------------------------------------------------------------- diff --git a/app/src/main/java/org/apache/taverna/mobile/utils/xmlparsers/MyExperimentXmlParserRules.java b/app/src/main/java/org/apache/taverna/mobile/utils/xmlparsers/MyExperimentXmlParserRules.java index 14ec7b5..8167968 100644 --- a/app/src/main/java/org/apache/taverna/mobile/utils/xmlparsers/MyExperimentXmlParserRules.java +++ b/app/src/main/java/org/apache/taverna/mobile/utils/xmlparsers/MyExperimentXmlParserRules.java @@ -2,10 +2,10 @@ package org.apache.taverna.mobile.utils.xmlparsers; /** * 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 @@ -24,14 +24,13 @@ package org.apache.taverna.mobile.utils.xmlparsers; * under the License. */ -import android.text.Html; - import com.thebuzzmedia.sjxp.XMLParser; import com.thebuzzmedia.sjxp.rule.DefaultRule; import org.apache.taverna.mobile.tavernamobile.User; import org.apache.taverna.mobile.tavernamobile.Workflow; -import org.apache.taverna.mobile.utils.WorkflowLoader; + +import android.text.Html; import java.util.ArrayList; import java.util.List; @@ -43,58 +42,63 @@ public class MyExperimentXmlParserRules { public static Workflow mWorkflow = new Workflow(); - public MyExperimentXmlParserRules(){ + public MyExperimentXmlParserRules() { } - public Workflow getWorkflowHere(){ + public Workflow getWorkflowHere() { return mWorkflow; } + //parse a single workflow from myexperiment - public final static class WorkflowDetailRule extends DefaultRule{ + public static final class WorkflowDetailRule extends DefaultRule { - public WorkflowDetailRule(Type type, String locationPath, String... attributeNames) throws IllegalArgumentException { + public WorkflowDetailRule(Type type, String locationPath, String... attributeNames) + throws IllegalArgumentException { super(type, locationPath, attributeNames); } @Override - public void handleParsedAttribute(XMLParser parser, int index, String value, Object userObject) { - switch(index){ + public void handleParsedAttribute(XMLParser parser, int index, String value, Object + userObject) { + switch (index) { case 0: //uri mWorkflow.setWorkflow_details_url(value); - ((Workflow)userObject).setWorkflow_details_url(value); + ((Workflow) userObject).setWorkflow_details_url(value); break; case 1: //resource mWorkflow.setWorkflow_web_url(value); - ((Workflow)userObject).setWorkflow_web_url(value); + ((Workflow) userObject).setWorkflow_web_url(value); break; case 2: //id mWorkflow.setId(Integer.parseInt(value)); - ((Workflow)userObject).setId(Integer.parseInt(value)); + ((Workflow) userObject).setId(Integer.parseInt(value)); break; case 3://version mWorkflow.setWorkflow_versions(value); - ((Workflow)userObject).setWorkflow_versions(value); + ((Workflow) userObject).setWorkflow_versions(value); break; } } } - public static class TitleRule extends DefaultRule{ + public static class TitleRule extends DefaultRule { - public TitleRule(Type type, String locationPath, String... attributeNames) throws IllegalArgumentException { + public TitleRule(Type type, String locationPath, String... attributeNames) throws + IllegalArgumentException { super(type, locationPath, attributeNames); } @Override public void handleParsedCharacters(XMLParser parser, String text, Object userObject) { mWorkflow.setWorkflow_title(text); - ((Workflow)userObject).setWorkflow_title(text); + ((Workflow) userObject).setWorkflow_title(text); } } - public static class DescriptionRule extends DefaultRule{ + public static class DescriptionRule extends DefaultRule { - public DescriptionRule(Type type, String locationPath, String... attributeNames) throws IllegalArgumentException { + public DescriptionRule(Type type, String locationPath, String... attributeNames) throws + IllegalArgumentException { super(type, locationPath, attributeNames); } @@ -102,19 +106,21 @@ public class MyExperimentXmlParserRules { public void handleParsedCharacters(XMLParser parser, String text, Object userObject) { mWorkflow.setWorkflow_description(String.valueOf(Html.fromHtml(text))); - ((Workflow)userObject).setWorkflow_description(String.valueOf(Html.fromHtml(text))); + ((Workflow) userObject).setWorkflow_description(String.valueOf(Html.fromHtml(text))); } } - public static class TypeRule extends DefaultRule{ + public static class TypeRule extends DefaultRule { - public TypeRule(Type type, String locationPath, String... attributeNames) throws IllegalArgumentException { + public TypeRule(Type type, String locationPath, String... attributeNames) throws + IllegalArgumentException { super(type, locationPath, attributeNames); } @Override - public void handleParsedAttribute(XMLParser parser, int index, String value, Object userObject) { - switch (index){ + public void handleParsedAttribute(XMLParser parser, int index, String value, Object + userObject) { + switch (index) { case 0: break; case 1: @@ -128,37 +134,40 @@ public class MyExperimentXmlParserRules { @Override public void handleParsedCharacters(XMLParser parser, String text, Object userObject) { mWorkflow.setWorkflow_Type(text); - ((Workflow)userObject).setWorkflow_Type(text); + ((Workflow) userObject).setWorkflow_Type(text); } } - public static class UploaderRule extends DefaultRule{ + public static class UploaderRule extends DefaultRule { User muser; - public UploaderRule(Type type, String locationPath, String... attributeNames) throws IllegalArgumentException { + + public UploaderRule(Type type, String locationPath, String... attributeNames) throws + IllegalArgumentException { super(type, locationPath, attributeNames); muser = new User("", null); } @Override - public void handleParsedAttribute(XMLParser parser, int index, String value, Object userObject) { - switch(index){ + public void handleParsedAttribute(XMLParser parser, int index, String value, Object + userObject) { + switch (index) { case 0: muser.setWebsite(value); - if( (userObject instanceof User)){ - ((User)userObject).setWebsite(value); + if ((userObject instanceof User)) { + ((User) userObject).setWebsite(value); } break; case 1: muser.setDetails_uri(value); - if( (userObject instanceof User)){ - ((User)userObject).setDetails_uri(value); + if ((userObject instanceof User)) { + ((User) userObject).setDetails_uri(value); } break; case 2: muser.setId(value); - if( (userObject instanceof User)){ - ((User)userObject).setId(value); + if ((userObject instanceof User)) { + ((User) userObject).setId(value); } break; } @@ -166,26 +175,29 @@ public class MyExperimentXmlParserRules { @Override public void handleParsedCharacters(XMLParser parser, String text, Object userObject) { - muser.setName(text); - mWorkflow.setUploader(muser); + muser.setName(text); + mWorkflow.setUploader(muser); - if( (userObject instanceof User)){ - ((User)userObject).setName(text); - }else{ - ((Workflow)userObject).setUploader(muser); + if ((userObject instanceof User)) { + ((User) userObject).setName(text); + } else { + ((Workflow) userObject).setUploader(muser); } } } + //rule used to parse author from main page - public static class AuthorRule extends DefaultRule{ + public static class AuthorRule extends DefaultRule { - public AuthorRule(Type type, String locationPath, String... attributeNames) throws IllegalArgumentException { + public AuthorRule(Type type, String locationPath, String... attributeNames) throws + IllegalArgumentException { super(type, locationPath, attributeNames); } @Override - public void handleParsedAttribute(XMLParser parser, int index, String value, Object userObject) { - switch(index){ + public void handleParsedAttribute(XMLParser parser, int index, String value, Object + userObject) { + switch (index) { case 0: ((User) userObject).setAvatar_url(value); break; @@ -205,93 +217,105 @@ public class MyExperimentXmlParserRules { //System.out.println("Author Name: "+text); } } + //rule for the date the workflow was created/uploaded - public static class DateRule extends DefaultRule{ + public static class DateRule extends DefaultRule { - public DateRule(Type type, String locationPath, String... attributeNames) throws IllegalArgumentException { + public DateRule(Type type, String locationPath, String... attributeNames) throws + IllegalArgumentException { super(type, locationPath, attributeNames); } - @Override - public void handleParsedCharacters(XMLParser parser, String text, Object userObject) { - mWorkflow.setWorkflow_datecreated(text); - ((Workflow)userObject).setWorkflow_datecreated(text); + @Override + public void handleParsedCharacters(XMLParser parser, String text, Object userObject) { + mWorkflow.setWorkflow_datecreated(text); + ((Workflow) userObject).setWorkflow_datecreated(text); + } } -} - public static class PreviewRule extends DefaultRule{ + public static class PreviewRule extends DefaultRule { - public PreviewRule(Type type, String locationPath, String... attributeNames) throws IllegalArgumentException { + public PreviewRule(Type type, String locationPath, String... attributeNames) throws + IllegalArgumentException { super(type, locationPath, attributeNames); } @Override public void handleParsedCharacters(XMLParser parser, String text, Object userObject) { mWorkflow.setWorkflow_preview(text); - ((Workflow)userObject).setWorkflow_preview(text); + ((Workflow) userObject).setWorkflow_preview(text); } } - public static class LicenceTypeRule extends DefaultRule{ + public static class LicenceTypeRule extends DefaultRule { - public LicenceTypeRule(Type type, String locationPath, String... attributeNames) throws IllegalArgumentException { + public LicenceTypeRule(Type type, String locationPath, String... attributeNames) throws + IllegalArgumentException { super(type, locationPath, attributeNames); } @Override - public void handleParsedAttribute(XMLParser parser, int index, String value, Object userObject) { + public void handleParsedAttribute(XMLParser parser, int index, String value, Object + userObject) { super.handleParsedAttribute(parser, index, value, userObject); } @Override public void handleParsedCharacters(XMLParser parser, String text, Object userObject) { - mWorkflow.setWorkflow_licence_type("Licence By "+text); - ((Workflow)userObject).setWorkflow_licence_type("Licence By "+text); + mWorkflow.setWorkflow_licence_type("Licence By " + text); + ((Workflow) userObject).setWorkflow_licence_type("Licence By " + text); } } + //set download link for the workflow - public static class ContentUriRule extends DefaultRule{ + public static class ContentUriRule extends DefaultRule { - public ContentUriRule(Type type, String locationPath, String... attributeNames) throws IllegalArgumentException { + public ContentUriRule(Type type, String locationPath, String... attributeNames) throws + IllegalArgumentException { super(type, locationPath, attributeNames); } @Override public void handleParsedCharacters(XMLParser parser, String text, Object userObject) { mWorkflow.setWorkflow_remote_url(text); - ((Workflow)userObject).setWorkflow_remote_url(text); + ((Workflow) userObject).setWorkflow_remote_url(text); } } - public static class ContentTypeRule extends DefaultRule{ + public static class ContentTypeRule extends DefaultRule { - public ContentTypeRule(Type type, String locationPath, String... attributeNames) throws IllegalArgumentException { + public ContentTypeRule(Type type, String locationPath, String... attributeNames) throws + IllegalArgumentException { super(type, locationPath, attributeNames); } @Override public void handleParsedCharacters(XMLParser parser, String text, Object userObject) { mWorkflow.setWorkflow_content_type(text); - ((Workflow)userObject).setWorkflow_content_type(text); + ((Workflow) userObject).setWorkflow_content_type(text); } } - public static class TagsRule extends DefaultRule{ + public static class TagsRule extends DefaultRule { - public TagsRule(Type type, String locationPath, String... attributeNames) throws IllegalArgumentException { + public TagsRule(Type type, String locationPath, String... attributeNames) throws + IllegalArgumentException { super(type, locationPath, attributeNames); } @Override - public void handleParsedAttribute(XMLParser parser, int index, String value, Object userObject) { + public void handleParsedAttribute(XMLParser parser, int index, String value, Object + userObject) { super.handleParsedAttribute(parser, index, value, userObject); } @Override public void handleParsedCharacters(XMLParser parser, String text, Object userObject) { - mWorkflow.setWorkflow_tags(new ArrayList<String>(){}); - ((Workflow)userObject).setWorkflow_tags(new ArrayList<String>(){}); + mWorkflow.setWorkflow_tags(new ArrayList<String>() { + }); + ((Workflow) userObject).setWorkflow_tags(new ArrayList<String>() { + }); } } @@ -299,29 +323,32 @@ public class MyExperimentXmlParserRules { /** * parse workflows from myExperiment */ - public final static class WorkflowRule extends DefaultRule{ - Workflow workflow; - List<Workflow> wlist; - static String uri,version,desc; - static String url=uri=version=desc=""; + public static final class WorkflowRule extends DefaultRule { + static String uri, version, desc; + static String url = uri = version = desc = ""; static long id = 0; + Workflow workflow; + List<Workflow> wlist; - public WorkflowRule(Type type, String locationPath, String... attributeNames) throws IllegalArgumentException { + public WorkflowRule(Type type, String locationPath, String... attributeNames) throws + IllegalArgumentException { super(type, locationPath, attributeNames); this.workflow = new Workflow(); wlist = new ArrayList<>(); } + //instantiated to parse xml data for a given workflow - public WorkflowRule(Type type, String path, int id, String attributenames){ - super(type,path,attributenames); + public WorkflowRule(Type type, String path, int id, String attributenames) { + super(type, path, attributenames); } @Override - public void handleParsedAttribute(XMLParser parser, int index, String value, Object userObject) { + public void handleParsedAttribute(XMLParser parser, int index, String value, Object + userObject) { - switch(index){ + switch (index) { case 0: - desc = "To view workflow on the web, click "+value; + desc = "To view workflow on the web, click " + value; break; case 1: uri = value; @@ -336,7 +363,8 @@ public class MyExperimentXmlParserRules { } @Override - public void handleParsedCharacters(XMLParser parser, String text, Object workflowListObject) { + public void handleParsedCharacters(XMLParser parser, String text, Object + workflowListObject) { //add the workflow to the workflow list this.workflow = new Workflow("", desc, id, url); this.workflow.setWorkflow_details_url(uri); @@ -344,7 +372,7 @@ public class MyExperimentXmlParserRules { this.workflow.setWorkflow_author(""); wlist.add(this.workflow); //WorkflowLoader.loadedWorkflows.add(this.workflow); - ((List<Workflow>)workflowListObject).add(this.workflow); + ((List<Workflow>) workflowListObject).add(this.workflow); this.workflow = null; } } http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/e752e97d/app/src/main/java/org/apache/taverna/mobile/utils/xmlparsers/WorkflowDetailParser.java ---------------------------------------------------------------------- diff --git a/app/src/main/java/org/apache/taverna/mobile/utils/xmlparsers/WorkflowDetailParser.java b/app/src/main/java/org/apache/taverna/mobile/utils/xmlparsers/WorkflowDetailParser.java index 906b99e..4c80085 100644 --- a/app/src/main/java/org/apache/taverna/mobile/utils/xmlparsers/WorkflowDetailParser.java +++ b/app/src/main/java/org/apache/taverna/mobile/utils/xmlparsers/WorkflowDetailParser.java @@ -12,10 +12,10 @@ import org.apache.taverna.mobile.tavernamobile.Workflow; /** * 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 @@ -47,9 +47,9 @@ public class WorkflowDetailParser extends XMLParser { //deliver results when parsing has completed and all the information required has been retrieved @Override protected void doEndDocument(Object userObject) { - if(userObject instanceof User){ - WorkflowItemFragment.startLoadingAvatar((User) userObject); - }else - WorkflowdetailFragment.setWorkflowDetails((Workflow) userObject); + if (userObject instanceof User) { + WorkflowItemFragment.startLoadingAvatar((User) userObject); + } else + WorkflowdetailFragment.setWorkflowDetails((Workflow) userObject); } } http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/e752e97d/config/quality/checkstyle/checkstyle-config.xml ---------------------------------------------------------------------- diff --git a/config/quality/checkstyle/checkstyle-config.xml b/config/quality/checkstyle/checkstyle-config.xml index 0f451bb..d7af4c3 100644 --- a/config/quality/checkstyle/checkstyle-config.xml +++ b/config/quality/checkstyle/checkstyle-config.xml @@ -32,14 +32,14 @@ <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/> </module> - <module name="EmptyBlock"> + <!--<module name="EmptyBlock"> <property name="option" value="TEXT"/> <property name="tokens" value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/> - </module> + </module>--> - <module name="EmptyCatchBlock"> + <!--<module name="EmptyCatchBlock"> <property name="exceptionVariableName" value="expected"/> - </module> + </module>--> <module name="LeftCurly"> <property name="maxLineLength" value="100"/> @@ -116,39 +116,39 @@ value="Package name ''{0}'' must match pattern ''{1}''."/> </module> - <module name="MethodName"> +<!-- <module name="MethodName"> <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/> <message key="name.invalidPattern" value="Method name ''{0}'' must match pattern ''{1}''."/> - </module> + </module>--> <module name="TypeName"> <message key="name.invalidPattern" value="Type name ''{0}'' must match pattern ''{1}''."/> </module> - <module name="MemberName"> + <!--<module name="MemberName"> <property name="applyToPublic" value="false" /> <property name="applyToPackage" value="false" /> <property name="applyToProtected" value="false" /> <property name="format" value="^m[A-Z][a-z0-9][a-zA-Z0-9]*$"/> <message key="name.invalidPattern" value="Member name ''{0}'' must match pattern ''{1}''."/> - </module> + </module>--> - <module name="ParameterName"> +<!-- <module name="ParameterName"> <property name="format" value="^[a-z][a-zA-Z0-9]*$"/> <message key="name.invalidPattern" value="Parameter name ''{0}'' must match pattern ''{1}''."/> - </module> + </module>--> - <module name="LocalVariableName"> + <!--<module name="LocalVariableName"> <property name="tokens" value="VARIABLE_DEF"/> <property name="format" value="^[a-z][a-zA-Z0-9]*$"/> <property name="allowOneCharVarInForLoop" value="true"/> <message key="name.invalidPattern" value="Local variable name ''{0}'' must match pattern ''{1}''."/> - </module> + </module>--> <module name="ClassTypeParameterName"> <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
