require 'dmao/api/entity' require 'dmao/api/errors/invalid_publication_dataset' require 'dmao/api/errors/invalid_publication_dataset_id' require 'dmao/api/errors/publication_dataset_not_found' require 'dmao/api/errors/invalid_publication_id' require 'dmao/api/errors/invalid_dataset_id' require 'dmao/api/errors/unsupported_query_by_system_uuid' require 'dmao/api/errors/action_unsupported' module DMAO module API class PublicationDataset < Entity ENDPOINT = 'publication_datasets' NOT_FOUND_ERROR = DMAO::API::Errors::PublicationDatasetNotFound INVALID_ID_ERROR = DMAO::API::Errors::InvalidPublicationDatasetID INVALID_ENTITY_CLASS = DMAO::API::Errors::InvalidPublicationDataset INVALID_ENTITY_ERROR_MESSAGE = "Invalid publication dataset details, please see errors." VALID_ATTRIBUTES = [:id, :institution_id, :publication_id, :dataset_id] attr_reader(*VALID_ATTRIBUTES) def initialize(attributes) @id = attributes[:id] @institution_id = attributes[:institution_id] @publication_id = attributes[:publication_id] @dataset_id= attributes[:dataset_id] end def self.instance_from_api_data data attributes = { id: data["id"], institution_id: data["relationships"]["institution"]["data"]["id"], publication_id: data["relationships"]["publication"]["data"]["id"], dataset_id: data["relationships"]["dataset"]["data"]["id"] } new(attributes) end def self.handle_unprocessable_entity error_response errors = parse_error_response error_response raise DMAO::API::Errors::InvalidPublicationDataset.new("Invalid publication dataset details, please see errors.", errors) if (errors.keys.include?("publication") && errors.keys.include?("dataset")) raise_error_if_key DMAO::API::Errors::InvalidPublicationID, errors, "publication" raise_error_if_key DMAO::API::Errors::InvalidDatasetID, errors, "dataset" raise DMAO::API::Errors::InvalidPublicationDataset.new("Invalid publication dataset details, please see errors.", errors) end def self.find_by_system_uuid _system_uuid raise DMAO::API::Errors::UnsupportedQueryBySystemUUID.new end def self.update _id, _attributes raise DMAO::API::Errors::ActionUnsupported.new("Updating publication dataset is not supported.") end end end end