Skip to content

Commit

Permalink
Merge pull request #686 from jayesh12234/develop
Browse files Browse the repository at this point in the history
MOSIP-38064-Added Nrc id in Id Json and resident data
  • Loading branch information
mohanachandran-s authored Dec 4, 2024
2 parents 71a4811 + 187cd3b commit c8a9989
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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<NrcId> generate(int count) {

List<NrcId> nrcIds = new ArrayList<NrcId>();
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -961,7 +968,10 @@ String generateIDJson(ResidentModel resident, HashMap<String, String[]> 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 = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -314,6 +315,7 @@ public List<ResidentModel> generate(String contextKey) {
}

List<Contact> contacts = ContactProvider.generate(eng_names, count);
List<NrcId> nrcIds = NrcIdProvider.generate( count);
ApplicationConfigIdSchema locations = LocationProvider.generate(primary_lang, count,contextKey);
ApplicationConfigIdSchema locations_secLang = null;
if(sec_lang != null)
Expand Down Expand Up @@ -365,6 +367,7 @@ public List<ResidentModel> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());

Expand Down

0 comments on commit c8a9989

Please sign in to comment.