Search in sources :

Example 11 with AccountData

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

the class TouchPoint method account.

@Override
public AccountData account(Account acc) throws IOException, JSONException, OpacErrorException {
    start();
    LoginResponse login = login(acc);
    if (!login.success) {
        return null;
    }
    AccountData adata = new AccountData(acc.getId());
    if (login.warning != null) {
        adata.setWarning(login.warning);
    }
    // Lent media
    httpGet(opac_url + "/userAccount.do?methodToCall=start", ENCODING);
    String html = httpGet(opac_url + "/userAccount.do?methodToCall=showAccount&accountTyp=loaned", ENCODING);
    List<LentItem> lent = new ArrayList<>();
    Document doc = Jsoup.parse(html);
    doc.setBaseUri(opac_url);
    List<LentItem> nextpageLent = parse_medialist(doc);
    if (nextpageLent != null) {
        lent.addAll(nextpageLent);
    }
    if (doc.select(".pagination").size() > 0 && lent != null) {
        Element pagination = doc.select(".pagination").first();
        Elements pages = pagination.select("a");
        for (Element page : pages) {
            if (!page.hasAttr("href")) {
                continue;
            }
            html = httpGet(page.attr("abs:href"), ENCODING);
            doc = Jsoup.parse(html);
            doc.setBaseUri(opac_url);
            nextpageLent = parse_medialist(doc);
            if (nextpageLent != null) {
                lent.addAll(nextpageLent);
            }
        }
    }
    adata.setLent(lent);
    // Requested media ("Vormerkungen")
    html = httpGet(opac_url + "/userAccount.do?methodToCall=showAccount&accountTyp=requested", ENCODING);
    doc = Jsoup.parse(html);
    doc.setBaseUri(opac_url);
    List<ReservedItem> requested = new ArrayList<>();
    List<ReservedItem> nextpageRes = parse_reslist(doc);
    if (nextpageRes != null) {
        requested.addAll(nextpageRes);
    }
    if (doc.select(".pagination").size() > 0 && requested != null) {
        Element pagination = doc.select(".pagination").first();
        Elements pages = pagination.select("a");
        for (Element page : pages) {
            if (!page.hasAttr("href")) {
                continue;
            }
            html = httpGet(page.attr("abs:href"), ENCODING);
            doc = Jsoup.parse(html);
            doc.setBaseUri(opac_url);
            nextpageRes = parse_reslist(doc);
            if (nextpageRes != null) {
                requested.addAll(nextpageRes);
            }
        }
    }
    // Ordered media ("Bestellungen")
    html = httpGet(opac_url + "/userAccount.do?methodToCall=showAccount&accountTyp=ordered", ENCODING);
    doc = Jsoup.parse(html);
    doc.setBaseUri(opac_url);
    List<ReservedItem> nextpageOrd = parse_reslist(doc);
    if (nextpageOrd != null) {
        requested.addAll(nextpageOrd);
    }
    if (doc.select(".pagination").size() > 0 && requested != null) {
        Element pagination = doc.select(".pagination").first();
        Elements pages = pagination.select("a");
        for (Element page : pages) {
            if (!page.hasAttr("href")) {
                continue;
            }
            html = httpGet(page.attr("abs:href"), ENCODING);
            doc = Jsoup.parse(html);
            doc.setBaseUri(opac_url);
            nextpageOrd = parse_reslist(doc);
            if (nextpageOrd != null) {
                requested.addAll(nextpageOrd);
            }
        }
    }
    adata.setReservations(requested);
    // Fees
    if (doc.select("#fees").size() > 0) {
        String text = doc.select("#fees").first().text().trim();
        if (text.matches("Geb.+hren[^\\(]+\\(([0-9.,]+)[^0-9€A-Z]*(€|EUR|CHF|Fr)\\)")) {
            text = text.replaceAll("Geb.+hren[^\\(]+\\(([0-9.,]+)[^0-9€A-Z]*(€|EUR|CHF|Fr)\\)", "$1 $2");
            adata.setPendingFees(text);
        }
    }
    return adata;
}
Also used : AccountData(de.geeksfactory.opacclient.objects.AccountData) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) LentItem(de.geeksfactory.opacclient.objects.LentItem) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Example 12 with AccountData

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

the class AccountFragment method export.

