Search in sources :

Example 1 with OpacErrorException

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);
    }
}
Also used : AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) OpacClient(de.geeksfactory.opacclient.OpacClient) Button(android.widget.Button) NotReachableException(de.geeksfactory.opacclient.networking.NotReachableException) FrameLayout(android.widget.FrameLayout) SSLSecurityException(de.geeksfactory.opacclient.networking.SSLSecurityException) OnClickListener(android.view.View.OnClickListener) OpacErrorException(de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) RecyclerView(android.support.v7.widget.RecyclerView)

Example 2 with OpacErrorException

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;
}
Also used : HashMap(java.util.HashMap) OpacApi(de.geeksfactory.opacclient.apis.OpacApi) JSONException(org.json.JSONException) List(java.util.List) OpacErrorException(de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException) IOException(java.io.IOException) ApacheBaseApi(de.geeksfactory.opacclient.apis.ApacheBaseApi)

Example 3 with OpacErrorException

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.
    }
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) SearchRequestResult(de.geeksfactory.opacclient.objects.SearchRequestResult) ArrayList(java.util.ArrayList) OpacErrorException(de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException) Test(org.junit.Test)

Example 4 with OpacErrorException

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);
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) OpacErrorException(de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException) Test(org.junit.Test)

Example 5 with OpacErrorException

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);
}
Also used : OnLoadMoreListener(de.geeksfactory.opacclient.frontend.ResultsAdapterEndless.OnLoadMoreListener) OpacClient(de.geeksfactory.opacclient.OpacClient) SearchRequestResult(de.geeksfactory.opacclient.objects.SearchRequestResult) NotReachableException(de.geeksfactory.opacclient.networking.NotReachableException) OpacApi(de.geeksfactory.opacclient.apis.OpacApi) SSLSecurityException(de.geeksfactory.opacclient.networking.SSLSecurityException) SearchResult(de.geeksfactory.opacclient.objects.SearchResult) OpacErrorException(de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException) JSONException(org.json.JSONException) OpacErrorException(de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException) IOException(java.io.IOException) SSLSecurityException(de.geeksfactory.opacclient.networking.SSLSecurityException) NotReachableException(de.geeksfactory.opacclient.networking.NotReachableException)

Aggregations

OpacErrorException (de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException)6 SearchRequestResult (de.geeksfactory.opacclient.objects.SearchRequestResult)3 OpacClient (de.geeksfactory.opacclient.OpacClient)2 OpacApi (de.geeksfactory.opacclient.apis.OpacApi)2 NotReachableException (de.geeksfactory.opacclient.networking.NotReachableException)2 SSLSecurityException (de.geeksfactory.opacclient.networking.SSLSecurityException)2 SearchResult (de.geeksfactory.opacclient.objects.SearchResult)2 SearchField (de.geeksfactory.opacclient.searchfields.SearchField)2 SearchQuery (de.geeksfactory.opacclient.searchfields.SearchQuery)2 TextSearchField (de.geeksfactory.opacclient.searchfields.TextSearchField)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 JSONException (org.json.JSONException)2 Test (org.junit.Test)2 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 Button (android.widget.Button)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1