use of de.geeksfactory.opacclient.objects.AccountData in project opacclient by opacapp.
the class BiBer1992 method account.
/*
* (non-Javadoc)
*
* @see
* OpacApi#account(de.geeksfactory.opacclient
* .objects.Account)
*
* POST-format: BENUTZER xxxxxxxxx FUNC medk LANG de PASSWORD ddmmyyyy
*/
@Override
public AccountData account(Account account) throws IOException, JSONException, OpacErrorException {
AccountData res = new AccountData(account.getId());
// get media
List<LentItem> media = accountGetMedia(account, res);
res.setLent(media);
// get reservations
List<ReservedItem> reservations = accountGetReservations(account);
res.setReservations(reservations);
return res;
}
use of de.geeksfactory.opacclient.objects.AccountData in project opacclient by opacapp.
the class SyncAccountJob method syncAccounts.
boolean syncAccounts(OpacClient app, AccountDataSource data, SharedPreferences sp, ReminderHelper helper) {
boolean failed = false;
List<Account> accounts = data.getAccountsWithPassword();
if (!sp.contains("update_151_clear_cache")) {
data.invalidateCachedData();
sp.edit().putBoolean("update_151_clear_cache", true).apply();
}
for (Account account : accounts) {
if (BuildConfig.DEBUG) {
Log.i(TAG, "Loading data for Account " + account.toString());
}
AccountData res;
try {
Library library = app.getLibrary(account.getLibrary());
if (!library.isAccountSupported()) {
data.deleteAccountData(account);
continue;
}
OpacApi api = app.getNewApi(library);
res = api.account(account);
if (res == null) {
failed = true;
continue;
}
} catch (JSONException | IOException | OpacApi.OpacErrorException e) {
e.printStackTrace();
failed = true;
continue;
} catch (OpacClient.LibraryRemovedException e) {
continue;
}
account.setPasswordKnownValid(true);
try {
data.update(account);
data.storeCachedAccountData(account, res);
} finally {
helper.generateAlarms();
}
}
return failed;
}
use of de.geeksfactory.opacclient.objects.AccountData in project opacclient by opacapp.
the class AccountDataSource method getCachedAccountData.
public AccountData getCachedAccountData(Account account) {
AccountData adata = new AccountData(account.getId());
List<LentItem> lent = new ArrayList<>();
String[] selectionArgs = { "" + account.getId() };
Cursor cursor = database.query(AccountDatabase.TABLENAME_LENT, AccountDatabase.COLUMNS_LENT, "account = ?", selectionArgs, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
LentItem entry = cursorToLentItem(cursor);
lent.add(entry);
cursor.moveToNext();
}
cursor.close();
adata.setLent(lent);
List<ReservedItem> res = new ArrayList<>();
cursor = database.query(AccountDatabase.TABLENAME_RESERVATION, AccountDatabase.COLUMNS_RESERVATIONS, "account = ?", selectionArgs, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
ReservedItem entry = cursorToReservedItem(cursor);
res.add(entry);
cursor.moveToNext();
}
cursor.close();
adata.setReservations(res);
String[] selA = { "" + account.getId() };
cursor = database.query("accounts", new String[] { "pendingFees", "validUntil", "warning" }, "id = ?", selA, null, null, null);
cursor.moveToFirst();
if (!cursor.isAfterLast()) {
adata.setPendingFees(cursor.getString(0));
adata.setValidUntil(cursor.getString(1));
adata.setWarning(cursor.getString(2));
cursor.moveToNext();
}
// Make sure to close the cursor
cursor.close();
return adata;
}
use of de.geeksfactory.opacclient.objects.AccountData 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.AccountData 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;
}
Aggregations