[TASK] Begin implementing a mapper class.
This commit is contained in:
parent
25e97c94b5
commit
59e2543018
|
@ -8,12 +8,12 @@ class PersonIdentityManager():
|
|||
def create_identity(self, project, uuid):
|
||||
pgi = PersonGlobalIdentity(type='citavi')
|
||||
pgi.save()
|
||||
cpi = CitaviProjectIdentity(global_identity=pgi, project=project, citavi_uuid=uuid, preferred_id=True)
|
||||
cpi = CitaviProjectIdentity(global_identity=pgi, project=project, citavi_uuid=uuid, preferred=True)
|
||||
cpi.save()
|
||||
return cpi
|
||||
|
||||
def add_identity_to_global_identity(self, global_identity, project, uuid, preferred):
|
||||
cpi = CitaviProjectIdentity(global_identity=global_identity, project=project, citavi_uuid=uuid, preferred_id=True)
|
||||
cpi = CitaviProjectIdentity(global_identity=global_identity, project=project, citavi_uuid=uuid, preferred=True)
|
||||
cpi.save()
|
||||
return cpi
|
||||
|
||||
|
|
|
@ -16,22 +16,37 @@ class PersonMapper():
|
|||
def get_unmapped_identities(self, project):
|
||||
citavi_persons = self._citavi_project_manager.get_persons_from_project(project.id)
|
||||
mapped_persons = self._person_identity_manager.get_mapped_identities_for_project(project)
|
||||
print "#"
|
||||
print citavi_persons
|
||||
print "##"
|
||||
print mapped_persons
|
||||
print "###"
|
||||
|
||||
print "Len citavi persons: " + str(len(citavi_persons))
|
||||
print "Len mapped persons: " + str(len(mapped_persons))
|
||||
|
||||
if len(mapped_persons) == 0:
|
||||
return citavi_persons
|
||||
|
||||
# Prepare citavi_persons into a uuid->person dict, then eliminate mapped ones. This is ugly and a little slow.
|
||||
citavi_uuid_dict = {}
|
||||
for person in citavi_persons:
|
||||
print str(person)
|
||||
print "########################################\n########################################"
|
||||
citavi_uuid_dict[person.ID] = person
|
||||
|
||||
print len(citavi_uuid_dict)
|
||||
|
||||
for person in mapped_persons:
|
||||
# TODO: Actually use this loop to remove persons in citavi_persons, return the rest.
|
||||
print str(person)
|
||||
if person.citavi_uuid in citavi_uuid_dict:
|
||||
# print "Match for: " + str(person.id) + " - uuid: " + str(person.citavi_uuid)
|
||||
del citavi_uuid_dict[person.citavi_uuid]
|
||||
|
||||
print len(citavi_uuid_dict)
|
||||
|
||||
return citavi_uuid_dict
|
||||
|
||||
def create_new_identity(self, project, person):
|
||||
self._person_identity_manager.create_identity(project, person.ID)
|
||||
|
||||
def test():
|
||||
from frontend.models import Project
|
||||
project = Project.objects.get(id=1)
|
||||
p = PersonMapper()
|
||||
p.get_unmapped_identities(project)
|
||||
unmapped = p.get_unmapped_identities(project)
|
||||
print unmapped
|
||||
# for person in unmapped:
|
||||
# p.create_new_identity(project, person)
|
||||
|
|
Loading…
Reference in New Issue