[TASK] Begin implementing a mapper class.

This commit is contained in:
Jan Philipp Timme 2014-09-19 16:22:11 +02:00
parent 25e97c94b5
commit 59e2543018
2 changed files with 27 additions and 12 deletions

View File

@ -8,12 +8,12 @@ class PersonIdentityManager():
def create_identity(self, project, uuid): def create_identity(self, project, uuid):
pgi = PersonGlobalIdentity(type='citavi') pgi = PersonGlobalIdentity(type='citavi')
pgi.save() 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() cpi.save()
return cpi return cpi
def add_identity_to_global_identity(self, global_identity, project, uuid, preferred): 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() cpi.save()
return cpi return cpi

View File

@ -16,22 +16,37 @@ class PersonMapper():
def get_unmapped_identities(self, project): def get_unmapped_identities(self, project):
citavi_persons = self._citavi_project_manager.get_persons_from_project(project.id) citavi_persons = self._citavi_project_manager.get_persons_from_project(project.id)
mapped_persons = self._person_identity_manager.get_mapped_identities_for_project(project) 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: for person in citavi_persons:
print str(person) citavi_uuid_dict[person.ID] = person
print "########################################\n########################################"
print len(citavi_uuid_dict)
for person in mapped_persons: for person in mapped_persons:
# TODO: Actually use this loop to remove persons in citavi_persons, return the rest. if person.citavi_uuid in citavi_uuid_dict:
print str(person) # 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(): def test():
from frontend.models import Project from frontend.models import Project
project = Project.objects.get(id=1) project = Project.objects.get(id=1)
p = PersonMapper() 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)