Skip to content

Commit

Permalink
[MODAUD-174] - Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
azizbekxm committed Nov 13, 2023
1 parent a2d8ae2 commit 7516c51
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public Future<PieceAuditEventCollection> 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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@
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
public class PieceEventsHandler implements AsyncRecordHandler<String, String> {

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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7516c51

Please sign in to comment.