require 'dmao_api' require 'dmao/api/person' require 'time' require 'dmao/ingesters/generic/ingester' require 'dmao/ingesters/errors/generic_ingester' require 'dmao/ingesters/errors/empty_attributes' require 'dmao/ingesters/errors/ingest_person_error' module DMAO module Ingesters module Generic class PeopleIngester < Ingester ENTITY = DMAO::API::Person ENTITY_ERROR = DMAO::Ingesters::Errors::IngestPersonError ENTITY_ERROR_MESSAGE = "Invalid person details" def ingest_person attributes={} ingest_entity attributes end private def add_entity attributes add_person attributes end def update_entity id, attributes update_person id, attributes end def add_person attributes begin DMAO::API::Person.create attributes rescue DMAO::API::Errors::InstitutionNotFound raise DMAO::Ingesters::Errors::IngestPersonError.new("Institution not found, cannot ingest person to non-existent institution") rescue DMAO::API::Errors::InvalidPerson => e parse_unprocessable_errors(e.errors) end end def update_person id, attributes begin DMAO::API::Person.update id, attributes rescue DMAO::API::Errors::PersonNotFound raise DMAO::Ingesters::Errors::IngestPersonError.new("Person not found, cannot update person that does not exist") rescue DMAO::API::Errors::InvalidPerson => e parse_unprocessable_errors(e.errors) end end end end end end