Skip to content

Commit

Permalink
MODORDERS-344 code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
grabsefx committed Sep 1, 2023
1 parent 95930e8 commit e483c56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/folio/rest/impl/PoLineBatchAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public void putOrdersStoragePoLinesBatch(PoLineCollection poLineCollection, Map<
poLinesBatchService.poLinesBatchUpdate(poLineCollection.getPoLines(), pgClient, okapiHeaders, vertxContext)
.onComplete(ar -> {
if (ar.failed()) {
log.error(getPoLineIdsForLogMessage(poLineCollection.getPoLines()), ar.cause());
log.error("putOrdersStoragePoLinesBatch:: failed, PO line ids: {} ", getPoLineIdsForLogMessage(poLineCollection.getPoLines()), ar.cause());
asyncResultHandler.handle(buildErrorResponse(ar.cause()));
} else {
log.info(getPoLineIdsForLogMessage(poLineCollection.getPoLines()));
log.info("putOrdersStoragePoLinesBatch:: completed, PO line ids: {} ", getPoLineIdsForLogMessage(poLineCollection.getPoLines()));
auditOutboxService.processOutboxEventLogs(okapiHeaders);
asyncResultHandler.handle(buildNoContentResponse());
}
Expand All @@ -62,7 +62,7 @@ protected String getEndpoint(Object entity) {
}

private String getPoLineIdsForLogMessage(List<PoLine> polines) {
return "putOrdersStoragePoLinesBatch completed, PO line ids: " + polines.stream()
return polines.stream()
.map(PoLine::getId)
.collect(Collectors.joining(", "));
}
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/org/folio/services/lines/PoLinesBatchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
import org.apache.logging.log4j.Logger;
import org.folio.event.service.AuditOutboxService;
import org.folio.okapi.common.GenericCompositeFuture;
import org.folio.rest.core.models.RequestContext;
import org.folio.rest.jaxrs.model.OrderLineAuditEvent;
import org.folio.rest.jaxrs.model.PoLine;
import org.folio.rest.persist.Conn;
import org.folio.rest.persist.PostgresClient;

import io.vertx.core.CompositeFuture;
import io.vertx.core.Context;
import io.vertx.core.Future;

Expand All @@ -25,10 +23,10 @@ public class PoLinesBatchService {
private final AuditOutboxService auditOutboxService;
private final PoLinesService poLinesService;


public PoLinesBatchService(AuditOutboxService auditOutboxService, PoLinesService poLinesService) {
this.auditOutboxService = auditOutboxService;
this.poLinesService = poLinesService;

}

public Future<Void> poLinesBatchUpdate(List<PoLine> poLines, PostgresClient pgClient, Map<String, String> okapiHeaders,
Expand All @@ -41,19 +39,20 @@ public Future<Void> poLinesBatchUpdate(List<PoLine> poLines, PostgresClient pgCl

return pgClient.withTrans(conn ->
conn.updateBatch(PO_LINE_TABLE, poLines)
.compose(rowSet -> updatePoLinesWithTitle(conn, poLines, okapiHeaders, vertxContext))
.compose(rowSet -> updatePoLinesWithTitle(conn, poLines))
.compose(rowSet -> auditOutboxService.saveOrderLinesOutboxLogs(conn, poLines, OrderLineAuditEvent.Action.EDIT, okapiHeaders))
.mapEmpty()
);

}

private CompositeFuture updatePoLinesWithTitle(Conn conn, List<PoLine> poLines, Map<String, String> okapiHeaders, Context vertxContext) {
private Future<Void> updatePoLinesWithTitle(Conn conn, List<PoLine> poLines) {
var futures = poLines.stream()
.filter(poLine -> !poLine.getIsPackage())
.map(poLine -> poLinesService.updatePoLineWithTitle(conn, poLine.getId(), poLine, new RequestContext(vertxContext, okapiHeaders)))
.map(poLine -> poLinesService.updateTitle(conn, poLine))
.toList();
return GenericCompositeFuture.join(futures);
return GenericCompositeFuture.join(futures)
.mapEmpty();
}

}

0 comments on commit e483c56

Please sign in to comment.