import org.evergreen_ils.accountAccess.checkout.CircRecord;
import org.evergreen_ils.accountAccess.fines.FinesRecord;
import org.evergreen_ils.accountAccess.holds.HoldRecord;
+import org.evergreen_ils.globals.GlobalConfigs;
import org.evergreen_ils.globals.Utils;
import org.evergreen_ils.searchCatalog.RecordInfo;
import org.evergreen_ils.auth.Const;
import org.opensrf.net.http.HttpConnection;
import org.opensrf.util.OSRFObject;
-import android.net.ConnectivityManager;
-
/**
* The Class AuthenticateUser. Singleton class
*/
/** The book bags. */
private ArrayList<BookBag> bookBags = new ArrayList<BookBag>();
- /** The conn. */
- public HttpConnection conn;
-
- /** The http address. */
- private String httpAddress = "http://ulysses.calvin.edu";
-
/** The TAG. */
private final String TAG = AccountAccess.class.getSimpleName();
* */
private String authToken = null;
- /** The cm. */
- private ConnectivityManager cm = null;
-
- /** The auth time. */
- private Integer authTime = null;
-
/** The user id. */
private Integer userID = null;
/**
* Instantiates a new authenticate user.
- *
- * @param httpAddress the http address
*/
- private AccountAccess(String httpAddress) {
-
- Log.d(TAG, "AccountAccess ctor: " + httpAddress);
- this.httpAddress = httpAddress;
-
- try {
- // configure the connection
- Log.d(TAG, "Connection with " + httpAddress);
- conn = new HttpConnection(httpAddress + "/osrf-gateway-v1");
-
- } catch (Exception e) {
- Log.d(TAG, "Exception in establishing connection", e);
- }
-
+ private AccountAccess() {
}
/**
* Gets the account access.
*
- * @param httpAddress the http address
* @return the account access
*/
- public static AccountAccess getAccountAccess(String httpAddress) {
+ public static AccountAccess getAccountAccess() {
if (accountAccess == null) {
- accountAccess = new AccountAccess(httpAddress);
+ accountAccess = new AccountAccess();
}
- if (!httpAddress.equals(accountAccess.httpAddress))
- accountAccess.updateHttpAddress(httpAddress);
-
- return accountAccess;
- }
-
- // the object must be initialized before
- /**
- * Gets the account access.
- *
- * @return the account access
- */
- public static AccountAccess getAccountAccess() {
return accountAccess;
}
this.homeLibraryID = homeLibraryID;
}
- /*
- * Change the Http conn to a new library address
- */
- /**
- * Update http address.
- *
- * @param httpAddress the http address
- */
- public void updateHttpAddress(String httpAddress) {
- Log.d(TAG, "update http address of account access to "
- + httpAddress);
- try {
- // configure the connection
- this.httpAddress = httpAddress;
- Log.d(TAG, "Connection with " + httpAddress);
- conn = new HttpConnection(httpAddress + "/osrf-gateway-v1");
-
- } catch (Exception e) {
- System.err.println("Exception in establishing connection "
- + e.getMessage());
- }
- }
-
/**
* Md5.
*
return "";
}
+ private HttpConnection conn() {
+ return GlobalConfigs.gatewayConnection();
+ }
+
/**
* Retrieve session.
* @throws SessionNotFoundException
this.haveSession = false;
this.authToken = auth_token;
- Object resp = Utils.doRequest(conn, SERVICE_AUTH,
+ Object resp = Utils.doRequest(conn(), SERVICE_AUTH,
METHOD_AUTH_SESSION_RETRV, authToken, new Object[] {
authToken});
if (resp != null) {
return retrieveSession(new_authToken, true);
}
+ public static String getLibraryUrl(Activity activity, String account_name, String account_type) {
+ final AccountManager am = AccountManager.get(activity);
+ Account account = new Account(account_name, account_type);
+ String library_url = am.getUserData(account, Const.KEY_LIBRARY_URL);
+
+ // compatibility with specific apps like cwmars_app. If no library_url exists as userdata on the account,
+ // get it from the resources.
+ if (TextUtils.isEmpty(library_url)) {
+ library_url = activity.getString(R.string.ou_library_url);
+ if (!TextUtils.isEmpty(library_url)) {
+ am.setUserData(account, Const.KEY_LIBRARY_URL, library_url);
+ }
+ }
+
+ return library_url;
+ }
+
+// 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
// -------------------------//
ArrayList<CircRecord> circRecords = new ArrayList<CircRecord>();
- Object resp = Utils.doRequest(conn, SERVICE_ACTOR,
+ Object resp = Utils.doRequest(conn(), SERVICE_ACTOR,
METHOD_FETCH_CHECKED_OUT_SUM, authToken, new Object[] {
authToken, userID });
if (resp == null)
private OSRFObject retrieveCircRecord(String id)
throws SessionNotFoundException {
- OSRFObject circ = (OSRFObject) Utils.doRequest(conn, SERVICE_CIRC,
+ OSRFObject circ = (OSRFObject) Utils.doRequest(conn(), SERVICE_CIRC,
METHOD_FETCH_CIRC_BY_ID, authToken, new Object[] {
authToken, id });
return circ;
* @return the oSRF object
*/
private OSRFObject fetchModsFromCopy(Integer target_copy) {
- OSRFObject mvr = (OSRFObject) Utils.doRequest(conn, SERVICE_SEARCH,
+ OSRFObject mvr = (OSRFObject) Utils.doRequest(conn(), SERVICE_SEARCH,
METHOD_FETCH_MODS_FROM_COPY, new Object[] { target_copy });
return mvr;
if (id.equals("-1"))
return "";
- OSRFObject resp = (OSRFObject) Utils.doRequestSimple(conn, PCRUD_SERVICE,
+ 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
* @return the oSRF object
*/
private OSRFObject fetchAssetCopy(Integer target_copy) {
- OSRFObject acp = (OSRFObject) Utils.doRequest(conn, SERVICE_SEARCH,
+ OSRFObject acp = (OSRFObject) Utils.doRequest(conn(), SERVICE_SEARCH,
METHOD_FETCH_COPY, new Object[] { target_copy });
return acp;
complexParam.put("copyid", target_copy);
complexParam.put("opac_renewal", 1);
- Object a_lot = (Object) Utils.doRequest(conn, SERVICE_CIRC,
+ Object a_lot = (Object) Utils.doRequest(conn(), SERVICE_CIRC,
METHOD_RENEW_CIRC, authToken, new Object[] {
authToken, complexParam });
public Object 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 });
+ OSRFObject response = (OSRFObject) Utils.doRequest(conn(), SERVICE_ACTOR,
+ METHOD_FETCH_ORG_SETTINGS, new Object[] {
+ org_id, setting });
return response;
}
// fields of interest : expire_time
List<OSRFObject> listHoldsAhr = null;
- Object resp = Utils.doRequest(conn, SERVICE_CIRC,
+ Object resp = Utils.doRequest(conn(), SERVICE_CIRC,
METHOD_FETCH_HOLDS, authToken, new Object[] {
authToken, userID });
if (resp == null) {
method = METHOD_FETCH_MRMODS;
else //(holdType.equals("T"))
method = METHOD_FETCH_RMODS;
- holdInfo = (OSRFObject) Utils.doRequest(conn, SERVICE_SEARCH,
+ holdInfo = (OSRFObject) Utils.doRequest(conn(), SERVICE_SEARCH,
method, new Object[] {
target });
if (call_number != null) {
- OSRFObject volume = (OSRFObject) Utils.doRequest(conn, SERVICE_SEARCH,
+ OSRFObject volume = (OSRFObject) Utils.doRequest(conn(), SERVICE_SEARCH,
METHOD_FETCH_VOLUME, new Object[] {
copyObject.getInt("call_number") });
// in volume object : record
holdObj.part_label = volume.getString("label");
Log.d(TAG, "Record " + record);
- OSRFObject holdInfo = (OSRFObject) Utils.doRequest(conn,
+ OSRFObject holdInfo = (OSRFObject) Utils.doRequest(conn(),
SERVICE_SEARCH, METHOD_FETCH_RMODS,
new Object[] { record });
// must test
// fetch_volume
- OSRFObject volume = (OSRFObject) Utils.doRequest(conn,
+ OSRFObject volume = (OSRFObject) Utils.doRequest(conn(),
SERVICE_SEARCH, METHOD_FETCH_VOLUME,
new Object[] { hold.getInt("target") });
// in volume object : record
holdObj.part_label = volume.getString("label");
Log.d(TAG, "Record " + record);
- OSRFObject holdInfo = (OSRFObject) Utils.doRequest(conn,
+ OSRFObject holdInfo = (OSRFObject) Utils.doRequest(conn(),
SERVICE_SEARCH, METHOD_FETCH_RMODS,
new Object[] { record });
holdObj.author = holdInfo.getString("author");
holdObj.recordInfo = new RecordInfo((OSRFObject) holdInfo);
} else if (type.equals("I")) {
- OSRFObject issuance = (OSRFObject) Utils.doRequest(conn,
+ OSRFObject issuance = (OSRFObject) Utils.doRequest(conn(),
SERVICE_SERIAL, METHOD_FETCH_ISSUANCE,
new Object[] { hold.getInt("target") });
// TODO
// returns [{record:id, label=part label}]
- List<Object> part = (List<Object>) Utils.doRequest(conn,
+ List<Object> part = (List<Object>) Utils.doRequest(conn(),
SERVICE_FIELDER, "open-ils.fielder.bmp.atomic",
new Object[] { param });
Integer recordID = (Integer) partObj.get("record");
String part_label = (String) partObj.get("label");
- OSRFObject holdInfo = (OSRFObject) Utils.doRequest(conn,
+ OSRFObject holdInfo = (OSRFObject) Utils.doRequest(conn(),
SERVICE_SEARCH, METHOD_FETCH_RMODS,
new Object[] { recordID });
Integer hold_id = hold.getInt("id");
// MAP : potential_copies, status, total_holds, queue_position,
// estimated_wait
- Object resp = Utils.doRequest(conn, SERVICE_CIRC,
+ Object resp = Utils.doRequest(conn(), SERVICE_CIRC,
METHOD_FETCH_HOLD_STATUS, authToken, new Object[] {
authToken, hold_id });
public boolean cancelHold(OSRFObject hold) throws SessionNotFoundException {
Integer hold_id = hold.getInt("id");
- Object response = Utils.doRequest(conn, SERVICE_CIRC,
+ Object response = Utils.doRequest(conn(), SERVICE_CIRC,
METHOD_CANCEL_HOLD, authToken, new Object[] {
authToken, hold_id });
// only if it is frozen
ahr.put("thaw_date", thaw_date);
- Object response = Utils.doRequest(conn, SERVICE_CIRC,
+ Object response = Utils.doRequest(conn(), SERVICE_CIRC,
METHOD_UPDATE_HOLD, authToken, new Object[] {
authToken, ahr });
// extra parameters (not mandatory for hold creation)
- Object response = Utils.doRequest(conn, SERVICE_CIRC,
+ Object response = Utils.doRequest(conn(), SERVICE_CIRC,
METHOD_CREATE_HOLD, authToken, new Object[] {
authToken, ahr });
// {"titleid":63,"mrid":60,"volume_id":null,"issuanceid":null,"copy_id":null,"hold_type":"T","holdable_formats":null,
// "patronid":2,"depth":0,"pickup_lib":"8","partid":null}
- Object response = Utils.doRequest(conn, SERVICE_CIRC,
+ Object response = Utils.doRequest(conn(), SERVICE_CIRC,
METHOD_VERIFY_HOLD_POSSIBLE, authToken, new Object[] {
authToken, mapAsk });
param.put("pickup_lib", pickup_lib);
param.put("record", recordID);
- Map<String, ?> response = (Map<String, ?>) Utils.doRequest(conn,
+ Map<String, ?> response = (Map<String, ?>) Utils.doRequest(conn(),
SERVICE_SEARCH,
"open-ils.search.metabib.record_to_descriptors",
new Object[] { param });
public float[] getFinesSummary() throws SessionNotFoundException {
// mous object
- OSRFObject finesSummary = (OSRFObject) Utils.doRequest(conn, SERVICE_ACTOR,
+ OSRFObject finesSummary = (OSRFObject) Utils.doRequest(conn(), SERVICE_ACTOR,
METHOD_FETCH_FINES_SUMMARY, authToken, new Object[] {
authToken, userID });
ArrayList<FinesRecord> finesRecords = new ArrayList<FinesRecord>();
- Object transactions = Utils.doRequest(conn, SERVICE_ACTOR,
+ Object transactions = Utils.doRequest(conn(), SERVICE_ACTOR,
METHOD_FETCH_TRANSACTIONS, authToken, new Object[] {
authToken, userID });
*/
public boolean retrieveBookbags() throws SessionNotFoundException {
- Object response = Utils.doRequest(conn, SERVICE_ACTOR,
+ Object response = Utils.doRequest(conn(), SERVICE_ACTOR,
METHOD_FLESH_CONTAINERS, authToken, new Object[] {
authToken, userID, "biblio", "bookbag" });
private Object getBookbagContent(BookBag bag, Integer bookbagID)
throws SessionNotFoundException {
- Map<String, ?> map = (Map<String, ?>) Utils.doRequest(conn, SERVICE_ACTOR,
+ Map<String, ?> map = (Map<String, ?>) Utils.doRequest(conn(), SERVICE_ACTOR,
METHOD_FLESH_PUBLIC_CONTAINER, authToken, new Object[] {
authToken, "biblio", bookbagID });
*/
public void deleteBookBag(Integer id) throws SessionNotFoundException {
- Object response = Utils.doRequest(conn, SERVICE_ACTOR,
+ Object response = Utils.doRequest(conn(), SERVICE_ACTOR,
METHOD_CONTAINER_FULL_DELETE, authToken, new Object[] {
authToken, "biblio", id });
}
cbrebi.put("target_biblio_record_entry", record_id);
cbrebi.put("id", null);
- Object response = Utils.doRequest(conn, SERVICE_ACTOR,
+ Object response = Utils.doRequest(conn(), SERVICE_ACTOR,
METHOD_CONTAINER_ITEM_CREATE, authToken, new Object[] {
authToken, "biblio", cbrebi });
}
private void removeContainer(String container, Integer id)
throws SessionNotFoundException {
- Object response = Utils.doRequest(conn, SERVICE_ACTOR,
+ Object response = Utils.doRequest(conn(), SERVICE_ACTOR,
METHOD_CONTAINER_DELETE, authToken, new Object[] {
authToken, container, id });
}
private void createContainer(String container, Object parameter)
throws SessionNotFoundException {
- Object response = Utils.doRequest(conn, SERVICE_ACTOR,
+ Object response = Utils.doRequest(conn(), SERVICE_ACTOR,
METHOD_CONTAINER_CREATE, authToken, new Object[] {
authToken, container, parameter });
}
bookBag = (BookBag) getIntent().getSerializableExtra("bookBag");
context = this;
- search = SearchCatalog.getInstance((ConnectivityManager) getSystemService(Service.CONNECTIVITY_SERVICE));
+ search = SearchCatalog.getInstance();
bookbag_name = (TextView) findViewById(R.id.bookbag_name);
delete_bookbag_button = (Button) findViewById(R.id.remove_bookbag);
bookbag_name.setText(bookBag.name);
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
+import org.evergreen_ils.searchCatalog.Library;
+import org.w3c.dom.Text;
public class AccountAuthenticator extends AbstractAccountAuthenticator {
}
final AccountManager am = AccountManager.get(context);
+ String library_url = am.getUserData(account, Const.KEY_LIBRARY_URL);
+ Log.d(TAG, "getAuthToken> library_url=" + library_url);
+// if (TextUtils.isEmpty(library_url)) {
+// }
+
String authToken = am.peekAuthToken(account, authTokenType);
Log.d(TAG, "getAuthToken> peekAuthToken returned " + authToken);
if (TextUtils.isEmpty(authToken)) {
if (password != null) {
try {
Log.d(TAG, "getAuthToken> attempting to sign in with existing password");
- authToken = EvergreenAuthenticator.signIn(context, account.name, password);
+ authToken = EvergreenAuthenticator.signIn(library_url, account.name, password);
Log.d(TAG, "getAuthToken> signIn returned token "+authToken);
} catch (AuthenticationException e) {
- Log.d(TAG, "getAuthToken> caught exception", e);
- Log.d(TAG, "getAuthToken> caught exception "+e.getMessage());
+ Log.d(TAG, "getAuthToken> caught auth exception", e);
final Bundle result = new Bundle();
result.putString(AccountManager.KEY_ERROR_MESSAGE, e.getMessage());
return result;
} catch (Exception e2) {
- Log.d(TAG, "getAuthToken> caught other Exception");
+ Log.d(TAG, "getAuthToken> caught exception", e2);
final Bundle result = new Bundle();
result.putString(AccountManager.KEY_ERROR_MESSAGE, "Sign in failed");
return result;
result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type);
result.putString(AccountManager.KEY_AUTHTOKEN, authToken);
+ result.putString(Const.KEY_LIBRARY_URL, library_url);
return result;
}
package org.evergreen_ils.auth;
import android.content.Context;
-import android.preference.PreferenceManager;
+import android.content.pm.ApplicationInfo;
import android.text.TextUtils;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import org.evergreen_ils.R;
-import org.evergreen_ils.auth.Const;
import android.accounts.Account;
import android.accounts.AccountAuthenticatorActivity;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.AsyncTask;
-import android.os.Build;
import android.os.Bundle;
import android.util.Log;
-import android.view.ContextThemeWrapper;
import android.view.View;
import android.widget.TextView;
import org.evergreen_ils.globals.AppPrefs;
-import org.evergreen_ils.globals.GlobalConfigs;
import org.evergreen_ils.globals.Utils;
import org.evergreen_ils.searchCatalog.Library;
import org.opensrf.util.JSONException;
public final static String ARG_ACCOUNT_NAME = "ACCOUNT_NAME";
//public final static String ARG_IS_ADDING_NEW_ACCOUNT = "IS_ADDING_ACCOUNT";
public static final String KEY_ERROR_MESSAGE = "ERR_MSG";
- public static final String KEY_LIBRARY_URL = "library_url";
public final static String PARAM_USER_PASS = "USER_PASS";
private final int REQ_SIGNUP = 1;
private static final String STATE_ALERT_MESSAGE = "state_dialog";
final String accountType = AuthenticatorActivity.this.getString(R.string.ou_account_type);
Bundle data = new Bundle();
try {
- authtoken = EvergreenAuthenticator.signIn(AuthenticatorActivity.this, username, password);
+ authtoken = EvergreenAuthenticator.signIn(selected_library.url, username, password);
Log.d(TAG, "task> signIn returned "+authtoken);
data.putString(AccountManager.KEY_ACCOUNT_NAME, username);
data.putString(AccountManager.KEY_ACCOUNT_TYPE, accountType);
data.putString(AccountManager.KEY_AUTHTOKEN, authtoken);
data.putString(PARAM_USER_PASS, password);
+ data.putString(Const.KEY_LIBRARY_URL, selected_library.url);
} catch (AuthenticationException e) {
if (e != null) errorMessage = e.getMessage();
Log.d(TAG, "task> signIn caught auth exception "+errorMessage);
String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
String accountType = intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE);
String accountPassword = intent.getStringExtra(PARAM_USER_PASS);
+ String library_url = intent.getStringExtra(Const.KEY_LIBRARY_URL);
final Account account = new Account(accountName, accountType);
Log.d(TAG, "onAuthSuccess> accountName="+accountName);
// Create the account on the device
Bundle userdata = null;
- if (selected_library != null) {
+ if (!TextUtils.isEmpty(library_url)) {
userdata = new Bundle();
- userdata.putString(KEY_LIBRARY_URL, selected_library.url);
+ userdata.putString(Const.KEY_LIBRARY_URL, library_url);
}
if (accountManager.addAccountExplicitly(account, accountPassword, userdata)) {
Log.d(TAG, "onAuthSuccess> true, setAuthToken "+authtoken);
private void parseLibrariesJSON(String json) {
libraries.clear();
+ boolean isDebuggable = ( 0 != ( getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE ) );
+ if (isDebuggable) {
+ Library library = new Library("https://demo.evergreencatalog.com", "Example Consortium", "00 (Example Consortium)");
+ libraries.add(library);
+ }
+
if (json != null) {
List<Map<String,?>> l;
try {
//public static final String ACCOUNT_TYPE = "org.evergreen_ils";
public static final String AUTHTOKEN_TYPE = "opac";
public static final String AUTHTOKEN_TYPE_LABEL = "Online Public Access Catalog";
+ public static final String KEY_LIBRARY_URL = "library_url";
}
}
@SuppressWarnings("unchecked")
- public static String signIn(Context context, String username, String password) throws AuthenticationException {
+ public static String signIn(String library_url, String username, String password) throws AuthenticationException {
Log.d(TAG, "signIn> "+username);
HttpConnection conn;
try {
- conn = new HttpConnection(AppPrefs.getString(AppPrefs.LIBRARY_URL) + "/osrf-gateway-v1");
+ conn = new HttpConnection(library_url + "/osrf-gateway-v1");
} catch (MalformedURLException e) {
throw new AuthenticationException(e);
}
Log.d(TAG, "authtoken: " + authtoken);
Integer authtime = ((Map<String, Integer>) payload).get("authtime");
Log.d(TAG, "authtime: " + authtime);
- AppPrefs.setBoolean(AppPrefs.EVER_LOGGED_IN, true);
return authtoken;
} else if (textcode.equals("LOGIN_FAILED")) {
String desc = ((Map<String, String>) resp).get("desc");
String name[] = new String[availableAccounts.length];
for (int i = 0; i < availableAccounts.length; i++) {
name[i] = availableAccounts[i].name;
+ String library_url = mAccountManager.getUserData(availableAccounts[i], Const.KEY_LIBRARY_URL);
+ Log.d(TAG, "name:"+name[i]+" url:"+library_url);
}
// Account picker
Log.d("kcxxx","getExistingAccountAuthToken account.name "+account.name+" account_name "+account_name+" token "+authtoken);
showMessage((authtoken != null) ? "SUCCESS with "+account_name+"\ntoken: " + authtoken : "FAIL");
Log.d(TAG, "GetToken Bundle is " + bnd);
- mLastTextView.setText(account.name);
+ //mLastTextView.setText(account.name);//todo: wrong thread here
} catch (Exception e) {
e.printStackTrace();
showMessage(e.getMessage());
bnd = future.getResult();
final String authtoken = bnd.getString(AccountManager.KEY_AUTHTOKEN);
final String account_name = bnd.getString(AccountManager.KEY_ACCOUNT_NAME);
- showMessage((authtoken != null) ? "SUCCESS with "+account_name+"\ntoken: " + authtoken : "FAIL");
+ final String library_url = bnd.getString(Const.KEY_LIBRARY_URL);
+ showMessage((authtoken != null) ? "SUCCESS with "+account_name+"\nlibrary_url: " + library_url: "FAIL");
Log.d(TAG, "GetTokenForAccount Bundle is " + bnd);
mLastTextView.setText(account_name);
} catch (Exception e) {
* Created by kenstir on 11/8/2015.
*/
public class AppPrefs {
- public static final String EVER_LOGGED_IN = "ever_logged_in";
public static final String LIBRARY_URL = "library_url";
public static final String LIBRARY_NAME = "library_name";
private static final String VERSION = "version";
SharedPreferences.Editor editor = prefs.edit();
version = PREFS_VERSION;
editor.putInt(VERSION, PREFS_VERSION);
- editor.putBoolean(EVER_LOGGED_IN, false);
editor.putString(LIBRARY_URL, context.getString(R.string.ou_library_url));
editor.putString(LIBRARY_NAME, context.getString(R.string.ou_library_name));
editor.commit();
import android.content.Context;
import android.net.ConnectivityManager;
+import android.text.TextUtils;
import android.util.Log;
-import org.evergreen_ils.accountAccess.AccountAccess;
-import org.evergreen_ils.accountAccess.SessionNotFoundException;
import org.evergreen_ils.searchCatalog.Organisation;
import org.evergreen_ils.searchCatalog.SearchCatalog;
import org.open_ils.idl.IDLParser;
+import org.opensrf.net.http.HttpConnection;
import org.opensrf.util.JSONException;
import org.opensrf.util.JSONReader;
import java.io.InputStream;
+import java.net.MalformedURLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
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_ASSETS = "fm_IDL.xml";
public static String httpAddress = "";
+ private static HttpConnection conn;
private boolean init = false;
private static String TAG = "GlobalConfigs";
- private static boolean debugMode = true;//KCXXX make a developer preference
+ private static boolean debugMode = true;//todo get from boolean isDebuggable = ( 0 != ( getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE ) );
public static boolean loadedIDL = false;
private boolean initialize(Context context) {
if (!init) {
loadIDLFile(context);
- getOrganisations();
- getCopyStatusesAvailable((ConnectivityManager) context
- .getSystemService(Context.CONNECTIVITY_SERVICE));
+ loadOrganizations();
+ loadCopyStatusesAvailable();
init = true;
return true;
}
return debugMode;
}
- public static void setDebugMode(boolean debugMode) {
- GlobalConfigs.debugMode = debugMode;
+ public static HttpConnection gatewayConnection() {
+ if (conn == null && !TextUtils.isEmpty(httpAddress)) {
+ try {
+ conn = new HttpConnection(httpAddress + "/osrf-gateway-v1");
+ } catch (MalformedURLException e) {
+ Log.d(TAG, "unable to open connection", e);
+ }
+ }
+ return conn;
}
public void loadIDLFile(Context context) {
/**
* Fetch the OrgTree.js file, and from it parse the list of organisations.
*/
- public void getOrganisations() {
+ public void loadOrganizations() {
String orgFile = null;
}
}
- public void getCopyStatusesAvailable(ConnectivityManager cm) {
+ public void loadCopyStatusesAvailable() {
- SearchCatalog search = SearchCatalog.getInstance(cm);
+ SearchCatalog search = SearchCatalog.getInstance();
try {
search.getCopyStatuses();
}
}
- 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) {
- }
-
- }
-
- }
-
public static String getStringDate(Date date) {
final SimpleDateFormat sdf = new SimpleDateFormat(
+++ /dev/null
-/*
- * Copyright (C) 2012 Evergreen Open-ILS
- * @author Daniel-Octavian Rizea
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * or the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be usefull,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- *
- */
-package org.evergreen_ils.globals;
-
-import android.app.AlertDialog;
-import android.content.Context;
-import android.content.DialogInterface;
-
-public class ShowServerNotAvailableRunnable implements Runnable {
-
- private Context context;
-
- public ShowServerNotAvailableRunnable(Context context) {
- this.context = context;
- }
-
- @Override
- public void run() {
- AlertDialog alertDialog = new AlertDialog.Builder(context).create();
- alertDialog.setTitle("Error");
- alertDialog.setMessage("There is no network connectivity to "
- + GlobalConfigs.httpAddress);
- alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
-
- @Override
- public void onClick(DialogInterface dialog, int id) {
- dialog.dismiss();
- }
- });
-
- alertDialog.show();
- }
-
-}
\ No newline at end of file
actionBar.setSubtitle(AccountAccess.userName);
actionBar.setDisplayHomeAsUpEnabled(true);
- search = SearchCatalog.getInstance((ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE));
+ search = SearchCatalog.getInstance();
records = (ArrayList<RecordInfo>) getIntent().getSerializableExtra("recordList");
public static SearchCatalog searchCatalogSingleton = null;
- public HttpConnection conn;
-
- public String TAG = "SearchCatalog";
+ public String TAG = SearchCatalog.class.getSimpleName();
// the org on witch the searches will be made
/** The selected organization. */
public String searchClass = null;
public String searchFormat = null;
- public static SearchCatalog getInstance(ConnectivityManager cm) {
-
+ public static SearchCatalog getInstance() {
if (searchCatalogSingleton == null) {
- searchCatalogSingleton = new SearchCatalog(cm);
+ searchCatalogSingleton = new SearchCatalog();
}
-
- return searchCatalogSingleton;
- }
-
- public static SearchCatalog getInstance() {
-
return searchCatalogSingleton;
}
/**
* Instantiates a new search catalog.
*/
- private SearchCatalog(ConnectivityManager cm) {
- super();
-
- try {
- // configure the connection
- conn = new HttpConnection(AppPrefs.getString(AppPrefs.LIBRARY_URL) + "/osrf-gateway-v1");
+ private SearchCatalog() {
+ }
- } catch (Exception e) {
- Log.d(TAG, "error", e);
- }
+ private HttpConnection conn() {
+ return GlobalConfigs.gatewayConnection();
}
/**
queryString += " search_format(" + searchFormat + ")";
// do request and check for connectivity
- Object resp = Utils.doRequest(conn, SERVICE, METHOD_MULTICLASS_QUERY,
+ Object resp = Utils.doRequest(conn(), SERVICE, METHOD_MULTICLASS_QUERY,
new Object[] { complexParm, queryString, 1 });
ArrayList<String> ids = new ArrayList<String>();
* @return the item short info
*/
private OSRFObject getItemShortInfo(Integer id) {
- OSRFObject response = (OSRFObject) Utils.doRequestSimple(conn, SERVICE,
+ OSRFObject response = (OSRFObject) Utils.doRequestSimple(conn(), SERVICE,
METHOD_SLIM_RETRIVE, new Object[] {
id });
return response;
public Object getCopyStatuses() {
- List<OSRFObject> ccs_list = (List<OSRFObject>) Utils.doRequestSimple(conn, SERVICE,
+ List<OSRFObject> ccs_list = (List<OSRFObject>) Utils.doRequestSimple(conn(), SERVICE,
METHOD_COPY_STATUS_ALL, new Object[] {});
CopyInformation.availableOrgStatuses = new LinkedHashMap<String, String>();
public Object getLocationCount(Integer recordID, Integer orgID,
Integer orgDepth) {
- List<?> list = (List<?>) Utils.doRequestSimple(conn, SERVICE,
+ List<?> list = (List<?>) Utils.doRequestSimple(conn(), SERVICE,
METHOD_COPY_LOCATION_COUNTS, new Object[] {
recordID, orgID, orgDepth });
return list;
public ArrayList<CopyCountInformation> getCopyCount(Integer recordID,
Integer orgID) {
- List<?> list = (List<?>) Utils.doRequestSimple(conn, SERVICE,
+ List<?> list = (List<?>) Utils.doRequestSimple(conn(), SERVICE,
METHOD_GET_COPY_COUNT, new Object[] { orgID, recordID, "" });
ArrayList<CopyCountInformation> copyInfoList = new ArrayList<CopyCountInformation>();
globalConfigs = GlobalConfigs.getGlobalConfigs(this);
context = this;
- search = SearchCatalog.getInstance((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE));
+ search = SearchCatalog.getInstance();
recordList = new ArrayList<RecordInfo>();
+++ /dev/null
-/*
- * Copyright (C) 2012 Evergreen Open-ILS
- * @author Daniel-Octavian Rizea
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * or the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be usefull,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- *
- */
-package org.evergreen_ils.views;
-
-import java.util.Calendar;
-
-import org.evergreen_ils.R;
-import org.evergreen_ils.services.NotificationAlert;
-import org.evergreen_ils.services.PeriodicServiceBroadcastReceiver;
-import org.evergreen_ils.services.ScheduledIntentService;
-
-import android.app.AlarmManager;
-import android.app.PendingIntent;
-import android.app.ProgressDialog;
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
-import android.os.Bundle;
-import android.preference.PreferenceActivity;
-import android.preference.PreferenceManager;
-import android.widget.Toast;
-
-public class UnusedPreferenceActivity extends PreferenceActivity implements
- OnSharedPreferenceChangeListener {
-
- private final String TAG = UnusedPreferenceActivity.class.getSimpleName();
-
- private ProgressDialog progressDialog;
-
- private UnusedPreferenceActivity reference;
-
- private Context context;
-
- private Thread coreFilesDownload = null;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
-
- super.onCreate(savedInstanceState);
-
- addPreferencesFromResource(R.xml.preferences);
-
- context = this;
- reference = this;
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
- prefs.registerOnSharedPreferenceChangeListener(this);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- reference = this;
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- reference = null;
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- reference = null;
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- reference = null;
- }
-
- @Override
- public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
- String key) {
-
- boolean httpAddressChange = false;
-
- boolean checkConnection = false;
-
- if (key.equals("notifications_enabled")) {
-
- if (sharedPreferences.getBoolean("notifications_enabled", false)) {
-
- Toast.makeText(context, "Set up notification updates",
- Toast.LENGTH_SHORT).show();
- // if enabled register the update service to run once per day
- // get a Calendar object with current time
- Calendar cal = Calendar.getInstance();
-
- Intent bRecvIntent = new Intent(this,
- PeriodicServiceBroadcastReceiver.class);
- bRecvIntent.setAction(ScheduledIntentService.ACTION);
- // update the current intent if it exists
- PendingIntent sender = PendingIntent.getBroadcast(this,
- NotificationAlert.NOTIFICATION_INTENT
- + PeriodicServiceBroadcastReceiver.INTENT_ID,
- bRecvIntent, PendingIntent.FLAG_UPDATE_CURRENT);
-
- // Get the AlarmManager service
- AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
- am.setRepeating(AlarmManager.RTC, cal.getTimeInMillis(),
- 10000 * ScheduledIntentService.SCHEDULE_TIME_INTERVAL,
- sender);
- } else {
- Toast.makeText(context, "Disable notification updates",
- Toast.LENGTH_SHORT).show();
- // cancel the service
-
- Intent bRecvIntent = new Intent(this,
- PeriodicServiceBroadcastReceiver.class);
-
- // update the current intent if it exists
- PendingIntent sender = PendingIntent.getBroadcast(this,
- NotificationAlert.NOTIFICATION_INTENT
- + PeriodicServiceBroadcastReceiver.INTENT_ID,
- bRecvIntent, PendingIntent.FLAG_UPDATE_CURRENT);
-
- // Get the AlarmManager service
- AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
- // cancel the service
- am.cancel(sender);
- }
- }
- }
-
-}
*/
package org.evergreen_ils.views.splashscreen;
+import android.text.TextUtils;
import org.evergreen_ils.R;
import org.evergreen_ils.accountAccess.AccountAccess;
import org.evergreen_ils.accountAccess.SessionNotFoundException;
+import org.evergreen_ils.globals.AppPrefs;
import org.evergreen_ils.globals.GlobalConfigs;
import org.evergreen_ils.auth.Const;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
+import org.w3c.dom.Text;
/** 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
AccountManagerFuture<Bundle> future = mAccountManager.getAuthTokenByFeatures(accountType, Const.AUTHTOKEN_TYPE, null, mCallingActivity, null, null, null, null);
Bundle bnd = future.getResult();
- Log.d(TAG, tag+"bnd="+bnd);
String auth_token = bnd.getString(AccountManager.KEY_AUTHTOKEN);
String account_name = bnd.getString(AccountManager.KEY_ACCOUNT_NAME);
- Log.d(TAG, tag+"account_name="+account_name+" token="+auth_token);
if (account_name == null)
return "no account";
+ String library_url = AccountAccess.getLibraryUrl(mCallingActivity, account_name, accountType);
+ AppPrefs.setString(AppPrefs.LIBRARY_URL, library_url);
+ GlobalConfigs.httpAddress = library_url;
+
Log.d(TAG, tag+"Loading resources");
publishProgress("Loading resources");
- GlobalConfigs.getGlobalConfigs(mCallingActivity); // loads IDL
+ GlobalConfigs.getGlobalConfigs(mCallingActivity);
Log.d(TAG, tag+"Starting session");
publishProgress("Starting session");
- AccountAccess ac = AccountAccess.getAccountAccess(GlobalConfigs.httpAddress);
+ AccountAccess ac = AccountAccess.getAccountAccess();
// auth token zen: try once and if it fails, invalidate the token and try again
boolean haveSession = false;
retry = true;
}
if (retry) {
+ // todo: replace with AccountAccess.reauthenticate?
final Account account = new Account(account_name, accountType);
future = mAccountManager.getAuthToken(account, Const.AUTHTOKEN_TYPE, null, mCallingActivity, null, null);
bnd = future.getResult();
Log.d(TAG, tag+"account_name="+account_name+" token="+auth_token);
if (account_name == null)
return "no account";
- haveSession = ac.retrieveSession(auth_token, true);
+ try {
+ haveSession = ac.retrieveSession(auth_token, true);
+ } catch (SessionNotFoundException e) {
+ Log.d(TAG, tag+"failed a 2nd time", e);
+ }
}
if (!haveSession)
return "no session";
protected void onStart() {
super.onStart();
GlobalConfigs.httpAddress = AppPrefs.getString(AppPrefs.LIBRARY_URL);// kenstir todo: replace all refs to GlobalConfigs.httpAddress
- boolean ever_logged_in = AppPrefs.getBoolean(AppPrefs.EVER_LOGGED_IN);
- Log.d(TAG, "kcxxx: onstart: url=" + GlobalConfigs.httpAddress + " ever_logged_in=" + ever_logged_in);
+ Log.d(TAG, "kcxxx: onstart: url=" + GlobalConfigs.httpAddress);
if (!restarted) {
startTask();
}
<activity android:name="org.evergreen_ils.views.MainActivity">
</activity>
+ <activity android:name="org.evergreen_ils.auth.TestAuthActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ </intent-filter>
+ </activity>
+
<service
android:name="org.evergreen_ils.auth.AuthenticatorService"
android:exported="false" >