forked from mosip/esignet-signup
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* change successfull registration sms content * send sms success notification to user * change SMS notification helper class for sendSMSNotificationAsync * update SMS helper name and rename properties key for SMS message template --------- Co-authored-by: Mengleang <[email protected]> Signed-off-by: Sreang Rathanak <[email protected]>
- Loading branch information
1 parent
70a51b9
commit 5c12ab6
Showing
4 changed files
with
92 additions
and
43 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
signup-service/src/main/java/io/mosip/signup/helper/NotificationHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.mosip.signup.helper; | ||
|
||
import io.mosip.esignet.core.util.IdentityProviderUtil; | ||
import io.mosip.signup.dto.NotificationRequest; | ||
import io.mosip.signup.dto.NotificationResponse; | ||
import io.mosip.signup.dto.RestRequestWrapper; | ||
import io.mosip.signup.dto.RestResponseWrapper; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.core.ParameterizedTypeReference; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
@Component | ||
public class NotificationHelper { | ||
|
||
@Autowired | ||
@Qualifier("selfTokenRestTemplate") | ||
private RestTemplate selfTokenRestTemplate; | ||
|
||
@Autowired | ||
private Environment environment; | ||
|
||
@Value("${mosip.signup.send-notification.endpoint}") | ||
private String sendNotificationEndpoint; | ||
|
||
|
||
@Async | ||
public CompletableFuture<RestResponseWrapper<NotificationResponse>> sendSMSNotificationAsync | ||
(String number, String locale, String templateKey, Map<String, String> params){ | ||
|
||
locale = locale != null ? locale : "khm"; | ||
String message = environment.getProperty(templateKey + "." + locale); | ||
|
||
if(params != null){ | ||
for (Map.Entry<String, String> entry: params.entrySet()){ | ||
message = message.replace(entry.getKey(), entry.getValue()); | ||
} | ||
} | ||
|
||
NotificationRequest notificationRequest = new NotificationRequest(number.substring(4), message); | ||
|
||
RestRequestWrapper<NotificationRequest> restRequestWrapper = new RestRequestWrapper<>(); | ||
restRequestWrapper.setRequesttime(IdentityProviderUtil.getUTCDateTime()); | ||
restRequestWrapper.setRequest(notificationRequest); | ||
|
||
return CompletableFuture.supplyAsync(() -> selfTokenRestTemplate | ||
.exchange(sendNotificationEndpoint, | ||
HttpMethod.POST, | ||
new HttpEntity<>(restRequestWrapper), | ||
new ParameterizedTypeReference<RestResponseWrapper<NotificationResponse>>(){}).getBody()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters