class DMAO::Ingesters::Generic::ProjectParticipantsIngester

Constants

ENTITY
ENTITY_ERROR
ENTITY_ERROR_MESSAGE
ERROR_HANDLING

Public Instance Methods

ingest_entity(attributes={}) click to toggle source
# File lib/dmao/ingesters/generic/project_participants_ingester.rb, line 21
def ingest_entity attributes={}

  validate_attributes_present attributes
  
  begin

    participant_system_uuid = attributes[:participant_system_uuid]
    project_system_uuid = attributes[:project_system_uuid]

    participant = DMAO::API::Person.find_by_system_uuid(participant_system_uuid)
    project = DMAO::API::Project.find_by_system_uuid(project_system_uuid)

    project_participant = DMAO::API::ProjectParticipant.find_project_participant project.id, participant.id

    update_entity project_participant.id, {person_id: participant.id, project_id: project.id}.merge(attributes)

  rescue DMAO::API::Errors::PersonNotFound
    raise self.class::ENTITY_ERROR.new("Participant not found, cannot add a non existent person to a project")
  rescue DMAO::API::Errors::ProjectNotFound
    raise self.class::ENTITY_ERROR.new("Project not found, cannot add participant to non existent project")
  rescue DMAO::API::Errors::ProjectParticipantNotFound
    add_entity({person_id: participant.id, project_id: project.id}.merge(attributes))
  rescue DMAO::API::Errors::InvalidResponseLength => e
    raise self.class::ENTITY_ERROR.new(e.message)
  end

end