-
Notifications
You must be signed in to change notification settings - Fork 8
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
Changes from 50 commits
854e82a
3a35fb9
dbaaf9f
38c6613
11961c6
066fbac
536e9ea
97e24a2
0d3017b
3262ab6
42fbbad
a2d8ae2
7516c51
90c5205
9a12aac
20a1b7f
ecd4f24
3811d8a
1646698
df807cc
aa96b19
821a46a
d43d0ee
d32bc03
6aef666
86d171f
18d7d11
ba9d212
97307d7
3152592
d3f3a3d
c30ce60
08482dc
a462a7c
2376e3c
9d66e94
f7e9581
19d7e9f
c72b7b8
6438c25
49b39b2
d04fa1f
3132186
f8c661e
82b48db
af27863
ec50fb3
26bcef4
1f00735
fda19eb
3881bdc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,4 @@ nbproject/ | |
.settings/ | ||
.classpath | ||
/bin/ | ||
/src/main/resources/postgres-conf.json |
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; | ||
|
@@ -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 { | ||
|
||
|
@@ -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; | ||
} | ||
|
@@ -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(); | ||
|
@@ -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); | ||
|
@@ -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()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for may knowledge why we need to change ZoneOffset here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1- orderAuditEvent.getActionDate().toInstant() this part converting date to second |
||
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); | ||
} | ||
|
@@ -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); | ||
} | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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