Search in sources :

Example 6 with AccountData

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;
}
Also used : AccountData(de.geeksfactory.opacclient.objects.AccountData) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) LentItem(de.geeksfactory.opacclient.objects.LentItem)

Example 7 with AccountData

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;
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) OpacClient(de.geeksfactory.opacclient.OpacClient) AccountData(de.geeksfactory.opacclient.objects.AccountData) OpacApi(de.geeksfactory.opacclient.apis.OpacApi) JSONException(org.json.JSONException) Library(de.geeksfactory.opacclient.objects.Library) IOException(java.io.IOException)

Example 8 with AccountData

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;
}
Also used : AccountData(de.geeksfactory.opacclient.objects.AccountData) ArrayList(java.util.ArrayList) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) LentItem(de.geeksfactory.opacclient.objects.LentItem) Cursor(android.database.Cursor)

Example 9 with AccountData

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;
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) ArrayList(java.util.ArrayList) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) Document(org.jsoup.nodes.Document) AccountData(de.geeksfactory.opacclient.objects.AccountData) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) LentItem(de.geeksfactory.opacclient.objects.LentItem)

Example 10 with AccountData

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;
}
Also used : JSONObject(org.json.JSONObject) AccountData(de.geeksfactory.opacclient.objects.AccountData) NotReachableException(de.geeksfactory.opacclient.networking.NotReachableException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ReservedItem(de.geeksfactory.opacclient.objects.ReservedItem) LentItem(de.geeksfactory.opacclient.objects.LentItem) LocalDate(org.joda.time.LocalDate)

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