Search in sources :

Example 6 with SearchQuery

use of de.geeksfactory.opacclient.searchfields.SearchQuery in project opacclient by opacapp.

the class SISIS method search.

@Override
public SearchRequestResult search(List<SearchQuery> query) throws IOException, OpacErrorException, JSONException {
    List<NameValuePair> params = new ArrayList<>();
    int index = 0;
    int restrictionIndex = 0;
    start();
    params.add(new BasicNameValuePair("methodToCall", "submit"));
    params.add(new BasicNameValuePair("CSId", CSId));
    params.add(new BasicNameValuePair("methodToCallParameter", "submitSearch"));
    for (SearchQuery entry : query) {
        if (entry.getValue().equals("")) {
            continue;
        }
        if (entry.getSearchField() instanceof DropdownSearchField) {
            JSONObject data = entry.getSearchField().getData();
            if (data.optBoolean("restriction", false)) {
                params.add(new BasicNameValuePair("searchRestrictionID[" + restrictionIndex + "]", entry.getSearchField().getId()));
                params.add(new BasicNameValuePair("searchRestrictionValue1[" + restrictionIndex + "]", entry.getValue()));
                restrictionIndex++;
            } else {
                params.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
            }
        } else {
            if (index != 0) {
                params.add(new BasicNameValuePair("combinationOperator[" + index + "]", "AND"));
            }
            params.add(new BasicNameValuePair("searchCategories[" + index + "]", entry.getKey()));
            params.add(new BasicNameValuePair("searchString[" + index + "]", entry.getValue()));
            index++;
        }
    }
    if (index == 0) {
        throw new OpacErrorException(stringProvider.getString(StringProvider.NO_CRITERIA_INPUT));
    }
    if (index > 4) {
        throw new OpacErrorException(stringProvider.getQuantityString(StringProvider.LIMITED_NUM_OF_CRITERIA, 4, 4));
    }
    params.add(new BasicNameValuePair("submitSearch", "Suchen"));
    params.add(new BasicNameValuePair("callingPage", "searchParameters"));
    params.add(new BasicNameValuePair("numberOfHits", "10"));
    String html = httpGet(opac_url + "/search.do?" + URLEncodedUtils.format(params, "UTF-8"), ENCODING);
    return parse_search_wrapped(html, 1);
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) JSONObject(org.json.JSONObject) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField)

Example 7 with SearchQuery

use of de.geeksfactory.opacclient.searchfields.SearchQuery in project opacclient by opacapp.

the class TouchPoint method search.

@Override
public SearchRequestResult search(List<SearchQuery> query) throws IOException, OpacErrorException, JSONException {
    List<NameValuePair> params = new ArrayList<>();
    boolean selectDatabase = false;
    int index = 0;
    start();
    params.add(new BasicNameValuePair("methodToCall", "submitButtonCall"));
    params.add(new BasicNameValuePair("CSId", CSId));
    params.add(new BasicNameValuePair("refine", "false"));
    params.add(new BasicNameValuePair("numberOfHits", "10"));
    for (SearchQuery entry : query) {
        if (entry.getValue().equals("")) {
            continue;
        }
        if (entry.getSearchField() instanceof DropdownSearchField) {
            if (entry.getKey().equals("_database")) {
                String[] parts = entry.getValue().split("=", 2);
                params.add(new BasicNameValuePair(parts[0], parts[1]));
                selectDatabase = true;
            } else {
                params.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
            }
        } else {
            if (index != 0) {
                params.add(new BasicNameValuePair("combinationOperator[" + index + "]", "AND"));
            }
            params.add(new BasicNameValuePair("searchCategories[" + index + "]", entry.getKey()));
            params.add(new BasicNameValuePair("searchString[" + index + "]", entry.getValue()));
            index++;
        }
    }
    if (index == 0) {
        throw new OpacErrorException(stringProvider.getString(StringProvider.NO_CRITERIA_INPUT));
    }
    if (index > 4) {
        throw new OpacErrorException(stringProvider.getQuantityString(StringProvider.LIMITED_NUM_OF_CRITERIA, 4, 4));
    }
    if (selectDatabase) {
        List<NameValuePair> selectParams = new ArrayList<>();
        selectParams.addAll(params);
        selectParams.add(new BasicNameValuePair("methodToCallParameter", "selectDatabase"));
        httpGet(opac_url + "/search.do?" + URLEncodedUtils.format(selectParams, "UTF-8"), ENCODING);
    }
    params.add(new BasicNameValuePair("submitButtonCall_submitSearch", "Suchen"));
    params.add(new BasicNameValuePair("methodToCallParameter", "submitSearch"));
    String html = httpGet(opac_url + "/search.do?" + URLEncodedUtils.format(params, "UTF-8"), ENCODING);
    return parse_search_wrapped(html, 1);
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField)

Example 8 with SearchQuery

