Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MODAUD-174] - Consume piece change events and implement endpoints #155

Merged
merged 51 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
854e82a
[MODAUD-174] - Consume piece change events and implement endpoints
azizbekxm Nov 9, 2023
3a35fb9
[MODAUD-174] - Fixed unit tests
azizbekxm Nov 9, 2023
dbaaf9f
[MODAUD-174] - Fixed Code smell
azizbekxm Nov 9, 2023
38c6613
[MODAUD-174] - Fixed Code smell
azizbekxm Nov 9, 2023
11961c6
[MODAUD-174] - Fixed Unit tests
azizbekxm Nov 9, 2023
066fbac
[MODAUD-174] - Minor improvements
azizbekxm Nov 9, 2023
536e9ea
[MODAUD-174] - Implements kafka handler and creating table
azizbekxm Nov 10, 2023
97e24a2
[MODAUD-174] - Increased code coverage
azizbekxm Nov 10, 2023
0d3017b
[MODAUD-174] - Increased code coverage
azizbekxm Nov 10, 2023
3262ab6
[MODAUD-174] - Minor improvements
azizbekxm Nov 10, 2023
42fbbad
[MODAUD-174] - Minor improvements
azizbekxm Nov 10, 2023
a2d8ae2
[MODAUD-174] - Minor improvements
azizbekxm Nov 10, 2023
7516c51
[MODAUD-174] - Minor improvements
azizbekxm Nov 13, 2023
90c5205
[MODAUD-174] - Minor improvements
azizbekxm Nov 13, 2023
9a12aac
[MODAUD-174] - Minor improvements
azizbekxm Nov 13, 2023
20a1b7f
[MODAUD-174] - Implemented uniq-status api
azizbekxm Nov 13, 2023
ecd4f24
[MODAUD-174] - Implemented status change history feature and cleaned …
azizbekxm Nov 14, 2023
3811d8a
[MODAUD-174] - Implemented status change history feature and cleaned …
azizbekxm Nov 14, 2023
1646698
[MODAUD-174] - Implemented status change history feature and cleaned …
azizbekxm Nov 14, 2023
df807cc
[MODAUD-174] - draft changes
azizbekxm Nov 14, 2023
aa96b19
[MODAUD-174] - Fixed error
azizbekxm Nov 14, 2023
821a46a
[MODAUD-174] - minor improvements
azizbekxm Nov 14, 2023
d43d0ee
[MODAUD-174] - minor improvements
azizbekxm Nov 14, 2023
d32bc03
[MODAUD-174] - minor improvements
azizbekxm Nov 14, 2023
6aef666
[MODAUD-174] - minor improvements
azizbekxm Nov 14, 2023
86d171f
[MODAUD-174] - minor improvements
azizbekxm Nov 14, 2023
18d7d11
[MODAUD-174] - Fixed unit tests
azizbekxm Nov 15, 2023
ba9d212
[MODAUD-174] - Fixed unit tests
azizbekxm Nov 15, 2023
97307d7
[MODAUD-174] - Fixed unit tests
azizbekxm Nov 15, 2023
3152592
[MODAUD-174] - Fixed unit tests
azizbekxm Nov 15, 2023
d3f3a3d
[MODAUD-174] - draft changes
azizbekxm Nov 15, 2023
c30ce60
[MODAUD-174] - Fixed unit tests
azizbekxm Nov 15, 2023
08482dc
[MODAUD-174] - Minor improvements
azizbekxm Nov 15, 2023
a462a7c
[MODAUD-174] - Minor improvements
azizbekxm Nov 15, 2023
2376e3c
[MODAUD-174] - Minor improvements
azizbekxm Nov 15, 2023
9d66e94
[MODAUD-174] - Improved code by changing field injection to construct…
azizbekxm Nov 15, 2023
f7e9581
[MODAUD-174] - Fixed unit tests
azizbekxm Nov 15, 2023
19d7e9f
[MODAUD-174] - Fixed unit tests
azizbekxm Nov 15, 2023
c72b7b8
[MODAUD-174] - Fixed sql query
azizbekxm Nov 15, 2023
6438c25
[MODAUD-174] - Extracted duplicate methods
azizbekxm Nov 15, 2023
49b39b2
[MODAUD-174] - Added java docs
azizbekxm Nov 15, 2023
d04fa1f
[MODAUD-174] - Improved java integration test
azizbekxm Nov 15, 2023
3132186
[MODAUD-174] - Extracted handleFauilures and optimized codebase
azizbekxm Nov 15, 2023
f8c661e
[MODAUD-174] - Fixed sql query
azizbekxm Nov 15, 2023
82b48db
[MODAUD-174] - Fixed sql query
azizbekxm Nov 15, 2023
af27863
[MODAUD-174] - Minor improvement
azizbekxm Nov 15, 2023
ec50fb3
[MODAUD-174] - Improved AuditDataAcquisitionImpl
azizbekxm Nov 15, 2023
26bcef4
[MODAUD-174] - Improved AuditDataAcquisitionImpl and changed debug to…
azizbekxm Nov 15, 2023
1f00735
[MODAUD-174] - Fixed ZoneOffset
azizbekxm Nov 15, 2023
fda19eb
[MODAUD-174] - Improved log.error message
azizbekxm Nov 15, 2023
3881bdc
[MODAUD-174] - Minor improvements
azizbekxm Nov 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doubt
Do we need to push this?

