Search in sources :

Example 11 with ReservedItem

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

the class Adis method account.

@Override
public AccountData account(Account account) throws IOException, JSONException, OpacErrorException {
    start();
    Document doc = htmlGet(opac_url + ";jsessionid=" + s_sid + "?service=" + s_service + getSpParams("SBK"));
    doc = handleLoginForm(doc, account);
    boolean split_title_author = true;
    if (doc.head().html().contains("VOEBB")) {
        split_title_author = false;
    }
    AccountData adata = new AccountData(account.getId());
    for (Element tr : doc.select(".aDISListe tr")) {
        if (tr.child(0).text().matches(".*F.+llige Geb.+hren.*")) {
            adata.setPendingFees(tr.child(1).text().trim());
        }
        if (tr.child(0).text().matches(".*Ausweis g.+ltig bis.*")) {
            adata.setValidUntil(tr.child(1).text().trim());
        }
    }
    DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN);
    // Ausleihen
    String alink = null;
    int anum = 0;
    List<LentItem> lent = new ArrayList<>();
    for (Element tr : doc.select(".rTable_div tr")) {
        if (tr.select("a").size() == 1) {
            if (tr.select("a").first().absUrl("href").contains("sp=SZA")) {
                alink = tr.select("a").first().absUrl("href");
                anum = Integer.parseInt(tr.child(0).text().trim());
            }
        }
    }
    if (alink != null) {
        Document adoc = htmlGet(alink);
        s_alink = alink;
        List<NameValuePair> form = new ArrayList<>();
        String prolongTest = null;
        for (Element input : adoc.select("input, select")) {
            if (!"image".equals(input.attr("type")) && !"submit".equals(input.attr("type")) && !"".equals(input.attr("name"))) {
                if (input.attr("type").equals("checkbox") && !input.hasAttr("value")) {
                    input.val("on");
                }
                form.add(new BasicNameValuePair(input.attr("name"), input.attr("value")));
            } else if (input.val().matches(".+verl.+ngerbar.+")) {
                prolongTest = input.attr("name");
            }
        }
        if (prolongTest != null) {
            form.add(new BasicNameValuePair(prolongTest, "Markierte Titel verlängerbar?"));
            Document adoc_new = htmlPost(opac_url + ";jsessionid=" + s_sid, form);
            if (adoc_new.select(".message h1").size() == 0) {
                adoc = adoc_new;
            }
        }
        parseMediaList(adoc, alink, lent, split_title_author);
        assert (lent.size() == anum);
        form = new ArrayList<>();
        boolean cancelButton = false;
        for (Element input : adoc.select("input, select")) {
            if (!"image".equals(input.attr("type")) && !"submit".equals(input.attr("type")) && !"checkbox".equals(input.attr("type")) && !"".equals(input.attr("name"))) {
                form.add(new BasicNameValuePair(input.attr("name"), input.attr("value")));
            }
            if ("submit".equals(input.attr("type")) && "Abbrechen".equals(input.attr("value")) && !cancelButton) {
                // Stuttgart: Cancel button instead of toolbar back button
                form.add(new BasicNameValuePair(input.attr("name"), input.attr("value")));
                cancelButton = true;
            }
        }
        if (!cancelButton) {
            form.add(new BasicNameValuePair("$Toolbar_0.x", "1"));
            form.add(new BasicNameValuePair("$Toolbar_0.y", "1"));
        }
        doc = htmlPost(opac_url + ";jsessionid=" + s_sid, form);
    } else {
        assert (anum == 0);
    }
    adata.setLent(lent);
    List<String[]> rlinks = new ArrayList<>();
    int rnum = 0;
    List<ReservedItem> res = new ArrayList<>();
    for (Element tr : doc.select(".rTable_div tr")) {
        if (tr.select("a").size() == 1) {
            if ((tr.text().contains("Reservationen") || tr.text().contains("Vormerkung") || tr.text().contains("Fernleihbestellung") || tr.text().contains("Bereitstellung") || tr.text().contains("Bestellw") || tr.text().contains("Magazin")) && !tr.child(0).text().trim().equals("")) {
                rlinks.add(new String[] { tr.select("a").text(), tr.select("a").first().absUrl("href") });
                rnum += Integer.parseInt(tr.child(0).text().trim());
            }
        }
    }
    for (String[] rlink : rlinks) {
        Document rdoc = htmlGet(rlink[1]);
        boolean error = parseReservationList(rdoc, rlink, split_title_author, res, fmt, stringProvider);
        if (error) {
            // Maybe we should send a bug report here, but using ACRA breaks
            // the unit tests
            adata.setWarning("Beim Abrufen der Reservationen ist ein Problem aufgetreten");
        }
        List<NameValuePair> form = new ArrayList<>();
        for (Element input : rdoc.select("input, select")) {
            if (!"image".equals(input.attr("type")) && !"submit".equals(input.attr("type")) && !"checkbox".equals(input.attr("type")) && !"".equals(input.attr("name"))) {
                form.add(new BasicNameValuePair(input.attr("name"), input.attr("value")));
            }
        }
        form.add(new BasicNameValuePair("$Toolbar_0.x", "1"));
        form.add(new BasicNameValuePair("$Toolbar_0.y", "1"));
        htmlPost(opac_url + ";jsessionid=" + s_sid, form);
    }
    assert (res.size() == rnum);
    adata.setReservations(res);
    return adata;
}
Also used : NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) 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) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 12 with ReservedItem

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

the class BiBer1992 method account.

