From bbae9bd3fb79db7b1fe80d8b849ffb9b3607937f Mon Sep 17 00:00:00 2001 From: Jayesh Kharode Date: Mon, 25 Nov 2024 21:12:18 +0530 Subject: [PATCH] MOSIP-35914 Signed-off-by: Jayesh Kharode --- .../service/PacketSyncService.java | 224 +++++++++--------- 1 file changed, 107 insertions(+), 117 deletions(-) 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 76169f96..7b15b9b9 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 @@ -97,10 +97,10 @@ public class PacketSyncService { @Autowired private ZipUtils zipUtils; - + private PacketMakerService packetMakerService; private PacketSyncService packetSyncService; - + @Autowired private ContextUtils contextUtils; @@ -142,7 +142,7 @@ public class PacketSyncService { @Value("${mosip.test.idrepo.idvidpath}") private String idvid; - + public PacketSyncService(@Lazy PacketSyncService packetSyncService, @Lazy PacketMakerService packetMakerService) { this.packetSyncService = packetSyncService; this.packetMakerService = packetMakerService; @@ -167,115 +167,105 @@ void loadServerContextProperties(String contextKey) { } public String generateResidentData(int count, PersonaRequestDto residentRequestDto, String contextKey) { - String personaId = VariableManager.getVariableValue(contextKey, "personaId") != null - ? VariableManager.getVariableValue(contextKey, "personaId").toString() - : null; JSONArray outIds = new JSONArray(); - if(personaId!=null && !personaId.isEmpty()) { - JSONObject id = new JSONObject(); - id.put("id",VariableManager.getVariableValue(contextKey, "id").toString()); - id.put("path", personaId); - outIds.put(id); - }else { - logger.info(" Entered Persona generation at time: " + System.currentTimeMillis()); - // TO do --Check why we need to load the context here -// loadServerContextProperties(contextKey); - VariableManager.setVariableValue(contextKey, "process", "NEW"); - Properties props = residentRequestDto.getRequests().get(PersonaRequestType.PR_ResidentAttribute); - Gender enumGender = Gender.Any; - ResidentDataProvider provider = new ResidentDataProvider(); - if (props.containsKey("Gender")) { - enumGender = Gender.valueOf(props.get("Gender").toString()); // Gender.valueOf(residentRequestDto.getGender()); - } - provider.addCondition(ResidentAttribute.RA_Count, count); + logger.info(" Entered Persona generation at time: " + System.currentTimeMillis()); + // TO do --Check why we need to load the context here + // loadServerContextProperties(contextKey); + VariableManager.setVariableValue(contextKey, "process", "NEW"); + Properties props = residentRequestDto.getRequests().get(PersonaRequestType.PR_ResidentAttribute); + Gender enumGender = Gender.Any; + ResidentDataProvider provider = new ResidentDataProvider(); + if (props.containsKey("Gender")) { + enumGender = Gender.valueOf(props.get("Gender").toString()); // Gender.valueOf(residentRequestDto.getGender()); + } + provider.addCondition(ResidentAttribute.RA_Count, count); - if (props.containsKey("Age")) { + if (props.containsKey("Age")) { - provider.addCondition(ResidentAttribute.RA_Age, ResidentAttribute.valueOf(props.get("Age").toString())); - } else - provider.addCondition(ResidentAttribute.RA_Age, ResidentAttribute.RA_Adult); + provider.addCondition(ResidentAttribute.RA_Age, ResidentAttribute.valueOf(props.get("Age").toString())); + } else + provider.addCondition(ResidentAttribute.RA_Age, ResidentAttribute.RA_Adult); - if (props.containsKey("SkipGaurdian")) { - provider.addCondition(ResidentAttribute.RA_SKipGaurdian, props.get("SkipGaurdian")); - } - provider.addCondition(ResidentAttribute.RA_Gender, enumGender); + if (props.containsKey("SkipGaurdian")) { + provider.addCondition(ResidentAttribute.RA_SKipGaurdian, props.get("SkipGaurdian")); + } + provider.addCondition(ResidentAttribute.RA_Gender, enumGender); - String primaryLanguage = "eng"; - if (props.containsKey("PrimaryLanguage")) { - primaryLanguage = props.get("PrimaryLanguage").toString(); - provider.addCondition(ResidentAttribute.RA_PRIMARAY_LANG, primaryLanguage); - } + String primaryLanguage = "eng"; + if (props.containsKey("PrimaryLanguage")) { + primaryLanguage = props.get("PrimaryLanguage").toString(); + provider.addCondition(ResidentAttribute.RA_PRIMARAY_LANG, primaryLanguage); + } - if (props.containsKey("SecondaryLanguage")) { - provider.addCondition(ResidentAttribute.RA_SECONDARY_LANG, props.get("SecondaryLanguage").toString()); - } - if (props.containsKey("Finger")) { - provider.addCondition(ResidentAttribute.RA_Finger, Boolean.parseBoolean(props.get("Finger").toString())); - } - if (props.containsKey("Iris")) { - provider.addCondition(ResidentAttribute.RA_Iris, Boolean.parseBoolean(props.get("Iris").toString())); - } - if (props.containsKey("Face")) { - provider.addCondition(ResidentAttribute.RA_Photo, Boolean.parseBoolean(props.get("Face").toString())); - } - if (props.containsKey("Document")) { - provider.addCondition(ResidentAttribute.RA_Document, - Boolean.parseBoolean(props.get("Document").toString())); - } - if (props.containsKey("Invalid")) { - List invalidList = Arrays.asList(props.get("invalid").toString().split(",", -1)); - provider.addCondition(ResidentAttribute.RA_InvalidList, invalidList); - } - if (props.containsKey("Miss")) { + if (props.containsKey("SecondaryLanguage")) { + provider.addCondition(ResidentAttribute.RA_SECONDARY_LANG, props.get("SecondaryLanguage").toString()); + } + if (props.containsKey("Finger")) { + provider.addCondition(ResidentAttribute.RA_Finger, Boolean.parseBoolean(props.get("Finger").toString())); + } + if (props.containsKey("Iris")) { + provider.addCondition(ResidentAttribute.RA_Iris, Boolean.parseBoolean(props.get("Iris").toString())); + } + if (props.containsKey("Face")) { + provider.addCondition(ResidentAttribute.RA_Photo, Boolean.parseBoolean(props.get("Face").toString())); + } + if (props.containsKey("Document")) { + provider.addCondition(ResidentAttribute.RA_Document, + Boolean.parseBoolean(props.get("Document").toString())); + } + if (props.containsKey("Invalid")) { + List invalidList = Arrays.asList(props.get("invalid").toString().split(",", -1)); + provider.addCondition(ResidentAttribute.RA_InvalidList, invalidList); + } + if (props.containsKey("Miss")) { - List missedList = Arrays.asList(props.get("Miss").toString().split(",", -1)); - provider.addCondition(ResidentAttribute.RA_MissList, missedList); - RestClient.logInfo(contextKey, "before Genrate: missthese:" + missedList.toString()); - } - if (props.containsKey("ThirdLanguage")) { + List missedList = Arrays.asList(props.get("Miss").toString().split(",", -1)); + provider.addCondition(ResidentAttribute.RA_MissList, missedList); + RestClient.logInfo(contextKey, "before Genrate: missthese:" + missedList.toString()); + } + if (props.containsKey("ThirdLanguage")) { - provider.addCondition(ResidentAttribute.RA_THIRD_LANG, props.get("ThirdLanguage").toString()); - } - if (props.containsKey("SchemaVersion")) { + provider.addCondition(ResidentAttribute.RA_THIRD_LANG, props.get("ThirdLanguage").toString()); + } + if (props.containsKey("SchemaVersion")) { - provider.addCondition(ResidentAttribute.RA_SCHEMA_VERSION, props.get("SchemaVersion").toString()); - } + provider.addCondition(ResidentAttribute.RA_SCHEMA_VERSION, props.get("SchemaVersion").toString()); + } - RestClient.logInfo(contextKey, "before Genrate"); - List lst = provider.generate(contextKey); - RestClient.logInfo(contextKey, "After Genrate"); + RestClient.logInfo(contextKey, "before Genrate"); + List lst = provider.generate(contextKey); + RestClient.logInfo(contextKey, "After Genrate"); - try { - String tmpDir; + try { + String tmpDir; - tmpDir = Files.createTempDirectory("residents_").toFile().getAbsolutePath(); + tmpDir = Files.createTempDirectory("residents_").toFile().getAbsolutePath(); - VariableManager.setVariableValue(contextKey, "residents_", tmpDir); + VariableManager.setVariableValue(contextKey, "residents_", tmpDir); - for (ResidentModel r : lst) { - Path tempPath = Path.of(tmpDir, r.getId() + ".json"); - r.setPath(tempPath.toString()); + for (ResidentModel r : lst) { + Path tempPath = Path.of(tmpDir, r.getId() + ".json"); + r.setPath(tempPath.toString()); - String jsonStr = r.toJSONString(); - - - String personaAbsPath = tempPath.toFile().getAbsolutePath(); - VariableManager.setVariableValue(contextKey, "id", r.getId()); - VariableManager.setVariableValue(contextKey, "personaId", personaAbsPath); - VariableManager.setVariableValue(contextKey, personaAbsPath, jsonStr); + String jsonStr = r.toJSONString(); - // Write to a file only when debug enabled -// To Do --------- CommonUtil.write(tempPath, jsonStr.getBytes()); - JSONObject id = new JSONObject(); - id.put("id", r.getId()); - id.put("path", tempPath.toFile().getAbsolutePath()); - outIds.put(id); - } - } catch (IOException e) { - logger.error(e.getMessage()); - return "{\"" + e.getMessage() + "\"}"; + String personaAbsPath = tempPath.toFile().getAbsolutePath(); + VariableManager.setVariableValue(contextKey, "id", r.getId()); + VariableManager.setVariableValue(contextKey, "personaId", personaAbsPath); + VariableManager.setVariableValue(contextKey, personaAbsPath, jsonStr); + + // Write to a file only when debug enabled + // To Do --------- CommonUtil.write(tempPath, jsonStr.getBytes()); + + JSONObject id = new JSONObject(); + id.put("id", r.getId()); + id.put("path", tempPath.toFile().getAbsolutePath()); + outIds.put(id); } + } catch (IOException e) { + logger.error(e.getMessage()); + return "{\"" + e.getMessage() + "\"}"; } JSONObject response = new JSONObject(); response.put(STATUS, SUCCESS); @@ -452,7 +442,7 @@ else if (entrySet.getKey().equals(MOSIP_TEST_REGCLIENT_MACHINEID)) private RidSyncRequestData prepareRidSyncRequest(String containerFile, String name, String supervisorStatus, String supervisorComment, String proc, String contextKey, String additionalInfoReqId) - throws Exception, Exception { + throws Exception, Exception { if (contextKey != null && !contextKey.equals("")) { Properties props = contextUtils.loadServerContext(contextKey); @@ -700,9 +690,9 @@ public String verifyOtp(String personaFilePath, String to, String otp, String co ResidentModel resident = ResidentModel.readPersona(personaFilePath, contextKey); ResidentPreRegistration preReg = new ResidentPreRegistration(resident); - if(otp != null && otp.isEmpty()) { - preReg.fetchOtp(contextKey); - } + if(otp != null && otp.isEmpty()) { + preReg.fetchOtp(contextKey); + } return preReg.verifyOtp(to, otp, contextKey); } @@ -855,7 +845,7 @@ public String createPacketTemplates(List personaFilePaths, String proces RestClient.logInfo(contextKey, "createPacketTemplates->outDir:" + outDir); -// loadServerContextProperties(contextKey); + // loadServerContextProperties(contextKey); if (process != null) { VariableManager.setVariableValue(contextKey, "process", process); } @@ -1153,7 +1143,7 @@ else if (cm.getBioSubType().equals("Right")) } } } - break; + break; case "iris_hash": IrisDataModel irisvalueh = null; if (persona.getBiometric().getCapture() != null) { @@ -1244,7 +1234,7 @@ public String updatePersonaData(List updatePersonaRequest, Str List missList = req.getMissAttributeList(); if (missList != null && !missList.isEmpty()) persona.setMissAttributes(missList); -// persona.save(); + // persona.save(); persona.writePersona(req.getPersonaFilePath(), contextKey); @@ -1322,19 +1312,19 @@ public String bulkuploadPackets(List packetPaths, String contextKey) { public String getPacketTags(String contextKey) { -// loadServerContextProperties(contextKey); + // loadServerContextProperties(contextKey); JSONObject packetTags = new JSONObject(); packetTags.put("META_INFO-OPERATIONS_DATA-supervisorId", VariableManager.getVariableValue(contextKey, "META_INFO-OPERATIONS_DATA-supervisorId") == null - ? "--TAG_VALUE_NOT_AVAILABLE--" + ? "--TAG_VALUE_NOT_AVAILABLE--" : VariableManager.getVariableValue(contextKey, "META_INFO-OPERATIONS_DATA-supervisorId") - .toString()); + .toString()); packetTags.put("Biometric_Quality-Iris", VariableManager.getVariableValue(contextKey, "Biometric_Quality-Iris") == null - ? "--TAG_VALUE_NOT_AVAILABLE--" + ? "--TAG_VALUE_NOT_AVAILABLE--" : VariableManager.getVariableValue(contextKey, "Biometric_Quality-Iris").toString()); packetTags.put("INTRODUCER_AVAILABILITY", @@ -1342,28 +1332,28 @@ public String getPacketTags(String contextKey) { packetTags.put("META_INFO-CAPTURED_REGISTERED_DEVICES-Finger", VariableManager.getVariableValue(contextKey, "META_INFO-CAPTURED_REGISTERED_DEVICES-Finger") == null - ? "--TAG_VALUE_NOT_AVAILABLE--" + ? "--TAG_VALUE_NOT_AVAILABLE--" : VariableManager.getVariableValue(contextKey, "META_INFO-CAPTURED_REGISTERED_DEVICES-Finger") - .toString()); + .toString()); packetTags.put("META_INFO-META_DATA-centerId", VariableManager.getVariableValue(contextKey, "META_INFO-META_DATA-centerId") == null - ? "--TAG_VALUE_NOT_AVAILABLE--" + ? "--TAG_VALUE_NOT_AVAILABLE--" : VariableManager.getVariableValue(contextKey, "META_INFO-META_DATA-centerId").toString()); packetTags.put("Biometric_Quality-Face", VariableManager.getVariableValue(contextKey, "Biometric_Quality-Face") == null - ? "--TAG_VALUE_NOT_AVAILABLE--" + ? "--TAG_VALUE_NOT_AVAILABLE--" : VariableManager.getVariableValue(contextKey, "Biometric_Quality-Face").toString()); packetTags.put("Biometric_Quality-Finger", VariableManager.getVariableValue(contextKey, "Biometric_Quality-Finger") == null - ? "--TAG_VALUE_NOT_AVAILABLE--" + ? "--TAG_VALUE_NOT_AVAILABLE--" : VariableManager.getVariableValue(contextKey, "Biometric_Quality-Finger").toString()); packetTags.put("EXCEPTION_BIOMETRICS", VariableManager.getVariableValue(contextKey, "EXCEPTION_BIOMETRICS") == null - ? "--TAG_VALUE_NOT_AVAILABLE--" + ? "--TAG_VALUE_NOT_AVAILABLE--" : VariableManager.getVariableValue(contextKey, "EXCEPTION_BIOMETRICS").toString()); packetTags.put("ID_OBJECT-gender", @@ -1372,9 +1362,9 @@ public String getPacketTags(String contextKey) { packetTags.put("META_INFO-CAPTURED_REGISTERED_DEVICES-Face", VariableManager.getVariableValue(contextKey, "META_INFO-CAPTURED_REGISTERED_DEVICES-Face") == null - ? "--TAG_VALUE_NOT_AVAILABLE--" + ? "--TAG_VALUE_NOT_AVAILABLE--" : VariableManager.getVariableValue(contextKey, "META_INFO-CAPTURED_REGISTERED_DEVICES-Face") - .toString()); + .toString()); packetTags.put("AGE_GROUP", VariableManager.getVariableValue(contextKey, "AGE_GROUP") == null ? "--TAG_VALUE_NOT_AVAILABLE--" @@ -1382,18 +1372,18 @@ public String getPacketTags(String contextKey) { packetTags.put("SUPERVISOR_APPROVAL_STATUS", VariableManager.getVariableValue(contextKey, "SUPERVISOR_APPROVAL_STATUS") == null - ? "--TAG_VALUE_NOT_AVAILABLE--" + ? "--TAG_VALUE_NOT_AVAILABLE--" : VariableManager.getVariableValue(contextKey, "SUPERVISOR_APPROVAL_STATUS").toString()); packetTags.put("META_INFO-OPERATIONS_DATA-officerId", VariableManager.getVariableValue(contextKey, "META_INFO-OPERATIONS_DATA-officerId") == null - ? "--TAG_VALUE_NOT_AVAILABLE--" + ? "--TAG_VALUE_NOT_AVAILABLE--" : VariableManager.getVariableValue(contextKey, "META_INFO-OPERATIONS_DATA-officerId") - .toString()); + .toString()); packetTags.put("ID_OBJECT-residenceStatus", VariableManager.getVariableValue(contextKey, "ID_OBJECT-residenceStatus") == null - ? "--TAG_VALUE_NOT_AVAILABLE--" + ? "--TAG_VALUE_NOT_AVAILABLE--" : VariableManager.getVariableValue(contextKey, "ID_OBJECT-residenceStatus").toString()); return packetTags.toString();