Skip to content

Commit 31fa782

Browse files
Klaas-RitenseThomasMinkeRitense
authored andcommitted
Fix/update abonnement to next minor (#1649)
1 parent b949182 commit 31fa782

File tree

6 files changed

+118
-4
lines changed

6 files changed

+118
-4
lines changed

zgw/notificaties-api/src/main/kotlin/com/ritense/notificatiesapi/NotificatiesApiPlugin.kt

+26-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class NotificatiesApiPlugin(
9999
client.deleteAbonnement(
100100
authenticationPluginConfiguration,
101101
url,
102-
it.url.substringAfterLast("/")
102+
it.getAbonnementId()
103103
)
104104
logger.info { "Abonnement with url '${it.url}' successfully deleted for Notificaties API configuration with id '${notificatiesApiConfigurationId.id}'" }
105105
} catch (e: Exception) {
@@ -118,8 +118,31 @@ class NotificatiesApiPlugin(
118118
PluginConfiguration::class.java.canonicalName to notificatiesApiConfigurationId.toString()
119119
) {
120120
logger.debug { "Updating abonnement for Notificaties API configuration with id '${notificatiesApiConfigurationId.id}'" }
121-
deleteAbonnement()
122-
createAbonnement()
121+
val dbAbonnement = notificatiesApiAbonnementLinkRepository.findByIdOrNull(notificatiesApiConfigurationId)
122+
if (dbAbonnement == null) {
123+
createAbonnement()
124+
} else {
125+
val abonnement = client.getAbonnement(
126+
authenticationPluginConfiguration,
127+
url,
128+
dbAbonnement.getAbonnementId(),
129+
)
130+
if (abonnement.equals(dbAbonnement.url, callbackUrl.toASCIIString(), DEFAULT_KANALEN_NAMES)) {
131+
logger.debug { "Skipping abonnement update. No change to abonnement detected for Notificaties API configuration with id '${notificatiesApiConfigurationId.id}'" }
132+
} else {
133+
client.updateAbonnement(
134+
authenticationPluginConfiguration,
135+
url,
136+
dbAbonnement.getAbonnementId(),
137+
Abonnement(
138+
callbackUrl = callbackUrl.toASCIIString(),
139+
auth = dbAbonnement.auth,
140+
kanalen = DEFAULT_KANALEN_NAMES.map { Abonnement.Kanaal(naam = it) }
141+
)
142+
)
143+
logger.info { "Abonnement with url '${dbAbonnement.url}' successfully updated for Notificaties API configuration with id '${notificatiesApiConfigurationId.id}'" }
144+
}
145+
}
123146
}
124147

125148
fun ensureKanalenExist(kanalen: Set<String>) {

zgw/notificaties-api/src/main/kotlin/com/ritense/notificatiesapi/client/NotificatiesApiClient.kt

+27
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,33 @@ class NotificatiesApiClient(
2828
private val restClientBuilder: RestClient.Builder
2929
) {
3030

31+
fun getAbonnement(
32+
authentication: NotificatiesApiAuthentication,
33+
baseUrl: URI,
34+
abonnementId: String,
35+
): Abonnement {
36+
return buildNotificatiesRestClient(authentication, baseUrl)
37+
.get()
38+
.uri("abonnement/$abonnementId")
39+
.retrieve()
40+
.body<Abonnement>()!!
41+
}
42+
43+
fun updateAbonnement(
44+
authentication: NotificatiesApiAuthentication,
45+
baseUrl: URI,
46+
abonnementId: String,
47+
abonnement: Abonnement
48+
): Abonnement {
49+
return buildNotificatiesRestClient(authentication, baseUrl)
50+
.put()
51+
.uri("abonnement/$abonnementId")
52+
.contentType(MediaType.APPLICATION_JSON)
53+
.body(abonnement)
54+
.retrieve()
55+
.body<Abonnement>()!!
56+
}
57+
3158
fun createAbonnement(
3259
authentication: NotificatiesApiAuthentication,
3360
baseUrl: URI,

zgw/notificaties-api/src/main/kotlin/com/ritense/notificatiesapi/domain/Abonnement.kt

+6
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,10 @@ data class Abonnement(
2929
val filters: Map<String, String> = mapOf(),
3030
val naam: String
3131
)
32+
33+
fun equals(url: String, callbackUrl: String, kanalen: Set<String>): Boolean {
34+
return this.url == url
35+
&& this.callbackUrl == callbackUrl
36+
&& this.kanalen == kanalen.map { Kanaal(naam = it) }
37+
}
3238
}

zgw/notificaties-api/src/main/kotlin/com/ritense/notificatiesapi/domain/NotificatiesApiAbonnementLink.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ class NotificatiesApiAbonnementLink(
3232

3333
@Column(name = "abonnement_auth_key")
3434
val auth: String
35-
)
35+
) {
36+
fun getAbonnementId() = url.substringAfterLast("/")
37+
}

zgw/notificaties-api/src/test/kotlin/com/ritense/notificatiesapi/NotificatiesApiPluginTest.kt

+55
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.junit.jupiter.api.BeforeEach
2727
import org.junit.jupiter.api.Test
2828
import org.mockito.ArgumentCaptor
2929
import org.mockito.kotlin.any
30+
import org.mockito.kotlin.eq
3031
import org.mockito.kotlin.mock
3132
import org.mockito.kotlin.never
3233
import org.mockito.kotlin.times
@@ -128,6 +129,60 @@ internal class NotificatiesApiPluginTest {
128129
assertEquals("some-key", linkCaptor.value.auth)
129130
}
130131

132+
@Test
133+
fun `updateAbonnement should update abonnement when abonnement changed`() {
134+
135+
val abonnementId = UUID.randomUUID()
136+
val abonnement = Abonnement(
137+
url = "http://example.com/abonnement/$abonnementId",
138+
callbackUrl = "http://example.com/changed-callback-url",
139+
auth = "some-key",
140+
kanalen = listOf(Abonnement.Kanaal(naam = "objecten"))
141+
)
142+
val abonnementLink = NotificatiesApiAbonnementLink(
143+
notificatiesApiConfigurationId = notificatiesApiConfigurationId,
144+
url = "http://example.com/abonnement/$abonnementId",
145+
auth = "some-key"
146+
)
147+
whenever(abonnementLinkRepository.findById(any()))
148+
.thenReturn(Optional.of(abonnementLink))
149+
whenever(notificatiesApiClient.getAbonnement(any(), any(), any()))
150+
.thenReturn(abonnement)
151+
whenever(notificatiesApiClient.updateAbonnement(any(), any(), any(), eq(abonnement)))
152+
.thenReturn(abonnement)
153+
154+
plugin.updateAbonnement()
155+
156+
verify(notificatiesApiClient, times(1)).updateAbonnement(any(), any(), any(), any())
157+
}
158+
159+
@Test
160+
fun `updateAbonnement should not update abonnement when abonnement didnt change`() {
161+
162+
val abonnementId = UUID.randomUUID()
163+
val abonnement = Abonnement(
164+
url = "http://example.com/abonnement/$abonnementId",
165+
callbackUrl = "http://example.com/callback",
166+
auth = "some-key",
167+
kanalen = listOf(Abonnement.Kanaal(naam = "objecten"))
168+
)
169+
val abonnementLink = NotificatiesApiAbonnementLink(
170+
notificatiesApiConfigurationId = notificatiesApiConfigurationId,
171+
url = "http://example.com/abonnement/$abonnementId",
172+
auth = "some-key"
173+
)
174+
whenever(abonnementLinkRepository.findById(any()))
175+
.thenReturn(Optional.of(abonnementLink))
176+
whenever(notificatiesApiClient.getAbonnement(any(), any(), any()))
177+
.thenReturn(abonnement)
178+
whenever(notificatiesApiClient.updateAbonnement(any(), any(), any(), eq(abonnement)))
179+
.thenReturn(abonnement)
180+
181+
plugin.updateAbonnement()
182+
183+
verify(notificatiesApiClient, times(0)).updateAbonnement(any(), any(), any(), any())
184+
}
185+
131186
@Test
132187
fun `deleteAbonnement should delete abonnement in Notificaties API and repository`() {
133188

zgw/verzoek/src/main/kotlin/com/ritense/verzoek/VerzoekPluginEventListener.kt

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ open class VerzoekPluginEventListener(
7979
}?.run {
8080
val verzoekObjectData = getVerzoekObjectData(objectManagement, event)
8181
val verzoekTypeProperties = getVerzoekTypeProperties(verzoekObjectData, event) ?: return
82+
logger.info { "Received verzoek notification. Verzoek objectUrl: ${event.resourceUrl}" }
8283
val document = createDocument(verzoekTypeProperties, verzoekObjectData)
8384
withLoggingContext(JsonSchemaDocument::class, document.id()) {
8485
val zaakTypeUrl = zaaktypeUrlProvider.getZaaktypeUrl(document.definitionId().name())

0 commit comments

Comments
 (0)