Skip to content

Commit 5590f1b

Browse files
author
dalilaacqua
committed
Fix logs
1 parent 706a092 commit 5590f1b

File tree

2 files changed

+12
-54
lines changed

2 files changed

+12
-54
lines changed

src/main/java/it/gov/pagopa/idpay/transactions/service/PointOfSaleTransactionServiceImpl.java

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,7 @@ public Mono<Void> updateInvoiceTransaction(String transactionId, String merchant
176176
return rewardTransactionRepository
177177
.findTransactionForUpdateInvoice(merchantId, pointOfSaleId, transactionId)
178178
.switchIfEmpty(Mono.defer(() -> Mono.error(new ClientExceptionNoBody(HttpStatus.BAD_REQUEST, TRANSACTION_MISSING_INVOICE))))
179-
.flatMap(trx -> validateBatchAndUpdateInvoiceFlow(trx, merchantId, pointOfSaleId, transactionId, file, docNumber))
180-
.doOnSuccess(v -> log.info("[UPDATE_INVOICE_FILE_SERVICE] - [findTransactionForUpdateInvoice] - success | trxId={} merchantId={} posId={}",
181-
transactionId, merchantId, pointOfSaleId));
179+
.flatMap(trx -> validateBatchAndUpdateInvoiceFlow(trx, merchantId, pointOfSaleId, transactionId, file, docNumber));
182180
}
183181

184182
private Mono<Void> validateBatchAndUpdateInvoiceFlow(RewardTransaction trx,
@@ -188,9 +186,6 @@ private Mono<Void> validateBatchAndUpdateInvoiceFlow(RewardTransaction trx,
188186
FilePart file,
189187
String docNumber) {
190188

191-
log.info("[UPDATE_INVOICE_FILE_SERVICE] - [validateBatchAndUpdateInvoiceFlow] - start | trxId={} merchantId={} posId={} docNumber={} filename={}",
192-
transactionId, merchantId, pointOfSaleId, docNumber, file != null ? file.filename() : null);
193-
194189
String oldBatchId = requireRewardBatchId(trx);
195190

196191
return rewardBatchRepository.findRewardBatchById(oldBatchId)
@@ -202,14 +197,7 @@ private Mono<Void> validateBatchAndUpdateInvoiceFlow(RewardTransaction trx,
202197
return updateInvoiceFileAndFields(trx, merchantId, pointOfSaleId, transactionId, file, docNumber)
203198
.flatMap(savedTrx -> suspendAndMoveTransaction(savedTrx, oldBatch))
204199
.then();
205-
})
206-
.doOnSuccess(v -> log.info("[UPDATE_INVOICE_FILE_SERVICE] - [validateBatchAndUpdateInvoiceFlow] - end success | trxId={} oldBatchId={}",
207-
transactionId, oldBatchId))
208-
.doOnError(e -> log.error("[UPDATE_INVOICE_FILE_SERVICE] - [validateBatchAndUpdateInvoiceFlow] - end fail | trxId={} oldBatchId={} errorType={} message={}",
209-
transactionId, oldBatchId,
210-
e != null ? e.getClass().getSimpleName() : null,
211-
e != null ? e.getMessage() : null,
212-
e));
200+
});
213201
}
214202

215203
private String requireRewardBatchId(RewardTransaction trx) {
@@ -248,9 +236,6 @@ private Mono<RewardTransaction> updateInvoiceFileAndFields(RewardTransaction trx
248236
FilePart file,
249237
String docNumber) {
250238

251-
log.info("[UPDATE_INVOICE_FILE_SERVICE] - [updateInvoiceFileAndFields] - start | trxId={} merchantId={} posId={} docNumber={} filename={}",
252-
transactionId, merchantId, pointOfSaleId, docNumber, file != null ? file.filename() : null);
253-
254239
InvoiceData oldDocumentData = validateTransactionData(trx, merchantId, pointOfSaleId);
255240

256241
return replaceInvoiceFile(file, oldDocumentData, merchantId, pointOfSaleId, transactionId)
@@ -262,51 +247,30 @@ private Mono<RewardTransaction> updateInvoiceFileAndFields(RewardTransaction trx
262247
trx.setInvoiceUploadDate(LocalDateTime.now());
263248
trx.setUpdateDate(LocalDateTime.now());
264249
return rewardTransactionRepository.save(trx);
265-
}))
266-
.doOnNext(saved -> log.info("[UPDATE_INVOICE_FILE_SERVICE] - [updateInvoiceFileAndFields] - end success | trxId={} invoiceFilename={} docNumber={}",
267-
transactionId,
268-
saved != null && saved.getInvoiceData() != null ? saved.getInvoiceData().getFilename() : null,
269-
saved != null && saved.getInvoiceData() != null ? saved.getInvoiceData().getDocNumber() : null))
270-
.doOnError(e -> log.error("[UPDATE_INVOICE_FILE_SERVICE] - [updateInvoiceFileAndFields] - end fail | trxId={} errorType={} message={}",
271-
transactionId,
272-
e != null ? e.getClass().getSimpleName() : null,
273-
e != null ? e.getMessage() : null,
274-
e));
250+
}));
275251
}
276252

