From 187cd3b3056b75dc27e854fa2123e630c25f762a Mon Sep 17 00:00:00 2001 From: Jayesh Kharode Date: Wed, 4 Dec 2024 18:09:57 +0530 Subject: [PATCH] MOSIP-38064 Signed-off-by: Jayesh Kharode --- .../service/PacketMakerService.java | 8 +--- .../service/PacketSyncService.java | 2 +- .../dslrig/dataprovider/NrcIdProvider.java | 43 +++++++++++++++++++ .../dataprovider/PacketTemplateProvider.java | 12 +++++- .../dataprovider/ResidentDataProvider.java | 3 ++ .../dslrig/dataprovider/models/NrcId.java | 18 ++++++++ .../dataprovider/models/ResidentModel.java | 2 + 7 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 mosipTestDataProvider/src/io/mosip/testrig/dslrig/dataprovider/NrcIdProvider.java create mode 100644 mosipTestDataProvider/src/io/mosip/testrig/dslrig/dataprovider/models/NrcId.java diff --git a/mosip-packet-creator/src/main/java/io/mosip/testrig/dslrig/packetcreator/service/PacketMakerService.java b/mosip-packet-creator/src/main/java/io/mosip/testrig/dslrig/packetcreator/service/PacketMakerService.java index f407d098..46e81e9f 100644 --- a/mosip-packet-creator/src/main/java/io/mosip/testrig/dslrig/packetcreator/service/PacketMakerService.java +++ b/mosip-packet-creator/src/main/java/io/mosip/testrig/dslrig/packetcreator/service/PacketMakerService.java @@ -531,19 +531,15 @@ boolean createPacket(String containerRootFolder, String regId, String dataFilePa if (dataFilePath != null) dataToMerge = Files.readString(Path.of(dataFilePath)); JSONObject jb=null; - try { jb = new JSONObject(dataToMerge).getJSONObject(IDENTITY); - }catch(Exception e){ - jb = new JSONObject(dataToMerge); - } // workaround for MOSIP-18123 JSONObject jb1 = new JSONObject(dataToMerge); List jsonList = jb.keySet().stream().filter(j -> j.startsWith("proof")).collect(Collectors.toList()); jsonList.forEach(o -> { - jb1.getJSONObject(IDENTITY).getJSONObject(o).put(VALUE, o); + jb1.getJSONObject(IDENTITY).getJSONObject(o).put(VALUE, o); - jb1.getJSONObject(IDENTITY).getJSONObject(o).remove("refNumber"); + jb1.getJSONObject(IDENTITY).getJSONObject(o).remove("refNumber"); }); dataToMerge = jb1.toString(); diff --git a/mosip-packet-creator/src/main/java/io/mosip/testrig/dslrig/packetcreator/service/PacketSyncService.java b/mosip-packet-creator/src/main/java/io/mosip/testrig/dslrig/packetcreator/service/PacketSyncService.java index 98c140a2..4251a5a5 100644 --- a/mosip-packet-creator/src/main/java/io/mosip/testrig/dslrig/packetcreator/service/PacketSyncService.java +++ b/mosip-packet-creator/src/main/java/io/mosip/testrig/dslrig/packetcreator/service/PacketSyncService.java @@ -1316,7 +1316,7 @@ public String getPacketTags(String contextKey) { packetTags.put("Biometric_Quality-Iris", VariableManager.getVariableValue(contextKey, "Biometric_Quality-Iris") == null - ? "--TAG_VALUE_NOT_AVAILABLE--" + ? "--Biometrics-Not-Available--" : VariableManager.getVariableValue(contextKey, "Biometric_Quality-Iris").toString()); packetTags.put("INTRODUCER_AVAILABILITY", diff --git a/mosipTestDataProvider/src/io/mosip/testrig/dslrig/dataprovider/NrcIdProvider.java b/mosipTestDataProvider/src/io/mosip/testrig/dslrig/dataprovider/NrcIdProvider.java new file mode 100644 index 00000000..6a65e9a2 --- /dev/null +++ b/mosipTestDataProvider/src/io/mosip/testrig/dslrig/dataprovider/NrcIdProvider.java @@ -0,0 +1,43 @@ +package io.mosip.testrig.dslrig.dataprovider; + +import java.security.SecureRandom; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import io.mosip.testrig.dslrig.dataprovider.models.NrcId; + +public class NrcIdProvider { + private static SecureRandom rand = new SecureRandom (); + + + static int MAX_NUM = 9999; + + public static List generate(int count) { + + List nrcIds = new ArrayList(); + for(int i=0; i < count; i++) { + + NrcId nrcId = new NrcId(); + nrcId.setNrcId(generateNrcId(rand)); + nrcIds.add(nrcId); + } + return nrcIds; + } + + static String generateNrcId(Random rand) { + return generateSixDigitNumber(rand) + "/" + generateTwoDigitNumber(rand) + "/" + generateOneDigitNumber(rand); + } + + private static String generateSixDigitNumber(Random rand) { + return String.format("%06d", rand.nextInt(1000000)); + } + + private static String generateTwoDigitNumber(Random rand) { + return String.format("%02d", rand.nextInt(100)); + } + + private static String generateOneDigitNumber(Random rand) { + return String.valueOf(rand.nextInt(10)); + } +} diff --git a/mosipTestDataProvider/src/io/mosip/testrig/dslrig/dataprovider/PacketTemplateProvider.java b/mosipTestDataProvider/src/io/mosip/testrig/dslrig/dataprovider/PacketTemplateProvider.java index 04c8b075..e8f3b2a4 100644 --- a/mosipTestDataProvider/src/io/mosip/testrig/dslrig/dataprovider/PacketTemplateProvider.java +++ b/mosipTestDataProvider/src/io/mosip/testrig/dslrig/dataprovider/PacketTemplateProvider.java @@ -177,6 +177,7 @@ public String generate(String source, String process, ResidentModel resident, St } JSONObject processMVEL = processMVEL(resident, idJson, process, contextSchemaDetail, contextKey); idJson = processMVEL.toString(); + CommonUtil.write(Paths.get(ridFolder + ID_JSON), idJson.getBytes()); String metadataJson = generateMetaDataJson(resident, preregId, machineId, centerId, fileInfo, contextKey, contextSchemaDetail); @@ -239,6 +240,12 @@ private JSONObject processMVEL(ResidentModel resident, String idJson, String pro } } } + //if the json is not under the identity element put inside identity + if(!json.has("identity")) { + JSONObject identityWrapper = new JSONObject(); + identityWrapper.put("identity", json.toMap()); + json = identityWrapper; // Reassign the updated JSON + } return json; } @@ -961,7 +968,10 @@ String generateIDJson(ResidentModel resident, HashMap fileInfo } if (processDynamicFields(s, identity, resident, contextKey)) continue; - + if (s.getFieldCategory().equals("evidence") && s.getId().equals("nrcId") ) { + identity.put(s.getId(),resident.getNrcId().getNrcId()); + continue; + } if (s.getFieldCategory().equals("pvt") || s.getFieldCategory().equals("kyc")) { String primaryValue = ""; String secValue = ""; diff --git a/mosipTestDataProvider/src/io/mosip/testrig/dslrig/dataprovider/ResidentDataProvider.java b/mosipTestDataProvider/src/io/mosip/testrig/dslrig/dataprovider/ResidentDataProvider.java index 5dccf331..b111580d 100644 --- a/mosipTestDataProvider/src/io/mosip/testrig/dslrig/dataprovider/ResidentDataProvider.java +++ b/mosipTestDataProvider/src/io/mosip/testrig/dslrig/dataprovider/ResidentDataProvider.java @@ -28,6 +28,7 @@ import io.mosip.testrig.dslrig.dataprovider.models.MosipLanguage; import io.mosip.testrig.dslrig.dataprovider.models.MosipPreRegLoginConfig; import io.mosip.testrig.dslrig.dataprovider.models.Name; +import io.mosip.testrig.dslrig.dataprovider.models.NrcId; import io.mosip.testrig.dslrig.dataprovider.models.ResidentModel; import io.mosip.testrig.dslrig.dataprovider.preparation.MosipMasterData; import io.mosip.testrig.dslrig.dataprovider.util.CommonUtil; @@ -314,6 +315,7 @@ public List generate(String contextKey) { } List contacts = ContactProvider.generate(eng_names, count); + List nrcIds = NrcIdProvider.generate( count); ApplicationConfigIdSchema locations = LocationProvider.generate(primary_lang, count,contextKey); ApplicationConfigIdSchema locations_secLang = null; if(sec_lang != null) @@ -365,6 +367,7 @@ public List generate(String contextKey) { if(bloodGroups != null && !bloodGroups.isEmpty()) res.setBloodgroup(bloodGroups.get(res.getPrimaryLanguage()).get(i)); res.setContact(contacts.get(i)); + res.setNrcId(nrcIds.get(i)); res.setDob( DateOfBirthProvider.generate((ResidentAttribute) attributeList.get(ResidentAttribute.RA_Age),contextKey)); ResidentAttribute age = (ResidentAttribute) attributeList.get(ResidentAttribute.RA_Age); Boolean skipGaurdian = false; diff --git a/mosipTestDataProvider/src/io/mosip/testrig/dslrig/dataprovider/models/NrcId.java b/mosipTestDataProvider/src/io/mosip/testrig/dslrig/dataprovider/models/NrcId.java new file mode 100644 index 00000000..82bd300c --- /dev/null +++ b/mosipTestDataProvider/src/io/mosip/testrig/dslrig/dataprovider/models/NrcId.java @@ -0,0 +1,18 @@ +package io.mosip.testrig.dslrig.dataprovider.models; + +import java.io.Serializable; + +public class NrcId implements Serializable { + + private static final long serialVersionUID = 1L; + + public String getNrcId() { + return nrcId; + } + public void setNrcId(String nrcId) { + this.nrcId = nrcId; + } + + private String nrcId; + +} diff --git a/mosipTestDataProvider/src/io/mosip/testrig/dslrig/dataprovider/models/ResidentModel.java b/mosipTestDataProvider/src/io/mosip/testrig/dslrig/dataprovider/models/ResidentModel.java index 69dc1a34..57b1009c 100644 --- a/mosipTestDataProvider/src/io/mosip/testrig/dslrig/dataprovider/models/ResidentModel.java +++ b/mosipTestDataProvider/src/io/mosip/testrig/dslrig/dataprovider/models/ResidentModel.java @@ -51,6 +51,7 @@ public class ResidentModel implements Serializable { ApplicationConfigIdSchema appConfigIdSchema_secLang; private Contact contact; + private NrcId nrcId; private Name name; private Name name_seclang; private MosipIndividualTypeModel residentStatus; @@ -193,6 +194,7 @@ public JSONObject loadDemoData() { demodata.put("UIN", UIN); demodata.put("RID", RID); demodata.put("emailId", contact.getEmailId()); + demodata.put("nrcId", nrcId.getNrcId()); demodata.put("mobileNumber", contact.getMobileNumber()); demodata.put("residenceNumber", contact.getResidenceNumber());