Copy link
Contributor Author

@azizbekxm azizbekxm Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it avoid situation where intellij idea asks whether add postgres-conf.json to git or not. For me it is useful

Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ nbproject/
.settings/
.classpath
/bin/
/src/main/resources/postgres-conf.json
32 changes: 31 additions & 1 deletion descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,30 @@
}
]
},
{
"id": "acquisition-piece-events",
"version": "1.0",
"handlers": [
{
"methods": [
"GET"
],
"pathPattern": "/audit-data/acquisition/piece/{id}",
"permissionsRequired": [
"acquisition.piece.events.get"
]
},
{
"methods": [
"GET"
],
"pathPattern": "/audit-data/acquisition/piece/{id}/status-change-history",
"permissionsRequired": [
"acquisition.piece.events.get"
]
}
]
},
{
"id": "circulation-logs",
"version": "1.2",
Expand Down Expand Up @@ -223,6 +247,11 @@
"displayName": "Acquisition order-line events - get order-line change events",
"description": "Get order-line change events"
},
{
"permissionName": "acquisition.piece.events.get",
"displayName": "Acquisition piece events - get piece change events",
"description": "Get piece change events"
},
{
"permissionName": "audit.all",
"displayName": "Audit - all permissions",
Expand All @@ -235,7 +264,8 @@
"audit.item.delete",
"circulation-logs.collection.get",
"acquisition.order.events.get",
"acquisition.order-line.events.get"
"acquisition.order-line.events.get",
"acquisition.piece.events.get"
]
}
],
Expand Down
4 changes: 2 additions & 2 deletions mod-audit-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>mod-audit-server</artifactId>
<version>2.8.1-SNAPSHOT</version>
<version>2.9.0-SNAPSHOT</version>
<packaging>jar</packaging>

<parent>
<artifactId>mod-audit</artifactId>
<groupId>org.folio</groupId>
<version>2.8.1-SNAPSHOT</version>
<version>2.9.0-SNAPSHOT</version>
</parent>

<licenses>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.folio.dao.acquisition;

import io.vertx.core.Future;
import io.vertx.sqlclient.Row;
import io.vertx.sqlclient.RowSet;
import org.folio.rest.jaxrs.model.PieceAuditEvent;
import org.folio.rest.jaxrs.model.PieceAuditEventCollection;

