* @param hdssId HDSS ID of the person this transaction is for.
* @param rowList List of transaction row details (column name/value pairs).
* @return true if we succeeded, otherwise false.
*/
private boolean updateTransaction(String transactionType, String hdssId, List<Row> rowList) {
Person p = new Person();
int requestTypeId;
if (transactionType.equals("INSERT")) {
requestTypeId = RequestTypeId.CREATE_PERSON_MPI;
} else if (transactionType.equals("UPDATE")) {
requestTypeId = RequestTypeId.MODIFY_PERSON_MPI;
} else if (transactionType.equals("DELETE")) {
//TODO: Determine and code how deletes be treated
//Treat as modify but remove hdssid?
requestTypeId = RequestTypeId.MODIFY_PERSON_MPI;
} else {
//this should never happen and should be logged as an error
Mediator.getLogger(Updater.class.getName()).log(Level.SEVERE, "Unknown transaction type [{0}] "
+ "exists in the shadow database", transactionType);
return false;
}
String marriageStatus = null;
String marriageType = null;
Fingerprint fp1 = new Fingerprint();
Fingerprint fp2 = new Fingerprint();
String event = "";
Date eventDate = null;
for (Row r : rowList) {
String value = r.value;
if (value == null) {
value = "";
} else {
value = value.trim(); // HDSS database values have a lot of trailing spaces.
value = value.replace('\u2018', '\'').replace('\u2019', '\''); // Some values have "curly" quote characters -- cause problems for XML.
}
if (r.name.equals("fname")) {
p.setFirstName(value);
} else if (r.name.equals("jname")) {
p.setMiddleName(value);
} else if (r.name.equals("lname")) {
p.setLastName(value);
} else if (r.name.equals("famcla")) {
p.setClanName(value);
} else if (r.name.equals("akaname")) {
p.setOtherName(value);
} else if (r.name.equals("gender")) {
p.setSex(HdssDataParser.sex(value, hdssId));
} else if (r.name.equals("dob")) {
p.setBirthdate(parseDate(value));
} else if (r.name.equals("mfname")) {
p.setMothersFirstName(value);
} else if (r.name.equals("mjname")) {
p.setMothersMiddleName(value);
} else if (r.name.equals("mlname")) {
p.setMothersLastName(value);
} else if (r.name.equals("ffname")) {
p.setFathersFirstName(value);
} else if (r.name.equals("fjname")) {
p.setFathersMiddleName(value);
} else if (r.name.equals("flname")) {
p.setFathersLastName(value);
} else if (r.name.equals("mtal")) {
marriageStatus = value;
} else if (r.name.equals("mtyp")) {
marriageType = value;
} else if (r.name.equals("cfname")) {
p.setCompoundHeadFirstName(value);
} else if (r.name.equals("cjname")) {
p.setCompoundHeadMiddleName(value);
} else if (r.name.equals("clname")) {
p.setCompoundHeadLastName(value);
} else if (r.name.equals("villname")) {
p.setVillageName(value);
} else if (r.name.equals("lasteventdate")) {
eventDate = parseDate(value);
} else if (r.name.equals("lastevent")) {
event = value;
} else if (r.name.equals("expectedDeliveryDate")) {
p.setExpectedDeliveryDate(parseDate(value));
} else if (r.name.equals("pregnancyEndDate")) {
p.setPregnancyEndDate(parseDate(value));
} else if (r.name.equals("pregnancyOutcome")) {
p.setPregnancyOutcome(HdssDataParser.pregnancyOutcome(value, hdssId));
} else if (r.name.equals("f_Template")) {
fp1.setTemplate(parseHex(value));
} else if (r.name.equals("f_Type")) {
fp1.setFingerprintType(HdssDataParser.fingerprintType(value, hdssId));
} else if (r.name.equals("f_Technology")) {
fp1.setTechnologyType(HdssDataParser.fingerprintTechnologyType(value, hdssId));
} else if (r.name.equals("f_DateEntered")) {
fp1.setDateEntered(parseDate(value));
} else if (r.name.equals("f_DateModified")) {
fp1.setDateChanged(parseDate(value));
} else if (r.name.equals("s_Template")) {
fp2.setTemplate(parseHex(value));
} else if (r.name.equals("s_Type")) {
fp2.setFingerprintType(HdssDataParser.fingerprintType(value, hdssId));
} else if (r.name.equals("s_Technology")) {
fp2.setTechnologyType(HdssDataParser.fingerprintTechnologyType(value, hdssId));
} else if (r.name.equals("s_DateEntered")) {
fp2.setDateEntered(parseDate(value));
} else if (r.name.equals("s_DateModified")) {
fp2.setDateChanged(parseDate(value));
}
}
if (event.equalsIgnoreCase("DTH")) {
//p.setAliveStatus(Person.AliveStatus.no);
p.setDeathdate(eventDate);
} else if (event.equalsIgnoreCase("EXT")) {
p.setLastMoveDate(eventDate);
}
//
// Set marital status, if present.
//
p.setMaritalStatus(HdssDataParser.maritalStatus(marriageStatus, marriageType, hdssId));
//
// Set the Kisumu HDSS person identifier.
//
List<PersonIdentifier> personIdentifierList = new ArrayList<PersonIdentifier>();
PersonIdentifier pi = new PersonIdentifier();
pi.setIdentifier(hdssId);
pi.setIdentifierType(PersonIdentifier.Type.kisumuHdssId);
personIdentifierList.add(pi);
p.setPersonIdentifierList(personIdentifierList);
//
// Set the fingerprints if present.
//
List<Fingerprint> fingerprintList = new ArrayList<Fingerprint>();
if (fp1.getTemplate() != null) {
fingerprintList.add(fp1);
}
if (fp2.getTemplate() != null) {
fingerprintList.add(fp2);
}
if (fingerprintList.size() > 0) {
p.setFingerprintList(fingerprintList);
} else {
p.setFingerprintList(null); // No need to return exisiting fingerprints.
}
boolean returnStatus = false; // Assume failure for the moment.
//
// If we are creating a new person entry, and the person has already died,
// don't bother putting the entry in the MPI. However if this is an update
// and the person has died, we want to update the person's status in the MPI.
if (requestTypeId == RequestTypeId.CREATE_PERSON_MPI && p.getDeathdate() != null) {
returnStatus = true; // Claim success; we won't insert a dead person into the MPI.
} else {
PersonResponse pr = requestMpi(p, requestTypeId);
if (pr != null && pr.isSuccessful()) {
returnStatus = true; // We succeeded!