Factored out PCRUD code to be used by search results and checked out activity.
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"
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";
* @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;
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) {
* @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.
*
* @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 });
* @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,
return true;
return false;
-
}
/**
import java.util.Date;
import org.evergreen_ils.globals.GlobalConfigs;
+import org.evergreen_ils.searchCatalog.SearchFormat;
import org.opensrf.util.OSRFObject;
/**
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;
Date currentDate = new Date(System.currentTimeMillis());
return getDueDateObject().compareTo(currentDate) < 0;
}
+
+ public String getFormatLabel() {
+ if (format != null) {
+ return SearchFormat.getLabelFromSearchFormat(format);
+ }
+ return "";
+ }
}
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;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
+import org.w3c.dom.Text;
public class ItemsCheckOutListView extends ActionBarActivity {
SplashActivity.restartApp(this);
return;
}
+ SearchFormat.init(this);
setContentView(R.layout.checkout_list);
private TextView recordTitle;
private TextView recordAuthor;
+ private TextView recordFormat;
private TextView recordDueDate;
private TextView recordIsOverdue;
private TextView renewButton;
// 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);
// 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() + "\""
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;
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";
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(
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,
SplashActivity.restartApp(this);
return;
}
+ SearchFormat.init(this);
setContentView(R.layout.search_result_list);
}
- 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);
});
} else
- Toast.makeText(context, "No bookbags", Toast.LENGTH_SHORT)
- .show();
+ Toast.makeText(context, "No bookbags", Toast.LENGTH_SHORT).show();
}
break;
}
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
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 {
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();