public interface PieceEventsDao {

/**
* Saves pieceAuditEvent entity to DB
*
* @param pieceAuditEvent pieceAuditEvent entity to save
* @param tenantId tenant id
* @return future with created row
*/
Future<RowSet<Row>> save(PieceAuditEvent pieceAuditEvent, String tenantId);

/**
* Searches for piece audit events by id
*
* @param pieceId piece id
* @param sortBy sort by
* @param sortOrder sort order
* @param limit limit
* @param offset offset
* @param tenantId tenant id
* @return future with PieceAuditEventCollection
*/
Future<PieceAuditEventCollection> getAuditEventsByPieceId(String pieceId, String sortBy, String sortOrder,
int limit, int offset, String tenantId);

/**
* Searches for piece audit events with status changes by piece id
* @param pieceId piece id
* @param sortBy sort by
* @param sortOrder sort order
* @param limit limit
* @param offset offset
* @param tenantId tenant id
* @return future with PieceAuditEventCollection
*/
Future<PieceAuditEventCollection> getAuditEventsWithStatusChangesByPieceId(String pieceId, String sortBy, String sortOrder,
int limit, int offset, String tenantId);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
package org.folio.dao.acquisition.impl;

import static java.lang.String.format;
import static org.folio.util.AuditEventDBConstants.ACTION_DATE_FIELD;
import static org.folio.util.AuditEventDBConstants.ACTION_FIELD;
import static org.folio.util.AuditEventDBConstants.EVENT_DATE_FIELD;
import static org.folio.util.AuditEventDBConstants.ID_FIELD;
import static org.folio.util.AuditEventDBConstants.MODIFIED_CONTENT_FIELD;
import static org.folio.util.AuditEventDBConstants.ORDER_BY_PATTERN;
import static org.folio.util.AuditEventDBConstants.ORDER_ID_FIELD;
import static org.folio.util.AuditEventDBConstants.TOTAL_RECORDS_FIELD;
import static org.folio.util.AuditEventDBConstants.USER_ID_FIELD;
import static org.folio.util.DbUtils.formatDBTableName;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.Date;
import java.util.UUID;

import io.vertx.core.Future;
import io.vertx.core.Promise;
import io.vertx.core.json.JsonObject;
Expand All @@ -12,18 +30,8 @@
import org.folio.rest.jaxrs.model.OrderAuditEvent;
import org.folio.rest.jaxrs.model.OrderAuditEventCollection;
import org.folio.util.PostgresClientFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;
import java.util.UUID;

import static java.lang.String.format;
import static org.folio.rest.persist.PostgresClient.convertToPsqlStandard;
import static org.folio.util.OrderAuditEventDBConstants.*;

@Repository
public class OrderEventsDaoImpl implements OrderEventsDao {

Expand All @@ -37,10 +45,8 @@ public class OrderEventsDaoImpl implements OrderEventsDao {
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
public OrderEventsDaoImpl(PostgresClientFactory pgClientFactory) {
this.pgClientFactory = pgClientFactory;
}
Expand All @@ -49,10 +55,9 @@ public OrderEventsDaoImpl(PostgresClientFactory pgClientFactory) {
public Future<RowSet<Row>> save(OrderAuditEvent orderAuditEvent, String tenantId) {
LOGGER.debug("save:: Saving Order AuditEvent with tenant id : {}", tenantId);
Promise<RowSet<Row>> promise = Promise.promise();
LOGGER.debug("formatDBTableName:: Formatting DB Table Name with tenant id : {}", tenantId);
String logTable = formatDBTableName(tenantId, TABLE_NAME);

String query = format(INSERT_SQL, logTable);

makeSaveCall(promise, query, orderAuditEvent, tenantId);
LOGGER.info("save:: Saved Order AuditEvent with tenant id : {}", tenantId);
return promise.future();
Expand All @@ -63,7 +68,7 @@ public Future<OrderAuditEventCollection> getAuditEventsByOrderId(String orderId,
LOGGER.debug("getAuditEventsByOrderId:: Retrieving AuditEvent with order id : {}", orderId);
Promise<RowSet<Row>> promise = Promise.promise();
try {
LOGGER.info("getAuditEventsByOrderId:: Trying to Retrieve AuditEvent with order id : {}", orderId);
LOGGER.debug("formatDBTableName:: Formatting DB Table Name with tenant id : {}", tenantId);
String logTable = formatDBTableName(tenantId, TABLE_NAME);
String query = format(GET_BY_ORDER_ID_SQL, logTable, logTable, format(ORDER_BY_PATTERN, sortBy, sortOrder));
Tuple queryParams = Tuple.of(UUID.fromString(orderId), limit, offset);
Expand All @@ -85,11 +90,11 @@ private void makeSaveCall(Promise<RowSet<Row>> promise, String query, OrderAudit
orderAuditEvent.getAction(),
orderAuditEvent.getOrderId(),
orderAuditEvent.getUserId(),
LocalDateTime.ofInstant(orderAuditEvent.getEventDate().toInstant(), ZoneOffset.UTC),
LocalDateTime.ofInstant(orderAuditEvent.getActionDate().toInstant(), ZoneOffset.UTC),
LocalDateTime.ofInstant(orderAuditEvent.getEventDate().toInstant(), ZoneId.systemDefault()),
LocalDateTime.ofInstant(orderAuditEvent.getActionDate().toInstant(), ZoneId.systemDefault()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for may knowledge why we need to change ZoneOffset here?

Copy link
Contributor Author

@azizbekxm azizbekxm Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1- orderAuditEvent.getActionDate().toInstant() this part converting date to second
2- LocalDateTime.ofInstant(orderAuditEvent.getActionDate().toInstant(), ZoneId.systemDefault()) localdatetime creating date time from second based on system zoneId

JsonObject.mapFrom(orderAuditEvent.getOrderSnapshot())), promise);
} catch (Exception e) {
LOGGER.warn("Failed to save record with id: {} for order id: {} in to table {}",
LOGGER.error("Failed to save record with id: {} for order id: {} in to table {}",
orderAuditEvent.getId(), orderAuditEvent.getOrderId(), TABLE_NAME, e);
promise.fail(e);
}
Expand Down Expand Up @@ -119,8 +124,4 @@ private OrderAuditEvent mapRowToOrderEvent(Row row) {
.withOrderSnapshot(JsonObject.mapFrom(row.getValue(MODIFIED_CONTENT_FIELD)));
}

private String formatDBTableName(String tenantId, String table) {
LOGGER.debug("formatDBTableName:: Formatting DB Table Name with tenant id : {}", tenantId);
return format("%s.%s", convertToPsqlStandard(tenantId), table);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
package org.folio.dao.acquisition.impl;

import static java.lang.String.format;
import static org.folio.util.AuditEventDBConstants.ACTION_DATE_FIELD;
import static org.folio.util.AuditEventDBConstants.ACTION_FIELD;
import static org.folio.util.AuditEventDBConstants.EVENT_DATE_FIELD;
import static org.folio.util.AuditEventDBConstants.ID_FIELD;
import static org.folio.util.AuditEventDBConstants.MODIFIED_CONTENT_FIELD;
import static org.folio.util.AuditEventDBConstants.ORDER_BY_PATTERN;
import static org.folio.util.AuditEventDBConstants.ORDER_ID_FIELD;
import static org.folio.util.AuditEventDBConstants.ORDER_LINE_ID_FIELD;
import static org.folio.util.AuditEventDBConstants.TOTAL_RECORDS_FIELD;
import static org.folio.util.AuditEventDBConstants.USER_ID_FIELD;
import static org.folio.util.DbUtils.formatDBTableName;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.Date;
import java.util.UUID;

import io.vertx.core.Future;
import io.vertx.core.Promise;
import io.vertx.core.json.JsonObject;
Expand All @@ -12,18 +31,8 @@
import org.folio.rest.jaxrs.model.OrderLineAuditEvent;
import org.folio.rest.jaxrs.model.OrderLineAuditEventCollection;
import org.folio.util.PostgresClientFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;
import java.util.UUID;

import static java.lang.String.format;
import static org.folio.rest.persist.PostgresClient.convertToPsqlStandard;
import static org.folio.util.OrderAuditEventDBConstants.*;

@Repository
public class OrderLineEventsDaoImpl implements OrderLineEventsDao {

Expand All @@ -38,10 +47,8 @@ public class OrderLineEventsDaoImpl implements OrderLineEventsDao {
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
public OrderLineEventsDaoImpl(PostgresClientFactory pgClientFactory) {
this.pgClientFactory = pgClientFactory;
}
Expand All @@ -50,12 +57,10 @@ public OrderLineEventsDaoImpl(PostgresClientFactory pgClientFactory) {
public Future<RowSet<Row>> save(OrderLineAuditEvent orderLineAuditEvent, String tenantId) {
LOGGER.debug("save:: Saving OrderLine AuditEvent with tenant id : {}", tenantId);
Promise<RowSet<Row>> promise = Promise.promise();
LOGGER.debug("formatDBTableName:: Formatting DB Table Name with tenant id : {}", tenantId);
String logTable = formatDBTableName(tenantId, TABLE_NAME);

String query = format(INSERT_SQL, logTable);

makeSaveCall(promise, query, orderLineAuditEvent, tenantId);

LOGGER.info("save:: Saved OrderLine AuditEvent with tenant id : {}", tenantId);
return promise.future();
}
Expand All @@ -65,7 +70,7 @@ public Future<OrderLineAuditEventCollection> getAuditEventsByOrderLineId(String
LOGGER.debug("getAuditEventsByOrderLineId:: Retrieving AuditEvent with order line id : {}", orderLineId);
Promise<RowSet<Row>> promise = Promise.promise();
try {
LOGGER.info("getAuditEventsByOrderLineId:: Trying to Retrieve AuditEvent with order line id : {}", orderLineId);
LOGGER.debug("formatDBTableName:: Formatting DB Table Name with tenant id : {}", tenantId);
String logTable = formatDBTableName(tenantId, TABLE_NAME);
String query = format(GET_BY_ORDER_LINE_ID_SQL, logTable, logTable, format(ORDER_BY_PATTERN, sortBy, sortOrder));
Tuple queryParams = Tuple.of(UUID.fromString(orderLineId), limit, offset);
Expand All @@ -88,11 +93,11 @@ private void makeSaveCall(Promise<RowSet<Row>> promise, String query, OrderLineA
orderLineAuditEvent.getOrderId(),
orderLineAuditEvent.getOrderLineId(),
orderLineAuditEvent.getUserId(),
LocalDateTime.ofInstant(orderLineAuditEvent.getEventDate().toInstant(), ZoneOffset.UTC),
LocalDateTime.ofInstant(orderLineAuditEvent.getActionDate().toInstant(), ZoneOffset.UTC),
LocalDateTime.ofInstant(orderLineAuditEvent.getEventDate().toInstant(), ZoneId.systemDefault()),
LocalDateTime.ofInstant(orderLineAuditEvent.getActionDate().toInstant(), ZoneId.systemDefault()),
JsonObject.mapFrom(orderLineAuditEvent.getOrderLineSnapshot())), promise);
} catch (Exception e) {
LOGGER.warn("Failed to save record with id: {} for order line id: {} in to table {}",
LOGGER.error("Failed to save record with id: {} for order line id: {} in to table {}",
orderLineAuditEvent.getId(), orderLineAuditEvent.getOrderLineId(), TABLE_NAME, e);
promise.fail(e);
}
Expand Down Expand Up @@ -122,9 +127,4 @@ private OrderLineAuditEvent mapRowToOrderLineEvent(Row row) {
.withActionDate(Date.from(row.getLocalDateTime(ACTION_DATE_FIELD).toInstant(ZoneOffset.UTC)))
.withOrderLineSnapshot(JsonObject.mapFrom(row.getValue(MODIFIED_CONTENT_FIELD)));
}

private String formatDBTableName(String tenantId, String table) {
LOGGER.debug("formatDBTableName:: Formatting DB Table Name with tenant id : {}", tenantId);
return format("%s.%s", convertToPsqlStandard(tenantId), table);
}
}
Loading