diff --git a/smtp-listeners/src/main/kotlin/no/nav/emottak/smtp/cpasync/CpaSyncService.kt b/smtp-listeners/src/main/kotlin/no/nav/emottak/smtp/cpasync/CpaSyncService.kt index 8b906572..c50055f1 100644 --- a/smtp-listeners/src/main/kotlin/no/nav/emottak/smtp/cpasync/CpaSyncService.kt +++ b/smtp-listeners/src/main/kotlin/no/nav/emottak/smtp/cpasync/CpaSyncService.kt @@ -98,13 +98,27 @@ class CpaSyncService(private val cpaRepoClient: HttpClient, private val nfsConne lastModified: Instant, cpaTimestamps: Map ): Boolean { - return cpaTimestamps - .filterKeys { cpaId -> filename.contains(cpaId.replace(":", ".")) } - .filterValues { timestamp -> lastModified.toString() == timestamp } - .ifEmpty { - log.info("Could not find matching timestamp for file $filename with lastModified timestamp $lastModified") - return false - }.any() +// return cpaTimestamps +// .filterKeys { cpaId -> filename.contains(cpaId.replace(":", ".")) } +// .filterValues { timestamp -> lastModified.toString() == timestamp } +// .ifEmpty { +// log.info("Could not find matching timestamp for file $filename with lastModified timestamp $lastModified") +// return false +// }.any() + + val filteredByCpaId = cpaTimestamps.filterKeys { cpaId -> filename.contains(cpaId.replace(":", ".")) } + if (filteredByCpaId.isEmpty()) { + log.info("Could not find matching filename in cpaTimestamps: $filename, will not skip") + return false + } + + val hasMatchingTimestamp = filteredByCpaId.any { (_, timestamp) -> lastModified.toString() == timestamp } + + if (!hasMatchingTimestamp) { + log.info("No matching timestamp found for file $filename with lastModified timestamp $lastModified. Will not skip. Available timestamps: ${filteredByCpaId.values}") + } + + return hasMatchingTimestamp } internal suspend fun deleteStaleCpaEntries(cpaTimestamps: Map) { diff --git a/smtp-listeners/src/test/kotlin/no/nav/emottak/smtp/cpasync/CpaSyncServiceTest.kt b/smtp-listeners/src/test/kotlin/no/nav/emottak/smtp/cpasync/CpaSyncServiceTest.kt index e8909421..c8fc97f6 100644 --- a/smtp-listeners/src/test/kotlin/no/nav/emottak/smtp/cpasync/CpaSyncServiceTest.kt +++ b/smtp-listeners/src/test/kotlin/no/nav/emottak/smtp/cpasync/CpaSyncServiceTest.kt @@ -210,7 +210,19 @@ class CpaSyncServiceTest { val shouldSkip = cpaSyncService.shouldSkipFile(filename, lastModified, cpaTimestamps) assertFalse(shouldSkip) - assertTrue(cpaTimestamps.isNotEmpty()) + } + + @Test + fun `shouldSkipFile should return true (skip) if the filename is found and we have a matching timestamp`() { + val filename = "nav.10086.xml" + val lastModified = Instant.parse("2022-12-30T20:14:50Z") + val cpaTimestamps = mutableMapOf("nav:10086" to "2022-12-30T20:14:50Z") + val mockedNFSConnector = mockNFSConnector(emptyList()) + cpaSyncService = spyk(CpaSyncService(cpaRepoClient, mockedNFSConnector)) + + val shouldSkip = cpaSyncService.shouldSkipFile(filename, lastModified, cpaTimestamps) + + assertTrue(shouldSkip) } @Test @@ -224,7 +236,6 @@ class CpaSyncServiceTest { val shouldSkip = cpaSyncService.shouldSkipFile(filename, lastModified, cpaTimestamps) assertTrue(shouldSkip) - assertTrue(cpaTimestamps.isNotEmpty()) } @Test