use of de.geeksfactory.opacclient.objects.LentItem in project opacclient by opacapp.
the class ZonesAccountTest method testParseMediaList.
@Test
public void testParseMediaList() throws OpacApi.OpacErrorException {
String html = readResource("/zones/medialist/" + file);
// we may not have all files for all libraries
if (html == null)
return;
List<LentItem> media = Zones.parseMediaList(Jsoup.parse(html));
assertTrue(media.size() > 0);
for (LentItem item : media) {
assertNotNull(item.getTitle());
assertNotNull(item.getDeadline());
}
}
use of de.geeksfactory.opacclient.objects.LentItem 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());
}
}
use of de.geeksfactory.opacclient.objects.LentItem in project opacclient by opacapp.
the class BibliothecaAccountTest method testParseMediaList.
@Test
public void testParseMediaList() throws OpacApi.OpacErrorException, JSONException, NotReachableException {
String html = readResource("/bibliotheca/account/" + file);
// we may not have all files for all libraries
if (html == null)
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.getLent().size() > 0);
for (LentItem item : data.getLent()) {
assertContainsData(item.getTitle());
assertNullOrNotEmpty(item.getAuthor());
assertNotNull(item.getProlongData());
assertNotNull(item.getDeadline());
}
}
use of de.geeksfactory.opacclient.objects.LentItem in project opacclient by opacapp.
the class PicaOldAccountTest method testParseMediaList.
@Test
public void testParseMediaList() throws OpacApi.OpacErrorException {
String html = readResource("/pica_old/medialist/" + file);
// we may not have all files for all libraries
if (html == null)
return;
List<LentItem> media = new ArrayList<>();
PicaOld.parseMediaList(media, Jsoup.parse(html), new DummyStringProvider(), new ArrayList<String>());
assertTrue(media.size() > 0);
for (LentItem item : media) {
assertNotNull(item.getTitle());
assertNotNull(item.getDeadline());
}
}
use of de.geeksfactory.opacclient.objects.LentItem in project opacclient by opacapp.
the class Bibliotheca method parse_account.
public static AccountData parse_account(Account acc, Document doc, JSONObject data, ReportHandler reportHandler, JSONObject headers_lent, JSONObject headers_reservations) throws JSONException, NotReachableException {
if (doc.select(".kontozeile_center table").size() == 0) {
throw new NotReachableException();
}
Map<String, Integer> copymap = new HashMap<>();
Elements headerCells = doc.select(".kontozeile_center table").get(0).select("tr.exemplarmenubar").get(0).children();
JSONArray headersList = new JSONArray();
JSONArray unknownHeaders = new JSONArray();
int i = 0;
for (Element headerCell : headerCells) {
String header = headerCell.text();
headersList.put(header);
if (headers_lent.has(header)) {
if (!headers_lent.isNull(header))
copymap.put(headers_lent.getString(header), i);
} else {
unknownHeaders.put(header);
}
i++;
}
if (unknownHeaders.length() > 0) {
// send report
JSONObject reportData = new JSONObject();
reportData.put("headers", headersList);
reportData.put("unknown_headers", unknownHeaders);
Report report = new Report(acc.getLibrary(), "bibliotheca", "unknown header - lent", DateTime.now(), reportData);
reportHandler.sendReport(report);
// fallback to JSON
JSONObject accounttable = data.getJSONObject("accounttable");
copymap = jsonToMap(accounttable);
}
List<LentItem> media = new ArrayList<>();
Elements exemplartrs = doc.select(".kontozeile_center table").get(0).select("tr.tabKonto");
DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN);
DateTimeFormatter fmt2 = DateTimeFormat.forPattern("d/M/yyyy").withLocale(Locale.GERMAN);
for (Element tr : exemplartrs) {
LentItem item = new LentItem();
for (Entry<String, Integer> entry : copymap.entrySet()) {
String key = entry.getKey();
int index = entry.getValue();
if (key.equals("prolongurl")) {
if (tr.child(index).children().size() > 0) {
item.setProlongData(tr.child(index).child(0).attr("href"));
item.setRenewable(!tr.child(index).child(0).attr("href").contains("vermsg"));
}
} else if (key.equals("returndate")) {
try {
item.setDeadline(fmt.parseLocalDate(tr.child(index).text()));
} catch (IllegalArgumentException e1) {
try {
item.setDeadline(fmt2.parseLocalDate(tr.child(index).text()));
} catch (IllegalArgumentException e2) {
e2.printStackTrace();
}
}
} else {
item.set(key, tr.child(index).text());
}
}
media.add(item);
}
copymap = new HashMap<>();
headerCells = doc.select(".kontozeile_center table").get(1).select("tr.exemplarmenubar").get(0).children();
headersList = new JSONArray();
unknownHeaders = new JSONArray();
i = 0;
for (Element headerCell : headerCells) {
String header = headerCell.text();
headersList.put(header);
if (headers_reservations.has(header)) {
if (!headers_reservations.isNull(header)) {
copymap.put(headers_reservations.getString(header), i);
}
} else {
unknownHeaders.put(header);
}
i++;
}
if (unknownHeaders.length() > 0) {
// send report
JSONObject reportData = new JSONObject();
reportData.put("headers", headersList);
reportData.put("unknown_headers", unknownHeaders);
Report report = new Report(acc.getLibrary(), "bibliotheca", "unknown header - reservations", DateTime.now(), reportData);
reportHandler.sendReport(report);
// fallback to JSON
JSONObject reservationtable = data.getJSONObject("reservationtable");
copymap = jsonToMap(reservationtable);
}
List<ReservedItem> reservations = new ArrayList<>();
exemplartrs = doc.select(".kontozeile_center table").get(1).select("tr.tabKonto");
for (Element tr : exemplartrs) {
ReservedItem item = new ReservedItem();
for (Entry<String, Integer> entry : copymap.entrySet()) {
String key = entry.getKey();
int index = entry.getValue();
if (key.equals("cancelurl")) {
if (tr.child(index).children().size() > 0) {
item.setCancelData(tr.child(index).child(0).attr("href"));
}
} else if (key.equals("availability")) {
try {
item.setReadyDate(fmt.parseLocalDate(tr.child(index).text()));
} catch (IllegalArgumentException e1) {
try {
item.setReadyDate(fmt2.parseLocalDate(tr.child(index).text()));
} catch (IllegalArgumentException e2) {
e2.printStackTrace();
}
}
} else if (key.equals("expirationdate")) {
try {
item.setExpirationDate(fmt.parseLocalDate(tr.child(index).text()));
} catch (IllegalArgumentException e1) {
try {
item.setExpirationDate(fmt2.parseLocalDate(tr.child(index).text()));
} catch (IllegalArgumentException e2) {
item.setStatus(tr.child(index).text());
}
}
} else {
item.set(key, tr.child(index).text());
}
}
reservations.add(item);
}
AccountData res = new AccountData(acc.getId());
for (Element row : doc.select(".kontozeile_center, div[align=center]")) {
String text = row.text().trim();
if (text.matches(".*Ausstehende Geb.+hren:[^0-9]+([0-9.,]+)[^0-9€A-Z]*(€|EUR|CHF|Fr.).*")) {
text = text.replaceAll(".*Ausstehende Geb.+hren:[^0-9]+([0-9.," + "]+)[^0-9€A-Z]*(€|EUR|CHF|Fr.).*", "$1 $2");
res.setPendingFees(text);
}
if (text.matches("Ihr Ausweis ist g.ltig bis:.*")) {
text = text.replaceAll("Ihr Ausweis ist g.ltig bis:[^A-Za-z0-9]+", "");
res.setValidUntil(text);
} else if (text.matches("Ausweis g.ltig bis:.*")) {
text = text.replaceAll("Ausweis g.ltig bis:[^A-Za-z0-9]+", "");
res.setValidUntil(text);
}
}
res.setLent(media);
res.setReservations(reservations);
return res;
}
Aggregations