Fixed crashes reported by Geoff Sams
authorkenstir <kenstir@gmail.com>
Thu, 26 Nov 2015 02:41:06 +0000 (21:41 -0500)
committerkenstir <kenstir@gmail.com>
Thu, 26 Nov 2015 02:41:06 +0000 (21:41 -0500)
* pcrud on NTLC did not accept "ANONYMOUS" and required a valid auth token
* some unrelated work toward fetching the org tree via OSRF

Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/AccountAccess.java
Open-ILS/src/Android/core/src/org/evergreen_ils/globals/GlobalConfigs.java
Open-ILS/src/Android/core/src/org/evergreen_ils/globals/Utils.java
Open-ILS/src/Android/core/src/org/evergreen_ils/views/splashscreen/LoadingTask.java

index 81f0aa0..6c1353e 100644 (file)
@@ -69,6 +69,8 @@ public class AccountAccess {
     /** The METHOD_FETCH_MODS_FROM_COPY description : used to return info. @returns : mvr class OSRF Object. Fields of interest : title, author */
     public static String METHOD_FETCH_MODS_FROM_COPY = "open-ils.search.biblio.mods_from_copy";
 
+    public static String METHOD_ORG_TREE_RETRIEVE = "open-ils.actor.org_tree.retrieve";
+
     /** The METHOD_FETCH_COPY description : used to return info for a PRE_CATALOGED object. @returns : acp class OSRF Object. Fields of interest : dummy_title, dummy_author */
     public static String METHOD_FETCH_COPY = "open-ils.search.asset.copy.retrieve";
     
@@ -281,22 +283,6 @@ public class AccountAccess {
         }
     }
 
-//    public void getOrgHiddentDepth() {
-//
-//        // logic can be found in the opac_utils.js file in web/opac/common/js
-//
-//        for (int i = 0; i < organisations.size(); i++) {
-//            AccountAccess ac = AccountAccess.getAccountAccess();
-//            try {
-//                Object obj = ac.fetchOrgSettings(organisations.get(i).id,
-//                        "opac.org_unit_hiding.depth");
-//            } catch (SessionNotFoundException e) {
-//            }
-//
-//        }
-//
-//    }
-
     // ------------------------Checked Out Items Section
     // -------------------------//
 
