Search in sources :

Example 1 with ItemStatus

use of org.folio.circulation.domain.ItemStatus 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;
}
Also used : ServicePoint(org.folio.circulation.domain.ServicePoint) JsonArray(io.vertx.core.json.JsonArray) ItemStatus(org.folio.circulation.domain.ItemStatus) LastCheckIn(org.folio.circulation.domain.LastCheckIn) User(org.folio.circulation.domain.User) Loan(org.folio.circulation.domain.Loan) Holdings(org.folio.circulation.domain.Holdings) Request(org.folio.circulation.domain.Request) JsonObject(io.vertx.core.json.JsonObject) PatronGroup(org.folio.circulation.domain.PatronGroup) Location(org.folio.circulation.domain.Location)

Aggregations

JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 Holdings (org.folio.circulation.domain.Holdings)1 ItemStatus (org.folio.circulation.domain.ItemStatus)1 LastCheckIn (org.folio.circulation.domain.LastCheckIn)1 Loan (org.folio.circulation.domain.Loan)1 Location (org.folio.circulation.domain.Location)1 PatronGroup (org.folio.circulation.domain.PatronGroup)1 Request (org.folio.circulation.domain.Request)1 ServicePoint (org.folio.circulation.domain.ServicePoint)1 User (org.folio.circulation.domain.User)1