Skip to content

Commit

Permalink
Merge pull request #747 from folio-org/CIRC-986-back-port
Browse files Browse the repository at this point in the history
Back port CIRC-986 to 2020 Q3 Release
  • Loading branch information
marcjohnson-kint authored Nov 10, 2020
2 parents fbc51e3 + bfc20d1 commit e79d969
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 46 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Blocks renewals in the presence of an automated patron block (CIRC-774)
* Does not include closed loan in check in response when item is lost and paid (CIRC-955)
* Include user details in aged to lost circulation log entries (CIRC-986)

## 19.2.2 2020-11-02

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.vertx.core.json.JsonObject;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.With;
import org.folio.circulation.domain.Item;
import org.folio.circulation.domain.Loan;
Expand All @@ -37,54 +36,54 @@ public class LoanLogContext {
private String instanceId;
private String holdingsRecordId;
private String action;
@Setter private String actionComment;
private String actionComment;
private DateTime date;
@Setter private String servicePointId;
@Setter private String updatedByUserId;
private String servicePointId;
private String updatedByUserId;
private String description;
private String loanId;

public static LoanLogContext from(Loan loan) {
LoanLogContext loanLogContext = new LoanLogContext()
.withUser(loan.getUser())
.withItem(loan.getItem())
.withAction(LogContextActionResolver.resolveAction(loan.getAction()))
.withDate(DateTime.now())
.withLoanId(loan.getId());
ofNullable(loan.getActionComment()).ifPresent(loanLogContext::setActionComment);
ofNullable(loan.getUpdatedByUserId()).ifPresent(loanLogContext::setUpdatedByUserId);
ofNullable(loan.getCheckoutServicePointId()).ifPresent(loanLogContext::setServicePointId);
return loanLogContext;
}

public static LoanLogContext fromAnonymize(Loan loan) {
return new LoanLogContext()
.withItemId(loan.getItemId())
.withAction("Anonymize")
.withUser(ofNullable(loan.getUser())
.orElse(userFromRepresentation(loan)))
.withItem(ofNullable(loan.getItem())
.orElse(itemFromRepresentation(loan)))
.withAction(LogContextActionResolver.resolveAction(loan.getAction()))
.withDate(DateTime.now())
.withLoanId(loan.getId())
.withServicePointId(ofNullable(loan.getCheckInServicePointId())
.orElse(loan.getCheckoutServicePointId()));
.orElse(loan.getCheckoutServicePointId()))
.withLoanId(loan.getId())
.withActionComment(loan.getActionComment())
.withUpdatedByUserId(loan.getUpdatedByUserId());
}

