Class: DMAO::Ingesters::Generic::ProjectParticipantsIngester

Inherits:
Ingester
  • Object
show all
Defined in:
lib/dmao/ingesters/generic/project_participants_ingester.rb

Constant Summary collapse

ENTITY =
DMAO::API::ProjectParticipant
ENTITY_ERROR =
DMAO::Ingesters::Errors::IngestProjectParticipantError
ENTITY_ERROR_MESSAGE =
"Invalid project participant details"
ERROR_HANDLING =
{
    "DMAO::API::Errors::ProjectParticipantNotFound" => "Project participant not found, cannot update project participant that does not exist",
    "DMAO::API::Errors::InvalidProjectID" => "Project not found, cannot add participant to non existent project",
    "DMAO::API::Errors::InvalidPersonID" => "Participant not found cannot a non existent person to a project",
    "DMAO::API::Errors::InstitutionNotFound" => "Institution not found, cannot ingest project participant to non-existent institution",

}

Constants inherited from Ingester

Ingester::INVALID_ENTITY_ERROR

Instance Method Summary collapse

Methods inherited from Ingester

entity_name, #generic_errors, #ingest, #initialize, #parse_unprocessable_errors

Constructor Details

This class inherits a constructor from DMAO::Ingesters::Generic::Ingester

Instance Method Details

#ingest_entity(attributes = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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