Skip to content

Commit

Permalink
MOSIP-35914
Browse files Browse the repository at this point in the history
Signed-off-by: Jayesh Kharode <[email protected]>
  • Loading branch information
Jayesh Kharode committed Nov 25, 2024
1 parent dbc3a4d commit bbae9bd
Showing 1 changed file with 107 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ public class PacketSyncService {

@Autowired
private ZipUtils zipUtils;

private PacketMakerService packetMakerService;
private PacketSyncService packetSyncService;

@Autowired
private ContextUtils contextUtils;

Expand Down Expand Up @@ -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;
Expand All @@ -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<String> 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<String> invalidList = Arrays.asList(props.get("invalid").toString().split(",", -1));
provider.addCondition(ResidentAttribute.RA_InvalidList, invalidList);
}
if (props.containsKey("Miss")) {

List<String> 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<String> 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<ResidentModel> lst = provider.generate(contextKey);
RestClient.logInfo(contextKey, "After Genrate");
RestClient.logInfo(contextKey, "before Genrate");
List<ResidentModel> 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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

}
Expand Down Expand Up @@ -855,7 +845,7 @@ public String createPacketTemplates(List<String> personaFilePaths, String proces

RestClient.logInfo(contextKey, "createPacketTemplates->outDir:" + outDir);

// loadServerContextProperties(contextKey);
// loadServerContextProperties(contextKey);
if (process != null) {
VariableManager.setVariableValue(contextKey, "process", process);
}
Expand Down Expand Up @@ -1153,7 +1143,7 @@ else if (cm.getBioSubType().equals("Right"))
}
}
}
break;
break;
case "iris_hash":
IrisDataModel irisvalueh = null;
if (persona.getBiometric().getCapture() != null) {
Expand Down Expand Up @@ -1244,7 +1234,7 @@ public String updatePersonaData(List<UpdatePersonaDto> updatePersonaRequest, Str
List<String> missList = req.getMissAttributeList();
if (missList != null && !missList.isEmpty())
persona.setMissAttributes(missList);
// persona.save();
// persona.save();

persona.writePersona(req.getPersonaFilePath(), contextKey);

Expand Down Expand Up @@ -1322,48 +1312,48 @@ public String bulkuploadPackets(List<String> 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",
VariableManager.getVariableValue(contextKey, "INTRODUCER_AVAILABILITY").toString());

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",
Expand All @@ -1372,28 +1362,28 @@ 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--"
: VariableManager.getVariableValue(contextKey, "AGE_GROUP").toString());

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();
Expand Down

0 comments on commit bbae9bd

Please sign in to comment.