From 7516c51c89b1b8a827509fb351989d4fa0d7756e Mon Sep 17 00:00:00 2001 From: azizbekxm Date: Mon, 13 Nov 2023 16:38:46 +0500 Subject: [PATCH] [MODAUD-174] - Minor improvements --- .../acquisition/impl/OrderEventsDaoImpl.java | 10 +++++++--- .../impl/OrderLineEventsDaoImpl.java | 8 ++++++-- .../acquisition/impl/PieceEventsDaoImpl.java | 3 ++- .../consumers/PieceEventsHandler.java | 8 +++++--- .../impl/AuditDataAcquisitionAPITest.java | 19 +++++++++---------- .../rest/impl/PieceEventsHandlerMockTest.java | 2 +- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/mod-audit-server/src/main/java/org/folio/dao/acquisition/impl/OrderEventsDaoImpl.java b/mod-audit-server/src/main/java/org/folio/dao/acquisition/impl/OrderEventsDaoImpl.java index e323cfe..f866e24 100644 --- a/mod-audit-server/src/main/java/org/folio/dao/acquisition/impl/OrderEventsDaoImpl.java +++ b/mod-audit-server/src/main/java/org/folio/dao/acquisition/impl/OrderEventsDaoImpl.java @@ -28,12 +28,16 @@ public class OrderEventsDaoImpl implements OrderEventsDao { private static final Logger LOGGER = LogManager.getLogger(); - private static final String TABLE_NAME = "acquisition_order_log"; - private static final String GET_BY_ORDER_ID_SQL = "SELECT id, action, order_id, user_id, event_date, action_date, modified_content_snapshot," + + + public static final String TABLE_NAME = "acquisition_order_log"; + + public static final String GET_BY_ORDER_ID_SQL = "SELECT id, action, order_id, user_id, event_date, action_date, modified_content_snapshot," + " (SELECT count(*) AS total_records FROM %s WHERE order_id = $1) FROM %s WHERE order_id = $1 %s LIMIT $2 OFFSET $3"; - private static final String INSERT_SQL = "INSERT INTO %s (id, action, order_id, user_id, event_date, action_date, modified_content_snapshot)" + + + public static final String INSERT_SQL = "INSERT INTO %s (id, action, order_id, user_id, event_date, action_date, modified_content_snapshot)" + " VALUES ($1, $2, $3, $4, $5, $6, $7)"; + @Autowired private final PostgresClientFactory pgClientFactory; @Autowired diff --git a/mod-audit-server/src/main/java/org/folio/dao/acquisition/impl/OrderLineEventsDaoImpl.java b/mod-audit-server/src/main/java/org/folio/dao/acquisition/impl/OrderLineEventsDaoImpl.java index 01cdc50..edae488 100644 --- a/mod-audit-server/src/main/java/org/folio/dao/acquisition/impl/OrderLineEventsDaoImpl.java +++ b/mod-audit-server/src/main/java/org/folio/dao/acquisition/impl/OrderLineEventsDaoImpl.java @@ -28,13 +28,17 @@ public class OrderLineEventsDaoImpl implements OrderLineEventsDao { private static final Logger LOGGER = LogManager.getLogger(); - private static final String TABLE_NAME = "acquisition_order_line_log"; - private static final String GET_BY_ORDER_LINE_ID_SQL = "SELECT id, action, order_id, order_line_id, user_id, event_date, action_date, modified_content_snapshot," + + + public static final String TABLE_NAME = "acquisition_order_line_log"; + + public static final String GET_BY_ORDER_LINE_ID_SQL = "SELECT id, action, order_id, order_line_id, user_id, event_date, action_date, modified_content_snapshot," + " (SELECT count(*) AS total_records FROM %s WHERE order_line_id = $1) " + " FROM %s WHERE order_line_id = $1 %s LIMIT $2 OFFSET $3"; + private static final String INSERT_SQL = "INSERT INTO %s (id, action, order_id, order_line_id, user_id, event_date, action_date, modified_content_snapshot) " + "VALUES ($1, $2, $3, $4, $5, $6, $7, $8)"; + @Autowired private final PostgresClientFactory pgClientFactory; @Autowired diff --git a/mod-audit-server/src/main/java/org/folio/dao/acquisition/impl/PieceEventsDaoImpl.java b/mod-audit-server/src/main/java/org/folio/dao/acquisition/impl/PieceEventsDaoImpl.java index ed07e30..2661781 100644 --- a/mod-audit-server/src/main/java/org/folio/dao/acquisition/impl/PieceEventsDaoImpl.java +++ b/mod-audit-server/src/main/java/org/folio/dao/acquisition/impl/PieceEventsDaoImpl.java @@ -76,7 +76,8 @@ public Future getAuditEventsByPieceId(String pieceId, promise.fail(e); } LOGGER.info("getAuditEventsByOrderId:: Retrieved AuditEvent with piece id : {}", pieceId); - return promise.future().map(rowSet -> rowSet.rowCount() == 0 ? new PieceAuditEventCollection().withTotalItems(0) : + return promise.future().map(rowSet -> rowSet.rowCount() == 0 ? + new PieceAuditEventCollection().withTotalItems(0) : mapRowToListOfPieceEvent(rowSet)); } diff --git a/mod-audit-server/src/main/java/org/folio/verticle/acquisition/consumers/PieceEventsHandler.java b/mod-audit-server/src/main/java/org/folio/verticle/acquisition/consumers/PieceEventsHandler.java index 923ebdf..e1c947d 100644 --- a/mod-audit-server/src/main/java/org/folio/verticle/acquisition/consumers/PieceEventsHandler.java +++ b/mod-audit-server/src/main/java/org/folio/verticle/acquisition/consumers/PieceEventsHandler.java @@ -16,6 +16,7 @@ import org.folio.rest.jaxrs.model.PieceAuditEvent; import org.folio.rest.util.OkapiConnectionParams; import org.folio.services.acquisition.PieceAuditEventsService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component @@ -23,10 +24,11 @@ public class PieceEventsHandler implements AsyncRecordHandler { private static final Logger LOGGER = LogManager.getLogger(); - private final PieceAuditEventsService pieceAuditEventsService; - private final Vertx vertx; + private PieceAuditEventsService pieceAuditEventsService; + private Vertx vertx; - public PieceEventsHandler(PieceAuditEventsService pieceAuditEventsService, Vertx vertx) { + public PieceEventsHandler(@Autowired Vertx vertx, + @Autowired PieceAuditEventsService pieceAuditEventsService) { this.pieceAuditEventsService = pieceAuditEventsService; this.vertx = vertx; } diff --git a/mod-audit-server/src/test/java/org/folio/rest/impl/AuditDataAcquisitionAPITest.java b/mod-audit-server/src/test/java/org/folio/rest/impl/AuditDataAcquisitionAPITest.java index e0333ff..6e68270 100644 --- a/mod-audit-server/src/test/java/org/folio/rest/impl/AuditDataAcquisitionAPITest.java +++ b/mod-audit-server/src/test/java/org/folio/rest/impl/AuditDataAcquisitionAPITest.java @@ -1,5 +1,14 @@ package org.folio.rest.impl; +import static io.restassured.RestAssured.given; +import static org.folio.utils.EntityUtils.ORDER_ID; +import static org.folio.utils.EntityUtils.ORDER_LINE_ID; +import static org.folio.utils.EntityUtils.PIECE_ID; +import static org.hamcrest.Matchers.containsString; + +import java.util.Date; +import java.util.UUID; + import io.restassured.http.Header; import io.vertx.core.Vertx; import io.vertx.core.json.JsonObject; @@ -16,16 +25,6 @@ import org.mockito.MockitoAnnotations; import org.mockito.Spy; -import java.util.Date; -import java.util.UUID; - -import static io.restassured.RestAssured.given; -import static org.folio.utils.EntityUtils.ORDER_ID; -import static org.folio.utils.EntityUtils.ORDER_LINE_ID; -import static org.folio.utils.EntityUtils.PIECE_ID; -import static org.folio.utils.EntityUtils.createPieceAuditEvent; -import static org.hamcrest.Matchers.*; - public class AuditDataAcquisitionAPITest extends ApiTestBase { private static final Header TENANT = new Header("X-Okapi-Tenant", "modaudittest"); diff --git a/mod-audit-server/src/test/java/org/folio/rest/impl/PieceEventsHandlerMockTest.java b/mod-audit-server/src/test/java/org/folio/rest/impl/PieceEventsHandlerMockTest.java index 0afcf97..553a446 100644 --- a/mod-audit-server/src/test/java/org/folio/rest/impl/PieceEventsHandlerMockTest.java +++ b/mod-audit-server/src/test/java/org/folio/rest/impl/PieceEventsHandlerMockTest.java @@ -54,7 +54,7 @@ public void setUp() throws Exception { MockitoAnnotations.openMocks(this).close(); pieceEventsDao = new PieceEventsDaoImpl(postgresClientFactory); pieceAuditEventsService = new PieceAuditEventsServiceImpl(pieceEventsDao); - pieceEventsHandler = new PieceEventsHandler(pieceAuditEventsService, vertx); + pieceEventsHandler = new PieceEventsHandler(vertx, pieceAuditEventsService); } @Test