Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private CompletableFuture<JsonObject> fetchUserDetails(JsonObject payload) {
LOGGER.debug("fetchUserDetails:: Fetching User Details");
String userBarcode = getProperty(payload, USER_BARCODE);

LOGGER.info("fetchUserDetails:: Fetched User Details with user barcode : {}", userBarcode);
LOGGER.info("fetchUserDetails:: Fetched user details");
return userBarcode != null
? fetchUserDetailsByUserBarcode(payload, userBarcode)
: fetchUserDetails(payload, getProperty(payload, USER_ID));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public abstract class LogRecordBuilder {
private static final Logger LOGGER = LogManager.getLogger();

private static final String OKAPI_URL = "x-okapi-url";
private static final String EXCEPTION_CALLING_ENDPOINT_MSG = "Exception calling {} {}";
private static final String EXCEPTION_CALLING_ENDPOINT_MSG = "Exception calling {} endpoint";

public static final String SEARCH_PARAMS = "?limit=%s&offset=%s%s";
public static final String ID = "id";
Expand All @@ -85,37 +85,37 @@ public LogRecordBuilder(Map<String, String> okapiHeaders, Context vertxContext,
}

private CompletableFuture<JsonObject> handleGetRequest(String endpoint) {
LOGGER.debug("handleGetRequest:: handling Get Request with endpoint : {}", endpoint);
LOGGER.debug("handleGetRequest:: Handling GET request");
CompletableFuture<JsonObject> future = new CompletableFuture<>();

final String okapiURL = okapiHeaders.getOrDefault(OKAPI_URL, "");
final String tenantId = TenantTool.calculateTenantId(okapiHeaders.get(OKAPI_HEADER_TENANT));
HttpClientInterface httpClient = HttpClientFactory.getHttpClient(okapiURL, tenantId);

try {
LOGGER.debug("handleGetRequest::Calling GET {}", endpoint);
LOGGER.debug("handleGetRequest:: Calling GET endpoint");
httpClient.request(HttpMethod.GET, endpoint, okapiHeaders)
.whenComplete((response, throwable) -> {
if (Objects.nonNull(throwable)) {
LOGGER.error(EXCEPTION_CALLING_ENDPOINT_MSG, HttpMethod.GET, endpoint);
LOGGER.error(EXCEPTION_CALLING_ENDPOINT_MSG, HttpMethod.GET);
future.completeExceptionally(throwable);
} else {
future.complete(verifyAndExtractBody(response));
}
httpClient.closeClient();
});
} catch (Exception e) {
LOGGER.warn(EXCEPTION_CALLING_ENDPOINT_MSG, HttpMethod.GET, endpoint);
LOGGER.warn(EXCEPTION_CALLING_ENDPOINT_MSG, HttpMethod.GET);
future.completeExceptionally(e);
httpClient.closeClient();
}
return future;
}

public <T> CompletableFuture<T> getEntitiesByQuery(String url, Class<T> collection, int limit, int offset, String query) {
LOGGER.debug("getEntitiesByQuery:: Getting Entities By Query : {}", query);
LOGGER.debug("getEntitiesByQuery:: Getting entities by query");
String endpoint = String.format(url + SEARCH_PARAMS, limit, offset, buildQuery(query));
LOGGER.debug("getEntitiesByQuery:: Entities successfully retrieved from endpoint: {}", endpoint);
LOGGER.debug("getEntitiesByQuery:: Entities successfully retrieved");
return handleGetRequest(endpoint).thenApply(response -> response.mapTo(collection));
}

Expand Down Expand Up @@ -152,31 +152,31 @@ public CompletableFuture<JsonObject> fetchTemplateName(JsonObject payload) {
}

public CompletableFuture<JsonObject> fetchUserDetails(JsonObject payload, String userId) {
LOGGER.debug("fetchUserDetails:: Fetching user details for user Id : {}", userId);
LOGGER.debug("fetchUserDetails:: Fetching user details");
return getEntitiesByIds(USERS_URL, UserCollection.class, 1, 0, userId)
.thenCompose(users -> {
users.getUsers()
.stream()
.findFirst()
.ifPresent(user -> updatePayload(payload, userId, user));
LOGGER.debug("fetchUserDetails:: Fetched user details for user Id : {}", userId);
LOGGER.debug("fetchUserDetails:: Fetched user details");
return CompletableFuture.completedFuture(payload);
});
}

private void updatePayload(JsonObject payload, String userId, User user) {
LOGGER.debug("updatePayload:: Updating payload with details for user ID {}", userId);
LOGGER.debug("updatePayload:: Updating payload with user details");
if (nonNull(user)) {
if (userId.equals(getProperty(payload, USER_ID))) {
LOGGER.debug("updatePayload:: Updating user id to payload because user id : {} matched with user id from payload", userId);
LOGGER.debug("updatePayload:: Updating user id in payload to match existing payload user id");
payload.put(USER_BARCODE.value(), user.getBarcode());
}
fetchUserPersonal(payload, user);
}
}

public CompletableFuture<JsonObject> fetchUserAndSourceDetails(JsonObject payload, String userId, String sourceId) {
LOGGER.debug("fetchUserAndSourceDetails:: Fetching user details for user Id : {} and source ID {}", userId, sourceId);
LOGGER.debug("fetchUserAndSourceDetails:: Fetching user and source details");
return getEntitiesByIds(USERS_URL, UserCollection.class, 2, 0, userId, sourceId)
.thenCompose(users -> {
Map<String, User> usersGroupedById = StreamEx.of(users.getUsers()).collect(toMap(User::getId, identity()));
Expand All @@ -190,24 +190,24 @@ public CompletableFuture<JsonObject> fetchUserAndSourceDetails(JsonObject payloa
payload.put(SOURCE.value(),
buildPersonalName(source.getPersonal().getFirstName(), source.getPersonal().getLastName()));
}
LOGGER.info("fetchUserAndSourceDetails:: Fetched user details for user Id : {} and source ID {}", userId, sourceId);
LOGGER.info("fetchUserAndSourceDetails:: Fetched user and source details");
return completedFuture(payload);
});
}

public CompletableFuture<JsonObject> fetchUserDetailsByUserBarcode(JsonObject payload, String userBarcode) {
LOGGER.debug("fetchUserDetailsByUserBarcode:: Fetching user details by user barcode {}", userBarcode);
LOGGER.debug("fetchUserDetailsByUserBarcode:: Fetching user details by user barcode");
return getEntitiesByQuery(USERS_URL, UserCollection.class, 1, 0, "barcode==" + userBarcode)
.thenCompose(users -> {
var user = users.getUsers().get(0);
if (nonNull(user)) {
if (userBarcode.equals(getProperty(payload, USER_BARCODE))) {
LOGGER.info("fetchUserDetailsByUserBarcode:: Adding user id to payload because user barcode : {} matched with user barcode from payload", userBarcode);
LOGGER.info("fetchUserDetailsByUserBarcode:: Adding user id to payload because user barcode matched payload");
payload.put(USER_ID.value(), user.getId());
}
fetchUserPersonal(payload, user);
}
LOGGER.info("fetchUserDetailsByUserBarcode:: Fetched user details by user barcode {}", userBarcode);
LOGGER.info("fetchUserDetailsByUserBarcode:: Fetched user details by user barcode");
return completedFuture(payload);
});
}
Expand Down Expand Up @@ -242,12 +242,12 @@ private String buildQuery(String query) {
* @return URL encoded string
*/
private String encodeQuery(String query) {
LOGGER.debug("encodeQuery:: Encoding Query : {}", query );
LOGGER.debug("encodeQuery:: Encoding query");
try {
LOGGER.debug("Encoded query");
return URLEncoder.encode(query, StandardCharsets.UTF_8.toString());
} catch (UnsupportedEncodingException e) {
LOGGER.warn("Error happened while attempting to encode '{}'", query);
LOGGER.warn("Error happened while attempting to encode query");
throw new CompletionException(e);
}
}
Expand Down Expand Up @@ -314,14 +314,12 @@ private JsonObject extractFirstItem(JsonObject payload) {

private static JsonObject verifyAndExtractBody(Response response) {
LOGGER.debug("verifyAndExtractBody:: Verifying and Extracting Body");
var endpoint = response.getEndpoint();
var code = response.getCode();
var body = response.getBody();
if (!Response.isSuccess(code)) {
LOGGER.warn("Error calling {} with code {}, response body: {}", endpoint, code, body);
LOGGER.warn("Error calling downstream endpoint with code {}", code);
return null;
}
LOGGER.debug("verifyAndExtractBody:: The response body for GET {}: {}", endpoint, nonNull(body) ? body.encodePrettily() : null);
LOGGER.debug("verifyAndExtractBody:: Response body received for GET request");
LOGGER.info("verifyAndExtractBody:: Verifying and Extracting Body completed");
return response.getBody();
}
Expand All @@ -342,15 +340,15 @@ protected LogRecord.Action resolveAction(String actionString) {
}

String buildPersonalName(String firstName, String lastName) {
LOGGER.debug("buildPersonalName:: Building Personal Name with firstname : {} and lastname : {}", firstName, lastName);
LOGGER.debug("buildPersonalName:: Building personal name");
if (isNotEmpty(firstName) && isNotEmpty(lastName)) {
LOGGER.debug("buildPersonalName:: Built Personal Name with firstname : {} and lastname : {}", firstName, lastName);
LOGGER.debug("buildPersonalName:: Built personal name from first and last name");
return lastName + ", " + firstName;
} else if (isEmpty(firstName) && isNotEmpty(lastName)) {
LOGGER.debug("buildPersonalName:: Built Personal Name with lastname : {}", lastName);
LOGGER.debug("buildPersonalName:: Built personal name from last name");
return lastName;
} else if (isNotEmpty(firstName) && isEmpty(lastName)) {
LOGGER.debug("buildPersonalName:: Built Personal Name with firstname : {}", firstName);
LOGGER.debug("buildPersonalName:: Built personal name from first name");
return firstName;
} else {
LOGGER.debug("buildPersonalName:: Error building personal name because there is no firstname and lastname");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Future<InvoiceAuditEventCollection> getAuditEventsByInvoiceId(String invo
}

private Future<RowSet<Row>> makeSaveCall(String query, InvoiceAuditEvent invoiceAuditEvent, String tenantId) {
LOGGER.debug("makeSaveCall:: Making save call with query : {} and tenant id : {}", query, tenantId);
LOGGER.debug("makeSaveCall:: Making save call for tenant id : {}", tenantId);
try {
return pgClientFactory.createInstance(tenantId).execute(query, Tuple.of(invoiceAuditEvent.getId(),
invoiceAuditEvent.getAction(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Future<InvoiceLineAuditEventCollection> getAuditEventsByInvoiceLineId(Str
}

private Future<RowSet<Row>> makeSaveCall(String query, InvoiceLineAuditEvent invoiceLineAuditEvent, String tenantId) {
LOGGER.debug("makeSaveCall:: Making save call with query : {} and tenant id : {}", query, tenantId);
LOGGER.debug("makeSaveCall:: Making save call for tenant id : {}", tenantId);
try {
return pgClientFactory.createInstance(tenantId).execute(query, Tuple.of(invoiceLineAuditEvent.getId(),
invoiceLineAuditEvent.getAction(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public Future<OrderAuditEventCollection> getAuditEventsByOrderId(String orderId,
}

private void makeSaveCall(Promise<RowSet<Row>> promise, String query, OrderAuditEvent orderAuditEvent, String tenantId) {
LOGGER.debug("makeSaveCall:: Making save call with query : {} and tenant id : {}", query, tenantId);
LOGGER.debug("makeSaveCall:: Making save call for tenant id : {}", tenantId);
try {
LOGGER.info("makeSaveCall:: Trying to make save call with query : {} and tenant id : {}", query, tenantId);
LOGGER.info("makeSaveCall:: Trying to make save call for tenant id : {}", tenantId);
pgClientFactory.createInstance(tenantId).execute(query, Tuple.of(orderAuditEvent.getId(),
orderAuditEvent.getAction(),
orderAuditEvent.getOrderId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Future<OrderLineAuditEventCollection> getAuditEventsByOrderLineId(String
}

private void makeSaveCall(Promise<RowSet<Row>> promise, String query, OrderLineAuditEvent orderLineAuditEvent, String tenantId) {
LOGGER.debug("makeSaveCall:: Making save call with query : {} and tenant id : {}", query, tenantId);
LOGGER.debug("makeSaveCall:: Making save call for tenant id : {}", tenantId);
try {
pgClientFactory.createInstance(tenantId).execute(query, Tuple.of(orderLineAuditEvent.getId(),
orderLineAuditEvent.getAction(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Future<OrganizationAuditEventCollection> getAuditEventsByOrganizationId(S
}

private Future<RowSet<Row>> makeSaveCall(String query, OrganizationAuditEvent organizationAuditEvent, String tenantId) {
LOGGER.debug("makeSaveCall:: Making save call with query : {} and tenant id : {}", query, tenantId);
LOGGER.debug("makeSaveCall:: Making save call for tenant id : {}", tenantId);
try {
return pgClientFactory.createInstance(tenantId).execute(query, Tuple.of(organizationAuditEvent.getId(),
organizationAuditEvent.getAction(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private PieceAuditEvent mapRowToPieceEvent(Row row) {
}

private void makeSaveCall(Promise<RowSet<Row>> promise, String query, PieceAuditEvent pieceAuditEvent, String tenantId) {
LOGGER.debug("makeSaveCall:: Making save call with query : {} and tenant id : {}", query, tenantId);
LOGGER.debug("makeSaveCall:: Making save call for tenant id : {}", tenantId);
try {
pgClientFactory.createInstance(tenantId).execute(query, Tuple.of(pieceAuditEvent.getId(),
pieceAuditEvent.getAction(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public String tableName() {
}

private void makeSaveCall(Promise<RowSet<Row>> promise, String query, InventoryAuditEntity event, String tenantId) {
LOGGER.debug("makeSaveCall:: Making save call with query : {} and tenant id : {}", query, tenantId);
LOGGER.debug("makeSaveCall:: Making save call for tenant id : {}", tenantId);
try {
pgClientFactory.createInstance(tenantId).execute(query, Tuple.of(event.eventId(),
LocalDateTime.ofInstant(event.eventDate().toInstant(), ZoneId.systemDefault()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public Future<Void> deleteOlderThanDate(Timestamp eventDate, String tenantId, So
}

private Future<RowSet<Row>> makeSaveCall(String query, MarcAuditEntity entity, String tenantId) {
LOGGER.debug("makeSaveCall:: Making save call with query : {} and tenant id : {}", query, tenantId);
LOGGER.debug("makeSaveCall:: Making save call for tenant id : {}", tenantId);
try {
return pgClientFactory.createInstance(tenantId).execute(query, Tuple.of(
entity.eventId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class AuditDataImpl implements AuditData {
public void getAuditData(String query, int offset, int limit, String lang, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {

LOGGER.debug("getAuditData:: Retrieving audit data with query: {}", query);
LOGGER.debug("getAuditData:: Retrieving audit data");
PgUtil.get(DB_TAB_AUDIT, Audit.class, AuditCollection.class, query, offset, limit, okapiHeaders, vertxContext,
GetAuditDataResponse.class, asyncResultHandler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ public class AuditHandlersService extends BaseService implements AuditHandlers {
@Validate
public void postAuditHandlersLogRecord(String entity, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
LOGGER.debug("postAuditHandlersLogRecord:: Trying to Save AuditHandlersLogRecord request with entity: {}", entity);
LOGGER.debug("postAuditHandlersLogRecord:: Trying to save AuditHandlersLogRecord request");
try {
JsonObject payload = new JsonObject(entity);
LogRecordBuilder builder = LogRecordBuilderResolver.getBuilder(payload.getString(LOG_EVENT_TYPE.value()), okapiHeaders, vertxContext);
builder.buildLogRecord(payload)
.thenCompose(logRecords -> processAnonymize(logRecords, okapiHeaders, vertxContext))
.thenCompose(logRecords -> saveLogRecords(logRecords, okapiHeaders, vertxContext))
.exceptionally(throwable -> {
LOGGER.warn("Error saving log event : {} due to : {}", entity, throwable.getLocalizedMessage());
LOGGER.warn("Error saving log event due to: {}", throwable.getLocalizedMessage());
return null;
});
} catch (Exception e) {
LOGGER.warn("Error saving log event for entity {} due to {} ", entity, e.getMessage());
LOGGER.warn("Error saving log event due to {}", e.getMessage());
} finally {
asyncResultHandler.handle(succeededFuture(PostAuditHandlersLogRecordResponse.respond204()));
}
Expand Down