Search in sources :

Example 1 with Volume

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

the class VolumesAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    final Volume volume = volumes.get(position);
    holder.tvTitle.setText(volume.getTitle());
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(context, SearchResultDetailActivity.class);
            intent.putExtra(SearchResultDetailFragment.ARG_ITEM_ID, volume.getId());
            intent.putExtra("from_collection", true);
            context.startActivity(intent);
        }
    });
}
Also used : Volume(de.geeksfactory.opacclient.objects.Volume) Intent(android.content.Intent) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Example 2 with Volume

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

the class VuFindSearchTest method testParseDetail.

@Test
public void testParseDetail() throws OpacApi.OpacErrorException, JSONException, NotReachableException {
    String html = readResource("/vufind/result_detail/" + file);
    // we may not have all files for all libraries
    if (html == null)
        return;
    DetailedItem result = VuFind.parseDetail("0", Jsoup.parse(html), getData(file));
    for (Copy copy : result.getCopies()) {
        assertContainsData(copy.getStatus());
        assertNullOrNotEmpty(copy.getBarcode());
        assertNullOrNotEmpty(copy.getBranch());
        assertNullOrNotEmpty(copy.getDepartment());
        assertNullOrNotEmpty(copy.getLocation());
        assertNullOrNotEmpty(copy.getReservations());
        assertNullOrNotEmpty(copy.getShelfmark());
        assertNullOrNotEmpty(copy.getUrl());
        if (copy.getStatus().equals("Entliehen"))
            assertNotNull(copy.getReturnDate());
    }
    for (Volume volume : result.getVolumes()) {
        assertContainsData(volume.getId());
        assertContainsData(volume.getTitle());
    }
    assertEquals(result.getTitle(), getDetailTitle(file));
}
Also used : Copy(de.geeksfactory.opacclient.objects.Copy) Volume(de.geeksfactory.opacclient.objects.Volume) DetailedItem(de.geeksfactory.opacclient.objects.DetailedItem) Test(org.junit.Test)

Example 3 with Volume

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

the class Bibliotheca method parseResult.

