2014-09-19 11:52:56 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from Citavi import ProjectManager
|
|
|
|
from Django import PersonIdentityManager
|
|
|
|
|
2014-09-29 13:40:07 +02:00
|
|
|
|
2014-09-19 11:52:56 +02:00
|
|
|
class PersonMapper():
|
|
|
|
|
|
|
|
def __init__(self):
|
2014-09-29 13:40:07 +02:00
|
|
|
""" Initializes ProjectManager and PersonIdentityManager. """
|
2014-09-19 11:52:56 +02:00
|
|
|
self._citavi_project_manager = ProjectManager()
|
|
|
|
self._person_identity_manager = PersonIdentityManager()
|
|
|
|
|
|
|
|
def __del__(self):
|
2014-09-29 13:40:07 +02:00
|
|
|
""" Destroys ProjectManager and PersonIdentityManager. """
|
2014-09-19 11:52:56 +02:00
|
|
|
del self._citavi_project_manager
|
|
|
|
del self._person_identity_manager
|
|
|
|
|
|
|
|
def get_unmapped_identities(self, project):
|
2014-09-29 13:40:07 +02:00
|
|
|
""" Returns a uuid->person dict for all unmapped persons within a project. """
|
2014-09-19 11:52:56 +02:00
|
|
|
citavi_persons = self._citavi_project_manager.get_persons_from_project(project.id)
|
|
|
|
mapped_persons = self._person_identity_manager.get_mapped_identities_for_project(project)
|
2014-09-19 16:22:11 +02:00
|
|
|
# Prepare citavi_persons into a uuid->person dict, then eliminate mapped ones. This is ugly and a little slow.
|
|
|
|
citavi_uuid_dict = {}
|
2014-09-19 11:52:56 +02:00
|
|
|
for person in citavi_persons:
|
2014-09-19 16:22:11 +02:00
|
|
|
citavi_uuid_dict[person.ID] = person
|
2014-09-25 17:36:42 +02:00
|
|
|
if len(mapped_persons) == 0:
|
|
|
|
return citavi_uuid_dict
|
2014-09-19 11:52:56 +02:00
|
|
|
for person in mapped_persons:
|
2014-09-19 16:22:11 +02:00
|
|
|
if person.citavi_uuid in citavi_uuid_dict:
|
|
|
|
del citavi_uuid_dict[person.citavi_uuid]
|
|
|
|
return citavi_uuid_dict
|
|
|
|
|
2014-09-29 13:40:07 +02:00
|
|
|
def get_mapped_identities(self, project):
|
|
|
|
""" Returns a uuid->person dict for all mapped persons within a project. """
|
|
|
|
mapped_persons = self._person_identity_manager.get_mapped_identities_for_project(project)
|
|
|
|
mapped_uuid_dict = {}
|
|
|
|
for person in mapped_persons:
|
|
|
|
mapped_uuid_dict[person.citavi_uuid] = person
|
|
|
|
return mapped_uuid_dict
|
|
|
|
|
2014-09-19 16:22:11 +02:00
|
|
|
def create_new_identity(self, project, person):
|
2014-09-29 13:40:07 +02:00
|
|
|
""" Creates a new identity for a given person. """
|
|
|
|
return self._person_identity_manager.create_identity(project, person.ID)
|
2014-09-19 11:52:56 +02:00
|
|
|
|
2014-09-29 13:40:07 +02:00
|
|
|
def get_person_by_uuid(self, project, uuid):
|
|
|
|
""" Returns a person from a citavi project by uuid. """
|
2014-09-25 17:36:42 +02:00
|
|
|
return self._citavi_project_manager.get_person_by_uuid(project.id, uuid)
|