use of org.folio.circulation.domain.LastCheckIn in project mod-circulation by folio-org.
the class ItemsInTransitReport method buildEntry.
private JsonObject buildEntry(Item item) {
if (item == null || item.isNotFound()) {
return new JsonObject();
}
item = ofNullable(item.getHoldingsRecordId()).map(reportContext.getHoldingsRecords()::get).map(Holdings::getInstanceId).map(reportContext.getInstances()::get).map(item::withInstance).orElse(item);
Loan loan = reportContext.getLoans().get(item.getItemId());
Request request = reportContext.getRequests().get(item.getItemId());
Location location = reportContext.getLocations().get(item.getLocationId());
if (location != null) {
ServicePoint primaryServicePoint = reportContext.getServicePoints().get(location.getPrimaryServicePointId().toString());
item = item.withLocation(location.withPrimaryServicePoint(primaryServicePoint));
}
ServicePoint inTransitDestinationServicePoint = reportContext.getServicePoints().get(item.getInTransitDestinationServicePointId());
ServicePoint lastCheckInServicePoint = reportContext.getServicePoints().get(item.getLastCheckInServicePointId().toString());
item = item.updateLastCheckInServicePoint(lastCheckInServicePoint).updateDestinationServicePoint(inTransitDestinationServicePoint);
final JsonObject entry = new JsonObject();
write(entry, "id", item.getItemId());
write(entry, "title", item.getTitle());
write(entry, "barcode", item.getBarcode());
write(entry, "contributors", mapContributorNamesToJson(item));
write(entry, "callNumber", item.getCallNumber());
write(entry, "enumeration", item.getEnumeration());
write(entry, "volume", item.getVolume());
write(entry, "yearCaption", new JsonArray(item.getYearCaption()));
writeNamedObject(entry, "status", ofNullable(item.getStatus()).map(ItemStatus::getValue).orElse(null));
write(entry, "inTransitDestinationServicePointId", item.getInTransitDestinationServicePointId());
write(entry, "copyNumber", item.getCopyNumber());
write(entry, "effectiveCallNumberComponents", createCallNumberComponents(item.getCallNumberComponents()));
if (inTransitDestinationServicePoint != null) {
writeServicePoint(entry, inTransitDestinationServicePoint, "inTransitDestinationServicePoint");
}
if (location != null) {
writeLocation(entry, location);
}
if (request != null) {
User requester = reportContext.getUsers().get(request.getRequesterId());
PatronGroup requesterPatronGroup = requester == null ? null : reportContext.getPatronGroups().get(requester.getPatronGroupId());
if (requesterPatronGroup != null) {
request = request.withRequester(requester.withPatronGroup(requesterPatronGroup));
}
ServicePoint pickupServicePoint = reportContext.getServicePoints().get(request.getPickupServicePointId());
request = request.withPickupServicePoint(pickupServicePoint);
writeRequest(request, entry);
}
if (loan != null) {
ServicePoint checkoutServicePoint = reportContext.getServicePoints().get(loan.getCheckoutServicePointId());
ServicePoint checkInServicePoint = reportContext.getServicePoints().get(loan.getCheckInServicePointId());
loan = loan.withCheckinServicePoint(checkInServicePoint).withCheckoutServicePoint(checkoutServicePoint);
writeLoan(entry, loan);
}
final LastCheckIn lastCheckIn = item.getLastCheckIn();
if (lastCheckIn != null) {
writeLastCheckIn(entry, lastCheckIn);
}
return entry;
}
Aggregations