Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
moqui
/
moqui-keycloak
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
24f8bd97
authored
2024-03-21 16:18:15 -0500
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Refactor the internal HookSynchronization to a separate external global
class.
1 parent
49398740
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
80 deletions
service/keycloak/HookServices.groovy
src/main/groovy/org/moqui/keycloak/HookSynchronization.groovy
service/keycloak/HookServices.groovy
View file @
24f8bd9
import
javax.transaction.Synchronization
import
javax.transaction.xa.XAResource
import
javax.transaction.xa.Xid
import
groovy.transform.Field
...
...
@@ -15,86 +12,10 @@ import org.moqui.entity.EntityFind
import
org.moqui.entity.EntityList
import
org.moqui.entity.EntityValue
import
org.moqui.keycloak.HookSynchronization
@Field
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
().
getName
())
//'HookServices')
class
HookSynchronization
implements
Synchronization
{
private
final
ExecutionContext
ec
;
private
static
class
EntityToken
{
protected
final
String
entityName
protected
final
String
keyName
protected
final
Object
keyValue
protected
final
Map
<
String
,
Object
>
extraParameters
=
new
HashMap
<
String
,
Object
>()
protected
EntityToken
(
String
entityName
,
String
keyName
,
Object
keyValue
)
{
this
.
entityName
=
entityName
this
.
keyName
=
keyName
this
.
keyValue
=
keyValue
}
public
boolean
equals
(
Object
other
)
{
if
(!(
other
instanceof
EntityToken
))
{
return
false
}
EntityToken
that
=
(
EntityToken
)
other
return
entityName
.
equals
(
that
.
entityName
)
&&
keyName
.
equals
(
that
.
keyName
)
&&
keyValue
.
equals
(
that
.
keyValue
)
}
public
int
hashCode
()
{
return
entityName
.
hashCode
()
^
keyName
.
hashCode
()
^
keyValue
.
hashCode
()
}
}
private
Map
<
EntityToken
,
Map
<
String
,
Object
>>
updates
=
new
LinkedHashMap
<>()
protected
HookSynchronization
(
ExecutionContext
ec
)
{
this
.
ec
=
ec
}
protected
void
add
(
String
entityName
,
String
keyName
,
Object
keyValue
,
Map
<
String
,
Object
>
extraParameters
)
{
EntityToken
entityToken
=
new
EntityToken
(
entityName
,
keyName
,
keyValue
)
// This always move the value to the end of the list
Map
<
String
,
Object
>
existingExtraParameters
=
updates
.
remove
(
entityToken
)
Map
<
String
,
Object
>
newExtraParameters
=
[:]
if
(
existingExtraParameters
)
{
newExtraParameters
.
putAll
(
existingExtraParameters
)
}
if
(
extraParameters
)
{
newExtraParameters
.
putAll
(
extraParameters
)
}
updates
.
put
(
entityToken
,
newExtraParameters
)
if
(
existingExtraParameters
==
null
)
{
ec
.
getLogger
().
info
(
"Add new synchronization for ${entityName}: [${keyValue}]"
)
}
else
{
ec
.
getLogger
().
info
(
"Updated synchronization for ${entityName}: [${keyValue}]"
)
}
}
@Override
public
void
beforeCompletion
()
{
List
<
Map
<
String
,
Object
>>
updates
=
[]
for
(
Map
.
Entry
<
EntityToken
,
Map
<
String
,
Object
>>
entry:
this
.
updates
.
entrySet
())
{
EntityToken
token
=
entry
.
getKey
()
Map
<
String
,
Object
>
extraParameters
=
entry
.
getValue
()
updates
.
add
([
entityName:
token
.
entityName
,
keyName:
token
.
keyName
,
keyValue:
token
.
keyValue
,
extraParameters:
extraParameters
,
])
}
if
(
updates
)
{
ec
.
getService
().
async
().
name
(
"keycloak.HookServices.process#Updates"
).
parameter
(
'updates'
,
updates
).
call
()
}
}
@Override
public
void
afterCompletion
(
int
status
)
{
}
}
HookSynchronization
getHookSync
()
{
HookSynchronization
hookSync
=
ec
.
transaction
.
getActiveSynchronization
(
getClass
().
getName
())
if
(
hookSync
==
null
)
{
...
...
src/main/groovy/org/moqui/keycloak/HookSynchronization.groovy
0 → 100644
View file @
24f8bd9
package
org.moqui.keycloak
import
javax.transaction.Synchronization
import
org.slf4j.Logger
import
org.slf4j.LoggerFactory
import
org.moqui.context.ExecutionContext
public
class
HookSynchronization
implements
Synchronization
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
().
getName
())
private
final
ExecutionContext
ec
;
private
static
final
class
EntityToken
{
protected
final
String
entityName
protected
final
String
keyName
protected
final
Object
keyValue
protected
final
Map
<
String
,
Object
>
extraParameters
=
new
HashMap
<
String
,
Object
>()
protected
EntityToken
(
String
entityName
,
String
keyName
,
Object
keyValue
)
{
this
.
entityName
=
entityName
this
.
keyName
=
keyName
this
.
keyValue
=
keyValue
}
public
boolean
equals
(
Object
other
)
{
if
(!(
other
instanceof
EntityToken
))
{
return
false
}
EntityToken
that
=
(
EntityToken
)
other
return
entityName
.
equals
(
that
.
entityName
)
&&
keyName
.
equals
(
that
.
keyName
)
&&
keyValue
.
equals
(
that
.
keyValue
)
}
public
int
hashCode
()
{
return
entityName
.
hashCode
()
^
keyName
.
hashCode
()
^
keyValue
.
hashCode
()
}
}
private
final
Map
<
EntityToken
,
Map
<
String
,
Object
>>
updates
=
new
LinkedHashMap
<>()
public
HookSynchronization
(
ExecutionContext
ec
)
{
this
.
ec
=
ec
}
protected
void
add
(
String
entityName
,
String
keyName
,
Object
keyValue
,
Map
<
String
,
Object
>
extraParameters
)
{
EntityToken
entityToken
=
new
EntityToken
(
entityName
,
keyName
,
keyValue
)
// This always move the value to the end of the list
Map
<
String
,
Object
>
existingExtraParameters
=
updates
.
remove
(
entityToken
)
Map
<
String
,
Object
>
newExtraParameters
=
[:]
if
(
existingExtraParameters
)
{
newExtraParameters
.
putAll
(
existingExtraParameters
)
}
if
(
extraParameters
)
{
newExtraParameters
.
putAll
(
extraParameters
)
}
updates
.
put
(
entityToken
,
newExtraParameters
)
if
(
existingExtraParameters
==
null
)
{
ec
.
getLogger
().
info
(
"Add new synchronization for ${entityName}: [${keyValue}]"
)
}
else
{
ec
.
getLogger
().
info
(
"Updated synchronization for ${entityName}: [${keyValue}]"
)
}
}
@Override
public
void
beforeCompletion
()
{
List
<
Map
<
String
,
Object
>>
updates
=
[]
for
(
Map
.
Entry
<
EntityToken
,
Map
<
String
,
Object
>>
entry:
this
.
updates
.
entrySet
())
{
EntityToken
token
=
entry
.
getKey
()
Map
<
String
,
Object
>
extraParameters
=
entry
.
getValue
()
updates
.
add
([
entityName:
token
.
entityName
,
keyName:
token
.
keyName
,
keyValue:
token
.
keyValue
,
extraParameters:
extraParameters
,
])
}
if
(
updates
)
{
ec
.
getService
().
async
().
name
(
"keycloak.HookServices.process#Updates"
).
parameter
(
'updates'
,
updates
).
call
()
}
}
@Override
public
void
afterCompletion
(
int
status
)
{
}
}
Please
register
or
sign in
to post a comment