That call is taking 30% of the total search time, and it is not even necessary until you look at the item details. Made sure that the orgID is properly passed from SearchCatalog through to BasicDetailsFragment. Not working yet because my first attempt was to call getCopyCount on the main thread. End goal: volley-based OSRF response handler.
@Override
public void run() {
-
- ArrayList<RecordInfo> records = new ArrayList<RecordInfo>();
ArrayList<Integer> ids = new ArrayList<Integer>();
for (int i = 0; i < bookBag.items.size(); i++) {
ids.add(bookBag.items.get(i).target_copy);
}
- records = search.getRecordsInfo(ids);
+ ArrayList<RecordInfo> records = search.getRecordsInfo(ids);
for (int i = 0; i < bookBag.items.size(); i++) {
bookBag.items.get(i).recordInfo = records.get(i);
private final String TAG = CopyInformation.class.getName();
public Integer org_id = -1;
-
public String call_number_sufix;
-
public String copy_location;
-
public HashMap<String, String> statuses;
// the hash from the request method
statusInformation = new LinkedHashMap<String, String>();
Set<Entry<String, String>> set = availableOrgStatuses.entrySet();
-
Iterator<Entry<String, String>> it = set.iterator();
-
while (it.hasNext()) {
Entry<String, String> entry = it.next();
if (hashValCopy.containsKey(entry.getKey())) {
statusInformation.put(entry.getValue(),
hashValCopy.get(entry.getKey()) + "");
-// Log.d(TAG, "Added " + entry.getKey() + " "
-// + entry.getValue() + " "
-// + hashValCopy.get(entry.getKey()));
+// Log.d(TAG, "Added " + entry.getKey() + " -> "
+// + entry.getValue() + " ("
+// + hashValCopy.get(entry.getKey()) + ")");
}
}
+ Log.d(TAG, "done");
}
}
public String author = null;
public String pubdate = null;
public String isbn = null;
- public Integer doc_id = null;
+ public Integer doc_id = -1;
public String publisher = null;
public String subject = "";
public String doc_type = null;
public boolean dummy = false;
public ArrayList<CopyCountInformation> copyCountListInfo = null;
-
- public List<CopyInformation> copyInformationList = null;
+ public List<CopyInformation> copyInformationList = new ArrayList<CopyInformation>();
public String search_format = null;
public RecordInfo() {
this.title = "Test title";
this.author = "Test author";
this.pubdate = "Publication date";
- copyInformationList = new ArrayList<CopyInformation>();
// marks the fact that this is a record made from no info
this.dummy = true;
}
public RecordInfo(OSRFObject info) {
- copyInformationList = new ArrayList<CopyInformation>();
try {
this.title = safeString(info.getString("title"));
this.author = safeString(info.getString("author"));
import java.util.ArrayList;
-import android.support.v7.app.ActionBar;
import android.view.MenuItem;
import org.evergreen_ils.R;
-import org.evergreen_ils.accountAccess.AccountAccess;
import org.evergreen_ils.utils.ui.*;
import org.evergreen_ils.views.splashscreen.SplashActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
-import android.net.ConnectivityManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.view.KeyEvent;
-import android.widget.Button;
-import android.widget.TextView;
public class SampleUnderlinesNoFade extends BaseSampleActivity {
private ArrayList<RecordInfo> records;
-
- private Button myAccountButton;
-
- private Button homeButton;
-
- private TextView headerTitle;
-
private SearchCatalog search;
-
private ArrayList<RecordInfo> searchRecords;
-
private Context context;
-
private ProgressDialog progressDialog;
-
private Runnable searchRunnableWithOffset;
public static final int RETURN_DATA = 5;
-
+ private Integer orgID = -1;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
search = SearchCatalog.getInstance();
+ orgID = getIntent().getIntExtra("orgID", -1);
records = (ArrayList<RecordInfo>) getIntent().getSerializableExtra("recordList");
if (records.get(records.size() - 1).dummy == true)
int record_position = getIntent().getIntExtra("recordPosition", 0);
mAdapter = new SearchFragmentAdapter(getSupportFragmentManager());
-
mPager = (ViewPager) findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
-
mPager.setCurrentItem(record_position);
UnderlinePageIndicator indicator = (UnderlinePageIndicator) findViewById(R.id.indicator);
@Override
public void run() {
- // don't clear record list
- // recordList.clear();
if (searchRecords.size() > 0) {
-
for (int j = 0; j < searchRecords.size(); j++)
records.add(searchRecords.get(j));
-
- // add extra record to display more
- // option button
-
}
mAdapter.notifyDataSetChanged();
progressDialog.dismiss();
}
});
-
}
};
getSearchResults.start();
}
return BasicDetailsFragment.newInstance(records.get(position),
- position + 1, search.visible);
-
+ position + 1, search.visible, orgID);
}
@Override
public int getCount() {
return records.size();
- // return TabsView.CONTENT.length;
}
-
}
}
\ No newline at end of file
public static SearchCatalog searchCatalogSingleton = null;
- public String TAG = SearchCatalog.class.getSimpleName();
+ public String TAG = SearchCatalog.class.getName();
// the org on which the searches will be made
public Organisation selectedOrganization = null;
private SearchCatalog() {
}
- private HttpConnection conn() {
+ private static HttpConnection conn() {
return GlobalConfigs.gatewayConnection();
}
this.searchFormat = searchFormat;
ArrayList<RecordInfo> resultsRecordInfo = new ArrayList<RecordInfo>();
- HashMap complexParm = new HashMap<String, Integer>();
- try {
- //KCXXX I'm not too sure about this depth option
- if (this.selectedOrganization != null) {
- if (this.selectedOrganization.id != null)
- complexParm.put("org_unit", this.selectedOrganization.id);
- if (this.selectedOrganization.level != null)
- complexParm.put("depth", this.selectedOrganization.level);
- }
- complexParm.put("limit", searchLimit);
- complexParm.put("offset", offset);
- if (searchClass != null) complexParm.put("default_class", searchClass);
-// complexParm.put("offset",0);
-// complexParm.put("visibility_limit", 3000);
- } catch (Exception e) {
- Log.d(TAG, "Exception in JSON " + e.getMessage());
+ HashMap complexParm = new HashMap<String, Integer>();
+ if (this.selectedOrganization != null) {
+ if (this.selectedOrganization.id != null)
+ complexParm.put("org_unit", this.selectedOrganization.id);
+ // I'm not too sure about this depth option
+ if (this.selectedOrganization.level != null)
+ complexParm.put("depth", this.selectedOrganization.level);
}
+ complexParm.put("limit", searchLimit);
+ complexParm.put("offset", offset);
+ if (searchClass != null) complexParm.put("default_class", searchClass);
String queryString = searchText;
if (!searchFormat.isEmpty())
queryString += " search_format(" + searchFormat + ")";
- // do request and check for connectivity
+ long start_ms = System.currentTimeMillis();
+ long now_ms = start_ms;
+
+ // do request
Object resp = Utils.doRequest(conn(), SERVICE, METHOD_MULTICLASS_QUERY,
new Object[] { complexParm, queryString, 1 });
-
- ArrayList<String> ids = new ArrayList<String>();
-
Log.d(TAG, "Sync Response: " + resp);
+ now_ms = logElapsedTime(TAG, now_ms, "search");
if (resp == null)
return resultsRecordInfo; // search failed or server crashed
Map<String, ?> response = (Map<String, ?>) resp;
- Log.d(TAG, " ids : " + response.get("ids") + " ");
-
List<List<String>> result_ids;
result_ids = (List<List<String>>) response.get("ids");
Log.d(TAG, "length:"+result_ids.size());
// sometimes count is an int ("count":0) and sometimes string ("count":"1103")
visible = Integer.parseInt(response.get("count").toString());
+ ArrayList<String> ids = new ArrayList<String>();
for (int i = 0; i < result_ids.size(); i++) {
ids.add(result_ids.get(i).get(0));
}
Integer record_id = Integer.parseInt(ids.get(i));
RecordInfo record = new RecordInfo(getItemShortInfo(record_id));
+ now_ms = logElapsedTime(TAG, now_ms, "search.getItemShortInfo");
resultsRecordInfo.add(record);
AccountAccess ac = AccountAccess.getAccountAccess();
record.search_format = ac.fetchFormat(record_id.toString());
+ now_ms = logElapsedTime(TAG, now_ms, "search.fetchFormat");
+ // todo This takes 30% of the total search time but is not required for SearchCatalogListView
+ // it is needed only for BasicDetailsFragment, but that would cause it to be run on the main thread
+ // and that fails, so continue to do it here for now
record.copyCountListInfo = getCopyCount(record_id, this.selectedOrganization.id);
List<List<Object>> list = (List<List<Object>>) getLocationCount(
record_id, this.selectedOrganization.id,
this.selectedOrganization.level);
+ now_ms = logElapsedTime(TAG, now_ms, "search.getLocationCount");
if (list != null)
for (int j = 0; j < list.size(); j++) {
CopyInformation copyInfo = new CopyInformation(list.get(j));
+ " Pubdate:" + record.pubdate
+ " Publisher:" + record.publisher);
}
+ logElapsedTime(TAG, start_ms, "search.total");
return resultsRecordInfo;
}
+ public long logElapsedTime(String tag, long start_ms, String s) {
+ long now_ms = System.currentTimeMillis();
+ Log.d(tag, s + ": " + (now_ms - start_ms) + "ms");
+ return now_ms;
+ }
+
/**
* Gets the item short info.
*
METHOD_COPY_LOCATION_COUNTS, new Object[] {
recordID, orgID, orgDepth });
return list;
-
}
public ArrayList<RecordInfo> getRecordsInfo(ArrayList<Integer> ids) {
this.selectedOrganization = org;
}
- public ArrayList<CopyCountInformation> getCopyCount(Integer recordID,
+ public static ArrayList<CopyCountInformation> getCopyCount(Integer recordID,
Integer orgID) {
List<?> list = (List<?>) Utils.doRequestSimple(conn(), SERVICE,
return copyInfoList;
}
+
+ // should be punted to volley
+ public static void ensureCopyCount(RecordInfo record, Integer org_id) {
+ if (record.copyCountListInfo == null) {
+ record.copyCountListInfo = getCopyCount(record.doc_id, org_id);
+ }
+ }
}
private final String TAG = BasicDetailsFragment.class.getName();
private RecordInfo record;
+ private Integer orgId;
private Integer position;
private Integer total;
private TextView copyCountTextView;
private Button placeHoldButton;
-
private Button addToBookbagButton;
private LinearLayout showMore;
- private SearchCatalog search = null;
-
private GlobalConfigs globalConfigs;
private ProgressDialog progressDialog;
private int list_size = 3;
public static BasicDetailsFragment newInstance(RecordInfo record,
- Integer position, Integer total) {
+ Integer position, Integer total, Integer orgID) {
BasicDetailsFragment fragment = new BasicDetailsFragment();
- fragment.setDetails(record, position, total);
+ fragment.orgId = orgID;
+ fragment.record = record;
+ fragment.position = position;
+ fragment.total = total;
return fragment;
}
- private void setDetails(RecordInfo record, Integer position,
- Integer total) {
-
- this.record = record;
- this.position = position;
- this.total = total;
- }
-
public BasicDetailsFragment() {
-
- search = SearchCatalog.getInstance();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
- record = (RecordInfo) savedInstanceState
- .getSerializable("recordInfo");
+ record = (RecordInfo) savedInstanceState.getSerializable("recordInfo");
+ orgId = savedInstanceState.getInt("orgId");
this.position = savedInstanceState.getInt("position");
this.total = savedInstanceState.getInt("total");
}
@Override
public void onClick(View v) {
- Intent intent = new Intent(getActivity()
- .getApplicationContext(), PlaceHold.class);
+ Intent intent = new Intent(getActivity().getApplicationContext(), PlaceHold.class);
intent.putExtra("recordInfo", record);
startActivity(intent);
}
isbnTextView.setText(record.isbn);
- int current_org = 0;
- if (search != null)
- current_org = search.selectedOrganization.id;
+ // todo this is not working because we are on the main thread
+ //SearchCatalog.ensureCopyCount(record, orgId);
Log.d(TAG, "Size " + record.copyCountListInfo.size());
-
for (int i = 0; i < record.copyCountListInfo.size(); i++) {
- Log.d(TAG, current_org + " "
- + record.copyCountListInfo.get(i).org_id + " "
- + record.copyCountListInfo.get(i).count);
- if (record.copyCountListInfo.get(i).org_id == current_org) {
+// Log.d(TAG, orgId + " "
+// + record.copyCountListInfo.get(i).org_id + " "
+// + record.copyCountListInfo.get(i).count);
+ if (record.copyCountListInfo.get(i).org_id == orgId) {
int total = record.copyCountListInfo.get(i).count;
int available = record.copyCountListInfo.get(i).available;
String totalCopies = getResources().getQuantityString(R.plurals.number_of_copies, total, total);
@Override
public void onClick(View v) {
// show more details
- Intent intent = new Intent(getActivity()
- .getApplicationContext(), MoreCopyInformation.class);
+ Intent intent = new Intent(getActivity().getApplicationContext(), MoreCopyInformation.class);
intent.putExtra("recordInfo", record);
+ intent.putExtra("orgId", orgId);
startActivity(intent);
}
});
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putSerializable("recordInfo", record);
+ outState.putInt("orgId", this.orgId);
outState.putInt("position", this.position);
outState.putInt("total", this.total);
super.onSaveInstanceState(outState);
if ($line =~ /GatewayRequest: ([^:]+):(.+)/) {
my($key,$val) = ($1,$2);
if ($key eq 'result') {
- my $obj = decode_json($val);
+ my $obj;
+ eval '$obj = decode_json($val);';
+ if ($@) {
+ $obj = '*** '.$val;
+ }
print "$key -> ", Dumper($obj);
} else {
print "${key}:${val}\n";
public class GatewayRequest extends HttpRequest {
private boolean readComplete;
- private String TAG = GatewayRequest.class.getSimpleName();
+ private String TAG = GatewayRequest.class.getName();
public GatewayRequest(HttpConnection conn, String service, Method method) {
super(conn, service, method);