def getPeoples(action, operation, id, query): logger.info("hoh-people-api->getPeoples - Entry") context = None if id == "": id = getQueryString( query, "id", "") # TODO this should be removed. Should only come from path. if (id != ""): # Just get the ID requested. logger.info("hoh-people-api->getPeoples - got the - id = [" + id + "]") list = peeps.getPeep(context, id) else: familyName = getQueryString(query, "familyName", "") birthSex = getQueryString(query, "birthSex", "") logger.info( "hoh-people-api->getPeoples - got the queryStrings - familyName = [" + familyName + "] - birthSex = [" + birthSex + "]") list = peeps.getPeepsList(context, familyName, birthSex) logger.info("hoh-people-api->getPeoples - the list of peeps has " + str(len(list)) + " peeps in it") # curate the list returned to just what we want retList = [] i = 0 for val in list: i += 1 logger.debug("hoh-people-api->getPeoples - processing peep " + str(i)) entry = {} entry['id'] = valIfExists(val, 'id') entry['firstName'] = valIfExists(val, 'firstName') entry['familyName'] = valIfExists(val, 'familyName') entry['preferredName'] = valIfExists(val, 'preferredName') entry['otherNames'] = valIfExists(val, 'otherNames') entry['birthSex'] = valIfExists(val, 'birthCertificateSex', "Unknown") entry['living'] = 'True' if 'dod' in val: if len(val['dod']) == 10: entry['living'] = 'False' bLiving = entry['living'] == 'True' entry['maidenName'] = PrivateValIfExists(val, 'maidenName', bLiving) entry['dob'] = PrivateValIfExists(val, 'dob', bLiving) entry['dod'] = PrivateValIfExists(val, 'dod', bLiving) entry['motherid'] = PrivateValIfExists(val, 'motherid', bLiving) entry['fatherid'] = PrivateValIfExists(val, 'fatherid', bLiving) entry['dqScore'] = CalcDQScore(entry) entry['notes'] = valIfExists(val, 'notes') retList.append(entry) retJson = json.dumps(retList) logger.debug("hoh-people-api->getPeoples - returning:" + retJson) logger.info("hoh-people-api->getPeoples - Exit") return retJson
def test5_2(): print("TEST5_0 - PEOPLE LIST TESTS - single peep not matched") context = None # context = peeps.loadPeepFile(context, '../hoh-people.json') context = mycontext.setPeepFile(context, '../hoh-people.json') p = peeps.getPeepsList(context, "11111111-2222-3333-8c03-3b529c01a1aa") print("peeps count = " + str(len(p))) assert (len(p) == 0) return
def test5_1(): print("TEST5_1 - PEOPLE LIST TESTS - list of peeps") context = None # context = peeps.loadPeepFile(context, '../hoh-people.json') context = mycontext.setPeepFile(context, '../hoh-people.json') p = peeps.getPeepsList(context, "") assert (len(p) >= 1) print("peeps count = " + str(len(p))) return
def test5_0(): print("TEST5_0 - PEOPLE LIST TESTS - single peep") context = None # context = peeps.loadPeepFile(context, '../hoh-people.json') context = mycontext.setPeepFile(context, '../hoh-people.json') testGuid = "09e34f8b-3f9c-43fa-8c03-3b529c01a1aa" p = peeps.getPeepsList(context, testGuid) print("peeps count = " + str(len(peeps))) assert (len(p) == 1) assert (p[0]['id'] == testGuid) assert (p[0]['firstName'] == 'Nita') return
def backupObjects(): context = mycontext.newContext() # set the handler to what we want. mycontext.setObjectHandler(jsonObjectFile) mycontext.setObjectHandler(jsonObjectDynamo) peepList = peeps.getPeepsList(context) ts = datetime.datetime.utcnow().isoformat() fileName = "/temp/backups/PeepsBackup-" + ts + ".json" fileName = fileName.replace(":", "-") print("Backuping up to file - [" + fileName + "]") with open(fileName, 'w') as json_file: json.dump(peepList, json_file) print("Saved " + str(len(peepList)) + " records.") return
def validateObjects(): context = mycontext.newContext() # set the handler to what we want. mycontext.setObjectHandler(jsonObjectFile) mycontext.setObjectHandler(jsonObjectDynamo) peepList = peeps.getPeepsList(context) for peep in peepList: #missing = validateEntry(peep, "id") missing = validateEntry(peep, "firstName") missing += validateEntry(peep, "familyName") missing += validateEntry(peep, "level") missing += validateEntry(peep, "motherid") missing += validateEntry(peep, "fatherid") missing += validateEntry(peep, "dob") missing += validateEntry(peep, "birthCertificateSex") if missing != "": print("Validation: " + asMuchAsWeKnow(peep) + " - missing - " + missing) return