Skip to content

Commit c3b8646

Browse files
authored
Merge pull request mosip#1825 from Khuddusshariff0022/release-1.2.0.1_Mosip_29895_1
[MOSIP-29895] Release 1.2.0.1 mosip 29895 1
2 parents 210d0bd + 295dc1c commit c3b8646

File tree

6 files changed

+132
-27
lines changed

6 files changed

+132
-27
lines changed

registration-processor/pre-processor/registration-processor-packet-validator-stage/src/main/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessor.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
import java.io.IOException;
55
import java.io.InputStream;
66
import java.nio.charset.StandardCharsets;
7+
import java.time.LocalDateTime;
8+
import java.time.format.DateTimeFormatter;
9+
import java.time.format.DateTimeParseException;
710
import java.util.Arrays;
811
import java.util.Date;
912
import java.util.Map;
1013
import java.util.concurrent.ExecutorService;
1114
import java.util.concurrent.Executors;
1215

16+
import io.mosip.kernel.core.util.DateUtils;
1317
import io.mosip.registration.processor.packet.storage.utils.Utilities;
1418
import org.apache.commons.io.IOUtils;
1519
import org.apache.commons.lang3.exception.ExceptionUtils;
@@ -154,6 +158,8 @@ public class PacketValidateProcessor {
154158
private static final String PRE_REG_ID = "mosip.pre-registration.datasync.store";
155159
private static final String VERSION = "1.0";
156160

161+
162+
157163
@Autowired
158164
RegistrationExceptionMapperUtil registrationStatusMapperUtil;
159165

@@ -166,12 +172,14 @@ public class PacketValidateProcessor {
166172
@Autowired
167173
private NotificationUtility notificationUtility;
168174

175+
@Value("${mosip.registration.processor.datetime.pattern}")
176+
private String dateformat;
177+
169178
public MessageDTO process(MessageDTO object, String stageName) {
170179
TrimExceptionMessage trimMessage = new TrimExceptionMessage();
171180
LogDescription description = new LogDescription();
172181
PacketValidationDto packetValidationDto = new PacketValidationDto();
173182
String registrationId = null;
174-
175183
InternalRegistrationStatusDto registrationStatusDto = new InternalRegistrationStatusDto();
176184
try {
177185
registrationStatusDto
@@ -184,17 +192,17 @@ public MessageDTO process(MessageDTO object, String stageName) {
184192
"", "PacketValidateProcessor::process()::entry");
185193
registrationId = object.getRid();
186194
packetValidationDto.setTransactionSuccessful(false);
187-
188195
registrationStatusDto = registrationStatusService.getRegistrationStatus(
189196
registrationId, object.getReg_type(), object.getIteration(), object.getWorkflowInstanceId());
190-
197+
setPacketCreatedDateTime(registrationStatusDto);
191198
registrationStatusDto
192199
.setLatestTransactionTypeCode(RegistrationTransactionTypeCode.VALIDATE_PACKET.toString());
193200
registrationStatusDto.setRegistrationStageName(stageName);
194201
boolean isValidSupervisorStatus = isValidSupervisorStatus(object);
195202
if (isValidSupervisorStatus) {
196203
Boolean isValid = compositePacketValidator.validate(object.getRid(),
197204
registrationStatusDto.getRegistrationType(), packetValidationDto);
205+
198206
if (isValid) {
199207
// save audit details
200208
InternalRegistrationStatusDto finalRegistrationStatusDto = registrationStatusDto;
@@ -447,6 +455,33 @@ public MessageDTO process(MessageDTO object, String stageName) {
447455

448456
}
449457

458+
459+
private void setPacketCreatedDateTime(InternalRegistrationStatusDto registrationStatusDto) throws ApisResourceAccessException, PacketManagerException, JsonProcessingException, IOException {
460+
try {
461+
Map<String, String> metaInfo = packetManagerService.getMetaInfo(
462+
registrationStatusDto.getRegistrationId(), registrationStatusDto.getRegistrationType(), ProviderStageName.PACKET_VALIDATOR);
463+
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateformat);
464+
String packetCreatedDateTime = metaInfo.get(JsonConstant.CREATIONDATE);
465+
if (packetCreatedDateTime != null && !packetCreatedDateTime.isEmpty()) {
466+
LocalDateTime dateTime = DateUtils.parseToLocalDateTime(packetCreatedDateTime);
467+
registrationStatusDto.setPacketCreateDateTime(dateTime);
468+
} else {
469+
regProcLogger.warn(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(),
470+
" -- " + registrationStatusDto.getRefId(),
471+
PlatformErrorMessages.RPR_PVM_PACKET_CREATED_DATE_TIME_EMPTY_OR_NULL.getMessage());
472+
}
473+
} catch (DateTimeParseException e) {
474+
regProcLogger.warn(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(),
475+
" -- " + registrationStatusDto.getRefId(),
476+
PlatformErrorMessages.RPR_PVM_PACKET_CREATED_DATE_TIME_PARSE_EXCEPTION.getMessage() + e.getMessage());
477+
}catch (IllegalArgumentException ex)
478+
{
479+
regProcLogger.warn(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(),
480+
" -- " + registrationStatusDto.getRefId(),
481+
PlatformErrorMessages.RPR_PVM_INVALID_ARGUMENT_EXCEPTION.getMessage() + ex.getMessage());
482+
}
483+
}
484+
450485
private boolean isValidSupervisorStatus(MessageDTO messageDTO) {
451486
SyncRegistrationEntity regEntity = syncRegistrationService.findByWorkflowInstanceId(messageDTO.getWorkflowInstanceId());
452487
if (regEntity.getSupervisorStatus().equalsIgnoreCase(APPROVED)) {

registration-processor/pre-processor/registration-processor-packet-validator-stage/src/test/java/io/mosip/registration/processor/stages/packet/validator/PacketValidateProcessorTest.java

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@
4242
import io.mosip.registration.processor.status.service.SyncRegistrationService;
4343
import org.apache.commons.io.IOUtils;
4444
import org.json.JSONException;
45+
import org.junit.Assert;
4546
import org.junit.Before;
4647
import org.junit.Test;
4748
import org.junit.runner.RunWith;
48-
import org.mockito.InjectMocks;
49-
import org.mockito.Matchers;
50-
import org.mockito.Mock;
51-
import org.mockito.Mockito;
49+
import org.mockito.*;
5250
import org.powermock.api.mockito.PowerMockito;
5351
import org.powermock.core.classloader.annotations.PowerMockIgnore;
5452
import org.powermock.core.classloader.annotations.PrepareForTest;
@@ -64,17 +62,19 @@
6462
import java.io.IOException;
6563
import java.io.InputStream;
6664
import java.security.MessageDigest;
65+
import java.time.LocalDateTime;
66+
import java.time.format.DateTimeFormatter;
6767
import java.util.ArrayList;
6868
import java.util.Arrays;
6969
import java.util.HashMap;
7070
import java.util.List;
7171
import java.util.Map;
7272

73-
import static org.junit.Assert.assertFalse;
74-
import static org.junit.Assert.assertTrue;
73+
7574
import static org.mockito.ArgumentMatchers.any;
7675
import static org.mockito.Matchers.anyString;
7776
import static org.mockito.Matchers.anyBoolean;
77+
import static org.junit.Assert.*;
7878

7979

8080
/**
@@ -127,6 +127,9 @@ public class PacketValidateProcessorTest {
127127

128128
@Mock
129129
private NotificationUtility notificationUtility;
130+
131+
@Mock
132+
DateTimeFormatter dateTimeFormatter;
130133

131134
private MessageDTO messageDTO;
132135
private String stageName;
@@ -136,6 +139,7 @@ public class PacketValidateProcessorTest {
136139
@Before
137140
public void setup() throws Exception {
138141
ReflectionTestUtils.setField(packetValidateProcessor, "notificationTypes", "SMS|EMAIL");
142+
ReflectionTestUtils.setField(packetValidateProcessor, "dateformat", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
139143
messageDTO=new MessageDTO();
140144
messageDTO.setRid("123456789");
141145
messageDTO.setInternalError(false);
@@ -245,43 +249,64 @@ public void setup() throws Exception {
245249
Map<String, String> metamap = new HashMap<>();
246250
org.json.JSONArray jsonArray = new org.json.JSONArray();
247251
org.json.JSONObject jsonObject1 = new org.json.JSONObject();
252+
metamap.put(JsonConstant.CREATIONDATE,"2023-10-17T03:01:09.893");
253+
metamap.put("creationDate","2023-10-17T03:01:09.893Z");
248254
jsonObject1.put("preRegistrationId", "12345");
249255
jsonArray.put(0, jsonObject1);
250256
metamap.put(JsonConstant.METADATA, jsonArray.toString());
251-
Mockito.when(packetManagerService.getMetaInfo(anyString(), any(), any())).thenReturn(metamap);
252-
257+
Mockito.when(packetManagerService.getMetaInfo(any(), any(), any())).thenReturn(metamap);
253258
Mockito.when(objectMapper.readValue(anyString(), any(Class.class))).thenReturn(new FieldValue("preRegistrationId", "12345"));
259+
}
254260

255-
261+
@Test
262+
public void PacketValidationSuccessTest() throws PacketManagerException, ApisResourceAccessException, IOException, JsonProcessingException {
263+
Map<String, String> metainfo1 = new HashMap<>();
264+
metainfo1.put(JsonConstant.CREATIONDATE,"2023-10-17T03:01:09.893");
265+
MessageDTO object = packetValidateProcessor.process(messageDTO, stageName);
266+
ArgumentCaptor<InternalRegistrationStatusDto> argument = ArgumentCaptor
267+
.forClass(InternalRegistrationStatusDto.class);
268+
Mockito.verify(registrationStatusService,Mockito.atLeastOnce()).updateRegistrationStatus(argument.capture(), Mockito.any(),
269+
Mockito.any());
270+
Assert.assertEquals(LocalDateTime.parse(metainfo1.get(JsonConstant.CREATIONDATE)), argument.getAllValues().get(0).getPacketCreateDateTime());
271+
Assert.assertTrue(object.getIsValid());
272+
Assert.assertFalse(object.getInternalError());
256273
}
257-
274+
258275
@Test
259-
public void PacketValidationSuccessTest() {
276+
public void PacketValidationSuccessTestwithPacketCreatedDateTimeNull() throws PacketManagerException, ApisResourceAccessException, IOException, JsonProcessingException {
277+
Map<String, String> metainfo = new HashMap<>();
278+
metainfo.put(JsonConstant.CREATIONDATE,null);
279+
Mockito.when(packetManagerService.getMetaInfo(any(), any(), any())).thenReturn(metainfo);
260280
MessageDTO object = packetValidateProcessor.process(messageDTO, stageName);
281+
ArgumentCaptor<InternalRegistrationStatusDto> argument = ArgumentCaptor
282+
.forClass(InternalRegistrationStatusDto.class);
283+
Mockito.verify(registrationStatusService,Mockito.atLeastOnce()).updateRegistrationStatus(argument.capture(), Mockito.any(),
284+
Mockito.any());
285+
assertEquals(metainfo.get(JsonConstant.CREATIONDATE), argument.getAllValues().get(0).getPacketCreateDateTime());
261286
assertTrue(object.getIsValid());
262287
assertFalse(object.getInternalError());
263288
}
264-
289+
265290
@Test
266-
public void PacketValidationFailureTest() throws PacketValidatorException, ApisResourceAccessException, JsonProcessingException, RegistrationProcessorCheckedException, IOException, PacketManagerException {
267-
registrationStatusDto.setRetryCount(1);
268-
Mockito.when(packetValidator.validate(any(), any(),any())).thenReturn(false);
291+
public void PacketValidationSuccessTestwithPacketCreatedDateTimeInvalidFormat() throws PacketManagerException, ApisResourceAccessException, IOException, JsonProcessingException {
292+
Map<String, String> metainfo = new HashMap<>();
293+
metainfo.put(JsonConstant.CREATIONDATE,"2023-10-1703:01:09.893");
294+
Mockito.when(packetManagerService.getMetaInfo(any(), any(), any())).thenReturn(metainfo);
269295
MessageDTO object = packetValidateProcessor.process(messageDTO, stageName);
270-
assertFalse(object.getIsValid());
271-
assertFalse(object.getInternalError());
296+
ArgumentCaptor<InternalRegistrationStatusDto> argument = ArgumentCaptor
297+
.forClass(InternalRegistrationStatusDto.class);
298+
Mockito.verify(registrationStatusService,Mockito.atLeastOnce()).updateRegistrationStatus(argument.capture(),any(),any());
299+
assertEquals(null, argument.getAllValues().get(0).getPacketCreateDateTime());
272300
}
273-
301+
274302
@Test
275-
public void invalidSupervisorStatusTest() throws PacketValidatorException {
303+
public void PacketValidationFailureTest() throws PacketValidatorException, ApisResourceAccessException, JsonProcessingException, RegistrationProcessorCheckedException, IOException, PacketManagerException {
276304
registrationStatusDto.setRetryCount(1);
277-
regEntity=new SyncRegistrationEntity();
278-
regEntity.setSupervisorStatus("REJECTED");
279-
Mockito.when(syncRegistrationService.findByWorkflowInstanceId(any())).thenReturn(regEntity);
305+
Mockito.when(packetValidator.validate(any(), any(),any())).thenReturn(false);
280306
MessageDTO object = packetValidateProcessor.process(messageDTO, stageName);
281307
assertFalse(object.getIsValid());
282308
assertFalse(object.getInternalError());
283309
}
284-
285310
@Test
286311
public void PacketValidationPacketManagerFailedTest()
287312
throws ApisResourceAccessException, PacketManagerException, JsonProcessingException, IOException {
@@ -293,7 +318,17 @@ public void PacketValidationPacketManagerFailedTest()
293318
assertTrue(object.getIsValid());
294319
assertTrue(object.getInternalError());
295320
}
296-
321+
322+
@Test
323+
public void invalidSupervisorStatusTest() throws PacketValidatorException {
324+
registrationStatusDto.setRetryCount(1);
325+
regEntity=new SyncRegistrationEntity();
326+
regEntity.setSupervisorStatus("REJECTED");
327+
Mockito.when(syncRegistrationService.findByWorkflowInstanceId(any())).thenReturn(regEntity);
328+
MessageDTO object = packetValidateProcessor.process(messageDTO, stageName);
329+
assertFalse(object.getIsValid());
330+
assertFalse(object.getInternalError());
331+
}
297332
@Test
298333
public void PacketValidationParsingFailedTest()
299334
throws ApisResourceAccessException, PacketManagerException, JsonProcessingException, IOException {

registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/exception/util/PlatformErrorMessages.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,16 @@ public enum PlatformErrorMessages {
411411
RPR_PVM_PACKET_REJECTED(PlatformConstants.RPR_PACKET_VALIDATOR_MODULE + "011",
412412
"Rejected by Supervisor"),
413413

414+
RPR_PVM_PACKET_CREATED_DATE_TIME_EMPTY_OR_NULL(PlatformConstants.RPR_PACKET_VALIDATOR_MODULE + "017",
415+
"Packet Created Date time is Null or Empty"),
416+
417+
RPR_PVM_PACKET_CREATED_DATE_TIME_PARSE_EXCEPTION(PlatformConstants.RPR_PACKET_VALIDATOR_MODULE + "018",
418+
"Packet Created Date time is not in correct format"),
419+
420+
RPR_PVM_INVALID_ARGUMENT_EXCEPTION(PlatformConstants.RPR_PACKET_VALIDATOR_MODULE + "019",
421+
"Invalid Argument"),
422+
423+
414424
/** The packet classification failed. */
415425
PACKET_CLASSIFICATION_FAILED(PlatformConstants.RPR_PACKET_CLASSIFIER_MODULE + "000", "Packet Classification failed"),
416426

registration-processor/registration-processor-registration-status-service-impl/src/main/java/io/mosip/registration/processor/status/dto/InternalRegistrationStatusDto.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ public class InternalRegistrationStatusDto implements Serializable {
4848
/** The update date time. */
4949
private LocalDateTime updateDateTime;
5050

51+
/** Packet Created Date and Time**/
52+
private LocalDateTime packetCreateDateTime;
53+
54+
public LocalDateTime getPacketCreateDateTime() {
55+
return packetCreateDateTime;
56+
}
57+
58+
public void setPacketCreateDateTime(LocalDateTime packetCreateDateTime) {
59+
this.packetCreateDateTime = packetCreateDateTime;
60+
}
61+
5162
/** The is deleted. */
5263
private Boolean isDeleted;
5364

registration-processor/registration-processor-registration-status-service-impl/src/main/java/io/mosip/registration/processor/status/entity/RegistrationStatusEntity.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ public class RegistrationStatusEntity extends BaseRegistrationEntity<BaseRegistr
6767

6868
private LocalDateTime createDateTime;
6969

70+
public LocalDateTime getPacketCreatedDateTime() {
71+
return packetCreatedDateTime;
72+
}
73+
74+
public void setPacketCreatedDateTime(LocalDateTime packetCreatedDateTime) {
75+
this.packetCreatedDateTime = packetCreatedDateTime;
76+
}
77+
78+
/** packet created date and time */
79+
@Column(name = "pkt_cr_dtimes")
80+
private LocalDateTime packetCreatedDateTime;
81+
7082
/** The updated by. */
7183
@Column(name = "upd_by")
7284
private String updatedBy;

registration-processor/registration-processor-registration-status-service-impl/src/main/java/io/mosip/registration/processor/status/service/impl/RegistrationStatusServiceImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ private InternalRegistrationStatusDto convertEntityToDto(RegistrationStatusEntit
641641
registrationStatusDto.setSource(entity.getSource());
642642
registrationStatusDto.setIteration(entity.getIteration());
643643
registrationStatusDto.setWorkflowInstanceId(entity.getId().getWorkflowInstanceId());
644+
registrationStatusDto.setPacketCreateDateTime(entity.getPacketCreatedDateTime());
644645
return registrationStatusDto;
645646
}
646647

@@ -702,6 +703,7 @@ private RegistrationStatusEntity convertDtoToEntity(InternalRegistrationStatusDt
702703
registrationStatusEntity.setLastSuccessStageName(dto.getRegistrationStageName());
703704
else
704705
registrationStatusEntity.setLastSuccessStageName(existingLastSuccessStageName);
706+
registrationStatusEntity.setPacketCreatedDateTime(dto.getPacketCreateDateTime());
705707
return registrationStatusEntity;
706708
}
707709

0 commit comments

Comments
 (0)