From 76863a994049ecaf3ebd2f774e2b1419ec9196a9 Mon Sep 17 00:00:00 2001 From: kenstir Date: Mon, 16 Nov 2015 22:31:40 -0500 Subject: [PATCH] Further refactoring: do not allow globally setting httpaddr w/out reloading IDL and all that jazz. --- .../org/evergreen_ils/globals/GlobalConfigs.java | 71 ++++++++++++---------- .../searchCatalog/MoreCopyInformation.java | 10 +-- .../searchCatalog/SearchCatalogListView.java | 2 +- .../services/ScheduledIntentService.java | 2 +- .../utils/ui/BasicDetailsFragment.java | 8 +-- .../views/splashscreen/LoadingTask.java | 12 +++- .../views/splashscreen/SplashActivity.java | 3 +- 7 files changed, 57 insertions(+), 51 deletions(-) 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 5de1189432..f22a4a2674 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,6 +21,7 @@ package org.evergreen_ils.globals; import android.content.Context; import android.net.ConnectivityManager; +import android.provider.Settings; import android.text.TextUtils; import android.util.Log; import org.evergreen_ils.searchCatalog.Organisation; @@ -40,20 +41,18 @@ 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 httpAddress = ""; + private static HttpConnection conn = null; private static String TAG = "GlobalConfigs"; private static boolean debugMode = true;//todo get from boolean isDebuggable = ( 0 != ( getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE ) ); - public static boolean loadedIDL = false; + private static boolean loadedIDL = false; - public static boolean loadedOrgTree = false; + private static boolean loadedOrgTree = false; - public static String hold_icon_address = "/opac/images/tor/"; + private static String hold_icon_address = "/opac/images/tor/"; // two days notification before checkout expires, this can be modified from // preferences @@ -66,6 +65,7 @@ public class GlobalConfigs { public String locale = "en-US"; private static GlobalConfigs globalConfigSingleton = null; + /** The organisations. */ public ArrayList organisations; @@ -73,29 +73,42 @@ public class GlobalConfigs { private String collectionsRequest = "/opac/common/js/" + locale + "/OrgTree.js"; - private GlobalConfigs(Context context) { - - initialize(context); + private GlobalConfigs() { } public static GlobalConfigs getGlobalConfigs(Context context) { + Log.d(TAG, "getGlobalConfigs (url="+httpAddress+")"); + if (globalConfigSingleton == null) + globalConfigSingleton = new GlobalConfigs(); + return globalConfigSingleton; + } - if (globalConfigSingleton == null) { - globalConfigSingleton = new GlobalConfigs(context); - } + public static GlobalConfigs getGlobalConfigs(Context context, String library_url) { + Log.d(TAG, "getGlobalConfigs library_url="+library_url); + GlobalConfigs globalConfigs = getGlobalConfigs(context); + globalConfigs.initialize(library_url); + return globalConfigs; + } - return globalConfigSingleton; + public static String getUrl() { + GlobalConfigs globalConfigs = getGlobalConfigs(null); + return globalConfigs.httpAddress; + } + + public static String getUrl(String relativeUrl) { + GlobalConfigs globalConfigs = getGlobalConfigs(null); + return globalConfigs.httpAddress + relativeUrl; } /* * Initialize function that retrieves IDL file and Orgs file */ - private boolean initialize(Context context) { - if (!init) { - loadIDLFile(context); + private boolean initialize(String library_url) { + if (!TextUtils.equals(library_url, httpAddress)) { + httpAddress = library_url; + loadIDL(); loadOrganizations(); loadCopyStatusesAvailable(); - init = true; return true; } return false; @@ -116,28 +129,20 @@ public class GlobalConfigs { return conn; } - public void loadIDLFile(Context context) { + public void loadIDL() { try { - Log.d(TAG, "loadIDLFile start"); + Log.d(TAG, "loadIDL fetching " + httpAddress + IDL_FILE_FROM_ROOT); long start_ms = System.currentTimeMillis(); - InputStream in_IDL; - if (false) { - // Use IDL file from assets. Much faster than downloading it, but it risks an NPE - // if the asset version is out of sync with the site version. - in_IDL = context.getAssets().open(IDL_FILE_FROM_ASSETS); - } else { - // Download IDL file from server. Safest and slowest. - in_IDL = Utils.getNetInputStream(GlobalConfigs.httpAddress + IDL_FILE_FROM_ROOT); - } + InputStream in_IDL = Utils.getNetInputStream(GlobalConfigs.httpAddress + IDL_FILE_FROM_ROOT); IDLParser parser = new IDLParser(in_IDL); parser.setKeepIDLObjects(false); - Log.d(TAG, "loadIDLFile parse"); + Log.d(TAG, "loadIDL parse"); parser.parse(); long duration_ms = System.currentTimeMillis() - start_ms; - Log.d(TAG, "loadIDLFile parse took "+duration_ms+"ms"); + Log.d(TAG, "loadIDL parse took "+duration_ms+"ms"); } catch (Exception e) { - Log.w(TAG, "Error in parsing IDL file", e); + Log.w(TAG, "loadIDL parse error", e); } loadedIDL = true; @@ -215,7 +220,7 @@ public class GlobalConfigs { }); long duration_ms = System.currentTimeMillis() - start_ms; - Log.d("init", "Loading organisations took "+duration_ms+"ms"); + Log.d("init", "getOrg took "+duration_ms+"ms"); loadedOrgTree = true; } } diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/MoreCopyInformation.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/MoreCopyInformation.java index 4af4822319..2310fcf849 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/MoreCopyInformation.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/MoreCopyInformation.java @@ -31,16 +31,12 @@ import org.evergreen_ils.accountAccess.AccountAccess; import org.evergreen_ils.globals.GlobalConfigs; import org.evergreen_ils.views.splashscreen.SplashActivity; -import android.app.Activity; import android.content.Context; -import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; -import android.view.View.OnClickListener; import android.view.ViewGroup.LayoutParams; import android.view.ViewGroup; -import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; @@ -50,7 +46,7 @@ public class MoreCopyInformation extends ActionBarActivity { private RecordInfo record; - private GlobalConfigs gl; + private GlobalConfigs globalConfigs; @Override protected void onCreate(Bundle savedInstanceState) { @@ -67,7 +63,7 @@ public class MoreCopyInformation extends ActionBarActivity { actionBar.setSubtitle(AccountAccess.userName); actionBar.setDisplayHomeAsUpEnabled(true); - gl = GlobalConfigs.getGlobalConfigs(context); + globalConfigs = GlobalConfigs.getGlobalConfigs(context); context = this; record = (RecordInfo) getIntent().getSerializableExtra("recordInfo"); @@ -106,7 +102,7 @@ public class MoreCopyInformation extends ActionBarActivity { TextView copy_location = (TextView) copy_info_view .findViewById(R.id.copy_information_copy_location); - library.setText(gl.getOrganizationName(record.copyInformationList + library.setText(globalConfigs.getOrganizationName(record.copyInformationList .get(i).org_id) + " "); call_number .setText(record.copyInformationList.get(i).call_number_sufix); 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 7f3d590325..ba3cd8acb7 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 @@ -699,7 +699,7 @@ public class SearchCatalogListView extends ActionBarActivity { // Get reference to ImageView recordImage = (ImageView) row.findViewById(R.id.search_record_img); - String imageHref = GlobalConfigs.httpAddress + "/opac/extras/ac/jacket/small/r/" + record.image; + String imageHref = GlobalConfigs.getUrl("/opac/extras/ac/jacket/small/r/" + record.image); //Log.d(TAG, "image url " + imageHref); // start async download of image diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/services/ScheduledIntentService.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/services/ScheduledIntentService.java index 72df1cb5fa..f1f610322c 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/services/ScheduledIntentService.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/services/ScheduledIntentService.java @@ -85,7 +85,7 @@ public class ScheduledIntentService extends IntentService { String idlFile = GlobalConfigs.IDL_FILE_FROM_ROOT; try { Log.d(TAG, "Load IDL start"); - InputStream in_IDL = Utils.getNetInputStream(GlobalConfigs.httpAddress + idlFile); + InputStream in_IDL = Utils.getNetInputStream(GlobalConfigs.getUrl(idlFile)); IDLParser parser = new IDLParser(in_IDL); parser.setKeepIDLObjects(false); parser.parse(); diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/utils/ui/BasicDetailsFragment.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/utils/ui/BasicDetailsFragment.java index 91ca957448..d3933399c6 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/utils/ui/BasicDetailsFragment.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/utils/ui/BasicDetailsFragment.java @@ -83,7 +83,7 @@ public class BasicDetailsFragment extends Fragment { private SearchCatalog search = null; - private GlobalConfigs gl; + private GlobalConfigs globalConfigs; private ProgressDialog progressDialog; @@ -135,7 +135,7 @@ public class BasicDetailsFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - gl = GlobalConfigs.getGlobalConfigs(getActivity()); + globalConfigs = GlobalConfigs.getGlobalConfigs(getActivity()); LinearLayout layout = (LinearLayout) inflater.inflate( R.layout.record_details_basic_fragment, null); @@ -169,7 +169,7 @@ public class BasicDetailsFragment extends Fragment { } }); - String imageHref = GlobalConfigs.httpAddress + "/opac/extras/ac/jacket/large/r/" + record.image; + String imageHref = GlobalConfigs.getUrl("/opac/extras/ac/jacket/large/r/" + record.image); // start async download of image imageDownloader.download(imageHref, recordImage); @@ -342,7 +342,7 @@ public class BasicDetailsFragment extends Fragment { .findViewById(R.id.copy_information_copy_location); CopyInformation info = record.copyInformationList.get(i); - library.setText(gl.getOrganizationName(info.org_id)); + library.setText(globalConfigs.getOrganizationName(info.org_id)); call_number.setText(info.call_number_sufix); copy_location.setText(info.copy_location); 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 b73301f0ae..2c92cbf4d0 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 @@ -109,11 +109,10 @@ public class LoadingTask { 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"); + Log.d(TAG, tag+"Loading resources from "+library_url); publishProgress("Loading resources"); - GlobalConfigs.getGlobalConfigs(mCallingActivity); + GlobalConfigs.getGlobalConfigs(mCallingActivity, library_url); Log.d(TAG, tag+"Starting session"); publishProgress("Starting session"); @@ -130,6 +129,12 @@ public class LoadingTask { } if (retry) { // todo: replace with AccountAccess.reauthenticate? + try { + haveSession = ac.reauthenticate(mCallingActivity); + } catch (Exception e) { + Log.d(TAG, tag+"failed a 2nd time", e); + } + /* final Account account = new Account(account_name, accountType); future = mAccountManager.getAuthToken(account, Const.AUTHTOKEN_TYPE, null, mCallingActivity, null, null); bnd = future.getResult(); @@ -144,6 +149,7 @@ public class LoadingTask { } 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 926b445ad2..acad756bdd 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 @@ -111,8 +111,7 @@ public class SplashActivity extends Activity implements LoadingTaskListener { @Override protected void onStart() { super.onStart(); - GlobalConfigs.httpAddress = AppPrefs.getString(AppPrefs.LIBRARY_URL);// kenstir todo: replace all refs to GlobalConfigs.httpAddress - Log.d(TAG, "kcxxx: onstart: url=" + GlobalConfigs.httpAddress); + Log.d(TAG, "kcxxx: onstart"); if (!restarted) { startTask(); } -- 2.11.0