use of de.geeksfactory.opacclient.objects.ReservedItem in project opacclient by opacapp.
the class AccountDataSource method storeCachedAccountData.
public void storeCachedAccountData(Account account, AccountData adata) {
if (adata == null) {
return;
}
long time = System.currentTimeMillis();
ContentValues update = new ContentValues();
update.put("cached", time);
update.put("pendingFees", adata.getPendingFees());
update.put("validUntil", adata.getValidUntil());
update.put("warning", adata.getWarning());
database.update(AccountDatabase.TABLENAME_ACCOUNTS, update, "id = ?", new String[] { "" + account.getId() });
database.delete(AccountDatabase.TABLENAME_LENT, "account = ?", new String[] { "" + account.getId() });
for (LentItem entry : adata.getLent()) {
ContentValues insertmapping = lentItemToContentValues(entry, account.getId());
database.insert(AccountDatabase.TABLENAME_LENT, null, insertmapping);
}
database.delete(AccountDatabase.TABLENAME_RESERVATION, "account = ?", new String[] { "" + account.getId() });
for (ReservedItem entry : adata.getReservations()) {
ContentValues insertmapping = reservedItemToContentValues(entry, account.getId());
database.insert(AccountDatabase.TABLENAME_RESERVATION, null, insertmapping);
}
}
use of de.geeksfactory.opacclient.objects.ReservedItem in project opacclient by opacapp.
the class PicaOld method account.
@Override
public AccountData account(Account account) throws IOException, JSONException, OpacErrorException {
if (!initialised) {
start();
}
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("ACT", "UI_DATA"));
params.add(new BasicNameValuePair("HOST_NAME", ""));
params.add(new BasicNameValuePair("HOST_PORT", ""));
params.add(new BasicNameValuePair("HOST_SCRIPT", ""));
params.add(new BasicNameValuePair("LOGIN", "KNOWNUSER"));
params.add(new BasicNameValuePair("STATUS", "HML_OK"));
params.add(new BasicNameValuePair("BOR_U", account.getName()));
params.add(new BasicNameValuePair("BOR_PW", account.getPassword()));
String html = httpPost(https_url + "/loan/DB=" + db + "/LNG=" + getLang() + "/USERINFO", new UrlEncodedFormEntity(params, getDefaultEncoding()), getDefaultEncoding());
Document doc = Jsoup.parse(html);
AccountData res = new AccountData(account.getId());
if (doc.select(".cnt .alert, .cnt .error").size() > 0) {
String text = doc.select(".cnt .alert, .cnt .error").text();
if (doc.select("table[summary^=User data]").size() > 0) {
res.setWarning(text);
} else {
throw new OpacErrorException(text);
}
}
// noinspection StatementWithEmptyBody
if (doc.select("input[name=BOR_PW_ENC]").size() > 0) {
pwEncoded = URLEncoder.encode(doc.select("input[name=BOR_PW_ENC]").attr("value"), "UTF-8");
} else {
// TODO: do something here to help fix bug #229
}
html = httpGet(https_url + "/loan/DB=" + db + "/LNG=" + getLang() + "/USERINFO?ACT=UI_LOL&BOR_U=" + account.getName() + "&BOR_PW_ENC=" + pwEncoded, getDefaultEncoding());
doc = Jsoup.parse(html);
html = httpGet(https_url + "/loan/DB=" + db + "/LNG=" + getLang() + "/USERINFO?ACT=UI_LOR&BOR_U=" + account.getName() + "&BOR_PW_ENC=" + pwEncoded, getDefaultEncoding());
Document doc2 = Jsoup.parse(html);
List<LentItem> media = new ArrayList<>();
List<ReservedItem> reserved = new ArrayList<>();
if (doc.select("table[summary^=list]").size() > 0 && !doc.select(".alert").text().contains("Keine Entleihungen") && !doc.select(".alert").text().contains("No outstanding loans") && !doc.select(".alert").text().contains("Geen uitlening") && !doc.select(".alert").text().contains("Aucun emprunt")) {
List<String> renewalCounts = loadRenewalCounts(doc);
parseMediaList(media, doc, stringProvider, renewalCounts);
}
if (doc2.select("table[summary^=list]").size() > 0 && !doc2.select(".alert").text().contains("Keine Vormerkungen") && !doc2.select(".alert").text().contains("No outstanding reservations") && !doc2.select(".alert").text().contains("Geen reservering") && !doc2.select(".alert").text().contains("Aucune réservation")) {
updateLorReservations(doc);
parseResList(reserved, doc2, stringProvider);
}
res.setLent(media);
res.setReservations(reserved);
return res;
}
use of de.geeksfactory.opacclient.objects.ReservedItem in project opacclient by opacapp.
the class PicaOld method parseResList.
static void parseResList(List<ReservedItem> media, Document doc, StringProvider stringProvider) throws OpacErrorException {
Elements copytrs = doc.select("table[summary^=list] > tbody > tr[valign=top]");
int trs = copytrs.size();
if (trs < 1) {
throw new OpacErrorException(stringProvider.getString(StringProvider.COULD_NOT_LOAD_ACCOUNT));
}
assert (trs > 0);
for (Element tr : copytrs) {
ReservedItem item = new ReservedItem();
if (tr.select("table[summary=title data]").size() > 0) {
// Check if there is a checkbox to cancel this item
if (tr.select("input").size() > 0) {
item.setCancelData(tr.select("input").attr("value"));
}
Elements datatrs = tr.select("table[summary=title data] tr");
item.setTitle(datatrs.get(0).text());
List<TextNode> textNodes = datatrs.get(1).select("td").first().textNodes();
List<TextNode> nodes = new ArrayList<>();
Elements titles = datatrs.get(1).select("span.label-small");
for (TextNode node : textNodes) {
if (!node.text().equals(" ")) {
nodes.add(node);
}
}
assert (nodes.size() == titles.size());
for (int j = 0; j < nodes.size(); j++) {
String title = titles.get(j).text();
String value = nodes.get(j).text().trim().replace(";", "");
// noinspection StatementWithEmptyBody
if (title.contains("Signatur") || title.contains("shelf mark") || title.contains("signatuur")) {
// not supported
} else // noinspection StatementWithEmptyBody
if (title.contains("Vormerkdatum")) {
// not supported
}
}
} else {
// like in Kiel
item.setTitle(tr.child(5).text().trim());
item.setStatus(tr.child(17).text().trim());
item.setCancelData(tr.child(1).select("input").attr("value"));
}
media.add(item);
}
assert (media.size() == trs);
}
use of de.geeksfactory.opacclient.objects.ReservedItem in project opacclient by opacapp.
the class TestApi method account.
@Override
public AccountData account(Account account) throws IOException, JSONException, OpacErrorException {
AccountData data = new AccountData(account.getId());
List<LentItem> lent = new ArrayList<>();
List<ReservedItem> reservations = new ArrayList<>();
try {
JSONObject d = new JSONObject(httpGet(library.getData().getString("url"), "UTF-8"));
for (int i = 0; i < d.getJSONArray("lent").length(); i++) {
JSONObject l = d.getJSONArray("lent").getJSONObject(i);
LentItem lentItem = new LentItem();
for (Iterator iter = l.keys(); iter.hasNext(); ) {
String key = (String) iter.next();
lentItem.set(key, l.getString(key));
}
lent.add(lentItem);
}
for (int i = 0; i < d.getJSONArray("reservations").length(); i++) {
JSONObject l = d.getJSONArray("reservations").getJSONObject(i);
ReservedItem resItem = new ReservedItem();
for (Iterator iter = l.keys(); iter.hasNext(); ) {
String key = (String) iter.next();
resItem.set(key, l.getString(key));
}
reservations.add(resItem);
}
} catch (NotReachableException e) {
for (int i = 0; i < 6; i++) {
LentItem lentItem = new LentItem();
lentItem.setAuthor("Max Mustermann");
lentItem.setTitle("Lorem Ipsum");
lentItem.setStatus("hier ist der Status");
lentItem.setDeadline(new LocalDate(1442564454547L));
lentItem.setRenewable(true);
lentItem.setProlongData("foo");
lentItem.setHomeBranch("Meine Zweigstelle");
lentItem.setLendingBranch("Ausleihzweigstelle");
lentItem.setBarcode("Barcode");
lent.add(lentItem);
ReservedItem reservedItem = new ReservedItem();
reservedItem.setAuthor("Max Mustermann");
reservedItem.setTitle("Lorem Ipsum");
reservedItem.setReadyDate(LocalDate.now());
reservations.add(reservedItem);
}
}
data.setLent(lent);
data.setReservations(reservations);
return data;
}
use of de.geeksfactory.opacclient.objects.ReservedItem in project opacclient by opacapp.
the class TouchPoint method parse_reslist.
static List<ReservedItem> parse_reslist(Document doc) {
List<ReservedItem> reservations = new ArrayList<>();
Elements copytrs = doc.select(".data tr, #account-data .table tr");
int trs = copytrs.size();
if (trs <= 1) {
return null;
}
for (int i = 1; i < trs; i++) {
Element tr = copytrs.get(i);
ReservedItem item = new ReservedItem();
if (tr.text().contains("keine Daten") || tr.children().size() == 1) {
return null;
}
item.setTitle(tr.child(2).select("b, strong").text().trim());
try {
String[] rowsplit2 = tr.child(2).html().split("<br[ /]*>");
String[] rowsplit3 = tr.child(3).html().split("<br[ /]*>");
if (rowsplit2.length > 1)
item.setAuthor(rowsplit2[1].replace("</a>", "").trim());
if (rowsplit3.length > 2)
item.setBranch(rowsplit3[2].replace("</a>", "").trim());
if (rowsplit3.length > 2) {
item.setStatus(rowsplit3[0].trim() + " (" + rowsplit3[1].trim() + ")");
}
if (tr.select("a").size() > 0) {
for (Element link : tr.select("a")) {
String href = link.attr("abs:href");
Map<String, String> hrefq = getQueryParamsFirst(href);
if (hrefq.containsKey("q")) {
item.setId(extractIdFromQ(hrefq.get("q")));
} else if ("cancel".equals(hrefq.get("methodToCall"))) {
item.setCancelData(href.split("\\?")[1]);
break;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
reservations.add(item);
}
return reservations;
}
Aggregations