diff --git a/descriptors/ModuleDescriptor-template.json b/descriptors/ModuleDescriptor-template.json index 838a3353..1dcc1b4d 100644 --- a/descriptors/ModuleDescriptor-template.json +++ b/descriptors/ModuleDescriptor-template.json @@ -33,6 +33,10 @@ { "id": "holdings-storage", "version": "4.4" + }, + { + "id": "cancellation-reason-storage", + "version": "1.1" } ], "provides": [ @@ -117,7 +121,8 @@ "users.collection.get", "templates.item.get", "inventory.items.item.get", - "inventory-storage.holdings.item.get" + "inventory-storage.holdings.item.get", + "circulation-storage.cancellation-reasons.collection.get" ] } ] diff --git a/mod-audit-server/src/main/java/org/folio/builder/description/RequestDescriptionBuilder.java b/mod-audit-server/src/main/java/org/folio/builder/description/RequestDescriptionBuilder.java index a846482f..feb98a5d 100644 --- a/mod-audit-server/src/main/java/org/folio/builder/description/RequestDescriptionBuilder.java +++ b/mod-audit-server/src/main/java/org/folio/builder/description/RequestDescriptionBuilder.java @@ -14,7 +14,6 @@ import static org.folio.util.LogEventPayloadField.REQUEST_PICKUP_SERVICE_POINT; import static org.folio.util.LogEventPayloadField.REQUEST_POSITION; import static org.folio.util.LogEventPayloadField.REQUEST_PREVIOUS_POSITION; -import static org.folio.util.LogEventPayloadField.REQUEST_REASON_FOR_CANCELLATION; import static org.folio.util.LogEventPayloadField.REQUEST_SERVICE_POINT; import static org.folio.util.LogEventPayloadField.REQUEST_TYPE; @@ -107,14 +106,13 @@ public String buildEditedDescription(JsonObject original, JsonObject updated) { .trim(); } - public String buildCancelledDescription(JsonObject original, JsonObject updated) { + public String buildCancelledDescription(JsonObject original, String reasonForCancellation) { StringBuilder description = buildBaseDescription(original); - Optional.ofNullable(getProperty(updated, REQUEST_REASON_FOR_CANCELLATION)) - .ifPresent(reason -> description.append("Reason for cancellation: ") - .append(reason) - .append(".")); + description.append("Reason for cancellation: ") + .append(reasonForCancellation) + .append("."); return description.toString() .trim(); diff --git a/mod-audit-server/src/main/java/org/folio/builder/service/LogRecordBuilder.java b/mod-audit-server/src/main/java/org/folio/builder/service/LogRecordBuilder.java index 3beaea8d..64e08b71 100644 --- a/mod-audit-server/src/main/java/org/folio/builder/service/LogRecordBuilder.java +++ b/mod-audit-server/src/main/java/org/folio/builder/service/LogRecordBuilder.java @@ -6,6 +6,7 @@ import static java.util.stream.Collectors.toList; import static org.apache.commons.lang.StringUtils.EMPTY; import static org.apache.commons.lang3.StringUtils.isEmpty; +import static org.apache.commons.lang3.StringUtils.isNotEmpty; import static org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT; import static org.folio.util.Constants.HOLDINGS_URL; import static org.folio.util.Constants.ITEMS_URL; @@ -34,7 +35,6 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; -import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; @@ -66,10 +66,13 @@ public abstract class LogRecordBuilder { public static final String SEARCH_PARAMS = "?limit=%s&offset=%s%s"; public static final String ID = "id"; public static final String USERS = "users"; + public static final String CANCELLATION_REASONS = "cancellationReasons"; protected final Map okapiHeaders; protected final Context vertxContext; + public abstract CompletableFuture> buildLogRecord(JsonObject payload); + public LogRecordBuilder(Map okapiHeaders, Context vertxContext) { this.okapiHeaders = okapiHeaders; this.vertxContext = vertxContext; @@ -115,9 +118,9 @@ private CompletableFuture handleGetRequest(String endpoint) { * @param ids List of item id's * @return future with list of item records */ - public CompletableFuture> getEntitiesByIds(List ids, String key) { + public CompletableFuture> getEntitiesByIds(String url, String key, int limit, int offset, String... ids) { String query = convertIdsToCqlQuery(ids); - String endpoint = String.format(USERS_URL + SEARCH_PARAMS, 2, 0, buildQuery(query)); + String endpoint = String.format(url + SEARCH_PARAMS, limit, offset, buildQuery(query)); return handleGetRequest(endpoint).thenApply(response -> extractEntities(response, key)); } @@ -140,9 +143,9 @@ public CompletableFuture fetchUserDetails(JsonObject payload, String ofNullable(getProperty(userJson, BARCODE)).ifPresent(barcode -> payload.put(USER_BARCODE.value(), barcode)); } JsonObject personal = getObjectProperty(userJson, PERSONAL); - if (nonNull(personal)) { + if (nonNull(personal) && nonNull(buildPersonalName(getProperty(personal, FIRST_NAME), getProperty(personal, LAST_NAME)))) { payload.put(PERSONAL_NAME.value(), - String.format(PERSONAL_NAME_PATTERN, getProperty(personal, LAST_NAME), getProperty(personal, FIRST_NAME))); + buildPersonalName(getProperty(personal, FIRST_NAME), getProperty(personal, LAST_NAME))); } } return CompletableFuture.completedFuture(payload); @@ -194,8 +197,8 @@ private String encodeQuery(String query) { * @param ids list of id's * @return String representing CQL query to get records by id's */ - private String convertIdsToCqlQuery(Collection ids) { - return convertIdsToCqlQuery(ids, ID, true); + private String convertIdsToCqlQuery(String... ids) { + return convertIdsToCqlQuery(ID, true, ids); } /** @@ -206,7 +209,7 @@ private String convertIdsToCqlQuery(Collection ids) { * @param strictMatch indicates whether strict match mode (i.e. ==) should be used or not (i.e. =) * @return String representing CQL query to get records by some property values */ - private String convertIdsToCqlQuery(Collection values, String fieldName, boolean strictMatch) { + private String convertIdsToCqlQuery(String fieldName, boolean strictMatch, String... values) { String prefix = fieldName + (strictMatch ? "==(" : "=("); return StreamEx.of(values) .joining(" or ", prefix, ")"); @@ -244,8 +247,6 @@ private static JsonObject verifyAndExtractBody(Response response) { return response.getBody(); } - public abstract CompletableFuture> buildLogRecord(JsonObject payload); - protected LogRecord.Action resolveAction(String actionString) { try { return LogRecord.Action.fromValue(actionString); @@ -253,4 +254,16 @@ protected LogRecord.Action resolveAction(String actionString) { throw new IllegalArgumentException("Builder isn't implemented yet for: " + actionString); } } + + String buildPersonalName(String firstName, String lastName) { + if (isNotEmpty(firstName) && isNotEmpty(lastName)) { + return lastName + ", " + firstName; + } else if (isEmpty(firstName) && isNotEmpty(lastName)) { + return lastName; + } else if (isNotEmpty(firstName) && isEmpty(lastName)) { + return firstName; + } else { + return null; + } + } } diff --git a/mod-audit-server/src/main/java/org/folio/builder/service/ManualBlockRecordBuilder.java b/mod-audit-server/src/main/java/org/folio/builder/service/ManualBlockRecordBuilder.java index 9a85f1f0..86b18ce8 100644 --- a/mod-audit-server/src/main/java/org/folio/builder/service/ManualBlockRecordBuilder.java +++ b/mod-audit-server/src/main/java/org/folio/builder/service/ManualBlockRecordBuilder.java @@ -1,13 +1,11 @@ package org.folio.builder.service; -import static java.util.Arrays.asList; import static java.util.Collections.singletonList; import static java.util.stream.Collectors.toMap; -import static org.apache.commons.lang3.StringUtils.isEmpty; -import static org.apache.commons.lang3.StringUtils.isNotEmpty; import static org.folio.builder.LogRecordBuilderResolver.MANUAL_BLOCK_CREATED; import static org.folio.builder.LogRecordBuilderResolver.MANUAL_BLOCK_DELETED; import static org.folio.builder.LogRecordBuilderResolver.MANUAL_BLOCK_MODIFIED; +import static org.folio.util.Constants.USERS_URL; import static org.folio.util.JsonPropertyFetcher.getNestedStringProperty; import static org.folio.util.JsonPropertyFetcher.getObjectProperty; import static org.folio.util.JsonPropertyFetcher.getProperty; @@ -27,7 +25,6 @@ import java.util.concurrent.CompletableFuture; import java.util.function.Function; -import one.util.streamex.StreamEx; import org.folio.builder.description.ManualBlockDescriptionBuilder; import org.folio.rest.jaxrs.model.LinkToIds; import org.folio.rest.jaxrs.model.LogRecord; @@ -35,6 +32,7 @@ import io.vertx.core.Context; import io.vertx.core.json.JsonObject; +import one.util.streamex.StreamEx; public class ManualBlockRecordBuilder extends LogRecordBuilder { public ManualBlockRecordBuilder(Map okapiHeaders, Context vertxContext) { @@ -50,7 +48,7 @@ public CompletableFuture> buildLogRecord(JsonObject event) { String userId = getProperty(payload, USER_ID); String sourceId = getNestedStringProperty(payload, METADATA, UPDATED_BY_USER_ID); - return getEntitiesByIds(asList(userId, sourceId), USERS).thenCompose(users -> { + return getEntitiesByIds(USERS_URL, USERS, 2, 0, userId, sourceId).thenCompose(users -> { Map usersGroupedById = StreamEx.of(users) .collect(toMap(u -> getProperty(u, LogEventPayloadField.ID), Function.identity())); LogRecord manualBlockLogRecord = buildManualBlockLogRecord(payload, logEventType, userId, sourceId, usersGroupedById); @@ -59,7 +57,7 @@ public CompletableFuture> buildLogRecord(JsonObject event) { } private LogRecord buildManualBlockLogRecord(JsonObject payload, String logEventType, String userId, String sourceId, - Map usersGroupedById) { + Map usersGroupedById) { return new LogRecord().withObject(LogRecord.Object.MANUAL_BLOCK) .withUserBarcode(getProperty(usersGroupedById.get(userId), BARCODE)) .withSource(getSource(logEventType, sourceId, usersGroupedById)) @@ -76,18 +74,6 @@ private String getSource(String logEventType, String sourceId, Map okapiHeaders, Context vertxConte @Override public CompletableFuture> buildLogRecord(JsonObject event) { - return CompletableFuture.completedFuture(new ArrayList<>(buildRequestLogRecord(event))); + return buildRequestLogRecord(event); } - private List buildRequestLogRecord(JsonObject event) { + private CompletableFuture> buildRequestLogRecord(JsonObject event) { List records = new ArrayList<>(); - LogRecord.Action action = resolveLogRecordAction(getProperty(event, LOG_EVENT_TYPE)); - - LogRecord record = new LogRecord().withObject(LogRecord.Object.REQUEST); + final LogRecord.Action action = resolveLogRecordAction(getProperty(event, LOG_EVENT_TYPE)); JsonObject requests = getNestedObjectProperty(event, PAYLOAD, REQUESTS); - String servicePointId = getNestedStringProperty(event, PAYLOAD, SERVICE_POINT_ID); if (LogRecord.Action.CREATED == action) { JsonObject created = getObjectProperty(requests, CREATED); - records.add(record.withAction(LogRecord.Action.CREATED) - .withUserBarcode(getNestedStringProperty(requests, REQUESTER, BARCODE)) - .withServicePointId(servicePointId) - .withItems(buildItems(created)) - .withDate(new Date()) - .withLinkToIds(new LinkToIds().withUserId(getProperty(created, USER_ID)) - .withRequestId(getProperty(created, REQUEST_ID))) - .withDescription(requestDescriptionBuilder.buildCreateDescription(created))); + return getEntitiesByIds(USERS_URL, USERS, 1, 0, getSourceIdFromMetadata(created)).thenApply(sources -> { + records.add(new LogRecord().withObject(LogRecord.Object.REQUEST) + .withAction(LogRecord.Action.CREATED) + .withUserBarcode(getNestedStringProperty(created, REQUESTER, BARCODE)) + .withServicePointId(getProperty(created, REQUEST_PICKUP_SERVICE_POINT_ID)) + .withItems(buildItems(created)) + .withDate(new Date()) + .withSource(buildSourceName(sources.get(0))) + .withLinkToIds(buildLinkToIds(created)) + .withDescription(requestDescriptionBuilder.buildCreateDescription(created))); + return records; + }); } else if (LogRecord.Action.EDITED == action) { JsonObject original = getObjectProperty(requests, ORIGINAL); JsonObject updated = getObjectProperty(requests, UPDATED); - String description; - if (getProperty(updated, STATUS).equals(CLOSED_CANCELLED_STATUS)) { - action = LogRecord.Action.CANCELLED; - description = requestDescriptionBuilder.buildCancelledDescription(original, updated); - } else { - description = requestDescriptionBuilder.buildEditedDescription(original, updated); - } - - records.add(record.withAction(action) - .withUserBarcode(getNestedStringProperty(original, REQUESTER, BARCODE)) - .withServicePointId(servicePointId) - .withItems(buildItems(original)) - .withDate(new Date()) - .withLinkToIds(new LinkToIds().withUserId(getProperty(original, USER_ID)) - .withRequestId(getProperty(original, REQUEST_ID))) - .withDescription(description)); + return getEntitiesByIds(USERS_URL, USERS, 1, 0, getSourceIdFromMetadata(original)) + .thenCompose(sources -> { + + LogRecord record = new LogRecord().withObject(LogRecord.Object.REQUEST); + + if (CLOSED_CANCELLED_STATUS.equals(getProperty(updated, STATUS))) { + return getEntitiesByIds(CANCELLATION_REASONS_URL, CANCELLATION_REASONS, 1, 0, getProperty(updated, REQUEST_REASON_FOR_CANCELLATION_ID)) + .thenApply(reasons -> { + record.setAction(LogRecord.Action.CANCELLED); + String description = requestDescriptionBuilder.buildCancelledDescription(original, getProperty(reasons.get(0), DESCRIPTION)); + + records.add(record.withUserBarcode(getNestedStringProperty(original, REQUESTER, BARCODE)) + .withServicePointId(getProperty(updated, REQUEST_PICKUP_SERVICE_POINT_ID)) + .withItems(buildItems(original)) + .withDate(new Date()) + .withSource(buildSourceName(sources.get(0))) + .withLinkToIds(buildLinkToIds(updated)) + .withDescription(description)); + return records; + }); + } else { + record.setAction(action); + String description = requestDescriptionBuilder.buildEditedDescription(original, updated); + + records.add(record.withUserBarcode(getNestedStringProperty(original, REQUESTER, BARCODE)) + .withServicePointId(getProperty(updated, REQUEST_PICKUP_SERVICE_POINT_ID)) + .withItems(buildItems(original)) + .withDate(new Date()) + .withSource(buildSourceName(sources.get(0))) + .withLinkToIds(buildLinkToIds(updated)) + .withDescription(description)); + + return CompletableFuture.completedFuture(records); + } + }); } else if (LogRecord.Action.MOVED == action) { JsonObject original = getObjectProperty(requests, ORIGINAL); JsonObject updated = getObjectProperty(requests, UPDATED); - records.add(record.withAction(LogRecord.Action.MOVED) - .withUserBarcode(getNestedStringProperty(original, REQUESTER, BARCODE)) - .withServicePointId(servicePointId) - .withItems(buildItems(original)) - .withDate(new Date()) - .withLinkToIds(new LinkToIds().withUserId(getProperty(original, USER_ID)) - .withRequestId(getProperty(original, REQUEST_ID))) - .withDescription(requestDescriptionBuilder.buildMovedDescription(original, updated))); + return getEntitiesByIds(USERS_URL, USERS, 1, 0, getSourceIdFromMetadata(original)) + .thenApply(sources -> { + + records.add(new LogRecord().withObject(LogRecord.Object.REQUEST) + .withAction(LogRecord.Action.MOVED) + .withUserBarcode(getNestedStringProperty(updated, REQUESTER, BARCODE)) + .withServicePointId(getProperty(updated, REQUEST_PICKUP_SERVICE_POINT_ID)) + .withItems(buildItems(updated)) + .withDate(new Date()) + .withSource(buildSourceName(sources.get(0))) + .withLinkToIds(buildLinkToIds(updated)) + .withDescription(requestDescriptionBuilder.buildMovedDescription(original, updated))); + return records; + }); } else if (LogRecord.Action.QUEUE_POSITION_REORDERED == action) { JsonArray reordered = getArrayProperty(requests, REORDERED); - LogRecord.Action efa = action; - reordered.forEach(r -> { - JsonObject o = (JsonObject) r; - records.add(record.withAction(efa) - .withUserBarcode(getNestedStringProperty(o, REQUESTER, BARCODE)) - .withServicePointId(servicePointId) - .withItems(buildItems(o)) - .withDate(new Date()) - .withLinkToIds(new LinkToIds().withUserId(getProperty(o, USER_ID)) - .withRequestId(getProperty(o, REQUEST_ID))) - .withDescription(requestDescriptionBuilder.buildReorderedDescription(o))); + List sourceIds = new ArrayList<>(); + for (int i = 0; i < reordered.size(); i++) { + sourceIds.add(getSourceIdFromMetadata(reordered.getJsonObject(i))); + } + + String[] sources = new String[sourceIds.size()]; + sourceIds.toArray(sources); + + return getEntitiesByIds(USERS_URL, USERS, sources.length, 0, sources).thenApply(s -> { + + Map usersGroupedById = StreamEx.of(s) + .collect(toMap(u -> getProperty(u, LogEventPayloadField.ID), + v -> buildPersonalName(getNestedStringProperty(v, PERSONAL, FIRST_NAME), + getNestedStringProperty(v, PERSONAL, LAST_NAME)))); + + reordered.forEach(request -> { + JsonObject r = (JsonObject) request; + records.add(new LogRecord().withObject(LogRecord.Object.REQUEST) + .withUserBarcode(getNestedStringProperty(r, REQUESTER, BARCODE)) + .withServicePointId(getProperty(r, REQUEST_PICKUP_SERVICE_POINT_ID)) + .withItems(buildItems(r)) + .withDate(new Date()) + .withAction(action) + .withSource(usersGroupedById.get(getSourceIdFromMetadata(r))) + .withLinkToIds(buildLinkToIds(r)) + .withDescription(requestDescriptionBuilder.buildReorderedDescription(r))); + }); + return records; }); } else { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Action isn't determined or invalid"); + } + } + + private LinkToIds buildLinkToIds(JsonObject created) { + return new LinkToIds().withUserId(getProperty(created, REQUESTER_ID)) + .withRequestId(getProperty(created, REQUEST_ID)); + } + + /** + * This method extracts sourceId from metadata + * + * @param json - JSON object + * @return id of source (id of user that editing object) + */ + private String getSourceIdFromMetadata(JsonObject json) { + return getNestedStringProperty(json, METADATA, UPDATED_BY_USER_ID); + } + + /** + * This method builds name of source + * + * @param personal JSON object source personal + * @return name of source (user that editing object) + */ + private String buildSourceName(JsonObject personal) { + String source = null; + if (Objects.nonNull(personal)) { + source = buildPersonalName(getNestedStringProperty(personal, PERSONAL, FIRST_NAME), + getNestedStringProperty(personal, PERSONAL, LAST_NAME)); } - return records; + return source; } private List buildItems(JsonObject payload) { diff --git a/mod-audit-server/src/main/java/org/folio/util/Constants.java b/mod-audit-server/src/main/java/org/folio/util/Constants.java index 38283ef4..16594d43 100644 --- a/mod-audit-server/src/main/java/org/folio/util/Constants.java +++ b/mod-audit-server/src/main/java/org/folio/util/Constants.java @@ -7,6 +7,7 @@ private Constants(){} public static final String HOLDINGS_URL = "/holdings-storage/holdings"; public static final String TEMPLATES_URL = "/templates"; public static final String USERS_URL = "/users"; + public static final String CANCELLATION_REASONS_URL = "/cancellation-reason-storage/cancellation-reasons"; public static final String URL_WITH_ID_PATTERN = "%s/%s"; public static final String SYSTEM = "System"; public static final String UUID_PATTERN = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$"; diff --git a/mod-audit-server/src/main/java/org/folio/util/LogEventPayloadField.java b/mod-audit-server/src/main/java/org/folio/util/LogEventPayloadField.java index a3dc8d82..4899dbe8 100644 --- a/mod-audit-server/src/main/java/org/folio/util/LogEventPayloadField.java +++ b/mod-audit-server/src/main/java/org/folio/util/LogEventPayloadField.java @@ -58,13 +58,15 @@ public enum LogEventPayloadField { REQUEST_TYPE("requestType"), REQUEST_EXPIRATION_DATE("requestExpirationDate"), REQUEST_ADDRESS_TYPE("addressType"), - REQUEST_REASON_FOR_CANCELLATION("addressType"), + REQUEST_REASON_FOR_CANCELLATION_ID("cancellationReasonId"), REQUEST_POSITION("position"), REQUEST_PREVIOUS_POSITION("previousPosition"), REQUEST_FULFILMENT_PREFERENCE("fulfilmentPreference"), REQUEST_SERVICE_POINT("servicePoint"), REQUEST_PICKUP_SERVICE_POINT("pickupServicePoint"), + REQUEST_PICKUP_SERVICE_POINT_ID("pickupServicePointId"), REQUESTER("requester"), + REQUESTER_ID("requesterId"), BARCODE("barcode"), MANUAL_BLOCK_BORROWING("borrowing"), MANUAL_BLOCK_RENEWALS("renewals"), diff --git a/mod-audit-server/src/test/java/org/folio/builder/service/RequestRecordBuilderTest.java b/mod-audit-server/src/test/java/org/folio/builder/service/RequestRecordBuilderTest.java index dd421115..857d2405 100644 --- a/mod-audit-server/src/test/java/org/folio/builder/service/RequestRecordBuilderTest.java +++ b/mod-audit-server/src/test/java/org/folio/builder/service/RequestRecordBuilderTest.java @@ -1,9 +1,5 @@ package org.folio.builder.service; -import static org.folio.util.JsonPropertyFetcher.getNestedStringProperty; -import static org.folio.util.LogEventPayloadField.ITEM_BARCODE; -import static org.folio.util.LogEventPayloadField.PAYLOAD; -import static org.folio.util.LogEventPayloadField.USER_ID; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; @@ -26,7 +22,7 @@ public class RequestRecordBuilderTest extends BuilderTestBase { private static final String EXPECTED_CREATE_DESCRIPTION = "Type: Recall."; private static final String EXPECTED_EDITED_DESCRIPTION = "Type: Recall. New expiration date: 2020-10-23 00:00:00 (from: 2020-10-19 00:00:00). New fulfilment preference: Hold Shelf (from: Hold)."; private static final String EXPECTED_MOVED_DESCRIPTION = "Type: Hold. New item barcode: 645398607547 (from: 653285216743)."; - private static final String EXPECTED_CANCELLED_DESCRIPTION = "Type: Hold."; + private static final String EXPECTED_CANCELLED_DESCRIPTION = "Type: Hold. Reason for cancellation: Cancelled at patron’s request."; private static final String EXPECTED_REORDERED_DESCRIPTION = "Type: Recall. New queue position: 2 (from: 3)."; private enum TestValue { @@ -77,9 +73,13 @@ void requestLogRecordTest(TestValue value) throws Exception { assertThat(requestLogRecord.getServicePointId(), notNullValue()); assertThat(requestLogRecord.getItems().get(0).getItemBarcode(), notNullValue()); - assertThat(requestLogRecord.getItems().get(0).getItemBarcode(), equalTo(getNestedStringProperty(payload, PAYLOAD, ITEM_BARCODE))); + assertThat(requestLogRecord.getItems().get(0).getItemBarcode(), notNullValue()); + + assertThat(requestLogRecord.getUserBarcode(), notNullValue()); + assertThat(requestLogRecord.getLinkToIds().getUserId(), notNullValue()); + assertThat(requestLogRecord.getLinkToIds().getRequestId(), notNullValue()); - assertThat(requestLogRecord.getLinkToIds().getUserId(), equalTo(getNestedStringProperty(payload, PAYLOAD, USER_ID))); + assertThat(requestLogRecord.getSource(), notNullValue()); assertThat(requestLogRecord.getDescription(), equalTo(value.getDescription())); } diff --git a/mod-audit-server/src/test/resources/mock_content.json b/mod-audit-server/src/test/resources/mock_content.json index e73b62e6..9a00464b 100644 --- a/mod-audit-server/src/test/resources/mock_content.json +++ b/mod-audit-server/src/test/resources/mock_content.json @@ -35,6 +35,24 @@ "receivedPath": "mocks/empty_users.json", "status": 200 }, + { + "url": "/users?limit=1&offset=0&query=id%3D%3D%280c8fb6eb-fb2b-58fa-8386-e4bc9e670fcc%29", + "method": "GET", + "receivedPath": "mocks/one-user-collection.json", + "status": 200 + }, + { + "url": "/users?limit=1&offset=0&query=id%3D%3D%2861da1f1b-eb9e-5a33-9d47-617c84191d12%29", + "method": "GET", + "receivedPath": "mocks/one-user-collection.json", + "status": 200 + }, + { + "url": "/cancellation-reason-storage/cancellation-reasons?limit=1&offset=0&query=id%3D%3D%2875187e8d-e25a-47a7-89ad-23ba612338de%29", + "method": "GET", + "receivedPath": "mocks/reason-for-cancellation.json", + "status": 200 + }, { "url": "/inventory/items/100d10bf-2f06-4aa0-be15-0b95b2d9f9e3", "method": "GET", diff --git a/mod-audit-server/src/test/resources/mocks/one-user-collection.json b/mod-audit-server/src/test/resources/mocks/one-user-collection.json new file mode 100644 index 00000000..a9dee37c --- /dev/null +++ b/mod-audit-server/src/test/resources/mocks/one-user-collection.json @@ -0,0 +1,49 @@ +{ + "users": [ + { + "username": "carlo", + "id": "61da1f1b-eb9e-5a33-9d47-617c84191d12", + "barcode": "605566117903595", + "active": false, + "type": "patron", + "patronGroup": "503a81cd-6c26-400f-b620-14c08943697c", + "departments": [], + "proxyFor": [], + "personal": { + "lastName": "Denesik", + "firstName": "Toney", + "middleName": "Alexzander", + "email": "tod@crooks-llc.io", + "phone": "1-308-768-9868", + "mobilePhone": "1-925-901-9660", + "dateOfBirth": "2011-07-10T00:00:00.000+00:00", + "addresses": [ + { + "countryId": "US", + "addressLine1": "65343 Ewald Mission", + "city": "Rosemead", + "region": "IA", + "postalCode": "24959-2664", + "addressTypeId": "93d3d88d-499b-45d0-9bc7-ac73c3a19880", + "primaryAddress": true + } + ], + "preferredContactTypeId": "004" + }, + "enrollmentDate": "2017-11-17T00:00:00.000+00:00", + "expirationDate": "2019-10-08T00:00:00.000+00:00", + "createdDate": "2020-11-01T01:41:52.878+00:00", + "updatedDate": "2020-11-01T01:41:52.878+00:00", + "metadata": { + "createdDate": "2020-11-01T01:41:52.874+00:00", + "updatedDate": "2020-11-01T01:41:52.874+00:00" + } + } + ], + "totalRecords": 1, + "resultInfo": { + "totalRecords": 1, + "facets": [], + "diagnostics": [] + } +} diff --git a/mod-audit-server/src/test/resources/mocks/reason-for-cancellation.json b/mod-audit-server/src/test/resources/mocks/reason-for-cancellation.json new file mode 100644 index 00000000..c8e6b5fa --- /dev/null +++ b/mod-audit-server/src/test/resources/mocks/reason-for-cancellation.json @@ -0,0 +1,15 @@ +{ + "cancellationReasons": [ + { + "id": "75187e8d-e25a-47a7-89ad-23ba612338de", + "name": "Patron Cancelled", + "description": "Cancelled at patron’s request", + "requiresAdditionalInformation": false, + "metadata": { + "createdDate": "2020-11-10T03:18:45.399+00:00", + "updatedDate": "2020-11-10T03:18:45.399+00:00" + } + } + ], + "totalRecords": 1 +} diff --git a/mod-audit-server/src/test/resources/payloads/request_edited.json b/mod-audit-server/src/test/resources/payloads/request_edited.json index d5d1c868..a9813d77 100644 --- a/mod-audit-server/src/test/resources/payloads/request_edited.json +++ b/mod-audit-server/src/test/resources/payloads/request_edited.json @@ -48,22 +48,6 @@ "itemId":"459afaba-5b39-468d-9072-eb1685e0ddf4", "status":"Open - Not yet filled", "position":3, - "item":{ - "title":"The Girl on the Train", - "barcode":"765475420716", - "identifiers":[ - { - "value":"B01LO7PJOE", - "identifierTypeId":"7f907515-a1bf-4513-8a38-92e1a07c539d" - } - ] - }, - "requester":{ - "firstName":"Doug", - "lastName":"Denesik", - "middleName":"Alf", - "barcode":"693787594998493" - }, "fulfilmentPreference":"Hold Shelf", "requestExpirationDate":"2020-10-23T00:00:00.000+0000", "pickupServicePointId":"c4c90014-c8c9-4ade-8f24-b5e313319f4b", diff --git a/mod-audit-server/src/test/resources/payloads/request_reordered.json b/mod-audit-server/src/test/resources/payloads/request_reordered.json index 125db82b..eb42c2f5 100644 --- a/mod-audit-server/src/test/resources/payloads/request_reordered.json +++ b/mod-audit-server/src/test/resources/payloads/request_reordered.json @@ -36,9 +36,9 @@ "pickupServicePointId":"c4c90014-c8c9-4ade-8f24-b5e313319f4b", "metadata":{ "createdDate":"2020-10-11T18:58:14.370+0000", - "createdByUserId":"0c8fb6eb-fb2b-58fa-8386-e4bc9e670fcc", + "createdByUserId":"61da1f1b-eb9e-5a33-9d47-617c84191d12", "updatedDate":"2020-10-11T18:59:32.985+0000", - "updatedByUserId":"0c8fb6eb-fb2b-58fa-8386-e4bc9e670fcc" + "updatedByUserId":"61da1f1b-eb9e-5a33-9d47-617c84191d12" }, "previousPosition":3 }