277253
private Mono<RewardBatch> findOrCreateTargetBatch(RewardTransaction oldTransaction,
278254
RewardBatch oldBatch) {
279255

280-
log.info("[UPDATE_INVOICE_FILE_SERVICE] - [findOrCreateTargetBatch] - start | oldBatchId={} trxId={} posType={} businessName={}",
281-
oldBatch.getId(), oldTransaction.getId(), oldTransaction.getPointOfSaleType(), oldTransaction.getBusinessName());
282-
283256
PosType posType = oldTransaction.getPointOfSaleType();
284257
String businessName = oldTransaction.getBusinessName();
285258

286259
YearMonth currentMonth = YearMonth.now();
287260
YearMonth oldMonth = YearMonth.parse(oldBatch.getMonth());
288261
YearMonth targetMonth = oldMonth.isAfter(currentMonth) ? oldMonth : currentMonth;
289262

290-
return rewardBatchService.findOrCreateBatch(oldBatch.getMerchantId(), posType, targetMonth.toString(), businessName)
291-
.doOnNext(b -> log.info("[UPDATE_INVOICE_FILE_SERVICE] - [findOrCreateTargetBatch] - end success | targetBatchId={} month={} status={}",
292-
b != null ? b.getId() : null,
293-
b != null ? b.getMonth() : null,
294-
b != null ? b.getStatus() : null))
295-
.doOnError(e -> log.error("[UPDATE_INVOICE_FILE_SERVICE] - [findOrCreateTargetBatch] - end fail | errorType={} message={}",
296-
e != null ? e.getClass().getSimpleName() : null,
297-
e != null ? e.getMessage() : null,
298-
e));
263+
log.info("[UPDATE_INVOICE_FILE_SERVICE] - [findOrCreateTargetBatch] - start | oldBatchId={} trxId={} targetMonth={}",
264+
oldBatch.getId(), oldTransaction.getId(), targetMonth);
265+
266+
return rewardBatchService.findOrCreateBatch(oldBatch.getMerchantId(), posType, targetMonth.toString(), businessName);
299267
}
300268

301269
private Mono<RewardTransaction> suspendAndMoveTransaction(
302270
RewardTransaction oldTransaction, RewardBatch oldBatch) {
303271

304-
log.info("[UPDATE_INVOICE_FILE_SERVICE] - [suspendAndMoveTransaction] - start | trxId={} oldBatchId={} oldBatchStatus={} trxBatchStatus={}",
305-
oldTransaction.getId(), oldBatch.getId(), oldBatch.getStatus(), oldTransaction.getRewardBatchTrxStatus());
306-
307272
if (CREATED.equals(oldBatch.getStatus())) {
308-
log.info("[UPDATE_INVOICE_FILE_SERVICE] - [suspendAndMoveTransaction] - end success | no-move (old batch CREATED) | trxId={} oldBatchId={}",
309-
oldTransaction.getId(), oldBatch.getId());
273+
log.info("[UPDATE_INVOICE_FILE_SERVICE] - [suspendAndMoveTransaction] - end success | no-move (old batch CREATED)");
310274
return Mono.just(oldTransaction);
311275
}
312276

@@ -348,9 +312,8 @@ private Mono<RewardTransaction> suspendAndMoveTransaction(
348312

349313
return findOrCreateTargetBatch(oldTransaction, oldBatch)
350314
.flatMap(newBatch -> {
351-
log.info("[UPDATE_INVOICE_FILE_SERVICE] - [suspendAndMoveTransaction] - moving trx | trxId={} fromBatchId={} toBatchId={} oldStatus={} newStatus=SUSPENDED oldCounters={} newCounters={}",
315+
log.info("[UPDATE_INVOICE_FILE_SERVICE] - [suspendAndMoveTransaction] - moving trx | trxId={} fromBatchId={} toBatchId={} oldCounters={} newCounters={}",
352316
oldTransaction.getId(), oldBatch.getId(), newBatch.getId(),
353-
oldTransaction.getRewardBatchTrxStatus(),
354317
oldBatchCounter, newBatchCounter);
355318

356319
oldTransaction.setRewardBatchTrxStatus(RewardBatchTrxStatus.SUSPENDED);
@@ -361,14 +324,7 @@ private Mono<RewardTransaction> suspendAndMoveTransaction(
361324
.then(rewardBatchRepository.updateTotals(oldBatch.getId(), oldBatchCounter))
362325
.then(rewardBatchRepository.updateTotals(newBatch.getId(), newBatchCounter))
363326
.thenReturn(oldTransaction);
364-
})
365-
.doOnNext(saved -> log.info("[UPDATE_INVOICE_FILE_SERVICE] - [suspendAndMoveTransaction] - end success | trxId={} rewardBatchId={} trxBatchStatus={}",
366-
saved.getId(), saved.getRewardBatchId(), saved.getRewardBatchTrxStatus()))
367-
.doOnError(e -> log.error("[UPDATE_INVOICE_FILE_SERVICE] - [suspendAndMoveTransaction] - end fail | trxId={} oldBatchId={} errorType={} message={}",
368-
oldTransaction.getId(), oldBatch.getId(),
369-
e != null ? e.getClass().getSimpleName() : null,
370-
e != null ? e.getMessage() : null,
371-
e));
327+
});
372328
}
373329

374330
public Mono<Void> reversalTransaction(

src/main/java/it/gov/pagopa/idpay/transactions/service/RewardBatchServiceImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ public Mono<RewardBatch> findOrCreateBatch(String merchantId, PosType posType, S
124124
month)
125125
.switchIfEmpty(Mono.defer(() ->
126126
createBatch(merchantId, posType, month, businessName)
127+
.doOnSuccess(batch -> log.info("[REWARD_BATCH_REPOSITORY]- findOrCreateBatch - created new batch with id: {}, month: {}",
128+
batch.getId(), batch.getMonth()))
127129
.onErrorResume(DuplicateKeyException.class, ex ->
128130
rewardBatchRepository.findByMerchantIdAndPosTypeAndMonth(merchantId,
129131
posType, month))));

0 commit comments

Comments
 (0)