adn-agov-iam-project/patterns/4f15bae09cbda04a7a515158_re.../eid_notify_user_first_login...

38 lines
1.0 KiB
Groovy

import ch.nevis.idm.client.IdmRestClient
import ch.nevis.idm.client.IdmRestClientFactory
String user_notification_dto = '''
{
"clientExtId": "{{clientExtId}}",
"userExtId": "{{userExtId}}",
"notificationType": "userNotification4",
"sendingMethod": [
"Email"
],
"async": false
}
'''
IdmRestClient idmRestClient = IdmRestClientFactory.get(parameters)
def sess = request.getAuthSession(true)
String baseUrl = parameters.get("baseUrl")
String clientExtId = parameters.get("clientExtId")
String endPoint = "$baseUrl/api/notification/v1/"
String userExtId = sess.getAttribute("agov.eid.linkedAccountExtId")
String restRequest = user_notification_dto.replaceAll("\\{\\{clientExtId}}", clientExtId).replaceAll("\\{\\{userExtId}}", userExtId)
try {
idmRestClient.post(endPoint, restRequest)
}catch(Exception e) {
LOG.error("Failed to send User Notification: First Login: ${e}")
response.setResult('error')
return
}
response.setResult('ok')
return