Skip to content

Commit

Permalink
fix: date comparison with null
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien committed Jan 3, 2024
1 parent 75221b0 commit 1c016cb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public void receiveMessage(Message message) throws Exception {
Map<String, String> data = gson.fromJson(new String(message.getBody()), Map.class);
Long documentId = Long.valueOf(data.get("id"));
if (documentService.documentIsUpToDateAt(msgTimestamp, documentId)) {
LocalDateTime executionDateTime = LocalDateTime.now();
Long executionTimestamp = System.currentTimeMillis();
StorageFile watermarkFile = pdfGeneratorService.generateBOPdfDocument(documentService.getDocument(documentId));
documentService.saveWatermarkFileAt(executionDateTime, watermarkFile, documentId);
documentService.saveWatermarkFileAt(executionTimestamp, watermarkFile, documentId);
} else {
log.debug("Ignore document pdf generation cause document is NOT up to date");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public boolean documentIsUpToDateAt(Long timestamp, Long documentId) {
LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault());
Document document = documentRepository.findById(documentId).orElse(null);

return document != null && ( document.getLastModifiedDate() == null || dateTime.isAfter(document.getLastModifiedDate()));
return document != null && (document.getLastModifiedDate() == null || dateTime.isAfter(document.getLastModifiedDate()));
}

@Override
Expand All @@ -37,15 +37,15 @@ public Document getDocument(Long documentId) {

@Transactional
@Override
public void saveWatermarkFileAt(LocalDateTime executionDateTime, StorageFile watermarkFile, Long documentId) {
public void saveWatermarkFileAt(Long executionTimestamp, StorageFile watermarkFile, Long documentId) {
Document document = documentRepository.findById(documentId).orElse(null);
if (document == null || executionDateTime.isBefore(document.getLastModifiedDate())) {
fileStorageService.delete(watermarkFile);
log.warn("PDF Generation execution is deprecated for documentId=" + documentId);
} else {
if (documentIsUpToDateAt(executionTimestamp, document.getId())) {
document.setWatermarkFile(watermarkFile);
documentRepository.save(document);
log.warn("PDF Generation execution is a success for documentId=" + documentId);
} else {
fileStorageService.delete(watermarkFile);
log.warn("PDF Generation execution is deprecated for documentId=" + documentId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public interface DocumentService {
boolean documentIsUpToDateAt(Long timestamp, Long documentId);

void saveWatermarkFileAt(LocalDateTime executionDateTime, StorageFile watermarkFile, Long documentId);
void saveWatermarkFileAt(Long executionTimestamp, StorageFile watermarkFile, Long documentId);

Document getDocument(Long documentId);
}

0 comments on commit 1c016cb

Please sign in to comment.