diff --git a/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/service/DemographicService.java b/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/service/DemographicService.java index 8fab319d1f7..10ee6929f3f 100644 --- a/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/service/DemographicService.java +++ b/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/service/DemographicService.java @@ -71,6 +71,7 @@ import io.mosip.preregistration.core.common.dto.DeleteBookingDTO; import io.mosip.preregistration.core.common.dto.DemographicResponseDTO; import io.mosip.preregistration.core.common.dto.DocumentMultipartResponseDTO; +import io.mosip.preregistration.core.common.dto.ExceptionJSONInfoDTO; import io.mosip.preregistration.core.common.dto.MainRequestDTO; import io.mosip.preregistration.core.common.dto.MainResponseDTO; import io.mosip.preregistration.core.common.dto.PreRegIdsByRegCenterIdDTO; @@ -822,15 +823,24 @@ public MainResponseDTO updatePreRegistrationStatus(String preRegId, Stri if (validationUtil.requstParamValidator(requestParamMap)) { DemographicEntity demographicEntity = demographicRepository.findBypreRegistrationId(preRegId); statusCheck(demographicEntity, status, userId); - } + response.setResponse("STATUS_UPDATED_SUCESSFULLY"); + } + } catch (RecordFailedToUpdateException | RecordNotFoundException ex) { + response.setResponse("STATUS_NOT_UPDATED_SUCESSFULLY"); + log.error("sessionId", "idType", "id", ExceptionUtils.getStackTrace(ex)); + log.error("sessionId", "idType", "id", + "Error in updatePreRegistrationStatus method of pre-registration service- " + ex.getMessage()); + // new DemographicExceptionCatcher().handle(ex, response); + ExceptionJSONInfoDTO errorDetails = new ExceptionJSONInfoDTO(ex.getErrorCode(), ex.getErrorText()); + List errorList = new ArrayList<>(); + errorList.add(errorDetails); + response.setErrors(errorList); } catch (Exception ex) { log.error("sessionId", "idType", "id", ExceptionUtils.getStackTrace(ex)); log.error("sessionId", "idType", "id", - "In updatePreRegistrationStatus method of pre-registration service- " + ex.getMessage()); + "Error in updatePreRegistrationStatus method of pre-registration service- " + ex.getMessage()); new DemographicExceptionCatcher().handle(ex, response); } - response.setResponse("STATUS_UPDATED_SUCESSFULLY"); - return response; } @@ -846,14 +856,19 @@ public void statusCheck(DemographicEntity demographicEntity, String status, Stri if (serviceUtil.isStatusValid(status)) { demographicEntity.setStatusCode(StatusCodes.valueOf(status.toUpperCase()).getCode()); if (status.toLowerCase().equals(StatusCodes.PENDING_APPOINTMENT.getCode().toLowerCase())) { - if (isupdateStausToPendingAppointmentValid(demographicEntity)) { - String prid = demographicEntity.getPreRegistrationId(); - serviceUtil.updateApplicationStatus(prid, status, userId); - log.info("Application booking status updated succesfully --> {}", status); - demographicRepository.update(demographicEntity); - log.info("demographic booking status updated succesfully --> {}", status); + try { + if (isupdateStausToPendingAppointmentValid(demographicEntity)) { + String prid = demographicEntity.getPreRegistrationId(); + serviceUtil.updateApplicationStatus(prid, status, userId); + log.info("Application booking status updated succesfully --> {}", status); + demographicRepository.update(demographicEntity); + log.info("demographic booking status updated succesfully --> {}", status); - } else { + } else { + throw new RecordFailedToUpdateException(DemographicErrorCodes.PRG_PAM_APP_023.getCode(), + DemographicErrorMessages.FAILED_TO_UPDATE_STATUS_PENDING_APPOINTMENT.getMessage()); + } + } catch(Exception e) { throw new RecordFailedToUpdateException(DemographicErrorCodes.PRG_PAM_APP_023.getCode(), DemographicErrorMessages.FAILED_TO_UPDATE_STATUS_PENDING_APPOINTMENT.getMessage()); } diff --git a/pre-registration/pre-registration-core/src/main/java/io/mosip/preregistration/core/util/NotificationUtil.java b/pre-registration/pre-registration-core/src/main/java/io/mosip/preregistration/core/util/NotificationUtil.java index 1158e5f52ff..5aa1bc44808 100644 --- a/pre-registration/pre-registration-core/src/main/java/io/mosip/preregistration/core/util/NotificationUtil.java +++ b/pre-registration/pre-registration-core/src/main/java/io/mosip/preregistration/core/util/NotificationUtil.java @@ -115,18 +115,18 @@ public MainResponseDTO emailNotification(NotificationDT for (KeyValuePairDto keyValuePair : acknowledgementDTO.getFullName()) { if (acknowledgementDTO.getIsBatch()) { fileText = templateUtil.getTemplate(keyValuePair.getKey(), cancelAppoinment); - fileText.concat(System.lineSeparator() + System.lineSeparator()); +// fileText.concat(System.lineSeparator() + System.lineSeparator()); } else { fileText = templateUtil.getTemplate(keyValuePair.getKey(), emailAcknowledgement); - fileText.concat(System.lineSeparator() + System.lineSeparator()); +// fileText.concat(System.lineSeparator() + System.lineSeparator()); } String languageWiseTemplate = templateUtil.templateMerge(fileText, acknowledgementDTO, (String) keyValuePair.getKey()); if (mergeTemplate == null) { - mergeTemplate = languageWiseTemplate; + mergeTemplate = languageWiseTemplate + System.lineSeparator(); } else { - mergeTemplate += System.lineSeparator() + languageWiseTemplate; + mergeTemplate += System.lineSeparator() + languageWiseTemplate +System.lineSeparator(); } } @@ -166,13 +166,15 @@ public MainResponseDTO emailNotification(NotificationDT */ public String getEmailSubject(NotificationDTO acknowledgementDTO) throws IOException { log.info("sessionId", "idType", "id", "In getEmailSubject method of NotificationUtil service"); - String emailSubject = null; + String emailSubject = ""; + int noOfLang = acknowledgementDTO.getFullName().size(); for (KeyValuePairDto keyValuePair : acknowledgementDTO.getFullName()) { - emailSubject = templateUtil.templateMerge( + emailSubject = emailSubject + templateUtil.templateMerge( templateUtil.getTemplate(keyValuePair.getKey(), emailAcknowledgementSubject), acknowledgementDTO, (String) keyValuePair.getKey()); - if (acknowledgementDTO.getFullName().size() > 1) { - emailSubject.concat(" / "); + if (noOfLang > 1) { + noOfLang--; + emailSubject = emailSubject + " / "; } } return emailSubject; diff --git a/pre-registration/pre-registration-core/src/test/java/io/mosip/preregistration/core/util/test/NotificationUtilTest.java b/pre-registration/pre-registration-core/src/test/java/io/mosip/preregistration/core/util/test/NotificationUtilTest.java index ae52af3f44f..0a92bd685ed 100644 --- a/pre-registration/pre-registration-core/src/test/java/io/mosip/preregistration/core/util/test/NotificationUtilTest.java +++ b/pre-registration/pre-registration-core/src/test/java/io/mosip/preregistration/core/util/test/NotificationUtilTest.java @@ -103,6 +103,8 @@ public void setUp() throws Exception { notificationDTO.setRegistrationCenterName(regCenterName); notificationDTO.setAddress(regCenterAddress); notificationDTO.setFullName(languageNamePairs); + notificationDTO.setRegistrationCenterName(languageNamePairs); + notificationDTO.setAddress(languageNamePairs); responseDTO = new MainResponseDTO<>(); responseDTO.setResponse(notificationDTO); // responseDTO.setStatus(Boolean.TRUE); @@ -138,6 +140,7 @@ public void notifyEmailsuccessTest() throws IOException { Mockito.when(restTemplate.exchange(Mockito.anyString(), Mockito.eq(HttpMethod.POST), Mockito.any(), Mockito.eq(new ParameterizedTypeReference>() { }))).thenReturn(resp); + MainResponseDTO response = notificationUtil.notify("email", notificationDTO, file); assertEquals(notificationResponseDTO.getMessage(), response.getResponse().getMessage()); } diff --git a/pre-registration/pre-registration-datasync-service/src/main/java/io/mosip/preregistration/datasync/service/DataSyncService.java b/pre-registration/pre-registration-datasync-service/src/main/java/io/mosip/preregistration/datasync/service/DataSyncService.java index 1d885b13ec2..d3bbb363796 100644 --- a/pre-registration/pre-registration-datasync-service/src/main/java/io/mosip/preregistration/datasync/service/DataSyncService.java +++ b/pre-registration/pre-registration-datasync-service/src/main/java/io/mosip/preregistration/datasync/service/DataSyncService.java @@ -281,16 +281,17 @@ public MainResponseDTO fetchPreRegistrationData(String preId, responseDto.setResponsetime(serviceUtil.getCurrentResponseTime()); responseDto.setResponse(preRegArchiveDTO); isRetrieveSuccess = true; - // insert the anonymous profile only if the appointment is being booked for the - // first time or being prefetched for the first time - if (preRegistrationDTO.getStatusCode().equals(StatusCodes.APPLICATION_INCOMPLETE.getCode()) - || preRegistrationDTO.getStatusCode().equals(StatusCodes.PENDING_APPOINTMENT.getCode())) { + // insert the anonymous profile only if the appointment is being prefetched for the first time + if (!preRegistrationDTO.getStatusCode().equals(StatusCodes.BOOKED.getCode()) + && !preRegistrationDTO.getStatusCode().equals(StatusCodes.PREFETCHED.getCode()) + && !preRegistrationDTO.getStatusCode().equals(StatusCodes.EXPIRED.getCode()) + && !preRegistrationDTO.getStatusCode().equals(StatusCodes.CANCELLED.getCode())) { preRegistrationDTO.setStatusCode(StatusCodes.PREFETCHED.getCode()); - anonymousProfileUtil.saveAnonymousProfile(preRegistrationDTO, documentsMetaData, - bookingRegistrationDTO, null); + anonymousProfileUtil.saveAnonymousProfile(preRegistrationDTO, documentsMetaData, bookingRegistrationDTO, + null); + // update status to prefetched + serviceUtil.updateApplicationStatusToPreFectched(preId); } - // update status to prefetched - serviceUtil.updateApplicationStatusToPreFectched(preId); } catch (AnonymousProfileException apex) { log.debug("sessionId", "idType", "id" + ExceptionUtils.getStackTrace(apex)); log.error("Unable to save AnonymousProfile in getPreRegistrationData method of datasync service -" + apex.getMessage());