Search in sources :

Example 26 with LentItem

use of de.geeksfactory.opacclient.objects.LentItem in project opacclient by opacapp.

the class AccountDataSource method storeCachedAccountData.

public void storeCachedAccountData(Account account, AccountData adata) {
    if (adata == null) {
        return;
    }
    long time = System.currentTimeMillis();
    ContentValues update = new ContentValues();
    update.put("cached", time);
    update.put("pendingFees", adata.getPendingFees());
    update.put("validUntil", adata.getValidUntil());
    update.put("warning", adata.getWarning());
    database.update(AccountDatabase.TABLENAME_ACCOUNTS, update, "id = ?", new String[] { "" + account.getId() });
    database.delete(AccountDatabase.TABLENAME_LENT, "account = ?", new String[] { "" + account.getId() });
    for (LentItem entry : adata.getLent()) {
        ContentValues insertmapping = lentItemToContentValues(entry, account.getId());
        database.insert(AccountDatabase.TABLENAME_LENT, null, insertmapping);
    }
    database.delete(AccountDatabase.TABLENAME_RESERVATION, "account = ?", new String[] { "" + account.getId() });
    for (ReservedItem entry : adata.getReservations()) {
        ContentValues insertmapping = reservedItemToContentValues(entry, account.getId());
        database.insert(AccountDatabase.TABLENAME_RESERVATION, null, insertmapping);
    }
}
Also used : ContentValues(android.content.ContentValues) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) LentItem(de.geeksfactory.opacclient.objects.LentItem)

Example 27 with LentItem

use of de.geeksfactory.opacclient.objects.LentItem in project opacclient by opacapp.

the class AccountDataSource method getLentItems.

public List<LentItem> getLentItems(long[] ids) {
    List<LentItem> items = new ArrayList<>();
    Cursor cursor = database.query(AccountDatabase.TABLENAME_LENT, AccountDatabase.COLUMNS_LENT, "id IN(" + joinLongs(ids, ",") + ")", null, null, null, null);
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        LentItem item = cursorToLentItem(cursor);
        items.add(item);
        cursor.moveToNext();
    }
    cursor.close();
    return items;
}
Also used : ArrayList(java.util.ArrayList) LentItem(de.geeksfactory.opacclient.objects.LentItem) Cursor(android.database.Cursor)

Example 28 with LentItem

use of de.geeksfactory.opacclient.objects.LentItem in project opacclient by opacapp.

the class PicaOld method account.

