Indicate item format in Checked Out activity.
authorkenstir <kenstir@gmail.com>
Mon, 19 Oct 2015 02:43:47 +0000 (22:43 -0400)
committerkenstir <kenstir@gmail.com>
Mon, 19 Oct 2015 02:43:47 +0000 (22:43 -0400)
Factored out PCRUD code to be used by search results and checked out activity.

Open-ILS/src/Android/core/res/layout/checkout_list_item.xml
Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/AccountAccess.java
Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/checkout/CircRecord.java
Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/checkout/ItemsCheckOutListView.java
Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalog.java
Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalogListView.java
Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchFormat.java

index 516957d..003539a 100644 (file)
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"/>
 
+        <TextView
+                android:id="@+id/checkout_record_format"
+                style="@style/AuthorSearchStyleList"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"/>
+
         <LinearLayout
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
index c16e578..309778f 100644 (file)
@@ -54,6 +54,9 @@ public class AccountAccess {
     public static String METHOD_AUTH_COMPLETE = "open-ils.auth.authenticate.complete";
     public static String METHOD_AUTH_SESSION_RETRV = "open-ils.auth.session.retrieve";
 
+    public static String PCRUD_SERVICE = "open-ils.pcrud";
+    public static String PCRUD_METHOD_RETRIEVE_MRA = "open-ils.pcrud.retrieve.mra";
+
     public static String SERVICE_ACTOR = "open-ils.actor";
     public static String SERVICE_CIRC = "open-ils.circ";
     public static String SERVICE_SEARCH = "open-ils.search";
@@ -436,8 +439,7 @@ public class AccountAccess {
      * @param circRecord the circ record
      * @return the oSRF object
      */
-    private OSRFObject fetchInfoForCheckedOutItem(Integer target_copy,
-            CircRecord circRecord) {
+    private OSRFObject fetchInfoForCheckedOutItem(Integer target_copy, CircRecord circRecord) {
 
         if (target_copy == null)
             return null;
@@ -449,6 +451,8 @@ public class AccountAccess {
         result = info_mvr;
         OSRFObject info_acp = null;
 
+        circRecord.format = fetchFormat(info_mvr.getInt("doc_id"));
+
         // the logic to establish mvr or acp is copied from the opac
         if (info_mvr.getString("title") == null
                 || info_mvr.getString("author") == null) {
@@ -471,14 +475,44 @@ public class AccountAccess {
      * @return the oSRF object
      */
     private OSRFObject fetchModsFromCopy(Integer target_copy) {
-
-        // sync request
         OSRFObject mvr = (OSRFObject) Utils.doRequest(conn, SERVICE_SEARCH,
                 METHOD_FETCH_MODS_FROM_COPY, new Object[] { target_copy });
 
         return mvr;
     }
 
+    public String fetchFormat(int id) {
+        return fetchFormat(Integer.valueOf(id).toString());
+    }
+
+    public String fetchFormat(String id) {
+        OSRFObject resp = (OSRFObject) Utils.doRequestSimple(conn, PCRUD_SERVICE,
+                PCRUD_METHOD_RETRIEVE_MRA, new Object[] { "ANONYMOUS", id });
+
+        // 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.
+        // '"biog"=>"b", "conf"=>"0", "search_format"=>"ebook"'.
+        String attrs = resp.getString("attrs");
+        Log.d(TAG, "attrs="+attrs);
+        String[] attr_arr = TextUtils.split(attrs, ", ");
+        String icon_format = "";
+        String search_format = "";
+        for (int i=0; i<attr_arr.length; ++i) {
+            String[] kv = TextUtils.split(attr_arr[i], "=>");
+            String key = kv[0].replace("\"", "");
+            if (key.equalsIgnoreCase("icon_format")) {
+                icon_format = kv[1].replace("\"", "");
+            } else if (key.equalsIgnoreCase("search_format")) {
+                search_format = kv[1].replace("\"", "");
+            }
+        }
+        if (!icon_format.isEmpty()) {
+            return icon_format;
+        } else {
+            return search_format;
+        }
+    }
+
     /**
      * Fetch asset copy.
      *
@@ -486,7 +520,6 @@ public class AccountAccess {
      * @return the oSRF object
      */
     private OSRFObject fetchAssetCopy(Integer target_copy) {
-
         OSRFObject acp = (OSRFObject) Utils.doRequest(conn, SERVICE_SEARCH,
                 METHOD_FETCH_COPY, new Object[] { target_copy });
 
@@ -802,7 +835,6 @@ public class AccountAccess {
      * @throws SessionNotFoundException the session not found exception
      */
     public boolean cancelHold(OSRFObject hold) throws SessionNotFoundException {
-
         Integer hold_id = hold.getInt("id");
 
         Object response = Utils.doRequest(conn, SERVICE_CIRC,
@@ -814,7 +846,6 @@ public class AccountAccess {
             return true;
 
         return false;
-
     }
 
     /**
index b232ef5..d071b04 100644 (file)
@@ -24,6 +24,7 @@ import java.text.SimpleDateFormat;
 import java.util.Date;
 
 import org.evergreen_ils.globals.GlobalConfigs;
+import org.evergreen_ils.searchCatalog.SearchFormat;
 import org.opensrf.util.OSRFObject;
 
 /**
@@ -39,10 +40,9 @@ public class CircRecord {
     public static final int UNDEF_OBJ_TYPE = 0;
 
     public OSRFObject mvr = null;
-
     public OSRFObject acp = null;
-
     public OSRFObject circ = null;
+    public String format = null;
 
     public int circ_info_type = UNDEF_OBJ_TYPE;
 
@@ -138,4 +138,11 @@ public class CircRecord {
         Date currentDate = new Date(System.currentTimeMillis());
         return getDueDateObject().compareTo(currentDate) < 0;
     }
+
+    public String getFormatLabel() {
+        if (format != null) {
+            return SearchFormat.getLabelFromSearchFormat(format);
+        }
+        return "";
+    }
 }
index 0ebc04c..533d8b6 100644 (file)
@@ -30,6 +30,7 @@ import org.evergreen_ils.accountAccess.AccountAccess;
 import org.evergreen_ils.accountAccess.MaxRenewalsException;
 import org.evergreen_ils.accountAccess.ServerErrorMessage;
 import org.evergreen_ils.accountAccess.SessionNotFoundException;
+import org.evergreen_ils.searchCatalog.SearchFormat;
 import org.evergreen_ils.views.splashscreen.SplashActivity;
 
 import android.app.ProgressDialog;
@@ -44,6 +45,7 @@ import android.widget.ArrayAdapter;
 import android.widget.ListView;
 import android.widget.TextView;
 import android.widget.Toast;
+import org.w3c.dom.Text;
 
 public class ItemsCheckOutListView extends ActionBarActivity {
 
@@ -74,6 +76,7 @@ public class ItemsCheckOutListView extends ActionBarActivity {
             SplashActivity.restartApp(this);
             return;
         }
+        SearchFormat.init(this);
 
         setContentView(R.layout.checkout_list);
 
@@ -157,6 +160,7 @@ public class ItemsCheckOutListView extends ActionBarActivity {
 
         private TextView recordTitle;
         private TextView recordAuthor;
+        private TextView recordFormat;
         private TextView recordDueDate;
         private TextView recordIsOverdue;
         private TextView renewButton;
@@ -194,6 +198,7 @@ public class ItemsCheckOutListView extends ActionBarActivity {
             // Get references to views
             recordTitle = (TextView) row.findViewById(R.id.checkout_record_title);
             recordAuthor = (TextView) row.findViewById(R.id.checkout_record_author);
+            recordFormat = (TextView) row.findViewById(R.id.checkout_record_format);
             recordDueDate = (TextView) row.findViewById(R.id.checkout_record_due_date);
             recordIsOverdue = (TextView) row.findViewById(R.id.checkout_record_overdue);
             renewButton = (TextView) row.findViewById(R.id.renew_button);
@@ -298,6 +303,7 @@ public class ItemsCheckOutListView extends ActionBarActivity {
             // set text
             recordTitle.setText(record.getTitle());
             recordAuthor.setText(record.getAuthor());
+            recordFormat.setText(record.getFormatLabel());
             recordDueDate.setText(getString(R.string.due) + " " + record.getDueDate());
             recordIsOverdue.setText(record.isOverdue() ? getString(R.string.overdue) : "");
             Log.d(TAG, "title: \"" + record.getTitle() + "\""
index d44834f..d4cc928 100644 (file)
@@ -26,6 +26,7 @@ import java.util.List;
 import java.util.Map;
 
 import android.text.TextUtils;
+import org.evergreen_ils.accountAccess.AccountAccess;
 import org.evergreen_ils.globals.GlobalConfigs;
 import org.evergreen_ils.globals.Utils;
 import org.opensrf.Method;
@@ -44,8 +45,6 @@ import android.util.Log;
 public class SearchCatalog {
 
     public static String SERVICE = "open-ils.search";
-    public static String PCRUD_SERVICE = "open-ils.pcrud";
-    public static String PCRUD_METHOD_RETRIEVE_MRA = "open-ils.pcrud.retrieve.mra";
     public static String METHOD_MULTICLASS_QUERY = "open-ils.search.biblio.multiclass.query";
     public static String METHOD_SLIM_RETRIVE = "open-ils.search.biblio.record.mods_slim.retrieve";
 
@@ -220,7 +219,8 @@ public class SearchCatalog {
             RecordInfo record = new RecordInfo(getItemShortInfo(record_id));
             resultsRecordInfo.add(record);
 
-            record.search_format = getFormat(record_id);
+            AccountAccess ac = AccountAccess.getAccountAccess();
+            record.search_format = ac.fetchFormat(record_id.toString());
 
             record.copyCountListInfo = getCopyCount(record_id, this.selectedOrganization.id);
             List<List<Object>> list = (List<List<Object>>) getLocationCount(
@@ -255,34 +255,6 @@ public class SearchCatalog {
         return response;
     }
 
-    private String getFormat(Integer id) {
-        OSRFObject resp = (OSRFObject) Utils.doRequestSimple(conn, PCRUD_SERVICE,
-                PCRUD_METHOD_RETRIEVE_MRA, new Object[] { "ANONYMOUS", id });
-
-        // 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.
-        // '"biog"=>"b", "conf"=>"0", "search_format"=>"ebook"'.
-        String attrs = resp.getString("attrs");
-        Log.d(TAG, "attrs="+attrs);
-        String[] attr_arr = TextUtils.split(attrs, ", ");
-        String icon_format = "";
-        String search_format = "";
-        for (int i=0; i<attr_arr.length; ++i) {
-            String[] kv = TextUtils.split(attr_arr[i], "=>");
-            String key = kv[0].replace("\"", "");
-            if (key.equalsIgnoreCase("icon_format")) {
-                icon_format = kv[1].replace("\"", "");
-            } else if (key.equalsIgnoreCase("search_format")) {
-                search_format = kv[1].replace("\"", "");
-            }
-        }
-        if (!icon_format.isEmpty()) {
-            return icon_format;
-        } else {
-            return search_format;
-        }
-    }
-
     public Object getCopyStatuses() {
 
         List<OSRFObject> ccs_list = (List<OSRFObject>) Utils.doRequestSimple(conn, SERVICE,
index 37bb5b7..9815a87 100644 (file)
@@ -130,6 +130,7 @@ public class SearchCatalogListView extends ActionBarActivity {
             SplashActivity.restartApp(this);
             return;
         }
+        SearchFormat.init(this);
 
         setContentView(R.layout.search_result_list);
 
@@ -459,26 +460,8 @@ public class SearchCatalogListView extends ActionBarActivity {
 
     }
 
-    private String loadJSONFromResource(int r) {
-        String json = "";
-        InputStream is = getResources().openRawResource(R.raw.search_formats);
-        int size = 0;
-        try {
-            size = is.available();
-            byte[] buf = new byte[size];
-            is.read(buf);
-            is.close();
-            json = new String(buf, "UTF-8");
-        } catch (IOException e) {
-            Log.d(TAG, "caught", e);
-        }
-        return json;
-    }
-
     // unpack the json map to populate our spinner, and allow translation from search_format keyword <=> label
     private void initSearchFormatSpinner() {
-        String formats_json = loadJSONFromResource(R.raw.search_formats);
-        SearchFormat.initFromJSON(formats_json);
         List<String> labels = SearchFormat.getSpinnerLabels();
         //ArrayAdapter<String> adapter = CompatSpinnerAdapter.CreateCompatSpinnerAdapter(this, labels);
         //ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, labels);
@@ -613,8 +596,7 @@ public class SearchCatalogListView extends ActionBarActivity {
 
                 });
             } else
-                Toast.makeText(context, "No bookbags", Toast.LENGTH_SHORT)
-                        .show();
+                Toast.makeText(context, "No bookbags", Toast.LENGTH_SHORT).show();
         }
             break;
         }
@@ -708,17 +690,12 @@ public class SearchCatalogListView extends ActionBarActivity {
             RecordInfo record = getItem(position);
 
             // if it is the right type of view
-            if (row == null
-                || row.findViewById(R.id.search_record_title) == null) {
-
-                Log.d(tag, "Starting XML Row Inflation ... ");
+            if (row == null || row.findViewById(R.id.search_record_title) == null) {
                 LayoutInflater inflater = (LayoutInflater) this
                         .getContext().getSystemService(
                                 Context.LAYOUT_INFLATER_SERVICE);
                 row = inflater.inflate(R.layout.search_result_item, parent,
                         false);
-                Log.d(tag, "Successfully completed XML Row Inflation!");
-
             }
 
             // Get reference to ImageView
index 0e8b407..312eaea 100644 (file)
@@ -1,14 +1,21 @@
 package org.evergreen_ils.searchCatalog;
 
+import android.content.Context;
 import android.util.Log;
+import org.evergreen_ils.R;
 import org.opensrf.util.JSONException;
 import org.opensrf.util.JSONReader;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
 /**
+ * Support translation between search_format strings ("book"), display labels as seen in the search format spinner
+ * ("All Books"), and display labels as shown on an item detail page ("Book").
+ *
  * Created by kenstir on 10/17/2015.
  */
 public class SearchFormat {
@@ -22,8 +29,31 @@ public class SearchFormat {
 
     private final static String TAG = SearchFormat.class.getSimpleName();
 
+    static boolean initialized = false;
     static List<SearchFormatItem> searchFormats = new ArrayList<SearchFormatItem>();
 
+    public static void init(Context context) {
+        if (initialized) return;
+        String formats_json = loadJSONFromResource(context, R.raw.search_formats);
+        SearchFormat.initFromJSON(formats_json);
+    }
+
+    private static String loadJSONFromResource(Context context, int r) {
+        String json = "";
+        InputStream is = context.getResources().openRawResource(r);
+        int size = 0;
+        try {
+            size = is.available();
+            byte[] buf = new byte[size];
+            is.read(buf);
+            is.close();
+            json = new String(buf, "UTF-8");
+        } catch (IOException e) {
+            Log.d(TAG, "caught", e);
+        }
+        return json;
+    }
+
     public static void initFromJSON(String formats_json) {
         searchFormats.clear();