use of de.geeksfactory.opacclient.searchfields.SearchQuery in project opacclient by opacapp.

the class BiBer1992 method search.

@Override
public SearchRequestResult search(List<SearchQuery> queryList) throws IOException {
    if (!initialised) {
        start();
    }
    nameValuePairs.clear();
    int count = 1;
    for (SearchQuery query : queryList) {
        if ((query.getSearchField() instanceof TextSearchField || query.getSearchField() instanceof BarcodeSearchField) && !query.getValue().equals("")) {
            nameValuePairs.add(new BasicNameValuePair("CNN" + count, "AND"));
            nameValuePairs.add(new BasicNameValuePair("FLD" + count, query.getValue()));
            nameValuePairs.add(new BasicNameValuePair("REG" + count, query.getKey()));
            count++;
        } else if (query.getSearchField() instanceof DropdownSearchField) {
            nameValuePairs.add(new BasicNameValuePair(query.getKey(), query.getValue()));
        }
    }
    nameValuePairs.add(new BasicNameValuePair("FUNC", "qsel"));
    nameValuePairs.add(new BasicNameValuePair("LANG", "de"));
    // but
    nameValuePairs.add(new BasicNameValuePair("SHOW", "20"));
    // result
    // gives 50
    nameValuePairs.add(new BasicNameValuePair("SHOWSTAT", "N"));
    nameValuePairs.add(new BasicNameValuePair("FROMPOS", "1"));
    return searchGetPage(1);
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField)

Example 9 with SearchQuery

use of de.geeksfactory.opacclient.searchfields.SearchQuery 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 10 with SearchQuery

use of de.geeksfactory.opacclient.searchfields.SearchQuery in project opacclient by opacapp.

the class SearchFragment method saveSearchQuery.

public List<SearchQuery> saveSearchQuery() {
    saveHomeBranch();
    List<SearchQuery> query = new ArrayList<>();
    if (fields == null || view == null) {
        return null;
    }
    for (SearchField field : fields) {
        if (!field.isVisible()) {
            continue;
        }
        ViewGroup v = (ViewGroup) view.findViewWithTag(field.getId());
        if (field instanceof TextSearchField) {
            EditText text;
            if (((TextSearchField) field).isFreeSearch()) {
                text = etSimpleSearch;
            } else {
                if (v == null)
                    continue;
                text = (EditText) v.findViewById(R.id.edittext);
            }
            query.add(new SearchQuery(field, text.getEditableText().toString().trim()));
        } else if (field instanceof BarcodeSearchField) {
            if (v == null)
                continue;
            EditText text = (EditText) v.findViewById(R.id.edittext);
            query.add(new SearchQuery(field, text.getEditableText().toString().trim()));
        } else if (field instanceof DropdownSearchField) {
            if (v == null)
                continue;
            Spinner spinner = (Spinner) v.findViewById(R.id.spinner);
            if (spinner.getSelectedItemPosition() != -1) {
                String key = ((DropdownSearchField) field).getDropdownValues().get(spinner.getSelectedItemPosition()).getKey();
                if (!key.equals("")) {
                    query.add(new SearchQuery(field, key));
                }
            }
        } else if (field instanceof CheckboxSearchField) {
            if (v == null)
                continue;
            CheckBox checkbox = (CheckBox) v.findViewById(R.id.checkbox);
            query.add(new SearchQuery(field, String.valueOf(checkbox.isChecked())));
        }
    }
    return query;
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) EditText(android.widget.EditText) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) ViewGroup(android.view.ViewGroup) Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) CheckboxSearchField(de.geeksfactory.opacclient.searchfields.CheckboxSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField) CheckboxSearchField(de.geeksfactory.opacclient.searchfields.CheckboxSearchField) CheckBox(android.widget.CheckBox)

Aggregations

SearchQuery (de.geeksfactory.opacclient.searchfields.SearchQuery)21 ArrayList (java.util.ArrayList)16 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)11 NameValuePair (org.apache.http.NameValuePair)9 TextSearchField (de.geeksfactory.opacclient.searchfields.TextSearchField)8 DropdownSearchField (de.geeksfactory.opacclient.searchfields.DropdownSearchField)6 SearchField (de.geeksfactory.opacclient.searchfields.SearchField)6 Element (org.jsoup.nodes.Element)4 SearchRequestResult (de.geeksfactory.opacclient.objects.SearchRequestResult)3 BarcodeSearchField (de.geeksfactory.opacclient.searchfields.BarcodeSearchField)3 Document (org.jsoup.nodes.Document)3 OpacErrorException (de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException)2 SearchResult (de.geeksfactory.opacclient.objects.SearchResult)2 CheckboxSearchField (de.geeksfactory.opacclient.searchfields.CheckboxSearchField)2 JsonSearchFieldDataSource (de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource)2 JSONObject (org.json.JSONObject)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1