use of de.geeksfactory.opacclient.objects.DetailedItem in project opacclient by opacapp.
the class SearchResultDetailFragment method reservationPerform.
public void reservationPerform() {
MultiStepResultHelper<DetailedItem> msrhReservation = new MultiStepResultHelper<>(getActivity(), item, R.string.doing_res);
msrhReservation.setCallback(new Callback<DetailedItem>() {
@Override
public void onSuccess(MultiStepResult result) {
AccountDataSource adata = new AccountDataSource(getActivity());
adata.invalidateCachedAccountData(app.getAccount());
if (result.getMessage() != null) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(result.getMessage()).setCancelable(false).setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}).setPositiveButton(R.string.account, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent(getActivity(), app.getMainActivity());
intent.putExtra(MainActivity.EXTRA_FRAGMENT, "account");
getActivity().startActivity(intent);
getActivity().finish();
}
});
AlertDialog alert = builder.create();
alert.show();
} else {
Intent intent = new Intent(getActivity(), app.getMainActivity());
intent.putExtra(MainActivity.EXTRA_FRAGMENT, "account");
getActivity().startActivity(intent);
getActivity().finish();
}
}
@Override
public void onError(MultiStepResult result) {
dialog_wrong_credentials(result.getMessage(), false);
}
@Override
public void onUnhandledResult(MultiStepResult result) {
}
@Override
public void onUserCancel() {
}
@Override
public StepTask<?> newTask(MultiStepResultHelper helper, int useraction, String selection, DetailedItem item) {
return new ResTask(helper, useraction, selection, item);
}
});
msrhReservation.start();
}
use of de.geeksfactory.opacclient.objects.DetailedItem in project opacclient by opacapp.
the class AccountFragment method bookingStart.
public void bookingStart(String booking_info) {
long age = System.currentTimeMillis() - refreshtime;
if (refreshing || fromcache || age > MAX_CACHE_AGE) {
Toast.makeText(getActivity(), R.string.account_no_concurrent, Toast.LENGTH_LONG).show();
if (!refreshing) {
refresh();
}
return;
}
DetailedItem item = new DetailedItem();
item.setBookable(true);
item.setBooking_info(booking_info);
MultiStepResultHelper<DetailedItem> msrhBooking = new MultiStepResultHelper<>(getActivity(), item, R.string.doing_booking);
msrhBooking.setCallback(new Callback<DetailedItem>() {
@Override
public void onSuccess(MultiStepResult result) {
invalidateData();
}
@Override
public void onError(MultiStepResult result) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(result.getMessage()).setCancelable(true).setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int id) {
d.cancel();
}
}).setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface d) {
if (d != null) {
d.cancel();
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
@Override
public void onUnhandledResult(MultiStepResult result) {
}
@Override
public void onUserCancel() {
}
@Override
public StepTask<?> newTask(MultiStepResultHelper helper, int useraction, String selection, DetailedItem argument) {
return new BookingTask(helper, useraction, selection, argument);
}
});
msrhBooking.start();
}
use of de.geeksfactory.opacclient.objects.DetailedItem in project opacclient by opacapp.
the class VuFindSearchTest method testParseDetail.
@Test
public void testParseDetail() throws OpacApi.OpacErrorException, JSONException, NotReachableException {
String html = readResource("/vufind/result_detail/" + file);
// we may not have all files for all libraries
if (html == null)
return;
DetailedItem result = VuFind.parseDetail("0", Jsoup.parse(html), getData(file));
for (Copy copy : result.getCopies()) {
assertContainsData(copy.getStatus());
assertNullOrNotEmpty(copy.getBarcode());
assertNullOrNotEmpty(copy.getBranch());
assertNullOrNotEmpty(copy.getDepartment());
assertNullOrNotEmpty(copy.getLocation());
assertNullOrNotEmpty(copy.getReservations());
assertNullOrNotEmpty(copy.getShelfmark());
assertNullOrNotEmpty(copy.getUrl());
if (copy.getStatus().equals("Entliehen"))
assertNotNull(copy.getReturnDate());
}
for (Volume volume : result.getVolumes()) {
assertContainsData(volume.getId());
assertContainsData(volume.getTitle());
}
assertEquals(result.getTitle(), getDetailTitle(file));
}
use of de.geeksfactory.opacclient.objects.DetailedItem in project opacclient by opacapp.
the class BibliothecaSearchTest method testParseResult.
@Test
public void testParseResult() throws OpacApi.OpacErrorException, JSONException, NotReachableException {
String html = readResource("/bibliotheca/result_detail/" + file);
// we may not have all files for all libraries
if (html == null)
return;
DetailedItem result = Bibliotheca.parseResult(html, getData(file));
for (Copy copy : result.getCopies()) {
assertContainsData(copy.getStatus());
assertNullOrNotEmpty(copy.getBarcode());
assertNullOrNotEmpty(copy.getBranch());
assertNullOrNotEmpty(copy.getDepartment());
assertNullOrNotEmpty(copy.getLocation());
assertNullOrNotEmpty(copy.getReservations());
assertNullOrNotEmpty(copy.getShelfmark());
assertNullOrNotEmpty(copy.getUrl());
if (copy.getStatus().equals("Entliehen"))
assertNotNull(copy.getReturnDate());
}
assertContainsData(result.getReservation_info());
assertEquals(result.getTitle(), getDetailTitle(file));
}
use of de.geeksfactory.opacclient.objects.DetailedItem in project opacclient by opacapp.
the class Bibliotheca method parseResult.
static DetailedItem parseResult(String html, JSONObject data) {
Document doc = Jsoup.parse(html);
doc.setBaseUri(data.optString("baseurl"));
DetailedItem result = new DetailedItem();
if (doc.select(".detail_cover img").size() == 1) {
result.setCover(doc.select(".detail_cover img").get(0).attr("src"));
}
result.setTitle(doc.select(".detail_titel").text());
Elements detailtrs = doc.select(".detailzeile table tr");
for (int i = 0; i < detailtrs.size(); i++) {
Element tr = detailtrs.get(i);
if (tr.child(0).hasClass("detail_feld")) {
String title = tr.child(0).text();
String content = tr.child(1).text();
if (title.equals("Gesamtwerk:") || title.equals("Erschienen in:")) {
try {
if (tr.child(1).select("a").size() > 0) {
Element link = tr.child(1).select("a").first();
List<NameValuePair> query = URLEncodedUtils.parse(new URI(link.absUrl("href")), "UTF-8");
for (NameValuePair q : query) {
if (q.getName().equals("MedienNr")) {
result.setCollectionId(q.getValue());
}
}
}
} catch (URISyntaxException e) {
}
} else {
if (content.contains("hier klicken") && tr.child(1).select("a").size() > 0) {
content += " " + tr.child(1).select("a").first().attr("href");
}
result.addDetail(new Detail(title, content));
}
}
}
Elements detailcenterlinks = doc.select(".detailzeile_center a.detail_link");
for (int i = 0; i < detailcenterlinks.size(); i++) {
Element a = detailcenterlinks.get(i);
result.addDetail(new Detail(a.text().trim(), a.absUrl("href")));
}
try {
JSONObject copymap = new JSONObject();
if (data.has("copiestable")) {
copymap = data.getJSONObject("copiestable");
} else {
Elements ths = doc.select(".exemplartab .exemplarmenubar th");
for (int i = 0; i < ths.size(); i++) {
Element th = ths.get(i);
String head = th.text().trim();
if (head.equals("Zweigstelle")) {
copymap.put("branch", i);
} else if (head.equals("Abteilung")) {
copymap.put("department", i);
} else if (head.equals("Bereich") || head.equals("Standort")) {
copymap.put("location", i);
} else if (head.equals("Signatur")) {
copymap.put("signature", i);
} else if (head.equals("Barcode") || head.equals("Medien-Nummer")) {
copymap.put("barcode", i);
} else if (head.equals("Status")) {
copymap.put("status", i);
} else if (head.equals("Frist") || head.matches("Verf.+gbar")) {
copymap.put("returndate", i);
} else if (head.equals("Vorbestellungen") || head.equals("Reservierungen")) {
copymap.put("reservations", i);
}
}
}
Elements exemplartrs = doc.select(".exemplartab .tabExemplar, .exemplartab .tabExemplar_");
DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN);
for (int i = 0; i < exemplartrs.size(); i++) {
Element tr = exemplartrs.get(i);
Copy copy = new Copy();
Iterator<?> keys = copymap.keys();
while (keys.hasNext()) {
String key = (String) keys.next();
int index;
try {
index = copymap.has(key) ? copymap.getInt(key) : -1;
} catch (JSONException e1) {
index = -1;
}
if (index >= 0) {
try {
copy.set(key, tr.child(index).text(), fmt);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
}
result.addCopy(copy);
}
} catch (Exception e) {
e.printStackTrace();
}
try {
Elements bandtrs = doc.select("table .tabBand a");
for (int i = 0; i < bandtrs.size(); i++) {
Element tr = bandtrs.get(i);
Volume volume = new Volume();
volume.setId(tr.attr("href").split("=")[1]);
volume.setTitle(tr.text());
result.addVolume(volume);
}
} catch (Exception e) {
e.printStackTrace();
}
if (doc.select(".detail_vorbest a").size() == 1) {
result.setReservable(true);
result.setReservation_info(doc.select(".detail_vorbest a").attr("href"));
}
return result;
}
Aggregations