def _merge_relationship(self, relationship_type, from_person, to_person):
     relationship = Relationship.type(relationship_type.name)
     tx = self._graph.begin()
     from_node = Node(Person.label(), **from_person.as_dict())
     to_node = Node(Person.label(), **to_person.as_dict())
     new_relationship = relationship(from_node, to_node)
     tx.merge(new_relationship, Person.label(), Person.key())
     tx.push(new_relationship)
     tx.commit()
    def update_or_create(self, person_input_dict):
        email_validation_result = PersonInputValidator.validate_email(
            **person_input_dict)
        if email_validation_result == ValidationResult.ABSENT or \
                email_validation_result == ValidationResult.INVALID:
            self._logger.warning(
                "valid email is required to insert or update person")
            raise ValueError(
                "valid email is required to insert or update person")

        birthday_validation_result = PersonInputValidator.validate_birthday(
            **person_input_dict)
        if not birthday_validation_result.ABSENT and birthday_validation_result.INVALID:
            self._logger.warning("provided birthday must be valid iso date")
            raise ValueError("provided birthday must be valid iso date")

        person = self.find(person_input_dict['email'])
        property_dict = {}
        if not person:
            properties_validation = PersonInputValidator.has_all_properties(
                **person_input_dict)
            if len(properties_validation) > 0:
                properties = Person.all_properties()
                self._logger.warning("new person requires all properties: " +
                                     ",".join(properties))
                raise ValueError("new person requires all properties: " +
                                 ",".join(properties))
        else:
            property_dict = person.as_dict()

        for key, value in person_input_dict.items():
            property_dict[key] = value
        tx = self._graph.begin()
        node = Node(Person.label(), **property_dict)
        tx.merge(node, Person.label(), Person.key())
        tx.push(node)
        tx.commit()
        return self.find(property_dict['email'])