Skip to content

Commit

Permalink
[NOD-933] fix: add control flag for events inclusion in reconciliatio…
Browse files Browse the repository at this point in the history
…n report
  • Loading branch information
andrea-deri committed Jun 6, 2024
1 parent df75cb5 commit 03ea814
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ public ResponseEntity<ReconciliationStatus> reconcileEventsByDate(
@Parameter(description = "The date, in yyyy-MM-dd format, on which the reconciliation will be executed.", example = "2024-01-01", required = true)
@RequestParam String date,
@Parameter(description = "The time frame according to which the blocks of elements to be reconciled are generated for each step. This avoids the large queries to storages. Defined in minutes.", example = "30")
@RequestParam(value = "time-frame-in-minutes", required = false, defaultValue = "1440") Long timeFrame) {
return ResponseEntity.ok(reconciliationService.reconcileEventsByDate(date, timeFrame));
@RequestParam(value = "time-frame-in-minutes", required = false, defaultValue = "1440") Long timeFrame,
@Parameter(description = "The flag that activate the extraction of the detailed report about the migration, generating the list of migrated events. Set it to 'false' if you know that a whole day's data must be migrated.", example = "false")
@RequestParam(value = "include-events-in-report", required = false, defaultValue = "false") Boolean includeEventsInReport) {
return ResponseEntity.ok(reconciliationService.reconcileEventsByDate(date, timeFrame, includeEventsInReport));
}

@PostMapping(value = "/reconciliation/check-event", produces = {MediaType.APPLICATION_JSON_VALUE})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,37 +84,7 @@ private static ReconciliationStatus generateReconciliationStatus(List<Reconciled
.build();
}


private static ReconciliationStatus generateReconciliationStatus(Set<String> coldToHotReconciledEvents, Set<String> hotToColdReconciledEvents, long inColdStorage, long inHotStorage, Date startTime, String date, String stringedDate) {
Date endTime = Calendar.getInstance().getTime();
return ReconciliationStatus.builder()
.statistics(ReconciliationStatistics.builder()
.startedAt(startTime)
.endedAt(endTime)
.analyzed(ReconciliationHotColdComparation.builder()
.inColdStorage(inColdStorage)
.inHotStorage(inHotStorage)
.build()
)
.toReconcile(ReconciliationHotColdComparation.builder()
.inHotStorage(coldToHotReconciledEvents.size())
.inColdStorage(hotToColdReconciledEvents.size())
.build())
.build())
.overview(ReconciliationData.builder()
.date(date)
.usedDateForSearch(stringedDate)
.inHotStorage(coldToHotReconciledEvents.stream()
.map(id -> new ReconciledEventStatus(null, id, ReconciledEventState.TO_RECONCILE, null))
.toList())
.inColdStorage(hotToColdReconciledEvents.stream()
.map(id -> new ReconciledEventStatus(null, id, ReconciledEventState.TO_RECONCILE, null))
.toList())
.build())
.build();
}

public ReconciliationStatus reconcileEventsByDate(String date, Long minutesForEachTimeFrame) {
public ReconciliationStatus reconcileEventsByDate(String date, Long minutesForEachTimeFrame, Boolean includeEventsInReport) {

Date startTime = Calendar.getInstance().getTime();

Expand Down Expand Up @@ -145,10 +115,16 @@ public ReconciliationStatus reconcileEventsByDate(String date, Long minutesForEa
log.info(String.format("Analyzing time section [%d-%d]. Found [%d] elements in the cold storage and [%d] in the hot storage for the date [%s] (searched as [%s])", dateLowerBoundTimestamp, dateUpperBoundTimestamp, coldStorageIDsForDate.size(), hotStorageIDsForDate.size(), date, stringedDate));

// Reconcile events from cold storage to hot storage and retrieve the list of status info for each persisted event
coldToHotReconciledEvents.addAll(reconcileEventsFromColdToHotStorage(coldStorageIDsForDate, hotStorageIDsForDate, stringedDate));
List<ReconciledEventStatus> insertedInHotStorage = reconcileEventsFromColdToHotStorage(coldStorageIDsForDate, hotStorageIDsForDate, stringedDate);

// Reconcile events from hot storage to cold storage and retrieve the list of status info for each persisted event
hotToColdReconciledEvents.addAll(reconcileEventsFromHotToColdStorage(coldStorageIDsForDate, hotStorageIDsForDate, stringedDate));
List<ReconciledEventStatus> insertedInColdStorage = reconcileEventsFromHotToColdStorage(coldStorageIDsForDate, hotStorageIDsForDate, stringedDate);

// include the whole list of reconciled events only if the flag is set as 'true'1
if (Boolean.TRUE.equals(includeEventsInReport)) {
coldToHotReconciledEvents.addAll(insertedInHotStorage);
hotToColdReconciledEvents.addAll(insertedInColdStorage);
}

// Update batch counter and date bounds
dateLowerBound = dateUpperBound;
Expand Down

0 comments on commit 03ea814

Please sign in to comment.