Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into develop
  • Loading branch information
aihamh committed Apr 18, 2023
2 parents 39fb0d4 + a2e9b4b commit 5ba20d1
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 63 deletions.
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

0 comments on commit 5ba20d1

Please sign in to comment.