Search in sources :

Example 6 with Library

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

the class Main method main.

public static void main(String[] args) throws IOException, JSONException {
    Security.addProvider(new BouncyCastleProvider());
    Collection<String[]> libraries = libraries();
    Set<String> ignored = new MeaningDetectorImpl(null).getIgnoredFields();
    Scanner in = new Scanner(System.in);
    final ExecutorService service = Executors.newFixedThreadPool(25);
    List<TaskInfo> tasks = new ArrayList<>();
    for (String[] libraryNameArray : libraries) {
        String libraryName = libraryNameArray[0];
        Library library;
        try {
            library = Library.fromJSON(libraryName, new JSONObject(readFile(BIBS_DIR + libraryName + ".json")));
            Future<Map<String, List<SearchField>>> future = service.submit(new GetSearchFieldsCallable(library));
            tasks.add(new TaskInfo(library, future));
        } catch (JSONException | IOException e) {
        // e.printStackTrace();
        }
    }
    for (TaskInfo entry : tasks) {
        Library library = entry.lib;
        try {
            Map<String, List<SearchField>> fields = entry.future.get();
            if (fields == null)
                continue;
            for (String lang : fields.keySet()) {
                System.out.println("Bibliothek: " + library.getIdent() + ", Sprache: " + lang);
                MeaningDetectorImpl detector = new MeaningDetectorImpl(library);
                for (int i = 0; i < fields.get(lang).size(); i++) {
                    fields.get(lang).set(i, detector.detectMeaning(fields.get(lang).get(i)));
                }
                for (SearchField field : fields.get(lang)) {
                    if (field.getMeaning() != null || ignored.contains(field.getDisplayName()) || field.getData() != null && field.getData().has("meaning") && ignored.contains(field.getData().getString("meaning")))
                        continue;
                    String name;
                    if (field.getData() != null && field.getData().has("meaning")) {
                        name = field.getData().getString("meaning");
                        System.out.print("Unbekanntes Feld: '" + name + "' (Anzeigename: " + field.getDisplayName() + ") ");
                    } else {
                        name = field.getDisplayName();
                        System.out.print("Unbekanntes Feld: '" + name + "' ");
                    }
                    Meaning meaning = null;
                    boolean ignoredField = false;
                    while (meaning == null && !ignoredField) {
                        String str = in.nextLine();
                        if (str.equals("") || str.toLowerCase().equals("ignore")) {
                            ignoredField = true;
                            addIgnoredField(name);
                            ignored.add(name);
                        } else {
                            try {
                                meaning = Meaning.valueOf(str.toUpperCase());
                            } catch (IllegalArgumentException e) {
                                meaning = null;
                            }
                        }
                    }
                    if (meaning != null) {
                        detector.addMeaning(name, meaning);
                        saveMeaning(name, meaning);
                    }
                }
            }
        } catch (JSONException | IOException | ExecutionException | InterruptedException e) {
            e.printStackTrace();
        }
    }
    in.close();
    service.shutdown();
}
Also used : Scanner(java.util.Scanner) MeaningDetectorImpl(de.geeksfactory.opacclient.searchfields.MeaningDetectorImpl) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) JSONException(org.json.JSONException) IOException(java.io.IOException) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) JSONObject(org.json.JSONObject) ExecutorService(java.util.concurrent.ExecutorService) Library(de.geeksfactory.opacclient.objects.Library) Map(java.util.Map) Meaning(de.geeksfactory.opacclient.searchfields.SearchField.Meaning)

Example 7 with Library

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

the class SyncAccountJobTest method setUp.

@Before
public void setUp() throws Exception {
    app = mock(OpacClient.class);
    sp = mock(SharedPreferences.class);
    data = mock(AccountDataSource.class);
    helper = mock(ReminderHelper.class);
    api1 = mock(OpacApi.class);
    api2 = mock(OpacApi.class);
    service = new SyncAccountJob();
    when(sp.contains("update_151_clear_cache")).thenReturn(true);
    accounts = new ArrayList<>();
    account1 = new Account();
    account1.setId(0);
    account2 = new Account();
    account2.setId(1);
    accounts.add(account1);
    accounts.add(account2);
    library = new Library();
    library.setAccountSupported(true);
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) OpacClient(de.geeksfactory.opacclient.OpacClient) SharedPreferences(android.content.SharedPreferences) OpacApi(de.geeksfactory.opacclient.apis.OpacApi) Library(de.geeksfactory.opacclient.objects.Library) Before(org.junit.Before)

Example 8 with Library

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

the class LibraryConfigUpdateServiceTest method setUp.

@Before
public void setUp() {
    service = mock(WebService.class);
    prefs = mock(PreferenceDataSource.class);
    output = mock(LibraryConfigUpdateService.FileOutput.class);
    searchFields = mock(SearchFieldDataSource.class);
    when(prefs.getLastLibraryConfigUpdate()).thenReturn(LAST_UPDATE);
    when(prefs.getLastLibraryConfigUpdateVersion()).thenReturn(BuildConfig.VERSION_CODE);
    library = new Library();
    library.setIdent(IDENT);
}
Also used : SearchFieldDataSource(de.geeksfactory.opacclient.storage.SearchFieldDataSource) PreferenceDataSource(de.geeksfactory.opacclient.storage.PreferenceDataSource) Library(de.geeksfactory.opacclient.objects.Library) Before(org.junit.Before)

Example 9 with Library

use of de.geeksfactory.opacclient.objects.Library 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 10 with Library

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

the class Utils method getAccountSubtitle.

public static String getAccountSubtitle(Account account, Context context) {
    try {
        OpacClient app = (OpacClient) context.getApplicationContext();
        Library library = app.getLibrary(account.getLibrary());
        if (context.getString(R.string.default_account_name).equals(account.getLabel())) {
            return library.getTitle();
        } else {
            return library.getCity() + " ยท " + library.getTitle();
        }
    } catch (IOException | JSONException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : OpacClient(de.geeksfactory.opacclient.OpacClient) JSONException(org.json.JSONException) Library(de.geeksfactory.opacclient.objects.Library) IOException(java.io.IOException)

Aggregations

Library (de.geeksfactory.opacclient.objects.Library)15 ArrayList (java.util.ArrayList)8 Bundle (android.os.Bundle)6 IOException (java.io.IOException)6 HashSet (java.util.HashSet)6 JSONException (org.json.JSONException)6 OpacClient (de.geeksfactory.opacclient.OpacClient)3 Account (de.geeksfactory.opacclient.objects.Account)3 Collator (java.text.Collator)3 List (java.util.List)3 ArrayAdapter (android.widget.ArrayAdapter)2 OpacApi (de.geeksfactory.opacclient.apis.OpacApi)2 JSONObject (org.json.JSONObject)2 Before (org.junit.Before)2 Activity (android.app.Activity)1 SharedPreferences (android.content.SharedPreferences)1 AssetManager (android.content.res.AssetManager)1 Criteria (android.location.Criteria)1 Location (android.location.Location)1 LocationListener (android.location.LocationListener)1