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();
}
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);
}
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);
}
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;
}
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;
}
}
Aggregations