Search in sources :

Example 26 with ReservedItem

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

the class PicaLBSAccountTest method testParseResList.

@Test
public void testParseResList() throws OpacApi.OpacErrorException {
    String html = readResource("/pica_lbs/reslist/" + file);
    // we may not have all files for all libraries
    if (html == null)
        return;
    List<ReservedItem> media = PicaLBS.parseResList(Jsoup.parse(html), new DummyStringProvider());
    assertTrue(media.size() > 0);
}
Also used : DummyStringProvider(de.geeksfactory.opacclient.i18n.DummyStringProvider) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) Test(org.junit.Test)

Example 27 with ReservedItem

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

the class AdisAccountTest method testParseReservationList.

@Test
public void testParseReservationList() throws OpacApi.OpacErrorException, JSONException {
    String html = readResource("/adis/reslist/" + file);
    // we may not have all files for all libraries
    if (html == null)
        return;
    List<ReservedItem> res = new ArrayList<>();
    DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN);
    String[] rlink = new String[] { "Vormerkungen zeigen oder löschen", "https://opac.sbs.stuttgart.de/aDISWeb/app;" + "jsessionid=98AAE50B33FC5A0C191319D406D1564E?service=direct/1/POOLM02Q" + "@@@@@@@@_4B032E00_349DAD80/Tabelle_Z1LW01.cellInternalLink" + ".directlink&sp=SRGLINK_3&sp=SZM&requestCount=2" };
    Adis.parseReservationList(Jsoup.parse(html), rlink, true, res, fmt, new DummyStringProvider());
    assertTrue(res.size() > 0);
    for (ReservedItem item : res) {
        assertNotNull(item.getTitle());
    }
}
Also used : DummyStringProvider(de.geeksfactory.opacclient.i18n.DummyStringProvider) ArrayList(java.util.ArrayList) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Test(org.junit.Test)

Example 28 with ReservedItem

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

the class BiBer1992AccountTest method testParseResList.

@Test
public void testParseResList() throws OpacApi.OpacErrorException, JSONException {
    String html = readResource("/biber1992/reslist/" + file);
    // we may not have all files for all libraries
    if (html == null)
        return;
    List<ReservedItem> media = BiBer1992.parseResList(new Account(), Jsoup.parse(html), new JSONObject(), reportHandler, new JSONObject(readResource("/biber1992/headers_reservations.json")));
    assertTrue(media.size() > 0);
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) JSONObject(org.json.JSONObject) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) Test(org.junit.Test)

Example 29 with ReservedItem

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

the class BibliothecaAccountTest method testParseReservationList.

@Test
public void testParseReservationList() throws OpacApi.OpacErrorException, JSONException, NotReachableException {
    String html = readResource("/bibliotheca/account/" + file);
    // we may not have all files for all libraries
    if (html == null)
        return;
    if (file.equals("gladbeck.html") || file.equals("halle.html") || file.equals("albstadt.html") || file.equals("bernau.html"))
        return;
    AccountData data = Bibliotheca.parse_account(new Account(), Jsoup.parse(html), new JSONObject(), reportHandler, new JSONObject(readResource("/bibliotheca/headers_lent.json")), new JSONObject(readResource("/bibliotheca/headers_reservations.json")));
    assertTrue(data.getReservations().size() > 0);
    for (ReservedItem item : data.getReservations()) {
        assertContainsData(item.getTitle());
        assertNullOrNotEmpty(item.getAuthor());
    }
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) JSONObject(org.json.JSONObject) AccountData(de.geeksfactory.opacclient.objects.AccountData) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) Test(org.junit.Test)

Example 30 with ReservedItem

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

the class PicaLBS method parseResList.

static List<ReservedItem> parseResList(Document doc, StringProvider stringProvider) {
    List<ReservedItem> reservations = new ArrayList<>();
    for (Element tr : doc.select(".resultset > tbody > tr:has(.rec_title)")) {
        ReservedItem item = new ReservedItem();
        if (tr.select("input[name=volumeReservationsToCancel]").size() > 0) {
            item.setCancelData(tr.select("input[name=volumeReservationsToCancel]").val());
        }
        String[] titleAndAuthor = extractTitleAndAuthor(tr);
        item.setTitle(titleAndAuthor[0]);
        if (titleAndAuthor[1] != null)
            item.setAuthor(titleAndAuthor[1]);
        item.setBranch(extractAccountInfo(tr, "Destination", "Theke"));
        // not supported: extractAccountInfo(tr, "Shelf mark", "Signatur")
        StringBuilder status = new StringBuilder();
        String numberOfReservations = extractAccountInfo(tr, "Vormerkung", "Number of reservations");
        if (numberOfReservations != null) {
            try {
                status.append(stringProvider.getQuantityString(StringProvider.RESERVATIONS_NUMBER, Integer.parseInt(numberOfReservations.trim()), Integer.parseInt(numberOfReservations.trim())));
            } catch (NumberFormatException e) {
                status.append(numberOfReservations);
            }
        }
        String reservationDate = extractAccountInfo(tr, "Reservationdate", "Vormerkungsdatum");
        if (reservationDate != null) {
            if (status.length() > 0) {
                status.append(", ");
            }
            status.append(stringProvider.getFormattedString(StringProvider.RESERVED_AT_DATE, reservationDate));
        }
        if (status.length() > 0)
            item.setStatus(status.toString());
        // TODO: I don't know how reservations are marked that are already available
        reservations.add(item);
    }
    return reservations;
}
Also used : Element(org.jsoup.nodes.Element) FormElement(org.jsoup.nodes.FormElement) ArrayList(java.util.ArrayList) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem)

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