From: kenstir Date: Tue, 17 Nov 2015 01:32:48 +0000 (-0500) Subject: Refactoring X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b1871e66276486eea3c99a1c691eae48cdc177c1;p=working%2FEvergreen.git Refactoring * http address and http connection for osrf moved to GlobalConfigs * dead code cleanup --- diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/AccountAccess.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/AccountAccess.java index 7f2319c183..61dfa22277 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/AccountAccess.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/AccountAccess.java @@ -36,14 +36,13 @@ import org.evergreen_ils.accountAccess.bookbags.BookBagItem; 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 */ @@ -143,12 +142,6 @@ public class AccountAccess { /** The book bags. */ private ArrayList bookBags = new ArrayList(); - /** The conn. */ - public HttpConnection conn; - - /** The http address. */ - private String httpAddress = "http://ulysses.calvin.edu"; - /** The TAG. */ private final String TAG = AccountAccess.class.getSimpleName(); @@ -157,12 +150,6 @@ public class AccountAccess { * */ private String authToken = null; - /** The cm. */ - private ConnectivityManager cm = null; - - /** The auth time. */ - private Integer authTime = null; - /** The user id. */ private Integer userID = null; @@ -181,49 +168,20 @@ public class AccountAccess { /** * 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; } @@ -235,29 +193,6 @@ public class 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. * @@ -293,6 +228,10 @@ public class AccountAccess { return ""; } + private HttpConnection conn() { + return GlobalConfigs.gatewayConnection(); + } + /** * Retrieve session. * @throws SessionNotFoundException @@ -304,7 +243,7 @@ public class AccountAccess { 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) { @@ -344,6 +283,39 @@ public class AccountAccess { 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 // -------------------------// @@ -358,7 +330,7 @@ public class AccountAccess { ArrayList circRecords = new ArrayList(); - 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) @@ -420,7 +392,7 @@ public class AccountAccess { 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; @@ -475,7 +447,7 @@ public class AccountAccess { * @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; @@ -490,7 +462,7 @@ public class AccountAccess { 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 @@ -524,7 +496,7 @@ public class AccountAccess { * @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; @@ -550,7 +522,7 @@ public class AccountAccess { 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 }); @@ -578,9 +550,9 @@ public class AccountAccess { 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; } @@ -598,7 +570,7 @@ public class AccountAccess { // fields of interest : expire_time List 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) { @@ -643,7 +615,7 @@ public class AccountAccess { 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 }); @@ -684,7 +656,7 @@ public class AccountAccess { 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 @@ -694,7 +666,7 @@ public class AccountAccess { 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 }); @@ -708,7 +680,7 @@ public class AccountAccess { // 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 @@ -720,7 +692,7 @@ public class AccountAccess { 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 }); @@ -728,7 +700,7 @@ public class AccountAccess { 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 @@ -750,7 +722,7 @@ public class AccountAccess { // returns [{record:id, label=part label}] - List part = (List) Utils.doRequest(conn, + List part = (List) Utils.doRequest(conn(), SERVICE_FIELDER, "open-ils.fielder.bmp.atomic", new Object[] { param }); @@ -759,7 +731,7 @@ public class AccountAccess { 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 }); @@ -785,7 +757,7 @@ public class AccountAccess { 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 }); @@ -807,7 +779,7 @@ public class AccountAccess { 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 }); @@ -841,7 +813,7 @@ public class AccountAccess { // 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 }); @@ -886,7 +858,7 @@ public class AccountAccess { // 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 }); @@ -941,7 +913,7 @@ public class AccountAccess { // {"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 }); @@ -964,7 +936,7 @@ public class AccountAccess { param.put("pickup_lib", pickup_lib); param.put("record", recordID); - Map response = (Map) Utils.doRequest(conn, + Map response = (Map) Utils.doRequest(conn(), SERVICE_SEARCH, "open-ils.search.metabib.record_to_descriptors", new Object[] { param }); @@ -998,7 +970,7 @@ public class AccountAccess { 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 }); @@ -1025,7 +997,7 @@ public class AccountAccess { ArrayList finesRecords = new ArrayList(); - Object transactions = Utils.doRequest(conn, SERVICE_ACTOR, + Object transactions = Utils.doRequest(conn(), SERVICE_ACTOR, METHOD_FETCH_TRANSACTIONS, authToken, new Object[] { authToken, userID }); @@ -1056,7 +1028,7 @@ public class AccountAccess { */ 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" }); @@ -1094,7 +1066,7 @@ public class AccountAccess { private Object getBookbagContent(BookBag bag, Integer bookbagID) throws SessionNotFoundException { - Map map = (Map) Utils.doRequest(conn, SERVICE_ACTOR, + Map map = (Map) Utils.doRequest(conn(), SERVICE_ACTOR, METHOD_FLESH_PUBLIC_CONTAINER, authToken, new Object[] { authToken, "biblio", bookbagID }); @@ -1152,7 +1124,7 @@ public class AccountAccess { */ 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 }); } @@ -1172,7 +1144,7 @@ public class AccountAccess { 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 }); } @@ -1187,7 +1159,7 @@ public class AccountAccess { 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 }); } @@ -1202,7 +1174,7 @@ public class AccountAccess { 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 }); } diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/bookbags/BookBagDetails.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/bookbags/BookBagDetails.java index fda5e0dc67..4e357e00e8 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/bookbags/BookBagDetails.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/bookbags/BookBagDetails.java @@ -102,7 +102,7 @@ public class BookBagDetails extends ActionBarActivity { 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); diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/AccountAuthenticator.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/AccountAuthenticator.java index 818408090b..7318165f05 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/AccountAuthenticator.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/AccountAuthenticator.java @@ -10,6 +10,8 @@ import android.content.Intent; 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 { @@ -48,6 +50,11 @@ 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)) { @@ -55,16 +62,15 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator { 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; @@ -79,6 +85,7 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator { 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; } diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/AuthenticatorActivity.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/AuthenticatorActivity.java index 90f98ef814..6400fa2ece 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/AuthenticatorActivity.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/AuthenticatorActivity.java @@ -1,13 +1,12 @@ 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; @@ -17,14 +16,11 @@ import android.content.DialogInterface; 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; @@ -41,7 +37,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity { 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"; @@ -190,13 +185,14 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity { 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); @@ -251,6 +247,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity { 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); @@ -261,9 +258,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity { // 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); @@ -288,6 +285,12 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity { 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> l; try { diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/Const.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/Const.java index e6f0aed24d..78e48625df 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/Const.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/Const.java @@ -4,4 +4,5 @@ public class Const { //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"; } diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/EvergreenAuthenticator.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/EvergreenAuthenticator.java index ddbb22c13d..4009f8dd87 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/EvergreenAuthenticator.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/EvergreenAuthenticator.java @@ -72,12 +72,12 @@ public class EvergreenAuthenticator { } @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); } @@ -107,7 +107,6 @@ public class EvergreenAuthenticator { Log.d(TAG, "authtoken: " + authtoken); Integer authtime = ((Map) 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) resp).get("desc"); diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/TestAuthActivity.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/TestAuthActivity.java index 70326fc180..cfb2df7518 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/TestAuthActivity.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/auth/TestAuthActivity.java @@ -146,6 +146,8 @@ public class TestAuthActivity extends Activity { 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 @@ -190,7 +192,7 @@ public class TestAuthActivity extends Activity { 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()); @@ -254,7 +256,8 @@ public class TestAuthActivity extends Activity { 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) { diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/globals/AppPrefs.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/globals/AppPrefs.java index fa28a7f38c..1112c27cc2 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/globals/AppPrefs.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/globals/AppPrefs.java @@ -11,7 +11,6 @@ import org.evergreen_ils.accountAccess.bookbags.BookBag; * 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"; @@ -35,7 +34,6 @@ public class AppPrefs { 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(); diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/globals/GlobalConfigs.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/globals/GlobalConfigs.java index a43a691469..5de1189432 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/globals/GlobalConfigs.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/globals/GlobalConfigs.java @@ -21,16 +21,17 @@ package org.evergreen_ils.globals; 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.*; @@ -40,12 +41,13 @@ 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_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; @@ -91,9 +93,8 @@ public class GlobalConfigs { private boolean initialize(Context context) { if (!init) { loadIDLFile(context); - getOrganisations(); - getCopyStatusesAvailable((ConnectivityManager) context - .getSystemService(Context.CONNECTIVITY_SERVICE)); + loadOrganizations(); + loadCopyStatusesAvailable(); init = true; return true; } @@ -104,8 +105,15 @@ public class GlobalConfigs { 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) { @@ -138,7 +146,7 @@ public class GlobalConfigs { /** * Fetch the OrgTree.js file, and from it parse the list of organisations. */ - public void getOrganisations() { + public void loadOrganizations() { String orgFile = null; @@ -212,9 +220,9 @@ public class GlobalConfigs { } } - public void getCopyStatusesAvailable(ConnectivityManager cm) { + public void loadCopyStatusesAvailable() { - SearchCatalog search = SearchCatalog.getInstance(cm); + SearchCatalog search = SearchCatalog.getInstance(); try { search.getCopyStatuses(); @@ -224,22 +232,6 @@ public class GlobalConfigs { } } - 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( diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/globals/ShowServerNotAvailableRunnable.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/globals/ShowServerNotAvailableRunnable.java deleted file mode 100644 index 53b42d7ba5..0000000000 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/globals/ShowServerNotAvailableRunnable.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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 diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SampleUnderlinesNoFade.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SampleUnderlinesNoFade.java index a228e8dfcb..c81e005b0d 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SampleUnderlinesNoFade.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SampleUnderlinesNoFade.java @@ -77,7 +77,7 @@ public class SampleUnderlinesNoFade extends BaseSampleActivity { actionBar.setSubtitle(AccountAccess.userName); actionBar.setDisplayHomeAsUpEnabled(true); - search = SearchCatalog.getInstance((ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE)); + search = SearchCatalog.getInstance(); records = (ArrayList) getIntent().getSerializableExtra("recordList"); diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalog.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalog.java index 53fcd8a77a..cc36da724d 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalog.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalog.java @@ -92,9 +92,7 @@ public class SearchCatalog { 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. */ @@ -110,33 +108,21 @@ public class SearchCatalog { 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(); } /** @@ -181,7 +167,7 @@ public class SearchCatalog { 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 ids = new ArrayList(); @@ -245,7 +231,7 @@ public class SearchCatalog { * @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; @@ -253,7 +239,7 @@ public class SearchCatalog { public Object getCopyStatuses() { - List ccs_list = (List) Utils.doRequestSimple(conn, SERVICE, + List ccs_list = (List) Utils.doRequestSimple(conn(), SERVICE, METHOD_COPY_STATUS_ALL, new Object[] {}); CopyInformation.availableOrgStatuses = new LinkedHashMap(); @@ -275,7 +261,7 @@ public class SearchCatalog { 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; @@ -311,7 +297,7 @@ public class SearchCatalog { public ArrayList 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 copyInfoList = new ArrayList(); diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalogListView.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalogListView.java index 47403c2f5d..7f3d590325 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalogListView.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalogListView.java @@ -145,7 +145,7 @@ public class SearchCatalogListView extends ActionBarActivity { globalConfigs = GlobalConfigs.getGlobalConfigs(this); context = this; - search = SearchCatalog.getInstance((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE)); + search = SearchCatalog.getInstance(); recordList = new ArrayList(); diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/views/UnusedPreferenceActivity.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/views/UnusedPreferenceActivity.java deleted file mode 100644 index 0ec67c689a..0000000000 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/views/UnusedPreferenceActivity.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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); - } - } - } - -} diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/views/splashscreen/LoadingTask.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/views/splashscreen/LoadingTask.java index c728ba82b1..b73301f0ae 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/views/splashscreen/LoadingTask.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/views/splashscreen/LoadingTask.java @@ -19,9 +19,11 @@ */ 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; @@ -31,6 +33,7 @@ import android.accounts.AccountManagerFuture; 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, except that it uses * a Thread. Starting with HONEYCOMB, tasks are executed on a single thread and the 2nd @@ -99,20 +102,22 @@ public class LoadingTask { AccountManagerFuture 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; @@ -124,6 +129,7 @@ public class LoadingTask { 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(); @@ -133,7 +139,11 @@ public class LoadingTask { 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"; diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/views/splashscreen/SplashActivity.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/views/splashscreen/SplashActivity.java index ec96bf62f7..926b445ad2 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/views/splashscreen/SplashActivity.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/views/splashscreen/SplashActivity.java @@ -112,8 +112,7 @@ public class SplashActivity extends Activity implements LoadingTaskListener { 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(); } diff --git a/Open-ILS/src/Android/eg_app/AndroidManifest.xml b/Open-ILS/src/Android/eg_app/AndroidManifest.xml index 6f45453403..7e49885c3c 100644 --- a/Open-ILS/src/Android/eg_app/AndroidManifest.xml +++ b/Open-ILS/src/Android/eg_app/AndroidManifest.xml @@ -115,6 +115,12 @@ + + + + + +