From 755b9cffc4dfb64d88b739c025d3d5304ac78ae5 Mon Sep 17 00:00:00 2001 From: Volodymyr Rohach Date: Wed, 5 Jun 2024 17:45:40 +0300 Subject: [PATCH] MODSOURCE-773: Remove default searching via "deleted"="false". (#626) * MODSOURCE-773: MARC Search omits suppressed from discovery records in default search. * MODSOURCE-773: Useless condition removed. * MODSOURCE-773: NEWS updated. * MODSOURCE-773: TEMPORARY SCHEMA CHANGE. REMOVE AFTER TESTING ON RANCHER! * MODSOURCE-773: REVERTING CHANGE. * MODSOURCE-773: Updating raml-storage. * MODSOURCE-773: Updating raml-storage. * MODSOURCE-773: Compilation errors due to schema profile wrappers changes - fixed. * MODSOURCE-773: Compilation errors due to schema profile wrappers changes in tests - fixed . * MODSOURCE-773: Schema updated. * MODSOURCE-773: Deleted-parameter searching mechanism changed. * MODSOURCE-773: Schema updated. * MODSOURCE-773: Condition improved. --- .../org/folio/dao/util/RecordDaoUtil.java | 8 +++- .../services/RecordSearchParameters.java | 6 +-- .../rest/impl/SourceStorageStreamApiTest.java | 39 +++++++++++++++++++ ramls/raml-storage | 2 +- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/mod-source-record-storage-server/src/main/java/org/folio/dao/util/RecordDaoUtil.java b/mod-source-record-storage-server/src/main/java/org/folio/dao/util/RecordDaoUtil.java index f00d3eebc..3202f44b8 100644 --- a/mod-source-record-storage-server/src/main/java/org/folio/dao/util/RecordDaoUtil.java +++ b/mod-source-record-storage-server/src/main/java/org/folio/dao/util/RecordDaoUtil.java @@ -592,6 +592,10 @@ public static Condition filterRecordByUpdatedDateRange(Date updatedAfter, Date u */ public static Condition filterRecordByDeleted(Boolean deleted) { Condition condition = filterRecordByState(RecordState.ACTUAL.name()); + if (deleted == null) { + condition = condition.or(filterRecordByState(RecordState.DELETED.name())) + .or(filterRecordByState(RecordState.ACTUAL.name())); + } if (Boolean.TRUE.equals(deleted)) { condition = condition.or(filterRecordByState(RecordState.DELETED.name())) .or(filterRecordByState(RecordState.ACTUAL.name()).and(filterRecordByLeaderRecordStatus(DELETED_LEADER_RECORD_STATUS))); @@ -618,7 +622,7 @@ public static Condition filterRecordByExternalIdNonNull() { /** * Convert {@link List} of {@link String} to {@link List} or {@link OrderField} - * + *

* Relies on strong convention between dto property name and database column name. * Property name being lower camel case and column name being lower snake case of the property name. * @@ -629,7 +633,7 @@ public static Condition filterRecordByExternalIdNonNull() { @SuppressWarnings("squid:S1452") public static List> toRecordOrderFields(List orderBy, Boolean forOffset) { if (forOffset && orderBy.isEmpty()) { - return Arrays.asList(new OrderField[] {RECORDS_LB.ID.asc()}); + return Arrays.asList(new OrderField[]{RECORDS_LB.ID.asc()}); } return orderBy.stream() .map(order -> order.split(COMMA)) diff --git a/mod-source-record-storage-server/src/main/java/org/folio/services/RecordSearchParameters.java b/mod-source-record-storage-server/src/main/java/org/folio/services/RecordSearchParameters.java index fdcc45af2..8aeff1174 100644 --- a/mod-source-record-storage-server/src/main/java/org/folio/services/RecordSearchParameters.java +++ b/mod-source-record-storage-server/src/main/java/org/folio/services/RecordSearchParameters.java @@ -12,7 +12,7 @@ public class RecordSearchParameters { private String leaderSearchExpression; private String fieldsSearchExpression; private Record.RecordType recordType; - private boolean deleted; + private Boolean deleted; private Boolean suppressedFromDiscovery; private Integer limit; private Integer offset; @@ -57,11 +57,11 @@ public void setRecordType(Record.RecordType recordType) { this.recordType = recordType; } - public boolean isDeleted() { + public Boolean isDeleted() { return deleted; } - public void setDeleted(boolean deleted) { + public void setDeleted(Boolean deleted) { this.deleted = deleted; } diff --git a/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/SourceStorageStreamApiTest.java b/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/SourceStorageStreamApiTest.java index 5510b7da7..5744be9fe 100644 --- a/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/SourceStorageStreamApiTest.java +++ b/mod-source-record-storage-server/src/test/java/org/folio/rest/impl/SourceStorageStreamApiTest.java @@ -1195,6 +1195,45 @@ public void shouldReturnRecordOnSearchMarcRecordWhenRecordWasNotSuppressedAndSet async.complete(); } + + @Test + public void shouldReturnRecordOnSearchMarcRecordWhenRecordWasDeletedAndDeletedNotSetInRequest(TestContext testContext) { + // given + postSnapshots(testContext, snapshot_2); + Response createParsed = RestAssured.given() + .spec(spec) + .body(marc_bib_record_2) + .when() + .post(SOURCE_STORAGE_RECORDS_PATH); + assertThat(createParsed.statusCode(), is(HttpStatus.SC_CREATED)); + Record parsed = createParsed.body().as(Record.class); + Async async = testContext.async(); + RestAssured.given() + .spec(spec) + .when() + .delete(SOURCE_STORAGE_RECORDS_PATH + "/" + parsed.getId()) + .then() + .statusCode(HttpStatus.SC_NO_CONTENT); + async.complete(); + MarcRecordSearchRequest searchRequest = new MarcRecordSearchRequest(); + searchRequest.setLeaderSearchExpression("p_05 = 'd'"); + // when + async = testContext.async(); + ExtractableResponse response = RestAssured.given() + .spec(spec) + .body(searchRequest) + .when() + .post("/source-storage/stream/marc-record-identifiers") + .then() + .extract(); + JsonObject responseBody = new JsonObject(response.body().asString()); + // then + assertEquals(HttpStatus.SC_OK, response.statusCode()); + assertEquals(1, responseBody.getJsonArray("records").size()); + assertEquals(1, responseBody.getInteger("totalCount").intValue()); + async.complete(); + } + @Test public void shouldReturnEmptyResponseOnSearchMarcRecordIdsWhenLimitIs0(TestContext testContext) { // given diff --git a/ramls/raml-storage b/ramls/raml-storage index 8f35e1fa5..195de7f9f 160000 --- a/ramls/raml-storage +++ b/ramls/raml-storage @@ -1 +1 @@ -Subproject commit 8f35e1fa5902bab4792a2b4a5511e9eb2a860aef +Subproject commit 195de7f9fd0f5ef76aac6542e11b0391a67e8af0