@Override
public AccountData account(Account account) throws IOException, JSONException, OpacErrorException {
    if (!initialised) {
        start();
    }
    List<NameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("ACT", "UI_DATA"));
    params.add(new BasicNameValuePair("HOST_NAME", ""));
    params.add(new BasicNameValuePair("HOST_PORT", ""));
    params.add(new BasicNameValuePair("HOST_SCRIPT", ""));
    params.add(new BasicNameValuePair("LOGIN", "KNOWNUSER"));
    params.add(new BasicNameValuePair("STATUS", "HML_OK"));
    params.add(new BasicNameValuePair("BOR_U", account.getName()));
    params.add(new BasicNameValuePair("BOR_PW", account.getPassword()));
    String html = httpPost(https_url + "/loan/DB=" + db + "/LNG=" + getLang() + "/USERINFO", new UrlEncodedFormEntity(params, getDefaultEncoding()), getDefaultEncoding());
    Document doc = Jsoup.parse(html);
    AccountData res = new AccountData(account.getId());
    if (doc.select(".cnt .alert, .cnt .error").size() > 0) {
        String text = doc.select(".cnt .alert, .cnt .error").text();
        if (doc.select("table[summary^=User data]").size() > 0) {
            res.setWarning(text);
        } else {
            throw new OpacErrorException(text);
        }
    }
    // noinspection StatementWithEmptyBody
    if (doc.select("input[name=BOR_PW_ENC]").size() > 0) {
        pwEncoded = URLEncoder.encode(doc.select("input[name=BOR_PW_ENC]").attr("value"), "UTF-8");
    } else {
    // TODO: do something here to help fix bug #229
    }
    html = httpGet(https_url + "/loan/DB=" + db + "/LNG=" + getLang() + "/USERINFO?ACT=UI_LOL&BOR_U=" + account.getName() + "&BOR_PW_ENC=" + pwEncoded, getDefaultEncoding());
    doc = Jsoup.parse(html);
    html = httpGet(https_url + "/loan/DB=" + db + "/LNG=" + getLang() + "/USERINFO?ACT=UI_LOR&BOR_U=" + account.getName() + "&BOR_PW_ENC=" + pwEncoded, getDefaultEncoding());
    Document doc2 = Jsoup.parse(html);
    List<LentItem> media = new ArrayList<>();
    List<ReservedItem> reserved = new ArrayList<>();
    if (doc.select("table[summary^=list]").size() > 0 && !doc.select(".alert").text().contains("Keine Entleihungen") && !doc.select(".alert").text().contains("No outstanding loans") && !doc.select(".alert").text().contains("Geen uitlening") && !doc.select(".alert").text().contains("Aucun emprunt")) {
        List<String> renewalCounts = loadRenewalCounts(doc);
        parseMediaList(media, doc, stringProvider, renewalCounts);
    }
    if (doc2.select("table[summary^=list]").size() > 0 && !doc2.select(".alert").text().contains("Keine Vormerkungen") && !doc2.select(".alert").text().contains("No outstanding reservations") && !doc2.select(".alert").text().contains("Geen reservering") && !doc2.select(".alert").text().contains("Aucune réservation")) {
        updateLorReservations(doc);
        parseResList(reserved, doc2, stringProvider);
    }
    res.setLent(media);
    res.setReservations(reserved);
    return res;
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) ArrayList(java.util.ArrayList) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) Document(org.jsoup.nodes.Document) AccountData(de.geeksfactory.opacclient.objects.AccountData) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) LentItem(de.geeksfactory.opacclient.objects.LentItem)

Example 29 with LentItem

use of de.geeksfactory.opacclient.objects.LentItem in project opacclient by opacapp.

the class SISIS method parse_medialist.

public static void parse_medialist(List<LentItem> media, Document doc, int offset, JSONObject data) {
    Elements copytrs = doc.select(".data tr");
    doc.setBaseUri(data.optString("baseurl"));
    DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN);
    int trs = copytrs.size();
    if (trs == 1) {
        return;
    }
    assert (trs > 0);
    for (int i = 1; i < trs; i++) {
        Element tr = copytrs.get(i);
        LentItem item = new LentItem();
        if (tr.text().contains("keine Daten") || (trs == 2 && tr.children().size() == 1)) {
            // Dresden: Konto entält keine &lt;Ausleihen&gt;. [sic!]
            return;
        }
        item.setTitle(tr.child(1).select("strong").text().trim());
        try {
            item.setAuthor(tr.child(1).html().split("<br[ /]*>")[1].trim());
            String[] col2split = tr.child(2).html().split("<br[ /]*>");
            String deadline = col2split[0].trim();
            if (deadline.contains("-")) {
                deadline = deadline.split("-")[1].trim();
            }
            try {
                item.setDeadline(fmt.parseLocalDate(deadline).toString());
            } catch (IllegalArgumentException e1) {
                e1.printStackTrace();
            }
            if (col2split.length > 1) {
                item.setHomeBranch(col2split[1].trim());
            }
            if (tr.select("a").size() > 0) {
                for (Element link : tr.select("a")) {
                    String href = link.attr("abs:href");
                    Map<String, String> hrefq = getQueryParamsFirst(href);
                    if (hrefq.get("methodToCall").equals("renewalPossible")) {
                        item.setProlongData(offset + "$" + href.split("\\?")[1]);
                        item.setRenewable(true);
                        break;
                    }
                }
            } else if (tr.select(".textrot, .textgruen, .textdunkelblau").size() > 0) {
                item.setProlongData("§" + tr.select(".textrot, .textgruen, .textdunkelblau").text());
                item.setRenewable(false);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        media.add(item);
    }
    assert (media.size() == trs - 1);
}
Also used : Element(org.jsoup.nodes.Element) LentItem(de.geeksfactory.opacclient.objects.LentItem) Elements(org.jsoup.select.Elements) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) URISyntaxException(java.net.URISyntaxException) JSONException(org.json.JSONException) NotReachableException(de.geeksfactory.opacclient.networking.NotReachableException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException)

