From d9826467adcbe01cf5210c2f4d775cff954cd7a6 Mon Sep 17 00:00:00 2001 From: Khuddus shariff Date: Mon, 30 Oct 2023 20:15:02 +0530 Subject: [PATCH 1/3] [ MOSIP-27859 ] Adding pkt_cr_dtimes and setting the packet date and time from metadata of the packet Signed-off-by: khuddus shariff --- .../packet/validator/PacketValidateProcessor.java | 10 +++++++++- .../validator/PacketValidateProcessorTest.java | 6 ++++++ .../status/dto/InternalRegistrationStatusDto.java | 11 +++++++++++ .../status/entity/RegistrationStatusEntity.java | 12 ++++++++++++ .../service/impl/RegistrationStatusServiceImpl.java | 2 ++ 5 files changed, 40 insertions(+), 1 deletion(-) diff --git a/registration-processor/pre-processor/registration-processor-packet-validator-stage/src/main/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessor.java b/registration-processor/pre-processor/registration-processor-packet-validator-stage/src/main/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessor.java index 02421e7b7e5..11e70924e56 100644 --- a/registration-processor/pre-processor/registration-processor-packet-validator-stage/src/main/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessor.java +++ b/registration-processor/pre-processor/registration-processor-packet-validator-stage/src/main/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessor.java @@ -4,6 +4,8 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.Date; import java.util.Map; @@ -168,6 +170,9 @@ public class PacketValidateProcessor { @Autowired private NotificationUtility notificationUtility; + @Value("${mosip.registration.processor.datetime.pattern}") + private String dateformat; + public MessageDTO process(MessageDTO object, String stageName) { TrimExceptionMessage trimMessage = new TrimExceptionMessage(); LogDescription description = new LogDescription(); @@ -188,7 +193,10 @@ public MessageDTO process(MessageDTO object, String stageName) { registrationStatusDto = registrationStatusService.getRegistrationStatus( registrationId, object.getReg_type(), object.getIteration(), object.getWorkflowInstanceId()); - + Map metaInfo = packetManagerService.getMetaInfo( + registrationId, registrationStatusDto.getRegistrationType(), ProviderStageName.PACKET_VALIDATOR); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateformat); + registrationStatusDto.setPacketCreateDateTime(LocalDateTime.parse(metaInfo.get(JsonConstant.CREATIONDATE),formatter)); registrationStatusDto .setLatestTransactionTypeCode(RegistrationTransactionTypeCode.VALIDATE_PACKET.toString()); registrationStatusDto.setRegistrationStageName(stageName); diff --git a/registration-processor/pre-processor/registration-processor-packet-validator-stage/src/test/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessorTest.java b/registration-processor/pre-processor/registration-processor-packet-validator-stage/src/test/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessorTest.java index 4b52a8820a2..b4f858b8762 100644 --- a/registration-processor/pre-processor/registration-processor-packet-validator-stage/src/test/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessorTest.java +++ b/registration-processor/pre-processor/registration-processor-packet-validator-stage/src/test/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessorTest.java @@ -64,6 +64,7 @@ import java.io.IOException; import java.io.InputStream; import java.security.MessageDigest; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -127,6 +128,9 @@ public class PacketValidateProcessorTest { @Mock private NotificationUtility notificationUtility; + + @Mock + DateTimeFormatter dateTimeFormatter; private MessageDTO messageDTO; private String stageName; @@ -136,6 +140,7 @@ public class PacketValidateProcessorTest { @Before public void setup() throws Exception { ReflectionTestUtils.setField(packetValidateProcessor, "notificationTypes", "SMS|EMAIL"); + ReflectionTestUtils.setField(packetValidateProcessor, "dateformat", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); messageDTO=new MessageDTO(); messageDTO.setRid("123456789"); messageDTO.setInternalError(false); @@ -245,6 +250,7 @@ public void setup() throws Exception { Map metamap = new HashMap<>(); org.json.JSONArray jsonArray = new org.json.JSONArray(); org.json.JSONObject jsonObject1 = new org.json.JSONObject(); + metamap.put("creationDate","2023-10-17T03:01:09.893Z"); jsonObject1.put("preRegistrationId", "12345"); jsonArray.put(0, jsonObject1); metamap.put(JsonConstant.METADATA, jsonArray.toString()); diff --git a/registration-processor/registration-processor-registration-status-service-impl/src/main/java/io/mosip/registration/processor/status/dto/InternalRegistrationStatusDto.java b/registration-processor/registration-processor-registration-status-service-impl/src/main/java/io/mosip/registration/processor/status/dto/InternalRegistrationStatusDto.java index e045890f79c..5779b35f83f 100644 --- a/registration-processor/registration-processor-registration-status-service-impl/src/main/java/io/mosip/registration/processor/status/dto/InternalRegistrationStatusDto.java +++ b/registration-processor/registration-processor-registration-status-service-impl/src/main/java/io/mosip/registration/processor/status/dto/InternalRegistrationStatusDto.java @@ -48,6 +48,17 @@ public class InternalRegistrationStatusDto implements Serializable { /** The update date time. */ private LocalDateTime updateDateTime; + /** Packet Created Date and Time**/ + private LocalDateTime packetCreateDateTime; + + public LocalDateTime getPacketCreateDateTime() { + return packetCreateDateTime; + } + + public void setPacketCreateDateTime(LocalDateTime packetCreateDateTime) { + this.packetCreateDateTime = packetCreateDateTime; + } + /** The is deleted. */ private Boolean isDeleted; diff --git a/registration-processor/registration-processor-registration-status-service-impl/src/main/java/io/mosip/registration/processor/status/entity/RegistrationStatusEntity.java b/registration-processor/registration-processor-registration-status-service-impl/src/main/java/io/mosip/registration/processor/status/entity/RegistrationStatusEntity.java index c44c9eb35f4..0f40de4eaa2 100644 --- a/registration-processor/registration-processor-registration-status-service-impl/src/main/java/io/mosip/registration/processor/status/entity/RegistrationStatusEntity.java +++ b/registration-processor/registration-processor-registration-status-service-impl/src/main/java/io/mosip/registration/processor/status/entity/RegistrationStatusEntity.java @@ -67,6 +67,18 @@ public class RegistrationStatusEntity extends BaseRegistrationEntity Date: Mon, 6 Nov 2023 17:38:45 +0530 Subject: [PATCH 2/3] [Mosip-27859] [ MOSIP-29896 ] Adding pkt_cr_dtimes and setting the packet date and time from metadata of the packet Signed-off-by: khuddus shariff --- .../validator/PacketValidateProcessor.java | 36 ++++++++-- .../PacketValidateProcessorTest.java | 65 +++++++++++-------- .../exception/util/PlatformErrorMessages.java | 10 +++ 3 files changed, 78 insertions(+), 33 deletions(-) diff --git a/registration-processor/pre-processor/registration-processor-packet-validator-stage/src/main/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessor.java b/registration-processor/pre-processor/registration-processor-packet-validator-stage/src/main/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessor.java index 11e70924e56..ff7708859a8 100644 --- a/registration-processor/pre-processor/registration-processor-packet-validator-stage/src/main/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessor.java +++ b/registration-processor/pre-processor/registration-processor-packet-validator-stage/src/main/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessor.java @@ -6,12 +6,14 @@ import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; import java.util.Arrays; import java.util.Date; import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import io.mosip.kernel.core.util.DateUtils; import io.mosip.registration.processor.packet.storage.utils.Utilities; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.exception.ExceptionUtils; @@ -177,7 +179,6 @@ public MessageDTO process(MessageDTO object, String stageName) { TrimExceptionMessage trimMessage = new TrimExceptionMessage(); LogDescription description = new LogDescription(); PacketValidationDto packetValidationDto = new PacketValidationDto(); - InternalRegistrationStatusDto registrationStatusDto = new InternalRegistrationStatusDto(); try { registrationStatusDto @@ -190,13 +191,9 @@ public MessageDTO process(MessageDTO object, String stageName) { "", "PacketValidateProcessor::process()::entry"); registrationId = object.getRid(); packetValidationDto.setTransactionSuccessful(false); - registrationStatusDto = registrationStatusService.getRegistrationStatus( registrationId, object.getReg_type(), object.getIteration(), object.getWorkflowInstanceId()); - Map metaInfo = packetManagerService.getMetaInfo( - registrationId, registrationStatusDto.getRegistrationType(), ProviderStageName.PACKET_VALIDATOR); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateformat); - registrationStatusDto.setPacketCreateDateTime(LocalDateTime.parse(metaInfo.get(JsonConstant.CREATIONDATE),formatter)); + setPacketCreatedDateTime(registrationStatusDto); registrationStatusDto .setLatestTransactionTypeCode(RegistrationTransactionTypeCode.VALIDATE_PACKET.toString()); registrationStatusDto.setRegistrationStageName(stageName); @@ -455,6 +452,33 @@ public MessageDTO process(MessageDTO object, String stageName) { } + + private void setPacketCreatedDateTime(InternalRegistrationStatusDto registrationStatusDto) throws ApisResourceAccessException, PacketManagerException, JsonProcessingException, IOException { + try { + Map metaInfo = packetManagerService.getMetaInfo( + registrationStatusDto.getRefId(), registrationStatusDto.getRegistrationType(), ProviderStageName.PACKET_VALIDATOR); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateformat); + String packetCreatedDateTime = metaInfo.get(JsonConstant.CREATIONDATE); + if (packetCreatedDateTime != null && !packetCreatedDateTime.isEmpty()) { + LocalDateTime dateTime = DateUtils.parseToLocalDateTime(packetCreatedDateTime); + registrationStatusDto.setPacketCreateDateTime(dateTime); + } else { + regProcLogger.warn(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), + " -- " + registrationStatusDto.getRefId(), + PlatformErrorMessages.RPR_PVM_PACKET_CREATED_DATE_TIME_EMPTY_OR_NULL.getMessage()); + } + } catch (DateTimeParseException e) { + regProcLogger.warn(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), + " -- " + registrationStatusDto.getRefId(), + PlatformErrorMessages.RPR_PVM_PACKET_CREATED_DATE_TIME_PARSE_EXCEPTION.getMessage() + e.getMessage()); + }catch (IllegalArgumentException ex) + { + regProcLogger.warn(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(), + " -- " + registrationStatusDto.getRefId(), + PlatformErrorMessages.RPR_PVM_INVALID_ARGUMENT_EXCEPTION.getMessage() + ex.getMessage()); + } + } + private boolean isValidSupervisorStatus(MessageDTO messageDTO) { SyncRegistrationEntity regEntity = syncRegistrationService.findByWorkflowInstanceId(messageDTO.getWorkflowInstanceId()); if (regEntity.getSupervisorStatus().equalsIgnoreCase(APPROVED)) { diff --git a/registration-processor/pre-processor/registration-processor-packet-validator-stage/src/test/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessorTest.java b/registration-processor/pre-processor/registration-processor-packet-validator-stage/src/test/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessorTest.java index b4f858b8762..db224f2da8d 100644 --- a/registration-processor/pre-processor/registration-processor-packet-validator-stage/src/test/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessorTest.java +++ b/registration-processor/pre-processor/registration-processor-packet-validator-stage/src/test/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessorTest.java @@ -42,13 +42,11 @@ import io.mosip.registration.processor.status.service.SyncRegistrationService; import org.apache.commons.io.IOUtils; import org.json.JSONException; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Matchers; -import org.mockito.Mock; -import org.mockito.Mockito; +import org.mockito.*; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; @@ -64,6 +62,7 @@ import java.io.IOException; import java.io.InputStream; import java.security.MessageDigest; +import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; @@ -71,11 +70,11 @@ import java.util.List; import java.util.Map; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; + import static org.mockito.ArgumentMatchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyBoolean; +import static org.junit.Assert.*; /** @@ -250,42 +249,54 @@ public void setup() throws Exception { Map metamap = new HashMap<>(); org.json.JSONArray jsonArray = new org.json.JSONArray(); org.json.JSONObject jsonObject1 = new org.json.JSONObject(); + metamap.put(JsonConstant.CREATIONDATE,"2023-10-17T03:01:09.893"); metamap.put("creationDate","2023-10-17T03:01:09.893Z"); jsonObject1.put("preRegistrationId", "12345"); jsonArray.put(0, jsonObject1); metamap.put(JsonConstant.METADATA, jsonArray.toString()); - Mockito.when(packetManagerService.getMetaInfo(anyString(), any(), any())).thenReturn(metamap); - + Mockito.when(packetManagerService.getMetaInfo(any(), any(), any())).thenReturn(metamap); Mockito.when(objectMapper.readValue(anyString(), any(Class.class))).thenReturn(new FieldValue("preRegistrationId", "12345")); - - } - + @Test - public void PacketValidationSuccessTest() { + public void PacketValidationSuccessTest() throws PacketManagerException, ApisResourceAccessException, IOException, JsonProcessingException { + Map metainfo1 = new HashMap<>(); + metainfo1.put(JsonConstant.CREATIONDATE,"2023-10-17T03:01:09.893"); MessageDTO object = packetValidateProcessor.process(messageDTO, stageName); - assertTrue(object.getIsValid()); - assertFalse(object.getInternalError()); + ArgumentCaptor argument = ArgumentCaptor + .forClass(InternalRegistrationStatusDto.class); + Mockito.verify(registrationStatusService,Mockito.atLeastOnce()).updateRegistrationStatus(argument.capture(), Mockito.any(), + Mockito.any()); + Assert.assertEquals(LocalDateTime.parse(metainfo1.get(JsonConstant.CREATIONDATE)), argument.getAllValues().get(0).getPacketCreateDateTime()); + Assert.assertTrue(object.getIsValid()); + Assert.assertFalse(object.getInternalError()); } - + @Test - public void PacketValidationFailureTest() throws PacketValidatorException, ApisResourceAccessException, JsonProcessingException, RegistrationProcessorCheckedException, IOException, PacketManagerException { - registrationStatusDto.setRetryCount(1); - Mockito.when(packetValidator.validate(any(), any(),any())).thenReturn(false); + public void PacketValidationSuccessTestwithPacketCreatedDateTimeNull() throws PacketManagerException, ApisResourceAccessException, IOException, JsonProcessingException { + Map metainfo = new HashMap<>(); + metainfo.put(JsonConstant.CREATIONDATE,null); + Mockito.when(packetManagerService.getMetaInfo(any(), any(), any())).thenReturn(metainfo); MessageDTO object = packetValidateProcessor.process(messageDTO, stageName); - assertFalse(object.getIsValid()); + ArgumentCaptor argument = ArgumentCaptor + .forClass(InternalRegistrationStatusDto.class); + Mockito.verify(registrationStatusService,Mockito.atLeastOnce()).updateRegistrationStatus(argument.capture(), Mockito.any(), + Mockito.any()); + assertEquals(metainfo.get(JsonConstant.CREATIONDATE), argument.getAllValues().get(0).getPacketCreateDateTime()); + assertTrue(object.getIsValid()); assertFalse(object.getInternalError()); } - + @Test - public void invalidSupervisorStatusTest() throws PacketValidatorException { - registrationStatusDto.setRetryCount(1); - regEntity=new SyncRegistrationEntity(); - regEntity.setSupervisorStatus("REJECTED"); - Mockito.when(syncRegistrationService.findByWorkflowInstanceId(any())).thenReturn(regEntity); + public void PacketValidationSuccessTestwithPacketCreatedDateTimeInvalidFormat() throws PacketManagerException, ApisResourceAccessException, IOException, JsonProcessingException { + Map metainfo = new HashMap<>(); + metainfo.put(JsonConstant.CREATIONDATE,"2023-10-1703:01:09.893"); + Mockito.when(packetManagerService.getMetaInfo(any(), any(), any())).thenReturn(metainfo); MessageDTO object = packetValidateProcessor.process(messageDTO, stageName); - assertFalse(object.getIsValid()); - assertFalse(object.getInternalError()); + ArgumentCaptor argument = ArgumentCaptor + .forClass(InternalRegistrationStatusDto.class); + Mockito.verify(registrationStatusService,Mockito.atLeastOnce()).updateRegistrationStatus(argument.capture(),any(),any()); + assertEquals(null, argument.getAllValues().get(0).getPacketCreateDateTime()); } @Test diff --git a/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/exception/util/PlatformErrorMessages.java b/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/exception/util/PlatformErrorMessages.java index 1dadfa1741f..7acdd09892d 100644 --- a/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/exception/util/PlatformErrorMessages.java +++ b/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/exception/util/PlatformErrorMessages.java @@ -411,6 +411,16 @@ public enum PlatformErrorMessages { RPR_PVM_PACKET_REJECTED(PlatformConstants.RPR_PACKET_VALIDATOR_MODULE + "011", "Rejected by Supervisor"), + RPR_PVM_PACKET_CREATED_DATE_TIME_EMPTY_OR_NULL(PlatformConstants.RPR_PACKET_VALIDATOR_MODULE + "017", + "Packet Created Date time is Null or Empty"), + + RPR_PVM_PACKET_CREATED_DATE_TIME_PARSE_EXCEPTION(PlatformConstants.RPR_PACKET_VALIDATOR_MODULE + "018", + "Packet Created Date time is not in correct format"), + + RPR_PVM_INVALID_ARGUMENT_EXCEPTION(PlatformConstants.RPR_PACKET_VALIDATOR_MODULE + "019", + "Invalid Argument"), + + /** The packet classification failed. */ PACKET_CLASSIFICATION_FAILED(PlatformConstants.RPR_PACKET_CLASSIFIER_MODULE + "000", "Packet Classification failed"), From 6602518467fc7e150baa857ba002d7cedeca12d9 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Mon, 6 Nov 2023 21:13:55 +0530 Subject: [PATCH 3/3] [Mosip-27859] [ MOSIP-29896 ] Adding pkt_cr_dtimes and setting the packet date and time from metadata of the packet Signed-off-by: khuddus shariff --- .../PacketValidateProcessorTest.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/registration-processor/pre-processor/registration-processor-packet-validator-stage/src/test/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessorTest.java b/registration-processor/pre-processor/registration-processor-packet-validator-stage/src/test/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessorTest.java index db224f2da8d..264e8799ab6 100644 --- a/registration-processor/pre-processor/registration-processor-packet-validator-stage/src/test/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessorTest.java +++ b/registration-processor/pre-processor/registration-processor-packet-validator-stage/src/test/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessorTest.java @@ -298,7 +298,15 @@ public void PacketValidationSuccessTestwithPacketCreatedDateTimeInvalidFormat() Mockito.verify(registrationStatusService,Mockito.atLeastOnce()).updateRegistrationStatus(argument.capture(),any(),any()); assertEquals(null, argument.getAllValues().get(0).getPacketCreateDateTime()); } - + + @Test + public void PacketValidationFailureTest() throws PacketValidatorException, ApisResourceAccessException, JsonProcessingException, RegistrationProcessorCheckedException, IOException, PacketManagerException { + registrationStatusDto.setRetryCount(1); + Mockito.when(packetValidator.validate(any(), any(),any())).thenReturn(false); + MessageDTO object = packetValidateProcessor.process(messageDTO, stageName); + assertFalse(object.getIsValid()); + assertFalse(object.getInternalError()); + } @Test public void PacketValidationPacketManagerFailedTest() throws ApisResourceAccessException, PacketManagerException, JsonProcessingException, IOException { @@ -310,7 +318,17 @@ public void PacketValidationPacketManagerFailedTest() assertTrue(object.getIsValid()); assertTrue(object.getInternalError()); } - + + @Test + public void invalidSupervisorStatusTest() throws PacketValidatorException { + registrationStatusDto.setRetryCount(1); + regEntity=new SyncRegistrationEntity(); + regEntity.setSupervisorStatus("REJECTED"); + Mockito.when(syncRegistrationService.findByWorkflowInstanceId(any())).thenReturn(regEntity); + MessageDTO object = packetValidateProcessor.process(messageDTO, stageName); + assertFalse(object.getIsValid()); + assertFalse(object.getInternalError()); + } @Test public void PacketValidationParsingFailedTest() throws ApisResourceAccessException, PacketManagerException, JsonProcessingException, IOException {