static DetailedItem parseResult(String html, JSONObject data) {
    Document doc = Jsoup.parse(html);
    doc.setBaseUri(data.optString("baseurl"));
    DetailedItem result = new DetailedItem();
    if (doc.select(".detail_cover img").size() == 1) {
        result.setCover(doc.select(".detail_cover img").get(0).attr("src"));
    }
    result.setTitle(doc.select(".detail_titel").text());
    Elements detailtrs = doc.select(".detailzeile table tr");
    for (int i = 0; i < detailtrs.size(); i++) {
        Element tr = detailtrs.get(i);
        if (tr.child(0).hasClass("detail_feld")) {
            String title = tr.child(0).text();
            String content = tr.child(1).text();
            if (title.equals("Gesamtwerk:") || title.equals("Erschienen in:")) {
                try {
                    if (tr.child(1).select("a").size() > 0) {
                        Element link = tr.child(1).select("a").first();
                        List<NameValuePair> query = URLEncodedUtils.parse(new URI(link.absUrl("href")), "UTF-8");
                        for (NameValuePair q : query) {
                            if (q.getName().equals("MedienNr")) {
                                result.setCollectionId(q.getValue());
                            }
                        }
                    }
                } catch (URISyntaxException e) {
                }
            } else {
                if (content.contains("hier klicken") && tr.child(1).select("a").size() > 0) {
                    content += " " + tr.child(1).select("a").first().attr("href");
                }
                result.addDetail(new Detail(title, content));
            }
        }
    }
    Elements detailcenterlinks = doc.select(".detailzeile_center a.detail_link");
    for (int i = 0; i < detailcenterlinks.size(); i++) {
        Element a = detailcenterlinks.get(i);
        result.addDetail(new Detail(a.text().trim(), a.absUrl("href")));
    }
    try {
        JSONObject copymap = new JSONObject();
        if (data.has("copiestable")) {
            copymap = data.getJSONObject("copiestable");
        } else {
            Elements ths = doc.select(".exemplartab .exemplarmenubar th");
            for (int i = 0; i < ths.size(); i++) {
                Element th = ths.get(i);
                String head = th.text().trim();
                if (head.equals("Zweigstelle")) {
                    copymap.put("branch", i);
                } else if (head.equals("Abteilung")) {
                    copymap.put("department", i);
                } else if (head.equals("Bereich") || head.equals("Standort")) {
                    copymap.put("location", i);
                } else if (head.equals("Signatur")) {
                    copymap.put("signature", i);
                } else if (head.equals("Barcode") || head.equals("Medien-Nummer")) {
                    copymap.put("barcode", i);
                } else if (head.equals("Status")) {
                    copymap.put("status", i);
                } else if (head.equals("Frist") || head.matches("Verf.+gbar")) {
                    copymap.put("returndate", i);
                } else if (head.equals("Vorbestellungen") || head.equals("Reservierungen")) {
                    copymap.put("reservations", i);
                }
            }
        }
        Elements exemplartrs = doc.select(".exemplartab .tabExemplar, .exemplartab .tabExemplar_");
        DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN);
        for (int i = 0; i < exemplartrs.size(); i++) {
            Element tr = exemplartrs.get(i);
            Copy copy = new Copy();
            Iterator<?> keys = copymap.keys();
            while (keys.hasNext()) {
                String key = (String) keys.next();
                int index;
                try {
                    index = copymap.has(key) ? copymap.getInt(key) : -1;
                } catch (JSONException e1) {
                    index = -1;
                }
                if (index >= 0) {
                    try {
                        copy.set(key, tr.child(index).text(), fmt);
                    } catch (IllegalArgumentException e) {
                        e.printStackTrace();
                    }
                }
            }
            result.addCopy(copy);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        Elements bandtrs = doc.select("table .tabBand a");
        for (int i = 0; i < bandtrs.size(); i++) {
            Element tr = bandtrs.get(i);
            Volume volume = new Volume();
            volume.setId(tr.attr("href").split("=")[1]);
            volume.setTitle(tr.text());
            result.addVolume(volume);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (doc.select(".detail_vorbest a").size() == 1) {
        result.setReservable(true);
        result.setReservation_info(doc.select(".detail_vorbest a").attr("href"));
    }
    return result;
}
Also used : NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) Element(org.jsoup.nodes.Element) JSONException(org.json.JSONException) URISyntaxException(java.net.URISyntaxException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) JSONException(org.json.JSONException) NotReachableException(de.geeksfactory.opacclient.networking.NotReachableException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) JSONObject(org.json.JSONObject) Copy(de.geeksfactory.opacclient.objects.Copy) Volume(de.geeksfactory.opacclient.objects.Volume) DetailedItem(de.geeksfactory.opacclient.objects.DetailedItem) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Detail(de.geeksfactory.opacclient.objects.Detail)

Example 4 with Volume

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

the class VuFind method parseVolumes.

private static void parseVolumes(DetailedItem res, Document doc, JSONObject data) {
    // only tested in Münster
    // e.g. https://www.stadt-muenster.de/opac2/Record/0900944
    Element table = doc.select(".recordsubcontent, .tab-container").first().select("table").first();
    for (Element link : table.select("tr a")) {
        Volume volume = new Volume();
        Matcher matcher = idPattern.matcher(link.attr("href"));
        if (matcher.find())
            volume.setId(matcher.group(1));
        volume.setTitle(link.text());
        res.addVolume(volume);
    }
}
Also used : Volume(de.geeksfactory.opacclient.objects.Volume) Matcher(java.util.regex.Matcher) Element(org.jsoup.nodes.Element)

Example 5 with Volume

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

the class SISISSearchTest method testParseDetail.

@Test
public void testParseDetail() throws OpacApi.OpacErrorException, JSONException, IOException {
    String html1 = readResource("/sisis/result_detail/" + file.replace(".html", "_1.html"));
    String html2 = readResource("/sisis/result_detail/" + file.replace(".html", "_2.html"));
    String html3 = readResource("/sisis/result_detail/" + file.replace(".html", "_3.html"));
    String coverJs = readResource("/sisis/result_detail/" + file.replace(".html", ".js"));
    if (html1 == null || html2 == null || html3 == null) {
        // we may not have all files for all libraries
        return;
    }
    DetailedItem result = SISIS.parseDetail(html1, html2, html3, coverJs, new JSONObject(), new DummyStringProvider());
    assertTrue(result.getCopies().size() > 0);
    for (Copy copy : result.getCopies()) {
        assertContainsData(copy.getStatus());
        assertNullOrNotEmpty(copy.getBarcode());
        assertNullOrNotEmpty(copy.getBranch());
        assertNullOrNotEmpty(copy.getDepartment());
        assertNullOrNotEmpty(copy.getLocation());
        assertNullOrNotEmpty(copy.getReservations());
        assertNullOrNotEmpty(copy.getShelfmark());
        assertNullOrNotEmpty(copy.getUrl());
        if (copy.getStatus().equals("Entliehen"))
            assertNotNull(copy.getReturnDate());
    }
    for (Volume volume : result.getVolumes()) {
        assertContainsData(volume.getId());
        assertContainsData(volume.getTitle());
    }
    assertEquals(result.getTitle(), getDetailTitle(file));
    if (file.equals("berlin_htw.html")) {
        assertTrue(result.getDetails().contains(new Detail("Signatur:", "15/2322")));
        assertNotNull(result.getCover());
    }
}
Also used : DummyStringProvider(de.geeksfactory.opacclient.i18n.DummyStringProvider) JSONObject(org.json.JSONObject) Copy(de.geeksfactory.opacclient.objects.Copy) Volume(de.geeksfactory.opacclient.objects.Volume) DetailedItem(de.geeksfactory.opacclient.objects.DetailedItem) Detail(de.geeksfactory.opacclient.objects.Detail) Test(org.junit.Test)

Aggregations

Volume (de.geeksfactory.opacclient.objects.Volume)6 Copy (de.geeksfactory.opacclient.objects.Copy)4 DetailedItem (de.geeksfactory.opacclient.objects.DetailedItem)4 Detail (de.geeksfactory.opacclient.objects.Detail)3 JSONObject (org.json.JSONObject)3 Element (org.jsoup.nodes.Element)3 IOException (java.io.IOException)2 Matcher (java.util.regex.Matcher)2 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)2 JSONException (org.json.JSONException)2 Elements (org.jsoup.select.Elements)2 Test (org.junit.Test)2 Intent (android.content.Intent)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 TextView (android.widget.TextView)1 DummyStringProvider (de.geeksfactory.opacclient.i18n.DummyStringProvider)1 NotReachableException (de.geeksfactory.opacclient.networking.NotReachableException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1