Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOSIP-26844 & fixed code for notification and track service #878

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
639cbeb
fixed id version for document APIs
Mar 24, 2023
f78abba
Merge branch 'develop' of https://github.com/mosip/resident-services …
Mar 24, 2023
1565410
update constant names
Mar 27, 2023
3ccfc54
used constant file_text
Mar 27, 2023
6917022
added validation on req credential API
Mar 28, 2023
ad66d56
Merge branch 'develop' of https://github.com/mosip/resident-services …
Mar 28, 2023
ad40dff
added validation for req credential API
Mar 29, 2023
1c27d17
Merge branch 'develop' of https://github.com/mosip/resident-services …
Mar 29, 2023
5ae27d1
Merge branch 'develop' of https://github.com/mosip/resident-services …
Mar 29, 2023
3983879
removed duplicate code
Mar 29, 2023
900e57c
fixed rid status issue
Mar 30, 2023
50fa48d
Merge branch 'develop' of https://github.com/mosip/resident-services …
Mar 30, 2023
bb6bff3
removed name from enum
Mar 30, 2023
e98a73c
code fix for rid status issue
Mar 31, 2023
4405796
update validate request body method
Mar 31, 2023
b90ff32
resolved merge conflict
Mar 31, 2023
861d167
Merge branch 'develop' of https://github.com/mosip/resident-services …
Apr 3, 2023
113c72e
Merge branch 'develop' of https://github.com/mosip/resident-services.…
Apr 4, 2023
605ac9f
Merge branch 'develop' of https://github.com/mosip/resident-services.…
Apr 4, 2023
c68783b
fixed registration center issue
Apr 5, 2023
265ec29
resolved merge conflict
Apr 5, 2023
b3f6e58
Merge branch 'develop' of https://github.com/mosip/resident-services.…
Apr 11, 2023
fb50ef1
added notification in validate otp API
Apr 12, 2023
2680167
fixed authentication request description
Apr 12, 2023
361eb27
removed space
Apr 12, 2023
ee70d26
removed validate otp from auth request service type
Apr 12, 2023
63c3b20
Merge branch 'develop' of https://github.com/mosip/resident-services …
Apr 12, 2023
af2aba1
Merge branch 'develop' of https://github.com/mosip/resident-services …
Apr 13, 2023
76ac174
added notification to get my uin API
Apr 13, 2023
2739dc8
Merge branch 'develop' of https://github.com/mosip/resident-services …
Apr 13, 2023
758d76f
added notification in personalised card API
Apr 13, 2023
a7d6f51
fixed null check
Apr 13, 2023
b42f6d4
Merge branch 'develop' of https://github.com/mosip/resident-services …
Apr 13, 2023
1a5d6f9
refactor code
Apr 13, 2023
c66ceda
Merge branch 'develop' of https://github.com/mosip/resident-services …
Apr 13, 2023
f0462d9
Merge branch 'develop' of https://github.com/mosip/resident-services.…
Apr 13, 2023
ceccca0
fixed code for notify
Apr 14, 2023
296cc0f
code refactoring
Apr 15, 2023
8f12ec9
fixed test case failure
Apr 15, 2023
127b1da
take templatetype code from properties
Apr 17, 2023
6bde245
Merge branch 'develop' of https://github.com/mosip/resident-services …
Apr 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
package io.mosip.resident.constant;

import org.springframework.core.env.Environment;