Example 30 with LentItem

use of de.geeksfactory.opacclient.objects.LentItem in project opacclient by opacapp.

the class TestApi method account.

@Override
public AccountData account(Account account) throws IOException, JSONException, OpacErrorException {
    AccountData data = new AccountData(account.getId());
    List<LentItem> lent = new ArrayList<>();
    List<ReservedItem> reservations = new ArrayList<>();
    try {
        JSONObject d = new JSONObject(httpGet(library.getData().getString("url"), "UTF-8"));
        for (int i = 0; i < d.getJSONArray("lent").length(); i++) {
            JSONObject l = d.getJSONArray("lent").getJSONObject(i);
            LentItem lentItem = new LentItem();
            for (Iterator iter = l.keys(); iter.hasNext(); ) {
                String key = (String) iter.next();
                lentItem.set(key, l.getString(key));
            }
            lent.add(lentItem);
        }
        for (int i = 0; i < d.getJSONArray("reservations").length(); i++) {
            JSONObject l = d.getJSONArray("reservations").getJSONObject(i);
            ReservedItem resItem = new ReservedItem();
            for (Iterator iter = l.keys(); iter.hasNext(); ) {
                String key = (String) iter.next();
                resItem.set(key, l.getString(key));
            }
            reservations.add(resItem);
        }
    } catch (NotReachableException e) {
        for (int i = 0; i < 6; i++) {
            LentItem lentItem = new LentItem();
            lentItem.setAuthor("Max Mustermann");
            lentItem.setTitle("Lorem Ipsum");
            lentItem.setStatus("hier ist der Status");
            lentItem.setDeadline(new LocalDate(1442564454547L));
            lentItem.setRenewable(true);
            lentItem.setProlongData("foo");
            lentItem.setHomeBranch("Meine Zweigstelle");
            lentItem.setLendingBranch("Ausleihzweigstelle");
            lentItem.setBarcode("Barcode");
            lent.add(lentItem);
            ReservedItem reservedItem = new ReservedItem();
            reservedItem.setAuthor("Max Mustermann");
            reservedItem.setTitle("Lorem Ipsum");
            reservedItem.setReadyDate(LocalDate.now());
            reservations.add(reservedItem);
        }
    }
    data.setLent(lent);
    data.setReservations(reservations);
    return data;
}
Also used : JSONObject(org.json.JSONObject) AccountData(de.geeksfactory.opacclient.objects.AccountData) NotReachableException(de.geeksfactory.opacclient.networking.NotReachableException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) LentItem(de.geeksfactory.opacclient.objects.LentItem) LocalDate(org.joda.time.LocalDate)

Aggregations

LentItem (de.geeksfactory.opacclient.objects.LentItem)43 ArrayList (java.util.ArrayList)26 ReservedItem (de.geeksfactory.opacclient.objects.ReservedItem)16 Element (org.jsoup.nodes.Element)16 AccountData (de.geeksfactory.opacclient.objects.AccountData)14 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)12 Test (org.junit.Test)10 JSONObject (org.json.JSONObject)9 Document (org.jsoup.nodes.Document)8 Elements (org.jsoup.select.Elements)8 NotReachableException (de.geeksfactory.opacclient.networking.NotReachableException)7 Pattern (java.util.regex.Pattern)5 Intent (android.content.Intent)4 Cursor (android.database.Cursor)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Matcher (java.util.regex.Matcher)4 LocalDate (org.joda.time.LocalDate)4 JSONException (org.json.JSONException)4 Account (de.geeksfactory.opacclient.objects.Account)3