public LoanLogContext withUser(User user) {
ofNullable(user).ifPresent(usr -> {
userBarcode = usr.getBarcode();
userId = usr.getId();
});
return this;
private LoanLogContext withUser(User user) {
userBarcode = user.getBarcode();
userId = user.getId();
return this;
}

public LoanLogContext withItem(Item item) {
ofNullable(item).ifPresent(i -> {
itemBarcode = i.getBarcode();
itemId = i.getItemId();
instanceId = i.getInstanceId();
holdingsRecordId = i.getHoldingsRecordId();
});
private LoanLogContext withItem(Item item) {
itemBarcode = item.getBarcode();
itemId = item.getItemId();
instanceId = item.getInstanceId();
holdingsRecordId = item.getHoldingsRecordId();
return this;
}

private static User userFromRepresentation(Loan loan) {
JsonObject userJson = new JsonObject();
ofNullable(loan).ifPresent(l -> write(userJson, "id", l.getUserId()));
return new User(userJson);
}

private static Item itemFromRepresentation(Loan loan) {
JsonObject itemJson = new JsonObject();
ofNullable(loan).ifPresent(l -> write(itemJson, "id", l.getItemId()));
return Item.from(itemJson);
}

public JsonObject asJson() {
JsonObject json = new JsonObject();
ofNullable(userBarcode).ifPresent(userBarcode -> write(json, USER_BARCODE.value(), userBarcode));
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/org/folio/circulation/services/EventPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import static org.folio.circulation.domain.representations.logs.CirculationCheckInCheckOutLogEventMapper.mapToCheckOutLogEventJson;
import static org.folio.circulation.domain.representations.logs.LogEventPayloadField.PAYLOAD;
import static org.folio.circulation.domain.representations.logs.LogEventType.LOAN;
import static org.folio.circulation.domain.representations.logs.LogEventType.NOTICE;
import static org.folio.circulation.support.AsyncCoordinationUtil.allOf;
import static org.folio.circulation.domain.representations.logs.RequestUpdateLogEventMapper.mapToRequestLogEventJson;
import static org.folio.circulation.support.json.JsonPropertyWriter.write;
Expand Down Expand Up @@ -218,7 +217,7 @@ public CompletableFuture<Result<LoanAnonymizationRecords>> publishAnonymizeEvent
}

public CompletableFuture<Result<Void>> publishAnonymizeEvent(Loan loan) {
return publishLogRecord(LoanLogContext.fromAnonymize(loan).asJson(), LOAN);
return publishLogRecord(LoanLogContext.from(loan).withAction("Anonymize").asJson(), LOAN);
}

public CompletableFuture<Result<Void>> publishRecallRequestedEvent(Loan loan) {
Expand All @@ -228,11 +227,10 @@ public CompletableFuture<Result<Void>> publishRecallRequestedEvent(Loan loan) {
}

public CompletableFuture<Result<Void>> publishLogRecord(JsonObject context, LogEventType payloadType) {
if (NOTICE.equals(payloadType)) {
context = new JsonObject().put(PAYLOAD.value(), context.encode());
}
write(context, LOG_EVENT_TYPE.value(), payloadType.value());
return pubSubPublishingService.publishEvent(LOG_RECORD.name(), context.encode())
JsonObject eventJson = new JsonObject();
write(eventJson, LOG_EVENT_TYPE.value(), payloadType.value());
write(eventJson, PAYLOAD.value(), context);
return pubSubPublishingService.publishEvent(LOG_RECORD.name(), eventJson.encode())
.thenApply(r -> succeeded(null));
}

Expand Down
1 change: 1 addition & 0 deletions src/test/java/api/queue/RequestQueueResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ && new JsonObject(o.getString("eventPayload")).getString("logEventType")

List<JsonObject> reorderedRequests = new JsonObject(JsonObject.mapFrom(reorderedLogEvents.get(0))
.getString("eventPayload"))
.getJsonObject("payload")
.getJsonObject("requests")
.getJsonArray("reordered")
.stream()
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/api/requests/RequestsAPIUpdatingTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -780,11 +780,11 @@ public void dueDateChangedEventIsPublished() {
Map<String, List<JsonObject>> logEvents = events.get(LOG_RECORD.name()).stream()
.collect(groupingBy(e -> new JsonObject(e.getString("eventPayload")).getString("logEventType")));

Request requestCreatedFromEventPayload = Request.from(new JsonObject(logEvents.get(REQUEST_CREATED.value()).get(0).getString("eventPayload")).getJsonObject("requests").getJsonObject("created"));
Request requestCreatedFromEventPayload = Request.from(new JsonObject(logEvents.get(REQUEST_CREATED.value()).get(0).getString("eventPayload")).getJsonObject("payload").getJsonObject("requests").getJsonObject("created"));
assertThat(requestCreatedFromEventPayload, notNullValue());

Request originalCreatedFromEventPayload = Request.from(new JsonObject(logEvents.get(REQUEST_UPDATED.value()).get(0).getString("eventPayload")).getJsonObject("requests").getJsonObject("original"));
Request updatedCreatedFromEventPayload = Request.from(new JsonObject(logEvents.get(REQUEST_UPDATED.value()).get(0).getString("eventPayload")).getJsonObject("requests").getJsonObject("updated"));
Request originalCreatedFromEventPayload = Request.from(new JsonObject(logEvents.get(REQUEST_UPDATED.value()).get(0).getString("eventPayload")).getJsonObject("payload").getJsonObject("requests").getJsonObject("original"));
Request updatedCreatedFromEventPayload = Request.from(new JsonObject(logEvents.get(REQUEST_UPDATED.value()).get(0).getString("eventPayload")).getJsonObject("payload").getJsonObject("requests").getJsonObject("updated"));

assertThat(requestCreatedFromEventPayload.getRequestType(), equalTo(originalCreatedFromEventPayload.getRequestType()));
assertThat(originalCreatedFromEventPayload.getRequestType(), not(equalTo(updatedCreatedFromEventPayload.getRequestType())));
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/api/requests/scenarios/MoveRequestTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -1030,8 +1030,8 @@ public void dueDateChangedEventIsPublished() {
Map<String, List<JsonObject>> logEvents = events.get(LOG_RECORD.name()).stream()
.collect(groupingBy(e -> new JsonObject(e.getString("eventPayload")).getString("logEventType")));

Request originalCreatedFromEventPayload = Request.from(new JsonObject(logEvents.get(REQUEST_MOVED.value()).get(0).getString("eventPayload")).getJsonObject("requests").getJsonObject("original"));
Request updatedCreatedFromEventPayload = Request.from(new JsonObject(logEvents.get(REQUEST_MOVED.value()).get(0).getString("eventPayload")).getJsonObject("requests").getJsonObject("updated"));
Request originalCreatedFromEventPayload = Request.from(new JsonObject(logEvents.get(REQUEST_MOVED.value()).get(0).getString("eventPayload")).getJsonObject("payload").getJsonObject("requests").getJsonObject("original"));
Request updatedCreatedFromEventPayload = Request.from(new JsonObject(logEvents.get(REQUEST_MOVED.value()).get(0).getString("eventPayload")).getJsonObject("payload").getJsonObject("requests").getJsonObject("updated"));
assertThat(originalCreatedFromEventPayload.asJson(), Matchers.not(equalTo(updatedCreatedFromEventPayload.asJson())));

assertThat(originalCreatedFromEventPayload.getItemId(), not(equalTo(updatedCreatedFromEventPayload.getItemId())));
Expand Down

0 comments on commit e79d969

Please sign in to comment.