/**
* @author Kamesh Shekhar Prasad
*/
public enum AttributeNameEnum {
FULL_NAME("fullName", "mosip.full.name.template.property"),
DATE_OF_BIRTH("dateOfBirth", "mosip.date.of.birth.template.property"),
UIN("UIN", "mosip.uin.template.property"),
PERPETUAL_VID("perpetualVID", "mosip.perpetual.vid.template.property"),
PHONE("phone", "mosip.phone.template.property"),
EMAIL("email", "mosip.email.template.property"),
ADDRESS("addressLine1", "mosip.address.template.property"),
GENDER("gender", "mosip.gender.template.property"),
DEFAULT("Default", "mosip.defualt.template.property");
FULL_NAME("fullName", "mosip.full.name.template.property.attribute.list"),
DATE_OF_BIRTH("dateOfBirth", "mosip.date.of.birth.template.property.attribute.list"),
UIN("UIN", "mosip.uin.template.property.attribute.list"),
PERPETUAL_VID("perpetualVID", "mosip.perpetual.vid.template.property.attribute.list"),
PHONE("phone", "mosip.phone.template.property.attribute.list"),
EMAIL("email", "mosip.email.template.property.attribute.list"),
ADDRESS("addressLine1", "mosip.address.template.property.attribute.list"),
PROVINCE("province", "mosip.province.template.property.attribute.list"),
CITY("city", "mosip.city.template.property.attribute.list"),
ZONE("zone", "mosip.zone.template.property.attribute.list"),
POSTAL_CODE("postalCode", "mosip.postal.code.template.property.attribute.list"),
REGION("region", "mosip.region.template.property.attribute.list"),
GENDER("gender", "mosip.gender.template.property.attribute.list"),
DEFAULT("Default", "mosip.defualt.template.property.attribute.list");
private String attributeValue;
private String templatePropertyName;
AttributeNameEnum(String name, String templatePropertyName){
this.attributeValue = name;
this.templatePropertyName = templatePropertyName;
}

public static String getTemplatePropertyName(String attributeName) {
for (AttributeNameEnum authenticationModeEnum : values()) {
if (authenticationModeEnum.attributeValue.equalsIgnoreCase(attributeName)) {
return authenticationModeEnum.templatePropertyName;
public static String getTemplatePropertyName(String attributeName, Environment env) {
for (AttributeNameEnum attributeNameEnum : values()) {
if (attributeNameEnum.attributeValue.equalsIgnoreCase(attributeName)) {
return env.getProperty(attributeNameEnum.templatePropertyName);
}
}
return AttributeNameEnum.DEFAULT.templatePropertyName;
return env.getProperty(AttributeNameEnum.DEFAULT.templatePropertyName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class TemplateVariablesConstants {
public static final String SUMMARY = "summary";
public static final String TRACKING_ID = "trackingId";
public static final String ORDER_TRACKING_LINK = "orderTrackingLink";
public static final String PARTNER_ID = "partner";
public static final String PARTNER_NAME = "partnerName";
public static final String PARTNER_LOGO = "partnerLogo";
public static final String ATTRIBUTE_LIST = "attributeList";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import static io.mosip.resident.constant.EventStatusSuccess.CARD_DOWNLOADED;
import static io.mosip.resident.constant.EventStatusSuccess.LOCKED;
import static io.mosip.resident.constant.EventStatusSuccess.UNLOCKED;
import static io.mosip.resident.constant.MappingJsonConstants.IDSCHEMA_VERSION;
import static io.mosip.resident.constant.RegistrationConstants.UIN_LABEL;
import static io.mosip.resident.constant.ResidentConstants.ATTRIBUTE_LIST_DELIMITER;
import static io.mosip.resident.constant.ResidentConstants.RESIDENT;
import static io.mosip.resident.constant.ResidentConstants.RESIDENT_NOTIFICATIONS_DEFAULT_PAGE_SIZE;
import static io.mosip.resident.constant.ResidentErrorCode.MACHINE_MASTER_CREATE_EXCEPTION;
Expand Down Expand Up @@ -1159,10 +1162,10 @@ private ResidentTransactionEntity createResidentTransEntity(ResidentUpdateReques
} else {
identityMap = dto.getIdentity();
}
HashSet<String> keys = new HashSet<String>(identityMap.keySet());
keys.remove("IDSchemaVersion");
keys.remove("UIN");
String attributeList = keys.stream().collect(Collectors.joining(AUTH_TYPE_LIST_DELIMITER));

String attributeList = identityMap.keySet().stream()
.filter(key -> !key.equals(IDSCHEMA_VERSION) && !key.equals(UIN_LABEL))
.collect(Collectors.joining(ATTRIBUTE_LIST_DELIMITER));
residentTransactionEntity.setAttributeList(attributeList);
residentTransactionEntity.setConsent(dto.getConsent());
residentTransactionEntity.setStatusCode(EventStatusInProgress.NEW.name());
Expand Down Expand Up @@ -1903,11 +1906,7 @@ private String getDescriptionForLangCode(String langCode, String statusCode, Req
templateType = TemplateType.FAILURE;
}
String templateTypeCode = templateUtil.getPurposeTemplateTypeCode(requestType, templateType);
ResponseWrapper<?> proxyResponseWrapper = proxyMasterdataService
.getAllTemplateBylangCodeAndTemplateTypeCode(langCode, templateTypeCode);
Map<String, String> templateResponse = new LinkedHashMap<>(
(Map<String, String>) proxyResponseWrapper.getResponse());
String fileText = templateResponse.get(ResidentConstants.FILE_TEXT);
String fileText = templateUtil.getTemplateValueFromTemplateTypeCodeAndLangCode(langCode, templateTypeCode);
return replacePlaceholderValueInTemplate(fileText, eventId, requestType, langCode);
}

Expand All @@ -1921,11 +1920,8 @@ public String getSummaryForLangCode(String langCode, String statusCode, RequestT
if (statusCode.equalsIgnoreCase(EventStatus.SUCCESS.toString())) {
templateType = TemplateType.SUCCESS;
String templateTypeCode = templateUtil.getSummaryTemplateTypeCode(requestType, templateType);
ResponseWrapper<?> proxyResponseWrapper = proxyMasterdataService
.getAllTemplateBylangCodeAndTemplateTypeCode(langCode, templateTypeCode);
Map<String, String> templateResponse = new LinkedHashMap<>(
(Map<String, String>) proxyResponseWrapper.getResponse());
return replacePlaceholderValueInTemplate(templateResponse.get(ResidentConstants.FILE_TEXT), eventId, requestType, langCode);
String fileText = templateUtil.getTemplateValueFromTemplateTypeCodeAndLangCode(langCode, templateTypeCode);
return replacePlaceholderValueInTemplate(fileText, eventId, requestType, langCode);
} else {
return getDescriptionForLangCode(langCode, statusCode, requestType, eventId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -18,10 +19,10 @@
import io.mosip.kernel.core.http.ResponseWrapper;
import io.mosip.kernel.core.logger.spi.Logger;
import io.mosip.kernel.core.util.DateUtils;
import io.mosip.kernel.core.util.StringUtils;
import io.mosip.resident.config.LoggerConfiguration;
import io.mosip.resident.constant.AttributeNameEnum;
import io.mosip.resident.constant.AuthenticationModeEnum;
import io.mosip.resident.constant.EventStatus;
import io.mosip.resident.constant.EventStatusFailure;
import io.mosip.resident.constant.EventStatusInProgress;
import io.mosip.resident.constant.EventStatusSuccess;
Expand Down Expand Up @@ -100,9 +101,9 @@ public Tuple2<Map<String, String>, ResidentTransactionEntity> getCommonTemplateV
templateVariables.put(TemplateVariablesConstants.EVENT_ID, eventId);
ResidentTransactionEntity residentTransactionEntity = getEntityFromEventId(eventId);
templateVariables.put(TemplateVariablesConstants.EVENT_TYPE,
RequestType.valueOf(residentTransactionEntity.getRequestTypeCode()).getName());
RequestType.getRequestTypeFromString(residentTransactionEntity.getRequestTypeCode()).getName());
templateVariables.put(TemplateVariablesConstants.EVENT_STATUS,
getEventStatusForRequestType(residentTransactionEntity.getStatusCode()));
residentService.getEventStatusCode(residentTransactionEntity.getStatusCode()));
templateVariables.put(TemplateVariablesConstants.SUMMARY, replaceNullWithEmptyString(
residentTransactionEntity.getRequestSummary()));
templateVariables.put(TemplateVariablesConstants.TIMESTAMP,
Expand Down Expand Up @@ -133,23 +134,23 @@ public Tuple2<Map<String, String>, ResidentTransactionEntity> getCommonTemplateV
* @return attribute value stored in the template.
*/
private String getAttributesDisplayText(String attributes, String languageCode) {
String phoneAttributeName = this.env.getProperty(ResidentConstants.PHOTO_ATTRIBUTE_NAME);
String photoAttributeName = this.env.getProperty(ResidentConstants.PHOTO_ATTRIBUTE_NAME);
List<String> attributeListTemplateValue = new ArrayList<>();
if (attributes != null && attributes.contains(Objects.requireNonNull(phoneAttributeName))) {
attributes = attributes.replace(phoneAttributeName, "");
if (attributes != null && attributes.contains(Objects.requireNonNull(photoAttributeName))) {
attributes = attributes.replace(photoAttributeName, "");
}
if (attributes != null) {
List<String> attributeList = List.of(attributes.trim().split(ResidentConstants.COMMA));
if (!StringUtils.isBlank(attributes)) {
List<String> attributeList = List.of(attributes.split(ResidentConstants.ATTRIBUTE_LIST_DELIMITER));
for (String attribute : attributeList) {
attribute = attribute.trim();
attributeListTemplateValue.add(getTemplateValueFromTemplateTypeCodeAndLangCode(languageCode,
AttributeNameEnum.getTemplatePropertyName(attribute)));
AttributeNameEnum.getTemplatePropertyName(attribute, env)));
}
}
if(attributeListTemplateValue.isEmpty()){
return "";
} else {
return String.join(ResidentConstants.COMMA, attributeListTemplateValue);
return attributeListTemplateValue.stream().collect(Collectors.joining(ResidentConstants.ATTRIBUTE_LIST_DELIMITER));
}

}
Expand Down Expand Up @@ -267,18 +268,6 @@ public String getIndividualIdType() throws ApisResourceAccessException {
return identityServiceImpl.getIndividualIdType(individualId);
}

private String getEventStatusForRequestType(String requestType) {
String eventStatus = "";
if(EventStatusSuccess.containsStatus(requestType)){
eventStatus = EventStatus.SUCCESS.getStatus();
} else if(EventStatusFailure.containsStatus(requestType)){
eventStatus = EventStatus.FAILED.getStatus();
} else {
eventStatus = EventStatus.IN_PROGRESS.getStatus();
}
return eventStatus;
}

public Tuple2<Map<String, String>, String> getAckTemplateVariablesForCredentialShare(String eventId, String languageCode, Integer timeZoneOffset) {
Tuple2<Map<String, String>, ResidentTransactionEntity> tupleResponse = getCommonTemplateVariables(eventId, languageCode, timeZoneOffset);
Map<String, String> templateVariables = tupleResponse.getT1();
Expand All @@ -304,7 +293,7 @@ public Tuple2<Map<String, String>, String> getAckTemplateVariablesForDownloadPer
Map<String, String> templateVariables = tupleResponse.getT1();
ResidentTransactionEntity residentTransactionEntity = tupleResponse.getT2();
templateVariables.put(TemplateVariablesConstants.PURPOSE, addAttributeInPurpose(getPurposeFromResidentTransactionEntityLangCode(
residentTransactionEntity, languageCode), getEntityFromEventId(eventId).getPurpose(), languageCode));
residentTransactionEntity, languageCode), residentTransactionEntity.getPurpose(), languageCode));
return Tuples.of(templateVariables, Objects.requireNonNull(
this.env.getProperty(ResidentConstants.ACK_DOWNLOAD_PERSONALIZED_CARD_TEMPLATE_PROPERTY)));
}
Expand Down Expand Up @@ -392,7 +381,7 @@ public String getPurposeFromResidentTransactionEntityLangCode(ResidentTransactio
try {
purpose = residentService.getSummaryForLangCode(languageCode, residentService.getEventStatusCode(
residentTransactionEntity.getStatusCode()),
RequestType.valueOf(residentTransactionEntity.getRequestTypeCode().trim()), residentTransactionEntity.getEventId());
RequestType.getRequestTypeFromString(residentTransactionEntity.getRequestTypeCode()), residentTransactionEntity.getEventId());
} catch (ResidentServiceCheckedException e) {
return "";
}
Expand Down Expand Up @@ -513,9 +502,6 @@ public Map<String, Object> getNotificationTemplateVariablesForAuthTypeLockUnlock

public Map<String, Object> getNotificationTemplateVariablesForUpdateMyUin(NotificationTemplateVariableDTO dto) {
Map<String, Object> templateVariables = getNotificationCommonTemplateVariables(dto);
if(TemplateType.SUCCESS.getType().equals(dto.getTemplateType().getType())) {
templateVariables.put(TemplateVariablesConstants.DOWNLOAD_LINK, utility.createTrackServiceRequestLink(dto.getEventId()));
}
return templateVariables;
}

Expand All @@ -531,22 +517,20 @@ public Map<String, Object> getNotificationTemplateVariablesForGetMyId(Notificati

public Map<String, Object> getNotificationTemplateVariablesForDownloadPersonalizedCard(NotificationTemplateVariableDTO dto) {
Map<String, Object> templateVariables = getNotificationCommonTemplateVariables(dto);
if(TemplateType.SUCCESS.getType().equals(dto.getTemplateType().getType())) {
templateVariables.put(TemplateVariablesConstants.DOWNLOAD_LINK, utility.createTrackServiceRequestLink(dto.getEventId()));
}
return templateVariables;
}

public Map<String, Object> getNotificationTemplateVariablesForOrderPhysicalCard(NotificationTemplateVariableDTO dto) {
Map<String, Object> templateVariables = getNotificationCommonTemplateVariables(dto);
if(TemplateType.SUCCESS.getType().equals(dto.getTemplateType().getType())) {
templateVariables.put(TemplateVariablesConstants.DOWNLOAD_LINK, utility.createTrackServiceRequestLink(dto.getEventId()));
}
return templateVariables;
}

public Map<String, Object> getNotificationTemplateVariablesForShareCredentialWithPartner(NotificationTemplateVariableDTO dto) {
Map<String, Object> templateVariables = getNotificationCommonTemplateVariables(dto);
if (TemplateType.SUCCESS.getType().equals(dto.getTemplateType().getType())) {
templateVariables.put(TemplateVariablesConstants.PARTNER_ID,
getEntityFromEventId(dto.getEventId()).getRequestedEntityId());
}
return templateVariables;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public void setUp() throws ApisResourceAccessException, ResidentServiceCheckedEx
responseWrapper.setResponse(templateResponse);
Mockito.when(proxyMasterdataService.getAllTemplateBylangCodeAndTemplateTypeCode(Mockito.anyString(), Mockito.anyString())).thenReturn(
responseWrapper);
Mockito.when(residentService.getEventStatusCode(Mockito.anyString())).thenReturn(EventStatus.SUCCESS.getStatus());
}

@Test
Expand Down Expand Up @@ -203,7 +204,7 @@ public void getCommonTemplateVariablesTestBadEventId() {
@Test
public void getCommonTemplateVariablesTestFailedEventStatus() {
residentTransactionEntity.setStatusCode(EventStatusFailure.AUTHENTICATION_FAILED.name());
Mockito.when(residentTransactionRepository.findById(eventId)).thenReturn(java.util.Optional.ofNullable(residentTransactionEntity));
Mockito.when(residentService.getEventStatusCode(Mockito.anyString())).thenReturn(EventStatus.FAILED.getStatus());
assertEquals(EventStatus.FAILED.getStatus(),templateUtil.getCommonTemplateVariables(eventId, "eng", 0).getT1().get(
TemplateVariablesConstants.EVENT_STATUS
));
Expand All @@ -212,7 +213,7 @@ public void getCommonTemplateVariablesTestFailedEventStatus() {
@Test
public void getCommonTemplateVariablesTestInProgressEventStatus() {
residentTransactionEntity.setStatusCode(EventStatusInProgress.OTP_REQUESTED.name());
Mockito.when(residentTransactionRepository.findById(eventId)).thenReturn(java.util.Optional.ofNullable(residentTransactionEntity));
Mockito.when(residentService.getEventStatusCode(Mockito.anyString())).thenReturn(EventStatus.IN_PROGRESS.getStatus());
assertEquals(EventStatus.IN_PROGRESS.getStatus(),templateUtil.getCommonTemplateVariables(eventId, "eng", 0).getT1().get(
TemplateVariablesConstants.EVENT_STATUS
));
Expand Down