From 9e54f34658e18a2307a4e6324d529ff4bae4a17c Mon Sep 17 00:00:00 2001 From: RitikJain4108 <99730411+RitikJain4108@users.noreply.github.com> Date: Mon, 17 Apr 2023 15:50:34 +0530 Subject: [PATCH] MOSIP-26844 & fixed code for notification and track service (#878) * fixed id version for document APIs * update constant names * used constant file_text * added validation on req credential API * added validation for req credential API * removed duplicate code * fixed rid status issue * removed name from enum * code fix for rid status issue * update validate request body method * fixed registration center issue * added notification in validate otp API * fixed authentication request description * removed space * removed validate otp from auth request service type * added notification to get my uin API * added notification in personalised card API * fixed null check * refactor code * fixed code for notify * code refactoring * fixed test case failure * take templatetype code from properties --------- Co-authored-by: Ritik Jain Signed-off-by: kameshsr --- .../resident/constant/AttributeNameEnum.java | 35 +++++++------ .../constant/TemplateVariablesConstants.java | 1 + .../service/impl/ResidentServiceImpl.java | 24 ++++----- .../io/mosip/resident/util/TemplateUtil.java | 50 +++++++------------ .../resident/test/util/TemplateUtilTest.java | 5 +- 5 files changed, 52 insertions(+), 63 deletions(-) diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/AttributeNameEnum.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/AttributeNameEnum.java index bbba7f13bb8..99882f376fe 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/AttributeNameEnum.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/AttributeNameEnum.java @@ -1,18 +1,25 @@ 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){ @@ -20,13 +27,13 @@ public enum AttributeNameEnum { 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); } } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/constant/TemplateVariablesConstants.java b/resident/resident-service/src/main/java/io/mosip/resident/constant/TemplateVariablesConstants.java index da8baeb2098..168fe7cae91 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/constant/TemplateVariablesConstants.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/constant/TemplateVariablesConstants.java @@ -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"; diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java index 5861b2047bb..98bfebbd2eb 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java @@ -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; @@ -1159,10 +1162,10 @@ private ResidentTransactionEntity createResidentTransEntity(ResidentUpdateReques } else { identityMap = dto.getIdentity(); } - HashSet keys = new HashSet(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()); @@ -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 templateResponse = new LinkedHashMap<>( - (Map) proxyResponseWrapper.getResponse()); - String fileText = templateResponse.get(ResidentConstants.FILE_TEXT); + String fileText = templateUtil.getTemplateValueFromTemplateTypeCodeAndLangCode(langCode, templateTypeCode); return replacePlaceholderValueInTemplate(fileText, eventId, requestType, langCode); } @@ -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 templateResponse = new LinkedHashMap<>( - (Map) 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); } diff --git a/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java b/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java index c434a4d729d..6aeff89fa21 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/util/TemplateUtil.java @@ -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; @@ -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; @@ -100,9 +101,9 @@ public Tuple2, 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, @@ -133,23 +134,23 @@ public Tuple2, 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 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 attributeList = List.of(attributes.trim().split(ResidentConstants.COMMA)); + if (!StringUtils.isBlank(attributes)) { + List 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)); } } @@ -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, String> getAckTemplateVariablesForCredentialShare(String eventId, String languageCode, Integer timeZoneOffset) { Tuple2, ResidentTransactionEntity> tupleResponse = getCommonTemplateVariables(eventId, languageCode, timeZoneOffset); Map templateVariables = tupleResponse.getT1(); @@ -304,7 +293,7 @@ public Tuple2, String> getAckTemplateVariablesForDownloadPer Map 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))); } @@ -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 ""; } @@ -513,9 +502,6 @@ public Map getNotificationTemplateVariablesForAuthTypeLockUnlock public Map getNotificationTemplateVariablesForUpdateMyUin(NotificationTemplateVariableDTO dto) { Map templateVariables = getNotificationCommonTemplateVariables(dto); - if(TemplateType.SUCCESS.getType().equals(dto.getTemplateType().getType())) { - templateVariables.put(TemplateVariablesConstants.DOWNLOAD_LINK, utility.createTrackServiceRequestLink(dto.getEventId())); - } return templateVariables; } @@ -531,22 +517,20 @@ public Map getNotificationTemplateVariablesForGetMyId(Notificati public Map getNotificationTemplateVariablesForDownloadPersonalizedCard(NotificationTemplateVariableDTO dto) { Map templateVariables = getNotificationCommonTemplateVariables(dto); - if(TemplateType.SUCCESS.getType().equals(dto.getTemplateType().getType())) { - templateVariables.put(TemplateVariablesConstants.DOWNLOAD_LINK, utility.createTrackServiceRequestLink(dto.getEventId())); - } return templateVariables; } public Map getNotificationTemplateVariablesForOrderPhysicalCard(NotificationTemplateVariableDTO dto) { Map templateVariables = getNotificationCommonTemplateVariables(dto); - if(TemplateType.SUCCESS.getType().equals(dto.getTemplateType().getType())) { - templateVariables.put(TemplateVariablesConstants.DOWNLOAD_LINK, utility.createTrackServiceRequestLink(dto.getEventId())); - } return templateVariables; } public Map getNotificationTemplateVariablesForShareCredentialWithPartner(NotificationTemplateVariableDTO dto) { Map templateVariables = getNotificationCommonTemplateVariables(dto); + if (TemplateType.SUCCESS.getType().equals(dto.getTemplateType().getType())) { + templateVariables.put(TemplateVariablesConstants.PARTNER_ID, + getEntityFromEventId(dto.getEventId()).getRequestedEntityId()); + } return templateVariables; } diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/util/TemplateUtilTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/util/TemplateUtilTest.java index 9cc8ee5ec5f..90002917bc7 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/util/TemplateUtilTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/util/TemplateUtilTest.java @@ -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 @@ -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 )); @@ -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 ));