8641efa9 by Adam Heath

Fix entity hook processing.

1 parent 93137dec
...@@ -64,6 +64,11 @@ class HookSynchronization implements Synchronization { ...@@ -64,6 +64,11 @@ class HookSynchronization implements Synchronization {
64 newExtraParameters.putAll(extraParameters) 64 newExtraParameters.putAll(extraParameters)
65 } 65 }
66 updates.put(entityToken, newExtraParameters) 66 updates.put(entityToken, newExtraParameters)
67 if (existingExtraParameters == null) {
68 ec.getLogger().info("Add new synchronization for ${entityName}: [${keyValue}]")
69 } else {
70 ec.getLogger().info("Updated synchronization for ${entityName}: [${keyValue}]")
71 }
67 } 72 }
68 73
69 @Override 74 @Override
...@@ -79,8 +84,10 @@ class HookSynchronization implements Synchronization { ...@@ -79,8 +84,10 @@ class HookSynchronization implements Synchronization {
79 extraParameters: extraParameters, 84 extraParameters: extraParameters,
80 ]) 85 ])
81 } 86 }
87 if (updates) {
82 ec.getService().async().name("keycloak.HookServices.process#Updates").parameter('updates', updates).call() 88 ec.getService().async().name("keycloak.HookServices.process#Updates").parameter('updates', updates).call()
83 } 89 }
90 }
84 91
85 @Override 92 @Override
86 public void afterCompletion(int status) { 93 public void afterCompletion(int status) {
...@@ -190,11 +197,6 @@ Map<String, Object> handleEntityUpdate() { ...@@ -190,11 +197,6 @@ Map<String, Object> handleEntityUpdate() {
190 logger.info("context: ${context}") 197 logger.info("context: ${context}")
191 ExecutionContext ec = context.ec 198 ExecutionContext ec = context.ec
192 Map<String, Object> contextRoot = ec.getContextRoot() 199 Map<String, Object> contextRoot = ec.getContextRoot()
193 Map<String, Set<Object>> toRegister = contextRoot['KeycloakEntityRegistrations']
194 logger.info("toRegister: ${toRegister}")
195 if (toRegister == null) {
196 toRegister = contextRoot['KeycloakEntityRegistrations'] = [:]
197 }
198 200
199 HookSynchronization hookSync = getHookSync() 201 HookSynchronization hookSync = getHookSync()
200 202
...@@ -205,13 +207,6 @@ Map<String, Object> handleEntityUpdate() { ...@@ -205,13 +207,6 @@ Map<String, Object> handleEntityUpdate() {
205 logger.info("processing entry: ${entry}") 207 logger.info("processing entry: ${entry}")
206 String entityName = entry.entityName 208 String entityName = entry.entityName
207 Object value = entry.value 209 Object value = entry.value
208 Set<Object> entityRegistrations = toRegister[entityName]
209 if (entityRegistrations == null) {
210 entityRegistrations = toRegister[entityName] = new HashSet()
211 entityRegistrations.add(value)
212 } else if (entityRegistrations.contains(value)) {
213 continue
214 }
215 String keyName 210 String keyName
216 switch (entityName) { 211 switch (entityName) {
217 case 'Party': 212 case 'Party':
...@@ -245,7 +240,6 @@ Map<String, Object> handleEntityUpdate() { ...@@ -245,7 +240,6 @@ Map<String, Object> handleEntityUpdate() {
245 keyName = 'roleTypeId' 240 keyName = 'roleTypeId'
246 break 241 break
247 } 242 }
248 ec.getLogger().info("Registered synchronization for ${entityName}: [${value}]")
249 hookSync.add(entityName, keyName, value, [:]) 243 hookSync.add(entityName, keyName, value, [:])
250 //ec.getService().special().name("keycloak.KeycloakServices.send#${entityName}").parameter(keyName, value).registerOnCommit() 244 //ec.getService().special().name("keycloak.KeycloakServices.send#${entityName}").parameter(keyName, value).registerOnCommit()
251 } 245 }
......