@@ -443,8 +429,14 @@ public class AccountAccess {
         if (id.equals("-1"))
             return "";
 
-        OSRFObject resp = (OSRFObject) Utils.doRequestSimple(conn(), PCRUD_SERVICE,
-                PCRUD_METHOD_RETRIEVE_MRA, new Object[] { "ANONYMOUS", id });
+        OSRFObject resp;
+        try {
+            resp = (OSRFObject) Utils.doRequest(conn(), PCRUD_SERVICE,
+                    PCRUD_METHOD_RETRIEVE_MRA, authToken, new Object[]{
+                            authToken, id});
+        } catch (SessionNotFoundException e) {
+            return "";
+        }
 
         // This is not beautiful.  This MRA record comes back with an 'attrs' field that
         // appears to have been serialized by perl Data::Dumper, e.g.
@@ -517,9 +509,21 @@ public class AccountAccess {
 
     }
 
-    // ------------------------Holds Section
+    // ------------------------orgs Section
     // --------------------------------------//
 
+    public OSRFObject fetchOrgs() {
+        OSRFObject response = (OSRFObject) Utils.doRequest(conn(), SERVICE_ACTOR,
+                METHOD_ORG_TREE_RETRIEVE, new Object[]{});
+        try {
+            //List<OSRFObject> l = (List<OSRFObject>) response;
+            Log.d(TAG, "response="+response);
+        } catch (Exception e) {
+            Log.d(TAG, "caught exception", e);
+        }
+        return response;
+    }
+
     /**
      * Fetch org settings.
      *
@@ -528,15 +532,33 @@ public class AccountAccess {
      * @return the object
      * @throws SessionNotFoundException the session not found exception
      */
-    public Object fetchOrgSettings(Integer org_id, String setting)
-            throws SessionNotFoundException {
+//    public OSRFObject fetchOrgSettings(Integer org_id, String setting)
+//            throws SessionNotFoundException {
+//
+//        OSRFObject response = (OSRFObject) Utils.doRequest(conn(), SERVICE_ACTOR,
+//                METHOD_FETCH_ORG_SETTINGS, new Object[]{
+//                        org_id, setting});
+//        return response;
+//    }
 
-        OSRFObject response = (OSRFObject) Utils.doRequest(conn(), SERVICE_ACTOR,
-                METHOD_FETCH_ORG_SETTINGS, new Object[] {
-                        org_id, setting });
-        return response;
+//    public void getOrgHiddentDepth() {
+//
+//        // logic can be found in the opac_utils.js file in web/opac/common/js
+//
+//        for (int i = 0; i < organisations.size(); i++) {
+//            AccountAccess ac = AccountAccess.getAccountAccess();
+//            try {
+//                Object obj = ac.fetchOrgSettings(organisations.get(i).id,
+//                        "opac.org_unit_hiding.depth");
+//            } catch (SessionNotFoundException e) {
+//            }
+//
+//        }
+//
+//    }
 
-    }
+    // ------------------------Holds Section
+    // --------------------------------------//
 
     /**
      * Gets the holds.
index 43b6fa6..55fb643 100644 (file)
@@ -40,7 +40,7 @@ import java.util.*;
 
 public class GlobalConfigs {
 
-    public static String IDL_FILE_FROM_ROOT = "/reports/fm_IDL.xml?class=acn&class=acp&class=ahr&class=ahtc&class=au&class=bmp&class=cbreb&class=cbrebi&class=cbrebin&class=cbrebn&class=ccs&class=circ&class=ex&class=mbt&class=mbts&class=mous&class=mra&class=mus&class=mvr&class=perm_ex";
+    public static String IDL_FILE_FROM_ROOT = "/reports/fm_IDL.xml?class=acn&class=acp&class=ahr&class=ahtc&class=aou&class=au&class=bmp&class=cbreb&class=cbrebi&class=cbrebin&class=cbrebn&class=ccs&class=circ&class=ex&class=mbt&class=mbts&class=mous&class=mra&class=mus&class=mvr&class=perm_ex";
     public static String IDL_FILE_FROM_ASSETS = "fm_IDL.xml";
     private static String httpAddress = "";
     private static HttpConnection conn = null;
index 0e71784..5ab43cb 100644 (file)
@@ -127,6 +127,16 @@ public class Utils {
         return textcode;
     }
 
+    private static void handleNPE(NullPointerException e, String service, String methodName) {
+        // I know it's bad form to catch NPE.  But until I implement some kind of on-demand IDL parsing,
+        // this is what happens when the JSONReader tries to parse a response of an unregistered class.
+        // Crash if debugMode, fail if not.
+        Log.d(TAG, "NPE...unregistered type from service "+service+" method "+methodName, e);
+        if (GlobalConfigs.isDebugMode()) {
+            throw(e);
+        }
+    }
+
     public static Object doRequest(HttpConnection conn, String service,
                                    String methodName, String authToken,
                                    Object[] params) throws SessionNotFoundException {
@@ -146,13 +156,7 @@ public class Utils {
         try {
             resp = req.recv();
         } catch (NullPointerException e) {
-            // I know it's bad form to catch NPE.  But until I implement some kind of on-demand IDL parsing,
-            // this is what happens when the JSONReader tries to parse a response of an unregistered class.
-            // Crash if debugMode, fail if not.
-            Log.d(TAG, "NPE...unregistered type?", e);
-            if (GlobalConfigs.isDebugMode()) {
-                throw(e);
-            }
+            handleNPE(e, service, methodName);
         }
         if (resp != null) {
             Log.d(TAG, "Sync Response: " + resp);
@@ -187,12 +191,15 @@ public class Utils {
         HttpRequest req = new GatewayRequest(conn, service, method).send();
         Object resp;
 
-        while ((resp = req.recv()) != null) {
-            Log.d(TAG, "Sync Response: " + resp);
-            Object response = (Object) resp;
-
-            return response;
+        try {
+            while ((resp = req.recv()) != null) {
+                Log.d(TAG, "Sync Response: " + resp);
+                Object response = (Object) resp;
 
+                return response;
+            }
+        } catch (NullPointerException e) {
+            handleNPE(e, service, methodName);
         }
         return null;
     }
index 1e77509..3a98cfa 100644 (file)
@@ -32,6 +32,7 @@ import android.app.Activity;
 import android.os.Bundle;
 import android.util.Log;
 import org.evergreen_ils.searchCatalog.Library;
+import org.opensrf.util.OSRFObject;
 
 /** This is basically the same as an AsyncTask<String,String,String>, except that it uses
  * a Thread.  Starting with HONEYCOMB, tasks are executed on a single thread and the 2nd
@@ -108,11 +109,19 @@ public class LoadingTask {
             publishProgress("Loading resources");
             GlobalConfigs.getGlobalConfigs(mCallingActivity, library.url);
 
-            Log.d(TAG, tag+"Starting session");
-            publishProgress("Starting session");
             AccountAccess ac = AccountAccess.getAccountAccess();
 
+            /* way to fetch org tree using OSRF rather than parsing JS
+            try {
+                OSRFObject o = ac.fetchOrgs();
+            } catch (Exception e) {
+                Log.d(TAG, tag+"caught exception", e);
+            }
+            */
+
             // auth token zen: try once and if it fails, invalidate the token and try again
+            Log.d(TAG, tag+"Starting session");
+            publishProgress("Starting session");
             boolean haveSession = false;
             try {
                 haveSession = ac.retrieveSession(auth_token);