use of de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException in project opacclient by opacapp.
the class AccountFragment method show_connectivity_error.
public void show_connectivity_error(Exception e) {
if (e != null) {
e.printStackTrace();
}
if (getActivity() == null) {
return;
}
if (e instanceof OpacErrorException) {
AccountDataSource adatasource = new AccountDataSource(getActivity());
adatasource.invalidateCachedAccountData(account);
dialog_wrong_credentials(e.getMessage());
return;
}
if (getView() != null) {
final FrameLayout errorView = (FrameLayout) getView().findViewById(R.id.error_view);
errorView.removeAllViews();
View connError = getActivity().getLayoutInflater().inflate(R.layout.error_connectivity, errorView);
TextView tvErrBody = (TextView) connError.findViewById(R.id.tvErrBody);
Button btnRetry = (Button) connError.findViewById(R.id.btRetry);
btnRetry.setVisibility(View.VISIBLE);
if (e != null && e instanceof SSLSecurityException) {
tvErrBody.setText(R.string.connection_error_detail_security);
} else if (e != null && e instanceof NotReachableException) {
tvErrBody.setText(R.string.connection_error_detail_nre);
} else if (e != null && e instanceof OpacClient.LibraryRemovedException) {
tvErrBody.setText(R.string.library_removed_error);
btnRetry.setVisibility(View.GONE);
}
btnRetry.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
refresh();
}
});
llLoading.setVisibility(View.GONE);
swipeRefreshLayout.setVisibility(View.GONE);
connError.setVisibility(View.VISIBLE);
}
}
use of de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException in project opacclient by opacapp.
the class GetSearchFieldsCallable method call.
@Override
public Map<String, List<SearchField>> call() {
OpacApi api = OpacApiFactory.create(lib, "OpacApp/Test");
if (api instanceof ApacheBaseApi) {
((ApacheBaseApi) api).setHttpLoggingEnabled(false);
}
Set<String> langs = null;
try {
langs = api.getSupportedLanguages();
} catch (IOException e) {
}
if (langs == null) {
// Use default language
try {
Map<String, List<SearchField>> map = new HashMap<>();
map.put("default", api.getSearchFields());
return map;
} catch (IOException | OpacErrorException | JSONException e) {
}
} else {
Map<String, List<SearchField>> map = new HashMap<>();
for (String lang : langs) {
api.setLanguage(lang);
try {
map.put(lang, api.getSearchFields());
} catch (IOException | OpacErrorException | JSONException e) {
}
}
return map;
}
return null;
}
use of de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException in project opacclient by opacapp.
the class LibraryApiTestCases method testEmptySearch.
@Test
public void testEmptySearch() throws IOException, OpacErrorException, JSONException {
List<SearchQuery> query = new ArrayList<>();
SearchField field = findFreeSearchOrTitle(fields);
if (field == null) {
throw new // TODO: prevent this
OpacErrorException("There is no free or title search field");
}
query.add(new SearchQuery(field, "fasgeadstrehdaxydsfstrgdfjxnvgfhdtnbfgn"));
try {
SearchRequestResult res = api.search(query);
assertTrue(res.getTotal_result_count() == 0);
} catch (OpacErrorException e) {
// Expected, should be an empty result.
}
}
use of de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException in project opacclient by opacapp.
the class LibraryApiTestCases method testWrongLogin.
/**
* Create an account with credentials that probably nobody has and try to login. This should
* normally give an {@link OpacErrorException}.
*/
@Test
public void testWrongLogin() throws IOException, JSONException {
if (!library.isAccountSupported()) {
return;
}
Account account = new Account();
account.setId(0);
account.setLabel("Test account");
account.setLibrary(library.getIdent());
account.setName("upvlgFLMNN2AyVsIzowcwzdypRXM2x");
account.setPassword("OTqbXhMJMKtjconhxX0LXMqWZsY2Ez");
OpacErrorException exception = null;
try {
api.checkAccountData(account);
} catch (OpacErrorException e) {
exception = e;
}
assertTrue(exception != null);
}
use of de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException in project opacclient by opacapp.
the class SearchResultListFragment method setSearchResult.
public void setSearchResult(final SearchRequestResult searchresult) {
for (SearchResult result : searchresult.getResults()) {
result.setPage(searchresult.getPage_index());
}
if (searchresult.getTotal_result_count() >= 0) {
((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(getResources().getQuantityString(R.plurals.result_number, searchresult.getTotal_result_count(), searchresult.getTotal_result_count()));
}
if (searchresult.getResults().size() == 0 && searchresult.getTotal_result_count() <= 0) {
setEmptyText(getString(R.string.no_results));
}
this.searchresult = searchresult;
OpacApi api = null;
try {
api = app.getApi();
} catch (OpacClient.LibraryRemovedException ignored) {
}
adapter = new ResultsAdapterEndless(getActivity(), searchresult, new OnLoadMoreListener() {
@Override
public SearchRequestResult onLoadMore(int page) throws Exception {
SearchRequestResult res = app.getApi().searchGetPage(page);
setLastLoadedPage(page);
return res;
}
@Override
public void onError(Exception e) {
if (getActivity() != null) {
if (e instanceof OpacErrorException) {
showConnectivityError(e.getMessage());
} else if (e instanceof SSLSecurityException) {
showConnectivityError(getResources().getString(R.string.connection_error_detail_security));
} else if (e instanceof NotReachableException) {
showConnectivityError(getResources().getString(R.string.connection_error_detail_nre));
} else {
e.printStackTrace();
showConnectivityError();
}
}
}
@Override
public void updateResultCount(int resultCount) {
/*
* When IOpac finds more than 200 results, the real
* result count is not known until the second page is
* loaded
*/
if (resultCount >= 0 && getActivity() != null) {
((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(getResources().getQuantityString(R.plurals.result_number, resultCount, resultCount));
}
}
}, api);
setListAdapter(adapter);
getListView().setTextFilterEnabled(true);
setListShown(true);
}
Aggregations