lib/dmao/ingesters/generic/organisation_ingester.rb in dmao-generic-ingesters-0.5.0 vs lib/dmao/ingesters/generic/organisation_ingester.rb in dmao-generic-ingesters-0.6.0
- old
+ new
@@ -13,10 +13,15 @@
class OrganisationIngester < Ingester
ENTITY = DMAO::API::OrganisationUnit
ENTITY_ERROR = DMAO::Ingesters::Errors::IngestOrganisationUnitError
ENTITY_ERROR_MESSAGE = "Invalid organisation unit details"
+ ERROR_HANDLING = {
+ "DMAO::API::Errors::OrganisationUnitNotFound" => "Organisation unit not found, cannot update organisation unit that does not exist",
+ "DMAO::API::Errors::InstitutionNotFound" => "Institution not found, cannot ingest organisation unit to non-existent institution",
+ "DMAO::API::Errors::InvalidParentId" => "Parent ID not found in DMA Online, cannot link organisation unit to non-existent parent"
+ }
def link_child_to_parent child_system_uuid, parent_system_uuid
child_unit = find_unit_or_raise_link_error child_system_uuid, "Organisation unit not found for child system uuid #{child_system_uuid}"
parent_unit = find_unit_or_raise_link_error parent_system_uuid, "Organisation unit not found for parent system uuid #{parent_system_uuid}"
@@ -27,48 +32,10 @@
update_organisation_unit child_unit.id, attributes
end
- def add_organisation_unit attributes
-
- begin
- DMAO::API::OrganisationUnit.create attributes
- rescue DMAO::API::Errors::InstitutionNotFound
- raise DMAO::Ingesters::Errors::IngestOrganisationUnitError.new("Institution not found, cannot ingest organisation unit to non-existent institution")
- rescue DMAO::API::Errors::InvalidParentId
- raise DMAO::Ingesters::Errors::IngestOrganisationUnitError.new("Parent ID not found in DMA Online, cannot link organisation unit to non-existent parent")
- rescue DMAO::API::Errors::InvalidOrganisationUnit => e
- parse_unprocessable_errors(e.errors)
- end
-
- end
-
- def update_organisation_unit id, attributes
-
- begin
-
- DMAO::API::OrganisationUnit.update id, attributes
-
- rescue DMAO::API::Errors::OrganisationUnitNotFound
- raise DMAO::Ingesters::Errors::IngestOrganisationUnitError.new("Organisation unit not found, cannot update organisation unit that does not exist")
- rescue DMAO::API::Errors::InvalidParentId
- raise DMAO::Ingesters::Errors::IngestOrganisationUnitError.new("Parent ID not found in DMA Online, cannot link organisation unit to non-existent parent")
- rescue DMAO::API::Errors::InvalidOrganisationUnit => e
- parse_unprocessable_errors(e.errors)
- end
-
- end
-
protected
-
- def add_entity attributes
- add_organisation_unit attributes
- end
-
- def update_entity id, attributes
- update_organisation_unit id, attributes
- end
def find_unit_or_raise_link_error unit_system_uuid, error_message
begin
DMAO::API::OrganisationUnit.find_by_system_uuid unit_system_uuid
\ No newline at end of file