/*
     * (non-Javadoc)
     *
     * @see
     * OpacApi#account(de.geeksfactory.opacclient
     * .objects.Account)
     *
     * POST-format: BENUTZER xxxxxxxxx FUNC medk LANG de PASSWORD ddmmyyyy
     */
@Override
public AccountData account(Account account) throws IOException, JSONException, OpacErrorException {
    AccountData res = new AccountData(account.getId());
    // get media
    List<LentItem> media = accountGetMedia(account, res);
    res.setLent(media);
    // get reservations
    List<ReservedItem> reservations = accountGetReservations(account);
    res.setReservations(reservations);
    return res;
}
Also used : AccountData(de.geeksfactory.opacclient.objects.AccountData) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) LentItem(de.geeksfactory.opacclient.objects.LentItem)

Example 13 with ReservedItem

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

the class IOpac method parseResList.

static void parseResList(List<ReservedItem> media, Document doc, JSONObject data) {
    if (doc.select("a[name=RES]").size() == 0)
        return;
    Elements copytrs = doc.select("a[name=RES] ~ table:contains(Titel)").first().select("tr");
    doc.setBaseUri(data.optString("baseurl"));
    DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN);
    int trs = copytrs.size();
    if (trs < 2) {
        return;
    }
    assert (trs > 0);
    for (int i = 1; i < trs; i++) {
        Element tr = copytrs.get(i);
        ReservedItem item = new ReservedItem();
        item.setTitle(tr.child(0).text().trim().replace("\u00a0", ""));
        item.setAuthor(tr.child(1).text().trim().replace("\u00a0", ""));
        String readyDate = tr.child(4).text().trim().replace("\u00a0", "");
        if (readyDate.equals("")) {
            item.setStatus("bereit");
        } else {
            try {
                item.setReadyDate(fmt.parseLocalDate(readyDate));
            } catch (IllegalArgumentException e) {
                item.setStatus(readyDate);
            }
        }
        if (tr.select("a").size() > 0) {
            item.setCancelData(tr.select("a").last().attr("href"));
        }
        media.add(item);
    }
    assert (media.size() == trs - 1);
}
Also used : Element(org.jsoup.nodes.Element) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) Elements(org.jsoup.select.Elements) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 14 with ReservedItem

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

the class AccountDataSource method cursorToReservedItem.

private ReservedItem cursorToReservedItem(Cursor cursor) {
    ReservedItem item = new ReservedItem();
    setAccountItemAttributes(cursor, item);
    item.setReadyDate(cursor.getString(7));
    item.setExpirationDate(cursor.getString(8));
    item.setBranch(cursor.getString(9));
    item.setCancelData(cursor.getString(10));
    item.setBookingData(cursor.getString(11));
    return item;
}
Also used : ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem)

Example 15 with ReservedItem

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

the class AccountDataSource method getCachedAccountData.

public AccountData getCachedAccountData(Account account) {
    AccountData adata = new AccountData(account.getId());
    List<LentItem> lent = new ArrayList<>();
    String[] selectionArgs = { "" + account.getId() };
    Cursor cursor = database.query(AccountDatabase.TABLENAME_LENT, AccountDatabase.COLUMNS_LENT, "account = ?", selectionArgs, null, null, null);
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        LentItem entry = cursorToLentItem(cursor);
        lent.add(entry);
        cursor.moveToNext();
    }
    cursor.close();
    adata.setLent(lent);
    List<ReservedItem> res = new ArrayList<>();
    cursor = database.query(AccountDatabase.TABLENAME_RESERVATION, AccountDatabase.COLUMNS_RESERVATIONS, "account = ?", selectionArgs, null, null, null);
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        ReservedItem entry = cursorToReservedItem(cursor);
        res.add(entry);
        cursor.moveToNext();
    }
    cursor.close();
    adata.setReservations(res);
    String[] selA = { "" + account.getId() };
    cursor = database.query("accounts", new String[] { "pendingFees", "validUntil", "warning" }, "id = ?", selA, null, null, null);
    cursor.moveToFirst();
    if (!cursor.isAfterLast()) {
        adata.setPendingFees(cursor.getString(0));
        adata.setValidUntil(cursor.getString(1));
        adata.setWarning(cursor.getString(2));
        cursor.moveToNext();
    }
    // Make sure to close the cursor
    cursor.close();
    return adata;
}
Also used : AccountData(de.geeksfactory.opacclient.objects.AccountData) ArrayList(java.util.ArrayList) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) LentItem(de.geeksfactory.opacclient.objects.LentItem) Cursor(android.database.Cursor)

Aggregations

ReservedItem (de.geeksfactory.opacclient.objects.ReservedItem)34 ArrayList (java.util.ArrayList)20 Element (org.jsoup.nodes.Element)17 LentItem (de.geeksfactory.opacclient.objects.LentItem)16 AccountData (de.geeksfactory.opacclient.objects.AccountData)13 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)8 Document (org.jsoup.nodes.Document)8 Elements (org.jsoup.select.Elements)8 JSONObject (org.json.JSONObject)7 Test (org.junit.Test)7 NotReachableException (de.geeksfactory.opacclient.networking.NotReachableException)6 DummyStringProvider (de.geeksfactory.opacclient.i18n.DummyStringProvider)4 HashMap (java.util.HashMap)4 IOException (java.io.IOException)3 Pattern (java.util.regex.Pattern)3 JSONException (org.json.JSONException)3 Intent (android.content.Intent)2 Account (de.geeksfactory.opacclient.objects.Account)2 Report (de.geeksfactory.opacclient.reporting.Report)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2