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

[MODORDERS-1227]. Perform a new round of deletion of sensitive information from logs in acq modules #1081

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 5 additions & 8 deletions src/main/java/org/folio/helper/PurchaseOrderHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,13 @@ public Future<CompositePurchaseOrder> postCompositeOrder(CompositePurchaseOrder
if (CollectionUtils.isEmpty(errors)) {
logger.info("postCompositeOrder :: Creating PO and POLines...");
return createPurchaseOrder(compPO, tenantConfig, requestContext)
.onSuccess(po -> logger.info("postCompositeOrder :: Successfully Placed Order: {}",
JsonObject.mapFrom(po).encodePrettily()));
.onSuccess(po -> logger.info("postCompositeOrder :: Successfully Placed Order"));
} else {
throw new HttpException(422, new Errors().withErrors(errors)
.withTotalRecords(errors.size()));
}
}))
.onFailure(t -> logger.error("postCompositeOrder :: Failed to create order: {}",
JsonObject.mapFrom(compPO).encodePrettily(), t));
.onFailure(t -> logger.error("postCompositeOrder :: Failed to create order", t));
}

/**
Expand Down Expand Up @@ -207,15 +205,14 @@ public Future<Void> putCompositeOrderById(String orderId, boolean deleteHoldings
.map(validationErrors -> {
if (CollectionUtils.isNotEmpty(validationErrors)) {
Errors errors = new Errors().withErrors(validationErrors).withTotalRecords(validationErrors.size());
logger.error("putCompositeOrderById :: Validation error. Failed to update purchase order : {}",
logger.error("putCompositeOrderById :: Validation error. Failed to update purchase order, errors: {}",
JsonObject.mapFrom(errors).encodePrettily());
throw new HttpException(RestConstants.VALIDATION_ERROR, errors);
}
return null;
}).compose(v -> updateOrder(compPO, deleteHoldings, requestContext))
.onSuccess(v -> logger.info("putCompositeOrderById :: Successfully updated order: {}", compPO.getId()))
.onFailure(t -> logger.error("putCompositeOrderById :: Failed to update order: {}",
JsonObject.mapFrom(compPO).encodePrettily(), t));
.onSuccess(v -> logger.info("putCompositeOrderById :: Successfully updated order, id: {}", compPO.getId()))
.onFailure(t -> logger.error("putCompositeOrderById :: Failed to update order", t));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public Future<CompositePoLine> createPoLine(CompositePoLine compPOL, JsonObject
.compose(v -> createPoLineWithOrder(compPOL, po, requestContext)));
}
var errors = new Errors().withErrors(validationErrors).withTotalRecords(validationErrors.size());
logger.error("Create POL validation error : {}", JsonObject.mapFrom(errors).encodePrettily());
logger.error("Create POL validation error: {}", JsonObject.mapFrom(errors).encodePrettily());
throw new HttpException(RestConstants.VALIDATION_ERROR, errors);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ protected AbstractOrderStatusHandler(Context ctx, EncumbranceService encumbrance

@Override
public void handle(Message<JsonObject> message) {
JsonObject body = message.body();
logger.debug("Received message body: {}", body);

Map<String, String> okapiHeaders = getOkapiHeaders(message);

List<Future<Void>> futures = new ArrayList<>();
Expand Down Expand Up @@ -103,7 +100,6 @@ protected Future<Void> updateOrderStatus(PurchaseOrder purchaseOrder, List<PoLin

protected JsonArray messageAsJsonArray(String rootElement, Message<JsonObject> message) {
JsonObject body = message.body();
logger.debug("Received message body: {}", body);
return body.getJsonArray(rootElement);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ public ReceiptStatusConsistency(Vertx vertx, PieceStorageService pieceStorageSer
@Override
public void handle(Message<JsonObject> message) {
var messageFromEventBus = message.body();
logger.info("Received message body: {}", messageFromEventBus);

var okapiHeaders = getOkapiHeaders(message);
var requestContext = new RequestContext(ctx, okapiHeaders);

var poLineId = getPoLineId(messageFromEventBus);
var future = pieceStorageService.getPiecesByLineId(poLineId, requestContext)
.compose(pieces -> purchaseOrderLineService.getOrderLineById(poLineId, requestContext)
Expand Down
45 changes: 2 additions & 43 deletions src/main/java/org/folio/rest/core/RestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import io.vertx.core.MultiMap;
import io.vertx.core.Promise;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.client.HttpResponse;
import io.vertx.ext.web.client.WebClient;
Expand All @@ -31,8 +30,6 @@
public class RestClient {

private static final Logger log = LogManager.getLogger(RestClient.class);
private static final String CALLING_ENDPOINT_MSG = "Sending {} {}";
private static final String SENDING_POST_WITH_BODY_MSG = "Sending 'POST {}' with body: {}";

private static final ErrorConverter ERROR_CONVERTER = ErrorConverter.createFullBody(
result -> {
Expand All @@ -48,9 +45,6 @@ public <T> Future<T> post(RequestEntry requestEntry, T entity, Class<T> response
}

public <T> Future<T> post(String endpoint, T entity, Class<T> responseType, RequestContext requestContext) {
if (log.isDebugEnabled()) {
log.debug(SENDING_POST_WITH_BODY_MSG, endpoint, JsonObject.mapFrom(entity).encodePrettily());
}
var caseInsensitiveHeader = convertToCaseInsensitiveMap(requestContext.getHeaders());
return getVertxWebClient(requestContext.getContext()).postAbs(buildAbsEndpoint(caseInsensitiveHeader, endpoint))
.putHeaders(caseInsensitiveHeader)
Expand All @@ -66,7 +60,6 @@ public <T> Future<T> post(String endpoint, T entity, Class<T> responseType, Requ
}

public <T> Future<Void> postEmptyResponse(String endpoint, T entity, RequestContext requestContext) {
log.debug(SENDING_POST_WITH_BODY_MSG, () -> endpoint, () -> JsonObject.mapFrom(entity).encodePrettily());
var caseInsensitiveHeader = convertToCaseInsensitiveMap(requestContext.getHeaders());
return getVertxWebClient(requestContext.getContext())
.postAbs(buildAbsEndpoint(caseInsensitiveHeader, endpoint))
Expand All @@ -89,11 +82,7 @@ public <T> Future<Void> put(RequestEntry requestEntry, T dataObject, RequestCont
}
public <T> Future<Void> put(String endpoint, T dataObject, RequestContext requestContext) {
var recordData = JsonObject.mapFrom(dataObject);
if (log.isDebugEnabled()) {
log.debug("Sending 'PUT {}' with body: {}", endpoint, recordData.encodePrettily());
}
var caseInsensitiveHeader = convertToCaseInsensitiveMap(requestContext.getHeaders());

return getVertxWebClient(requestContext.getContext())
.putAbs(buildAbsEndpoint(caseInsensitiveHeader, endpoint))
.putHeaders(caseInsensitiveHeader)
Expand All @@ -109,14 +98,8 @@ public <T>Future<Void> patch(RequestEntry requestEntry, T dataObject, RequestCon
}

public <T>Future<Void> patch(String endpoint, T dataObject, RequestContext requestContext) {
var recordData = JsonObject.mapFrom(dataObject);
if (log.isDebugEnabled()) {
log.debug("Sending 'PATCH {}' with body: {}", endpoint, recordData.encodePrettily());
}
var caseInsensitiveHeader = convertToCaseInsensitiveMap(requestContext.getHeaders());

Promise<Void> promise = Promise.promise();

return getVertxWebClient(requestContext.getContext())
.patchAbs(buildAbsEndpoint(caseInsensitiveHeader, endpoint))
.putHeaders(caseInsensitiveHeader)
Expand All @@ -133,11 +116,8 @@ public Future<Void> delete(RequestEntry requestEntry, boolean skipError404, Requ
}

public Future<Void> delete(String endpointById, boolean skipError404, RequestContext requestContext) {
log.debug(CALLING_ENDPOINT_MSG, HttpMethod.DELETE, endpointById);

var caseInsensitiveHeader = convertToCaseInsensitiveMap(requestContext.getHeaders());
Promise<Void> promise = Promise.promise();

getVertxWebClient(requestContext.getContext())
.deleteAbs(buildAbsEndpoint(caseInsensitiveHeader, endpointById))
.putHeaders(caseInsensitiveHeader)
Expand Down Expand Up @@ -185,22 +165,15 @@ public <T> Future<T> get(RequestEntry requestEntry, Class<T> responseType, Reque
}

public <T> Future<T> get(String endpoint, boolean skipError404, Class<T> responseType, RequestContext requestContext) {
log.debug("Calling GET {}", endpoint);
var caseInsensitiveHeader = convertToCaseInsensitiveMap(requestContext.getHeaders());

Promise<T> promise = Promise.promise();
getVertxWebClient(requestContext.getContext())
.getAbs(buildAbsEndpoint(caseInsensitiveHeader, endpoint))
.putHeaders(caseInsensitiveHeader)
.expect(SUCCESS_RESPONSE_PREDICATE)
.send()
.map(HttpResponse::bodyAsJsonObject)
.map(jsonObject -> {
if (log.isDebugEnabled()) {
log.debug("Successfully retrieved: {}", jsonObject.encodePrettily());
}
return jsonObject.mapTo(responseType);
})
.map(jsonObject -> jsonObject.mapTo(responseType))
.onSuccess(promise::complete)
.onFailure(t -> handleGetMethodErrorResponse(promise, t, skipError404));

Expand All @@ -209,22 +182,15 @@ public <T> Future<T> get(String endpoint, boolean skipError404, Class<T> respons


public Future<JsonObject> getAsJsonObject(String endpoint, boolean skipError404, RequestContext requestContext) {
log.debug("Calling GET {}", endpoint);
Promise<JsonObject> promise = Promise.promise();
var caseInsensitiveHeader = convertToCaseInsensitiveMap(requestContext.getHeaders());
var webClient = getVertxWebClient(requestContext.getContext());

webClient.getAbs(buildAbsEndpoint(caseInsensitiveHeader, endpoint))
.putHeaders(caseInsensitiveHeader)
.expect(SUCCESS_RESPONSE_PREDICATE)
.send()
.map(HttpResponse::bodyAsJsonObject)
.onSuccess(jsonObject -> {
if (log.isDebugEnabled()) {
log.debug("Successfully retrieved: {}", jsonObject.encodePrettily());
}
promise.complete(jsonObject);
})
.onSuccess(promise::complete)
.onFailure(t -> handleGetMethodErrorResponse(promise, t, skipError404));
return promise.future();
}
Expand Down Expand Up @@ -266,11 +232,7 @@ private String buildAbsEndpoint(MultiMap okapiHeaders, String endpoint) {
}

public Future<String> postJsonObjectAndGetId(RequestEntry requestEntry, JsonObject entity, RequestContext requestContext) {
if (log.isDebugEnabled()) {
log.debug(SENDING_POST_WITH_BODY_MSG, requestEntry.buildEndpoint(), JsonObject.mapFrom(entity).encodePrettily());
}
var caseInsensitiveHeader = convertToCaseInsensitiveMap(requestContext.getHeaders());

return getVertxWebClient(requestContext.getContext())
.postAbs(buildAbsEndpoint(caseInsensitiveHeader, requestEntry.buildEndpoint()))
.putHeaders(caseInsensitiveHeader)
Expand All @@ -281,9 +243,6 @@ public Future<String> postJsonObjectAndGetId(RequestEntry requestEntry, JsonObje
}

public Future<JsonObject> postJsonObject(RequestEntry requestEntry, JsonObject jsonObject, RequestContext requestContext) {
if (log.isDebugEnabled()) {
log.debug(SENDING_POST_WITH_BODY_MSG, requestEntry.buildEndpoint(), jsonObject.encodePrettily());
}
var endpoint = requestEntry.buildEndpoint();
var caseInsensitiveHeader = convertToCaseInsensitiveMap(requestContext.getHeaders());
return getVertxWebClient(requestContext.getContext()).postAbs(buildAbsEndpoint(caseInsensitiveHeader, requestEntry.buildEndpoint()))
Expand Down
47 changes: 8 additions & 39 deletions src/main/java/org/folio/rest/impl/AcquisitionsUnitsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import io.vertx.core.Context;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;

public class AcquisitionsUnitsApi extends BaseApi implements AcquisitionsUnits {

Expand All @@ -46,13 +45,8 @@ public void postAcquisitionsUnitsUnits(AcquisitionsUnit entity, Map<String, Stri
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {

acquisitionsUnitsService.createAcquisitionsUnit(entity, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(unit -> {
if (logger.isInfoEnabled()) {
logger.debug("Successfully created new acquisitions unit: {} ", JsonObject.mapFrom(unit).encodePrettily());
}
asyncResultHandler.handle(succeededFuture(buildResponseWithLocation(
okapiHeaders.get(OKAPI_URL), resourceByIdPath(ACQUISITIONS_UNITS, unit.getId()), unit)));
})
.onSuccess(unit -> asyncResultHandler.handle(succeededFuture(buildResponseWithLocation(
okapiHeaders.get(OKAPI_URL), resourceByIdPath(ACQUISITIONS_UNITS, unit.getId()), unit))))
.onFailure(t -> handleErrorResponse(asyncResultHandler, t));
}

Expand All @@ -62,12 +56,7 @@ public void getAcquisitionsUnitsUnits(String query, String totalRecords, int off
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {

acquisitionsUnitsService.getAcquisitionsUnits(query, offset, limit, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(units -> {
if (logger.isInfoEnabled()) {
logger.debug("Successfully retrieved acquisitions units: {}", JsonObject.mapFrom(units).encodePrettily());
}
asyncResultHandler.handle(succeededFuture(buildOkResponse(units)));
})
.onSuccess(units -> asyncResultHandler.handle(succeededFuture(buildOkResponse(units))))
.onFailure(t -> handleErrorResponse(asyncResultHandler, t));
}

Expand Down Expand Up @@ -95,12 +84,7 @@ public void getAcquisitionsUnitsUnitsById(String id, Map<String, String> okapiHe
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {

acquisitionsUnitsService.getAcquisitionsUnit(id, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(unit -> {
if (logger.isInfoEnabled()) {
logger.debug("Successfully retrieved acquisitions unit: {}", JsonObject.mapFrom(unit).encodePrettily());
}
asyncResultHandler.handle(succeededFuture(buildOkResponse(unit)));
})
.onSuccess(unit -> asyncResultHandler.handle(succeededFuture(buildOkResponse(unit))))
.onFailure(t -> handleErrorResponse(asyncResultHandler, t));
}

Expand All @@ -125,13 +109,8 @@ public void postAcquisitionsUnitsMemberships(AcquisitionsUnitMembership entity,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {

acquisitionsUnitsService.createAcquisitionsUnitsMembership(entity, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(membership -> {
if (logger.isInfoEnabled()) {
logger.debug("Successfully created new acquisitions units membership: {}", JsonObject.mapFrom(membership).encodePrettily());
}
asyncResultHandler.handle(
succeededFuture(buildResponseWithLocation(okapiHeaders.get(OKAPI_URL), resourceByIdPath(ACQUISITIONS_MEMBERSHIPS, membership.getId()), membership)));
})
.onSuccess(membership -> asyncResultHandler.handle(
succeededFuture(buildResponseWithLocation(okapiHeaders.get(OKAPI_URL), resourceByIdPath(ACQUISITIONS_MEMBERSHIPS, membership.getId()), membership))))
.onFailure(t -> handleErrorResponse(asyncResultHandler, t));
}

Expand All @@ -140,12 +119,7 @@ public void postAcquisitionsUnitsMemberships(AcquisitionsUnitMembership entity,
public void getAcquisitionsUnitsMemberships(String query, String totalRecords, int offset, int limit, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
acquisitionsUnitsService.getAcquisitionsUnitsMemberships(query, offset, limit, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(memberships -> {
if (logger.isInfoEnabled()) {
logger.debug("Successfully retrieved acquisitions units memberships: {}", JsonObject.mapFrom(memberships).encodePrettily());
}
asyncResultHandler.handle(succeededFuture(buildOkResponse(memberships)));
})
.onSuccess(memberships -> asyncResultHandler.handle(succeededFuture(buildOkResponse(memberships))))
.onFailure(t -> handleErrorResponse(asyncResultHandler, t));
}

Expand All @@ -169,12 +143,7 @@ public void putAcquisitionsUnitsMembershipsById(String id, AcquisitionsUnitMembe
@Validate
public void getAcquisitionsUnitsMembershipsById(String id, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
acquisitionsUnitsService.getAcquisitionsUnitsMembership(id, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(membership -> {
if (logger.isInfoEnabled()) {
logger.debug("Successfully retrieved acquisitions units membership: {}", JsonObject.mapFrom(membership).encodePrettily());
}
asyncResultHandler.handle(succeededFuture(buildOkResponse(membership)));
})
.onSuccess(membership -> asyncResultHandler.handle(succeededFuture(buildOkResponse(membership))))
.onFailure(t -> handleErrorResponse(asyncResultHandler, t));
}

Expand Down
9 changes: 1 addition & 8 deletions src/main/java/org/folio/rest/impl/CompositePoLineAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import io.vertx.core.Context;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;

public class CompositePoLineAPI extends BaseApi implements OrdersOrderLines {
private static final Logger logger = LogManager.getLogger();
Expand Down Expand Up @@ -87,13 +86,7 @@ public void getOrdersOrderLinesById(String lineId, Map<String, String> okapiHead
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
logger.debug("Started Invocation of POLine Request with id = {}", lineId);
helper.getCompositePoLine(lineId, new RequestContext(vertxContext, okapiHeaders))
.onSuccess(poLine -> {
if (logger.isInfoEnabled()) {
logger.debug("Received PO Line Response: {}", JsonObject.mapFrom(poLine)
.encodePrettily());
}
asyncResultHandler.handle(succeededFuture(buildOkResponse(poLine)));
})
.onSuccess(poLine -> asyncResultHandler.handle(succeededFuture(buildOkResponse(poLine))))
.onFailure(t -> handleErrorResponse(asyncResultHandler, t));
}

Expand Down
12 changes: 1 addition & 11 deletions src/main/java/org/folio/rest/impl/HoldingsSummaryAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

import javax.ws.rs.core.Response;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.folio.rest.annotations.Validate;
import org.folio.rest.core.models.RequestContext;
import org.folio.rest.jaxrs.resource.OrdersHoldingSummary;
Expand All @@ -19,12 +17,9 @@
import io.vertx.core.Context;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;

public class HoldingsSummaryAPI extends BaseApi implements OrdersHoldingSummary {

private static final Logger logger = LogManager.getLogger();

@Autowired
private HoldingsSummaryService holdingsSummaryService;

Expand All @@ -40,12 +35,7 @@ public void getOrdersHoldingSummaryById(String holdingId, Map<String, String> ok
var requestContext = new RequestContext(vertxContext, okapiHeaders);

holdingsSummaryService.getHoldingsSummary(holdingId, requestContext)
.onSuccess(holdingSummary -> {
if (logger.isInfoEnabled()) {
logger.debug("Successfully retrieved : {}", JsonObject.mapFrom(holdingSummary).encodePrettily());
}
asyncResultHandler.handle(succeededFuture(this.buildOkResponse(holdingSummary)));
})
.onSuccess(holdingSummary -> asyncResultHandler.handle(succeededFuture(this.buildOkResponse(holdingSummary))))
.onFailure(t -> handleErrorResponse(asyncResultHandler, t));
}

Expand Down
Loading
Loading