private void export() {
    if (refreshing) {
        Toast.makeText(getActivity(), R.string.account_no_concurrent, Toast.LENGTH_LONG).show();
        if (!refreshing) {
            refresh();
        }
        return;
    }
    Context ctx = getActivity() != null ? getActivity() : OpacClient.getEmergencyContext();
    AccountDataSource adatasource = new AccountDataSource(ctx);
    AccountData data = adatasource.getCachedAccountData(account);
    LocalDateTime dt = new LocalDateTime(adatasource.getCachedAccountDataTime(account));
    if (data == null)
        return;
    StringBuilder string = new StringBuilder();
    DateTimeFormatter fmt1 = DateTimeFormat.shortDateTime().withLocale(getResources().getConfiguration().locale);
    DateTimeFormatter fmt2 = DateTimeFormat.shortDate().withLocale(getResources().getConfiguration().locale);
    String dateStr = fmt1.print(dt);
    string.append(getResources().getString(R.string.accountdata_export_header, account.getLabel(), dateStr));
    string.append("\n\n");
    string.append(getResources().getString(R.string.lent_head));
    string.append("\n\n");
    for (LentItem item : data.getLent()) {
        appendIfNotEmpty(string, item.getTitle(), R.string.accountdata_title);
        appendIfNotEmpty(string, item.getAuthor(), R.string.accountdata_author);
        appendIfNotEmpty(string, item.getFormat(), R.string.accountdata_format);
        appendIfNotEmpty(string, item.getStatus(), R.string.accountdata_status);
        appendIfNotEmpty(string, item.getBarcode(), R.string.accountdata_lent_barcode);
        if (item.getDeadline() != null) {
            appendIfNotEmpty(string, fmt2.print(item.getDeadline()), R.string.accountdata_lent_deadline);
        }
        appendIfNotEmpty(string, item.getHomeBranch(), R.string.accountdata_lent_home_branch);
        appendIfNotEmpty(string, item.getLendingBranch(), R.string.accountdata_lent_lending_branch);
        string.append("\n");
    }
    if (data.getLent().size() == 0) {
        string.append(getResources().getString(R.string.lent_none));
    }
    string.append(getResources().getString(R.string.reservations_head));
    string.append("\n\n");
    for (ReservedItem item : data.getReservations()) {
        appendIfNotEmpty(string, item.getTitle(), R.string.accountdata_title);
        appendIfNotEmpty(string, item.getAuthor(), R.string.accountdata_author);
        appendIfNotEmpty(string, item.getFormat(), R.string.accountdata_format);
        appendIfNotEmpty(string, item.getStatus(), R.string.accountdata_status);
        if (item.getReadyDate() != null) {
            appendIfNotEmpty(string, fmt2.print(item.getReadyDate()), R.string.accountdata_reserved_ready_date);
        }
        if (item.getExpirationDate() != null) {
            appendIfNotEmpty(string, fmt2.print(item.getExpirationDate()), R.string.accountdata_reserved_expiration_date);
        }
        appendIfNotEmpty(string, item.getBranch(), R.string.accountdata_reserved_branch);
        string.append("\n");
    }
    if (data.getReservations().size() == 0) {
        string.append(getResources().getString(R.string.reservations_none));
    }
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, string.toString());
    sendIntent.setType("text/plain");
    startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.share_dialog_select)));
}
Also used : Context(android.content.Context) LocalDateTime(org.joda.time.LocalDateTime) AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) AccountData(de.geeksfactory.opacclient.objects.AccountData) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) Intent(android.content.Intent) LentItem(de.geeksfactory.opacclient.objects.LentItem) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 13 with AccountData

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

the class ZonesAccountTest method testParseSummary.

@Test
public void testParseSummary() throws OpacApi.OpacErrorException {
    String html = readResource("/zones/summary/" + file);
    // we may not have all files for all libraries
    if (html == null)
        return;
    AccountData adata = new AccountData(0);
    Zones.AccountLinks links = new Zones.AccountLinks(Jsoup.parse(html), adata);
    assertEquals("https://katalog.stbib-koeln.de/alswww2" + ".dll/APS_ZONES?fn=MyLoans&Style=Portal3&SubStyle=&Lang=GER" + "&ResponseEncoding=utf-8", links.getLentLink());
    assertEquals("https://katalog.stbib-koeln.de/alswww2" + ".dll/APS_ZONES?fn=MyReservations&PageSize=10&Style=Portal3&SubStyle" + "=&Lang=GER&ResponseEncoding=utf-8", links.getResLink());
    assertEquals("€ 0,00", adata.getPendingFees());
    assertEquals("22/04/2017", adata.getValidUntil());
}
Also used : AccountData(de.geeksfactory.opacclient.objects.AccountData) Test(org.junit.Test)

Example 14 with AccountData

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

the class BiBer1992AccountTest method testParseMediaList.

@Test
public void testParseMediaList() throws OpacApi.OpacErrorException, JSONException {
    String html = readResource("/biber1992/medialist/" + file);
    // we may not have all files for all libraries
    if (html == null)
        return;
    List<LentItem> media = BiBer1992.parseMediaList(new AccountData(0), new Account(), Jsoup.parse(html), new JSONObject(), reportHandler, new JSONObject(readResource("/biber1992/headers_lent.json")));
    assertTrue(media.size() > 0);
    for (LentItem item : media) {
        assertNotNull(item.getDeadline());
        // sensible dates
        assertTrue(item.getDeadline().isAfter(new LocalDate(2010, 1, 1)));
        assertNotNull(item.getId());
    }
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) JSONObject(org.json.JSONObject) AccountData(de.geeksfactory.opacclient.objects.AccountData) LentItem(de.geeksfactory.opacclient.objects.LentItem) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

Example 15 with AccountData

use of de.geeksfactory.opacclient.objects.AccountData 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)

Aggregations

AccountData (de.geeksfactory.opacclient.objects.AccountData)19 LentItem (de.geeksfactory.opacclient.objects.LentItem)14 ReservedItem (de.geeksfactory.opacclient.objects.ReservedItem)13 ArrayList (java.util.ArrayList)10 Document (org.jsoup.nodes.Document)9 Element (org.jsoup.nodes.Element)7 JSONObject (org.json.JSONObject)5 Account (de.geeksfactory.opacclient.objects.Account)4 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)4 Test (org.junit.Test)4 NotReachableException (de.geeksfactory.opacclient.networking.NotReachableException)3 Elements (org.jsoup.select.Elements)3 HashMap (java.util.HashMap)2 Pattern (java.util.regex.Pattern)2 NameValuePair (org.apache.http.NameValuePair)2 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)2 LocalDate (org.joda.time.LocalDate)2 Context (android.content.Context)1 Intent (android.content.Intent)1 Cursor (android.database.Cursor)1