From cb68cb9a94d2b7b69956806f296b73509b6aa016 Mon Sep 17 00:00:00 2001 From: Kristina Spurgin Date: Mon, 28 Sep 2020 10:38:36 -0400 Subject: [PATCH 1/3] do not alias Mapper to global namespace --- lib/collectionspace/mapper.rb | 4 +--- .../mapper/data_handler_spec.rb | 20 +++++++++---------- .../mapper/data_mapper_anthro_spec.rb | 2 +- .../mapper/data_mapper_bonsai_spec.rb | 2 +- .../mapper/data_mapper_botgarden_spec.rb | 2 +- .../mapper/data_mapper_core_spec.rb | 2 +- .../mapper/data_mapper_spec.rb | 12 +++++------ .../mapper/data_prepper_spec.rb | 8 ++++---- .../mapper/data_validator_spec.rb | 4 ++-- spec/collectionspace/mapper/response_spec.rb | 18 ++++++++--------- .../mapper/term_handler_spec.rb | 2 +- .../mapper/tools/dates_spec.rb | 2 +- spec/collectionspace/mapper_spec.rb | 16 +++++++-------- 13 files changed, 46 insertions(+), 48 deletions(-) diff --git a/lib/collectionspace/mapper.rb b/lib/collectionspace/mapper.rb index 6122ed1e..8caefb9c 100644 --- a/lib/collectionspace/mapper.rb +++ b/lib/collectionspace/mapper.rb @@ -15,8 +15,6 @@ module CollectionSpace module Mapper - ::Mapper = CollectionSpace::Mapper - LOGGER = Logger.new(STDERR) DEFAULT_CONFIG = { delimiter: ';', subgroup_delimiter: '^^', @@ -62,7 +60,7 @@ def self.setup_data(data) raise Errors::UnprocessableDataError.new("Cannot process a #{data.class}. Need a Hash or Mapper::Response", data) rescue Errors::UnprocessableDataError => error error.set_backtrace([]) - Mapper::LOGGER.error(error) + CollectionSpace::Mapper::LOGGER.error(error) err_resp = Response.new(data) err_resp.errors << error err_resp diff --git a/spec/collectionspace/mapper/data_handler_spec.rb b/spec/collectionspace/mapper/data_handler_spec.rb index 423d0088..c40d93d5 100644 --- a/spec/collectionspace/mapper/data_handler_spec.rb +++ b/spec/collectionspace/mapper/data_handler_spec.rb @@ -19,7 +19,7 @@ context 'when no config is passed at initialization' do it 'uses default config' do - expect(@anthro_place_handler.config).to eq(Mapper::DEFAULT_CONFIG) + expect(@anthro_place_handler.config).to eq(CollectionSpace::Mapper::DEFAULT_CONFIG) end end @@ -50,7 +50,7 @@ context 'anthro profile' do context 'collectionobject record' do before(:all) do - @config = Mapper::DEFAULT_CONFIG.merge({ + @config = CollectionSpace::Mapper::DEFAULT_CONFIG.merge({ transforms: { 'Collection' => { special: %w[downcase_value], @@ -153,10 +153,10 @@ end describe '#validate' do - it 'returns Mapper::Response object' do + it 'returns CollectionSpace::Mapper::Response object' do data = { 'objectNumber' => '123' } result = @anthro_object_handler.validate(data) - expect(result).to be_a(Mapper::Response) + expect(result).to be_a(CollectionSpace::Mapper::Response) end end @@ -197,7 +197,7 @@ end context 'when response_mode = verbose' do it 'returned response includes detailed data transformation info' do - config = Mapper::DEFAULT_CONFIG.merge({ response_mode: 'verbose' }) + config = CollectionSpace::Mapper::DEFAULT_CONFIG.merge({ response_mode: 'verbose' }) handler = DataHandler.new(@anthro_object_mapper, @anthro_client, @anthro_cache, config) result = handler.prep(@data) expect(result.transformed_data).not_to be_empty @@ -226,7 +226,7 @@ end context 'when response_mode = verbose' do it 'returned response includes detailed data transformation info' do - config = Mapper::DEFAULT_CONFIG.merge({ response_mode: 'verbose' }) + config = CollectionSpace::Mapper::DEFAULT_CONFIG.merge({ response_mode: 'verbose' }) handler = DataHandler.new(@anthro_object_mapper, @anthro_client, @anthro_cache, config) result = handler.process(@data) expect(result.transformed_data).not_to be_empty @@ -242,11 +242,11 @@ @result = @anthro_object_handler.map(prep_response, prepper.xphash) end - it 'returns Mapper::Response object' do - expect(@result).to be_a(Mapper::Response) + it 'returns CollectionSpace::Mapper::Response object' do + expect(@result).to be_a(CollectionSpace::Mapper::Response) end - it 'the Mapper::Response object doc attribute is a Nokogiri XML Document' do + it 'the CollectionSpace::Mapper::Response object doc attribute is a Nokogiri XML Document' do expect(@result.doc).to be_a(Nokogiri::XML::Document) end context 'when response_mode = normal' do @@ -256,7 +256,7 @@ end context 'when response_mode = verbose' do it 'returned response includes detailed data transformation info' do - config = Mapper::DEFAULT_CONFIG.merge({ response_mode: 'verbose' }) + config = CollectionSpace::Mapper::DEFAULT_CONFIG.merge({ response_mode: 'verbose' }) handler = DataHandler.new(@anthro_object_mapper, @anthro_client, @anthro_cache, config) prepper = DataPrepper.new(@data, handler) result = handler.map(handler.prep(@data), prepper.xphash) diff --git a/spec/collectionspace/mapper/data_mapper_anthro_spec.rb b/spec/collectionspace/mapper/data_mapper_anthro_spec.rb index a111c541..c2b434f4 100644 --- a/spec/collectionspace/mapper/data_mapper_anthro_spec.rb +++ b/spec/collectionspace/mapper/data_mapper_anthro_spec.rb @@ -4,7 +4,7 @@ RSpec.describe CollectionSpace::Mapper::DataMapper do before(:all) do - @config = Mapper::DEFAULT_CONFIG + @config = CollectionSpace::Mapper::DEFAULT_CONFIG end context 'anthro profile' do diff --git a/spec/collectionspace/mapper/data_mapper_bonsai_spec.rb b/spec/collectionspace/mapper/data_mapper_bonsai_spec.rb index 173f63eb..646260ca 100644 --- a/spec/collectionspace/mapper/data_mapper_bonsai_spec.rb +++ b/spec/collectionspace/mapper/data_mapper_bonsai_spec.rb @@ -4,7 +4,7 @@ RSpec.describe CollectionSpace::Mapper::DataMapper do before(:all) do - @config = Mapper::DEFAULT_CONFIG + @config = CollectionSpace::Mapper::DEFAULT_CONFIG end context 'bonsai profile' do diff --git a/spec/collectionspace/mapper/data_mapper_botgarden_spec.rb b/spec/collectionspace/mapper/data_mapper_botgarden_spec.rb index afd0bb5a..b78ce9f5 100644 --- a/spec/collectionspace/mapper/data_mapper_botgarden_spec.rb +++ b/spec/collectionspace/mapper/data_mapper_botgarden_spec.rb @@ -4,7 +4,7 @@ RSpec.describe CollectionSpace::Mapper::DataMapper do before(:all) do - @config = Mapper::DEFAULT_CONFIG + @config = CollectionSpace::Mapper::DEFAULT_CONFIG end context 'botgarden profile' do diff --git a/spec/collectionspace/mapper/data_mapper_core_spec.rb b/spec/collectionspace/mapper/data_mapper_core_spec.rb index 53e9648f..0e6e077d 100644 --- a/spec/collectionspace/mapper/data_mapper_core_spec.rb +++ b/spec/collectionspace/mapper/data_mapper_core_spec.rb @@ -4,7 +4,7 @@ RSpec.describe CollectionSpace::Mapper::DataMapper do before(:all) do - @config = Mapper::DEFAULT_CONFIG + @config = CollectionSpace::Mapper::DEFAULT_CONFIG end context 'core profile' do diff --git a/spec/collectionspace/mapper/data_mapper_spec.rb b/spec/collectionspace/mapper/data_mapper_spec.rb index 01adc17e..04b969be 100644 --- a/spec/collectionspace/mapper/data_mapper_spec.rb +++ b/spec/collectionspace/mapper/data_mapper_spec.rb @@ -4,7 +4,7 @@ RSpec.describe CollectionSpace::Mapper::DataMapper do before(:all) do - @config = Mapper::DEFAULT_CONFIG + @config = CollectionSpace::Mapper::DEFAULT_CONFIG end context 'lhmc profile' do before(:all) do @@ -93,7 +93,7 @@ context 'collectionobject record' do before(:all) do - config = Mapper::DEFAULT_CONFIG.merge({ + config = CollectionSpace::Mapper::DEFAULT_CONFIG.merge({ transforms: { 'collection' => { special: %w[downcase_value], @@ -128,11 +128,11 @@ end describe '#response' do - it 'returns Mapper::Response object' do + it 'returns CollectionSpace::Mapper::Response object' do res = @datamapper.response - expect(res).to be_a(Mapper::Response) + expect(res).to be_a(CollectionSpace::Mapper::Response) end - it 'Mapper::Response.doc is XML document' do + it 'CollectionSpace::Mapper::Response.doc is XML document' do res = @datamapper.response.doc expect(res).to be_a(Nokogiri::XML::Document) end @@ -160,7 +160,7 @@ cache = botgarden_cache populate_botgarden(cache) prop_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/botgarden/botgarden_1_1_0-propagation.json') - prop_handler = DataHandler.new(prop_mapper, client, cache, Mapper::DEFAULT_CONFIG) + prop_handler = DataHandler.new(prop_mapper, client, cache, CollectionSpace::Mapper::DEFAULT_CONFIG) datahash = get_datahash(path: 'spec/fixtures/files/datahashes/botgarden/propagation1.json') prepper = DataPrepper.new(datahash, prop_handler) mapper = DataMapper.new(prepper.prep, prop_handler, prepper.xphash) diff --git a/spec/collectionspace/mapper/data_prepper_spec.rb b/spec/collectionspace/mapper/data_prepper_spec.rb index b387dfa9..3aeec11c 100644 --- a/spec/collectionspace/mapper/data_prepper_spec.rb +++ b/spec/collectionspace/mapper/data_prepper_spec.rb @@ -4,7 +4,7 @@ RSpec.describe CollectionSpace::Mapper::DataPrepper do before(:all) do - @config = Mapper::DEFAULT_CONFIG + @config = CollectionSpace::Mapper::DEFAULT_CONFIG end context 'anthro profile' do @@ -63,7 +63,7 @@ end context 'and :force_defaults = true' do it 'maps the default value, overwriting value in the incoming data' do - config = Mapper::DEFAULT_CONFIG.merge({ + config = CollectionSpace::Mapper::DEFAULT_CONFIG.merge({ default_values: { 'collection' => 'library-collection' }, @@ -234,8 +234,8 @@ before(:all) do @res = @prepper.prep end - it 'returns Mapper::Response object' do - expect(@res).to be_a(Mapper::Response) + it 'returns CollectionSpace::Mapper::Response object' do + expect(@res).to be_a(CollectionSpace::Mapper::Response) end it 'contains orig data hash' do expect(@res.orig_data).not_to be_empty diff --git a/spec/collectionspace/mapper/data_validator_spec.rb b/spec/collectionspace/mapper/data_validator_spec.rb index 2ab79693..c7f1811b 100644 --- a/spec/collectionspace/mapper/data_validator_spec.rb +++ b/spec/collectionspace/mapper/data_validator_spec.rb @@ -15,9 +15,9 @@ end describe '#validate' do - it 'returns a Mapper::Response' do + it 'returns a CollectionSpace::Mapper::Response' do data = { 'objectNumber' => '123' } - expect(@anthro_dv.validate(data)).to be_a(Mapper::Response) + expect(@anthro_dv.validate(data)).to be_a(CollectionSpace::Mapper::Response) end context 'when recordtype has required field(s)' do diff --git a/spec/collectionspace/mapper/response_spec.rb b/spec/collectionspace/mapper/response_spec.rb index 60261b06..0f8f3186 100644 --- a/spec/collectionspace/mapper/response_spec.rb +++ b/spec/collectionspace/mapper/response_spec.rb @@ -8,7 +8,7 @@ @cache = botgarden_cache populate_botgarden(@cache) @mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/botgarden/botgarden_1_1_0-taxon.json') - @handler = DataHandler.new(@mapper, @cache, @client, Mapper::DEFAULT_CONFIG) + @handler = DataHandler.new(@mapper, @cache, @client, CollectionSpace::Mapper::DEFAULT_CONFIG) end describe '#valid?' do @@ -35,28 +35,28 @@ vresponse = @handler.validate(@data) @response = @handler.process(vresponse) end - it 'returns Mapper::Response with populated doc' do + it 'returns CollectionSpace::Mapper::Response with populated doc' do expect(@response.doc).to be_a(Nokogiri::XML::Document) end - it 'returns Mapper::Response with populated warnings' do + it 'returns CollectionSpace::Mapper::Response with populated warnings' do expect(@response.warnings).not_to be_empty end - it 'returns Mapper::Response with populated identifier' do + it 'returns CollectionSpace::Mapper::Response with populated identifier' do expect(@response.identifier).not_to be_empty end - it 'returns Mapper::Response with Hash of orig_data' do + it 'returns CollectionSpace::Mapper::Response with Hash of orig_data' do expect(@response.orig_data).to be_a(Hash) end - it 'returns Mapper::Response with unpopulated merged_data' do + it 'returns CollectionSpace::Mapper::Response with unpopulated merged_data' do expect(@response.merged_data).to be_empty end - it 'returns Mapper::Response with unpopulated split_data' do + it 'returns CollectionSpace::Mapper::Response with unpopulated split_data' do expect(@response.split_data).to be_empty end - it 'returns Mapper::Response with unpopulated transformed_data' do + it 'returns CollectionSpace::Mapper::Response with unpopulated transformed_data' do expect(@response.transformed_data).to be_empty end - it 'returns Mapper::Response with unpopulated combined_data' do + it 'returns CollectionSpace::Mapper::Response with unpopulated combined_data' do expect(@response.combined_data).to be_empty end end diff --git a/spec/collectionspace/mapper/term_handler_spec.rb b/spec/collectionspace/mapper/term_handler_spec.rb index ffc16aa5..f570ffc2 100644 --- a/spec/collectionspace/mapper/term_handler_spec.rb +++ b/spec/collectionspace/mapper/term_handler_spec.rb @@ -4,7 +4,7 @@ RSpec.describe CollectionSpace::Mapper::TermHandler do before(:all) do - @config = Mapper::DEFAULT_CONFIG + @config = CollectionSpace::Mapper::DEFAULT_CONFIG @client = core_client @cache = core_cache populate_core(@cache) diff --git a/spec/collectionspace/mapper/tools/dates_spec.rb b/spec/collectionspace/mapper/tools/dates_spec.rb index 6a78e8d5..934f876b 100644 --- a/spec/collectionspace/mapper/tools/dates_spec.rb +++ b/spec/collectionspace/mapper/tools/dates_spec.rb @@ -6,7 +6,7 @@ before(:all) do @client = anthro_client @cache = anthro_cache - @config = Mapper::DEFAULT_CONFIG + @config = CollectionSpace::Mapper::DEFAULT_CONFIG end describe Dates::CspaceDate do diff --git a/spec/collectionspace/mapper_spec.rb b/spec/collectionspace/mapper_spec.rb index 0e0ec5e2..352cfa4a 100644 --- a/spec/collectionspace/mapper_spec.rb +++ b/spec/collectionspace/mapper_spec.rb @@ -22,19 +22,19 @@ end describe '#setup_data' do - context 'when passed a Mapper::Response' do + context 'when passed a CollectionSpace::Mapper::Response' do it 'returns that Response' do response = Response.new({ 'objectNumber'=>'123' }) - expect(Mapper::setup_data(response)).to eq(response) + expect(CollectionSpace::Mapper::setup_data(response)).to eq(response) end end context 'when passed a Hash' do before(:all) do @data = { 'objectNumber'=>'123' } - @response = Mapper::setup_data(@data) + @response = CollectionSpace::Mapper::setup_data(@data) end - it 'returns a Mapper::Response' do - expect(@response).to be_a(Mapper::Response) + it 'returns a CollectionSpace::Mapper::Response' do + expect(@response).to be_a(CollectionSpace::Mapper::Response) end it 'sets Hash as Response.orig_data' do expect(@response.orig_data).to eq(@data) @@ -43,10 +43,10 @@ context 'when passed other class of object' do before(:all) do @data = ['objectNumber', '123'] - @response = Mapper::setup_data(@data) + @response = CollectionSpace::Mapper::setup_data(@data) end - it 'returns a Mapper::Response' do - expect(@response).to be_a(Mapper::Response) + it 'returns a CollectionSpace::Mapper::Response' do + expect(@response).to be_a(CollectionSpace::Mapper::Response) end it 'sets data passed as Response.orig_data' do expect(@response.orig_data).to eq(@data) From ec6501964b8c9186a4fcdfa258a72c7c1f85bad7 Mon Sep 17 00:00:00 2001 From: Kristina Spurgin Date: Mon, 28 Sep 2020 10:44:42 -0400 Subject: [PATCH 2/3] Mapper extend self --- lib/collectionspace/mapper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/collectionspace/mapper.rb b/lib/collectionspace/mapper.rb index 8caefb9c..bdd8f591 100644 --- a/lib/collectionspace/mapper.rb +++ b/lib/collectionspace/mapper.rb @@ -15,6 +15,7 @@ module CollectionSpace module Mapper + extend self LOGGER = Logger.new(STDERR) DEFAULT_CONFIG = { delimiter: ';', subgroup_delimiter: '^^', @@ -50,7 +51,7 @@ def initialize(message, input) end end - def self.setup_data(data) + def setup_data(data) if data.is_a?(Hash) Response.new(data) elsif data.is_a?(CollectionSpace::Mapper::Response) From aa0bbc21e351f3395dfab2c094fec7d0067fb7a1 Mon Sep 17 00:00:00 2001 From: Kristina Spurgin Date: Mon, 28 Sep 2020 12:45:45 -0400 Subject: [PATCH 3/3] remove aliases to global namespace --- lib/collectionspace/mapper/data_handler.rb | 23 +++--- lib/collectionspace/mapper/data_mapper.rb | 3 +- lib/collectionspace/mapper/data_prepper.rb | 25 +++--- .../mapper/data_quality_checker.rb | 1 - lib/collectionspace/mapper/data_splitter.rb | 3 - lib/collectionspace/mapper/data_validator.rb | 3 +- lib/collectionspace/mapper/map_result.rb | 21 ----- lib/collectionspace/mapper/response.rb | 1 - lib/collectionspace/mapper/term_handler.rb | 3 +- lib/collectionspace/mapper/tools/config.rb | 16 ++-- lib/collectionspace/mapper/tools/dates.rb | 3 - .../mapper/tools/identifiers.rb | 1 - .../mapper/tools/record_mapper.rb | 1 - lib/collectionspace/mapper/tools/refname.rb | 3 +- .../mapper/value_transformer.rb | 1 - lib/collectionspace/mapper/version.rb | 2 +- .../mapper/data_handler_spec.rb | 18 ++--- .../mapper/data_mapper_anthro_spec.rb | 18 ++--- .../mapper/data_mapper_bonsai_spec.rb | 6 +- .../mapper/data_mapper_botgarden_spec.rb | 18 ++--- .../mapper/data_mapper_core_spec.rb | 78 +++++++++---------- .../mapper/data_mapper_spec.rb | 30 +++---- .../mapper/data_prepper_spec.rb | 26 +++---- .../mapper/data_quality_checker_spec.rb | 4 +- .../mapper/data_splitter_spec.rb | 20 ++--- .../mapper/data_validator_spec.rb | 4 +- spec/collectionspace/mapper/response_spec.rb | 2 +- .../mapper/term_handler_spec.rb | 10 +-- .../mapper/tools/dates_spec.rb | 14 ++-- .../mapper/tools/identifiers_spec.rb | 4 +- .../mapper/tools/refname_spec.rb | 4 +- .../mapper/value_transformer_spec.rb | 6 +- spec/collectionspace/mapper_spec.rb | 2 +- 33 files changed, 167 insertions(+), 207 deletions(-) delete mode 100644 lib/collectionspace/mapper/map_result.rb diff --git a/lib/collectionspace/mapper/data_handler.rb b/lib/collectionspace/mapper/data_handler.rb index 051184ae..51ee595a 100644 --- a/lib/collectionspace/mapper/data_handler.rb +++ b/lib/collectionspace/mapper/data_handler.rb @@ -5,14 +5,13 @@ module Mapper # given a RecordMapper hash and a data hash, returns CollectionSpace XML document class DataHandler - ::DataHandler = CollectionSpace::Mapper::DataHandler attr_reader :mapper, :client, :cache, :config, :blankdoc, :defaults, :validator, :is_authority, :known_fields def initialize(record_mapper, client, cache, - config = Mapper::DEFAULT_CONFIG + config = CollectionSpace::Mapper::DEFAULT_CONFIG ) - @mapper = RecordMapper.convert(record_mapper) + @mapper = CollectionSpace::Mapper::Tools::RecordMapper.convert(record_mapper) @client = client @cache = cache @config = get_config(config) @@ -24,15 +23,15 @@ def initialize(record_mapper, client, cache, @blankdoc = build_xml @defaults = @config[:default_values] ? @config[:default_values].transform_keys(&:downcase) : {} merge_config_transforms - @validator = DataValidator.new(@mapper, @cache) + @validator = CollectionSpace::Mapper::DataValidator.new(@mapper, @cache) end def process(data) - response = Mapper::setup_data(data) + response = CollectionSpace::Mapper::setup_data(data) if response.valid? - prepper = DataPrepper.new(response, self) + prepper = CollectionSpace::Mapper::DataPrepper.new(response, self) prepper.prep - mapper = DataMapper.new(prepper.response, self, prepper.xphash) + mapper = CollectionSpace::Mapper::DataMapper.new(prepper.response, self, prepper.xphash) @response_mode == 'normal' ? mapper.response.normal : mapper.response else response @@ -51,9 +50,9 @@ def validate(data) end def prep(data) - response = Mapper::setup_data(data) + response = CollectionSpace::Mapper::setup_data(data) if response.valid? - prepper = DataPrepper.new(response, self) + prepper = CollectionSpace::Mapper::DataPrepper.new(response, self) prepper.split_data prepper.transform_data prepper.check_data @@ -65,14 +64,14 @@ def prep(data) end def map(response, xphash) - mapper = DataMapper.new(response, self, xphash) + mapper = CollectionSpace::Mapper::DataMapper.new(response, self, xphash) @response_mode == 'normal' ? mapper.response.normal : mapper.response end private def get_config(config) - config_object = Config.new(config) + config_object = CollectionSpace::Mapper::Tools::Config.new(config) config_object.hash end @@ -97,7 +96,7 @@ def get_is_authority end # you can specify per-data-key transforms in your config.json - # This method merges the config.json transforms into the RecordMapper field + # This method merges the config.json transforms into the CollectionSpace::Mapper::RecordMapper field # mappings for the appropriate fields def merge_config_transforms return unless @config[:transforms] diff --git a/lib/collectionspace/mapper/data_mapper.rb b/lib/collectionspace/mapper/data_mapper.rb index 91b0326b..5f9afd01 100644 --- a/lib/collectionspace/mapper/data_mapper.rb +++ b/lib/collectionspace/mapper/data_mapper.rb @@ -3,7 +3,6 @@ module CollectionSpace module Mapper class DataMapper - ::DataMapper = CollectionSpace::Mapper::DataMapper attr_reader :handler, :xphash attr_accessor :doc, :response def initialize(response, handler, xphash) @@ -39,7 +38,7 @@ def add_short_id .first targetnode = @doc.xpath("/document/#{ns}").first child = Nokogiri::XML::Node.new('shortIdentifier', @doc) - child.content = Identifiers.short_identifier(term, :authority) + child.content = CollectionSpace::Mapper::Tools::Identifiers.short_identifier(term, :authority) targetnode.add_child(child) end diff --git a/lib/collectionspace/mapper/data_prepper.rb b/lib/collectionspace/mapper/data_prepper.rb index 6dbaad5e..754f475e 100644 --- a/lib/collectionspace/mapper/data_prepper.rb +++ b/lib/collectionspace/mapper/data_prepper.rb @@ -3,14 +3,13 @@ module CollectionSpace module Mapper class DataPrepper - ::DataPrepper = CollectionSpace::Mapper::DataPrepper attr_reader :data, :handler, :config attr_accessor :response, :xphash def initialize(data, handler) @handler = handler @config = @handler.config @cache = @handler.cache - @response = Mapper::setup_data(data) + @response = CollectionSpace::Mapper::setup_data(data) if @response.valid? @data = @response.orig_data.transform_keys(&:downcase) @response.merged_data = merge_default_values @@ -97,21 +96,21 @@ def do_splits(xpath, xphash) column = mapping[:datacolumn] data = @response.merged_data.fetch(column, nil) next if data.nil? || data.empty? - @response.split_data[column] = mapping[:repeats] == 'y' ? SimpleSplitter.new(data, @config).result : [data.strip] + @response.split_data[column] = mapping[:repeats] == 'y' ? CollectionSpace::Mapper::SimpleSplitter.new(data, @config).result : [data.strip] end elsif xphash[:is_group] == true && xphash[:is_subgroup] == false xphash[:mappings].each do |mapping| column = mapping[:datacolumn] data = @response.merged_data.fetch(column, nil) next if data.nil? || data.empty? - @response.split_data[column] = SimpleSplitter.new(data, @config).result + @response.split_data[column] = CollectionSpace::Mapper::SimpleSplitter.new(data, @config).result end elsif xphash[:is_group] && xphash[:is_subgroup] xphash[:mappings].each do |mapping| column = mapping[:datacolumn] data = @response.merged_data.fetch(column, nil) next if data.nil? || data.empty? - @response.split_data[column] = SubgroupSplitter.new(data, @config).result + @response.split_data[column] = CollectionSpace::Mapper::SubgroupSplitter.new(data, @config).result end end end @@ -128,9 +127,9 @@ def do_transforms(xpath, xphash) else targetdata[column] = data.map do |d| if d.is_a?(String) - ValueTransformer.new(d, mapping[:transforms], @cache).result + CollectionSpace::Mapper::ValueTransformer.new(d, mapping[:transforms], @cache).result else - d.map{ |val| ValueTransformer.new(val, mapping[:transforms], @cache).result} + d.map{ |val| CollectionSpace::Mapper::ValueTransformer.new(val, mapping[:transforms], @cache).result} end end end @@ -170,7 +169,7 @@ def do_term_handling(xpath, xphash) data = sourcedata.fetch(column, nil) next if data.blank? - th = TermHandler.new(mapping, data, @cache) + th = CollectionSpace::Mapper::TermHandler.new(mapping, data, @cache) @response.transformed_data[column] = th.result @response.terms << th.terms end @@ -190,9 +189,9 @@ def get_source_type(source_type_string) def structured_date_transform(data) data.map do |d| if d.is_a?(String) - CspaceDate.new(d, @handler.client, @handler.cache, @config).mappable + CollectionSpace::Mapper::Tools::Dates::CspaceDate.new(d, @handler.client, @handler.cache, @config).mappable else - d.map{ |v| CspaceDate.new(v, @handler.client, @handler.cache, @config).mappable } + d.map{ |v| CollectionSpace::Mapper::Tools::Dates::CspaceDate.new(v, @handler.client, @handler.cache, @config).mappable } end end end @@ -200,9 +199,9 @@ def structured_date_transform(data) def unstructured_date_transform(data) data.map do |d| if d.is_a?(String) - CspaceDate.new(d, @handler.client, @handler.cache, @config).stamp + CollectionSpace::Mapper::Tools::Dates::CspaceDate.new(d, @handler.client, @handler.cache, @config).stamp else - d.map{ |v| CspaceDate.new(v, @handler.client, @handler.cache, @config).stamp } + d.map{ |v| CollectionSpace::Mapper::Tools::Dates::CspaceDate.new(v, @handler.client, @handler.cache, @config).stamp } end end end @@ -212,7 +211,7 @@ def check_data_quality(xpath, xphash) xphash[:mappings].each do |mapping| data = xformdata[mapping[:datacolumn]] next if data.blank? - qc = DataQualityChecker.new(mapping, data) + qc = CollectionSpace::Mapper::DataQualityChecker.new(mapping, data) @response.warnings << qc.warnings unless qc.warnings.empty? end end diff --git a/lib/collectionspace/mapper/data_quality_checker.rb b/lib/collectionspace/mapper/data_quality_checker.rb index 4655f121..1dc85c1e 100644 --- a/lib/collectionspace/mapper/data_quality_checker.rb +++ b/lib/collectionspace/mapper/data_quality_checker.rb @@ -3,7 +3,6 @@ module CollectionSpace module Mapper class DataQualityChecker - ::DataQualityChecker = CollectionSpace::Mapper::DataQualityChecker attr_reader :mapping, :data, :warnings, :terms def initialize(mapping, data) @mapping = mapping diff --git a/lib/collectionspace/mapper/data_splitter.rb b/lib/collectionspace/mapper/data_splitter.rb index ba2fc5c7..d1fb1a5f 100644 --- a/lib/collectionspace/mapper/data_splitter.rb +++ b/lib/collectionspace/mapper/data_splitter.rb @@ -3,7 +3,6 @@ module CollectionSpace module Mapper class DataSplitter - ::DataSplitter = CollectionSpace::Mapper::DataSplitter attr_reader :data, :result def initialize(data, config) @data = data.strip @@ -14,7 +13,6 @@ def initialize(data, config) end class SimpleSplitter < DataSplitter - ::SimpleSplitter = CollectionSpace::Mapper::SimpleSplitter def initialize(data, config) super # negative limit parameter turns off suppression of trailing empty fields @@ -23,7 +21,6 @@ def initialize(data, config) end class SubgroupSplitter < DataSplitter - ::SubgroupSplitter = CollectionSpace::Mapper::SubgroupSplitter def initialize(data, config) super # negative limit parameter turns off suppression of trailing empty fields diff --git a/lib/collectionspace/mapper/data_validator.rb b/lib/collectionspace/mapper/data_validator.rb index f3430b43..9d1125b4 100644 --- a/lib/collectionspace/mapper/data_validator.rb +++ b/lib/collectionspace/mapper/data_validator.rb @@ -3,7 +3,6 @@ module CollectionSpace module Mapper class DataValidator - ::DataValidator = CollectionSpace::Mapper::DataValidator attr_reader :mapper, :cache, :required_fields def initialize(record_mapper, cache) @mapper = record_mapper @@ -14,7 +13,7 @@ def initialize(record_mapper, cache) end def validate(data) - response = Mapper::setup_data(data) + response = CollectionSpace::Mapper::setup_data(data) if response.valid? data = data.transform_keys(&:downcase) res = check_required_fields(data) unless @required_fields.empty? diff --git a/lib/collectionspace/mapper/map_result.rb b/lib/collectionspace/mapper/map_result.rb deleted file mode 100644 index 1bbb532a..00000000 --- a/lib/collectionspace/mapper/map_result.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -module CollectionSpace - module Mapper - class MapResult - ::MapResult = CollectionSpace::Mapper::MapResult - attr_reader :orig_data - attr_accessor :split_data, :merged_data, :transformed_data, :combined_data, :doc, :warnings - def initialize(data_hash:) - @orig_data = data_hash - @merged_data = {} - @split_data = {} - @transformed_data = {} - @combined_data = {} - @doc = nil - @warnings = [] - end - end - end -end - diff --git a/lib/collectionspace/mapper/response.rb b/lib/collectionspace/mapper/response.rb index 24bda6f3..0834f8be 100644 --- a/lib/collectionspace/mapper/response.rb +++ b/lib/collectionspace/mapper/response.rb @@ -3,7 +3,6 @@ module CollectionSpace module Mapper class Response - ::Response = CollectionSpace::Mapper::Response attr_reader :orig_data attr_accessor :split_data, :merged_data, :transformed_data, :combined_data, :doc, :errors, :warnings, :identifier, :terms def initialize(data_hash) diff --git a/lib/collectionspace/mapper/term_handler.rb b/lib/collectionspace/mapper/term_handler.rb index 4b9ed08e..b2bab461 100644 --- a/lib/collectionspace/mapper/term_handler.rb +++ b/lib/collectionspace/mapper/term_handler.rb @@ -3,7 +3,6 @@ module CollectionSpace module Mapper class TermHandler - ::TermHandler = CollectionSpace::Mapper::TermHandler attr_reader :result, :terms def initialize(mapping, data, cache) @mapping = mapping @@ -52,7 +51,7 @@ def handle_term(val) refname else @terms << term_report.merge({ found: false }) - RefName.build(@source_type, @type, @subtype, val, @cache) + CollectionSpace::Mapper::Tools::RefName.build(@source_type, @type, @subtype, val, @cache) end end end diff --git a/lib/collectionspace/mapper/tools/config.rb b/lib/collectionspace/mapper/tools/config.rb index ca24a45f..c5c57128 100644 --- a/lib/collectionspace/mapper/tools/config.rb +++ b/lib/collectionspace/mapper/tools/config.rb @@ -3,7 +3,6 @@ module CollectionSpace module Mapper module Errors - ::Errors = CollectionSpace::Mapper::Errors class ConfigKeyMissingError < StandardError attr_reader :keys def initialize(message, keys) @@ -17,7 +16,6 @@ class ConfigResponseModeError < StandardError; end module Tools class Config - ::Config = CollectionSpace::Mapper::Tools::Config attr_reader :hash def initialize(hash) @hash = hash @@ -31,18 +29,18 @@ def validate has_required_keys rescue => error error.keys.each do |key| - value = Mapper::DEFAULT_CONFIG[key] + value = CollectionSpace::Mapper::DEFAULT_CONFIG[key] @hash[key] = value - Mapper::LOGGER.warn("#{error.message}: #{key}. Set to: #{value}") + CollectionSpace::Mapper::LOGGER.warn("#{error.message}: #{key}. Set to: #{value}") end end begin valid_response_mode rescue => error - replacement_value = Mapper::DEFAULT_CONFIG[:response_mode] + replacement_value = CollectionSpace::Mapper::DEFAULT_CONFIG[:response_mode] @hash[:response_mode] = replacement_value - Mapper::LOGGER.warn("#{error.message}. Reset to: #{replacement_value}") + CollectionSpace::Mapper::LOGGER.warn("#{error.message}. Reset to: #{replacement_value}") end end @@ -52,15 +50,15 @@ def valid_response_mode valid = %w[normal verbose] value = @hash[:response_mode] unless valid.any?(value) - raise Errors::ConfigResponseModeError.new("Invalid response_mode value in config: #{value}") + raise CollectionSpace::Mapper::Errors::ConfigResponseModeError.new("Invalid response_mode value in config: #{value}") end end def has_required_keys - required_keys = Mapper::DEFAULT_CONFIG.keys + required_keys = CollectionSpace::Mapper::DEFAULT_CONFIG.keys remaining_keys = required_keys - @hash.keys unless remaining_keys.empty? - raise Errors::ConfigKeyMissingError.new('Config missing key', remaining_keys) + raise CollectionSpace::Mapper::Errors::ConfigKeyMissingError.new('Config missing key', remaining_keys) end end end diff --git a/lib/collectionspace/mapper/tools/dates.rb b/lib/collectionspace/mapper/tools/dates.rb index c43dd47a..eeb28bcd 100644 --- a/lib/collectionspace/mapper/tools/dates.rb +++ b/lib/collectionspace/mapper/tools/dates.rb @@ -8,11 +8,9 @@ module CollectionSpace module Mapper module Tools module Dates - ::Dates = CollectionSpace::Mapper::Tools::Dates extend self class CspaceDate - ::CspaceDate = CollectionSpace::Mapper::Tools::Dates::CspaceDate attr_reader :date_string, :client, :cache, :config, :timestamp, :mappable, :stamp def initialize(date_string, client, cache, config) @@ -65,7 +63,6 @@ def try_services_query def map(doc, parentnode, groupname) @parser_result.each do |datefield, value| value = DateTime.parse(value).iso8601(3).sub('+00:00', "Z") if datefield['ScalarValue'] - end end end diff --git a/lib/collectionspace/mapper/tools/identifiers.rb b/lib/collectionspace/mapper/tools/identifiers.rb index c6bd0065..ca8b1bcb 100644 --- a/lib/collectionspace/mapper/tools/identifiers.rb +++ b/lib/collectionspace/mapper/tools/identifiers.rb @@ -4,7 +4,6 @@ module CollectionSpace module Mapper module Tools module Identifiers - ::Identifiers = CollectionSpace::Mapper::Tools::Identifiers extend self def short_identifier(name, source_type) v = name.gsub(/\W/, '') diff --git a/lib/collectionspace/mapper/tools/record_mapper.rb b/lib/collectionspace/mapper/tools/record_mapper.rb index e8f1c6e4..85285c50 100644 --- a/lib/collectionspace/mapper/tools/record_mapper.rb +++ b/lib/collectionspace/mapper/tools/record_mapper.rb @@ -4,7 +4,6 @@ module CollectionSpace module Mapper module Tools module RecordMapper - ::RecordMapper = CollectionSpace::Mapper::Tools::RecordMapper extend self def convert(json) diff --git a/lib/collectionspace/mapper/tools/refname.rb b/lib/collectionspace/mapper/tools/refname.rb index f491ec6b..5cd62048 100644 --- a/lib/collectionspace/mapper/tools/refname.rb +++ b/lib/collectionspace/mapper/tools/refname.rb @@ -4,11 +4,10 @@ module CollectionSpace module Mapper module Tools module RefName - ::RefName = CollectionSpace::Mapper::Tools::RefName extend self def build(source_type, type, subtype, term, cache) domain = cache.domain - identifier = Identifiers.short_identifier(term, source_type) + identifier = CollectionSpace::Mapper::Tools::Identifiers.short_identifier(term, source_type) "urn:cspace:#{domain}:#{type}:name(#{subtype}):item:name(#{identifier})'#{term}'" end end diff --git a/lib/collectionspace/mapper/value_transformer.rb b/lib/collectionspace/mapper/value_transformer.rb index 8530149f..c1231985 100644 --- a/lib/collectionspace/mapper/value_transformer.rb +++ b/lib/collectionspace/mapper/value_transformer.rb @@ -3,7 +3,6 @@ module CollectionSpace module Mapper class ValueTransformer - ::ValueTransformer = CollectionSpace::Mapper::ValueTransformer attr_reader :orig, :result def initialize(value, transforms, cache) @value = value diff --git a/lib/collectionspace/mapper/version.rb b/lib/collectionspace/mapper/version.rb index f6fd9d0e..7e1c1928 100644 --- a/lib/collectionspace/mapper/version.rb +++ b/lib/collectionspace/mapper/version.rb @@ -1,5 +1,5 @@ module CollectionSpace module Mapper - VERSION = "1.2.2" + VERSION = "1.2.3" end end diff --git a/spec/collectionspace/mapper/data_handler_spec.rb b/spec/collectionspace/mapper/data_handler_spec.rb index c40d93d5..82229ef9 100644 --- a/spec/collectionspace/mapper/data_handler_spec.rb +++ b/spec/collectionspace/mapper/data_handler_spec.rb @@ -7,14 +7,14 @@ @anthro_client = anthro_client @anthro_cache = anthro_cache @anthro_object_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4_1_0-collectionobject.json') - @anthro_object_handler = DataHandler.new(@anthro_object_mapper, @anthro_client, @anthro_cache) + @anthro_object_handler = CollectionSpace::Mapper::DataHandler.new(@anthro_object_mapper, @anthro_client, @anthro_cache) @anthro_place_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4_1_0-place.json') - @anthro_place_handler = DataHandler.new(@anthro_place_mapper, @anthro_client, @anthro_cache) + @anthro_place_handler = CollectionSpace::Mapper::DataHandler.new(@anthro_place_mapper, @anthro_client, @anthro_cache) @bonsai_client = bonsai_client @bonsai_cache = bonsai_cache @bonsai_conservation_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/bonsai/bonsai_4_1_0-conservation.json') - @bonsai_conservation_handler = DataHandler.new(@bonsai_conservation_mapper, @bonsai_client, @bonsai_cache) + @bonsai_conservation_handler = CollectionSpace::Mapper::DataHandler.new(@bonsai_conservation_mapper, @bonsai_client, @bonsai_cache) end context 'when no config is passed at initialization' do @@ -63,7 +63,7 @@ end context 'collection data field' do it 'merges data field specific transforms' do - handler = DataHandler.new(@anthro_object_mapper, @anthro_client, @anthro_cache, @config) + handler = CollectionSpace::Mapper::DataHandler.new(@anthro_object_mapper, @anthro_client, @anthro_cache, @config) fieldmap = handler.mapper[:mappings].select{ |m| m[:fieldname] == 'collection' }.first xforms = { special: %w[downcase_value], @@ -198,7 +198,7 @@ context 'when response_mode = verbose' do it 'returned response includes detailed data transformation info' do config = CollectionSpace::Mapper::DEFAULT_CONFIG.merge({ response_mode: 'verbose' }) - handler = DataHandler.new(@anthro_object_mapper, @anthro_client, @anthro_cache, config) + handler = CollectionSpace::Mapper::DataHandler.new(@anthro_object_mapper, @anthro_client, @anthro_cache, config) result = handler.prep(@data) expect(result.transformed_data).not_to be_empty end @@ -227,7 +227,7 @@ context 'when response_mode = verbose' do it 'returned response includes detailed data transformation info' do config = CollectionSpace::Mapper::DEFAULT_CONFIG.merge({ response_mode: 'verbose' }) - handler = DataHandler.new(@anthro_object_mapper, @anthro_client, @anthro_cache, config) + handler = CollectionSpace::Mapper::DataHandler.new(@anthro_object_mapper, @anthro_client, @anthro_cache, config) result = handler.process(@data) expect(result.transformed_data).not_to be_empty end @@ -237,7 +237,7 @@ describe '#map' do before(:all) do @data = { 'objectNumber' => '123' } - prepper = DataPrepper.new(@data, @anthro_object_handler) + prepper = CollectionSpace::Mapper::DataPrepper.new(@data, @anthro_object_handler) prep_response = @anthro_object_handler.prep(@data) @result = @anthro_object_handler.map(prep_response, prepper.xphash) end @@ -257,8 +257,8 @@ context 'when response_mode = verbose' do it 'returned response includes detailed data transformation info' do config = CollectionSpace::Mapper::DEFAULT_CONFIG.merge({ response_mode: 'verbose' }) - handler = DataHandler.new(@anthro_object_mapper, @anthro_client, @anthro_cache, config) - prepper = DataPrepper.new(@data, handler) + handler = CollectionSpace::Mapper::DataHandler.new(@anthro_object_mapper, @anthro_client, @anthro_cache, config) + prepper = CollectionSpace::Mapper::DataPrepper.new(@data, handler) result = handler.map(handler.prep(@data), prepper.xphash) expect(result.transformed_data).not_to be_empty end diff --git a/spec/collectionspace/mapper/data_mapper_anthro_spec.rb b/spec/collectionspace/mapper/data_mapper_anthro_spec.rb index c2b434f4..8716e823 100644 --- a/spec/collectionspace/mapper/data_mapper_anthro_spec.rb +++ b/spec/collectionspace/mapper/data_mapper_anthro_spec.rb @@ -21,13 +21,13 @@ # Problem in claimantGroupList before(:all) do @claimmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4_1_0-claim.json') - @handler = DataHandler.new(@claimmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(@claimmapper, @client, @cache, @config) end context 'record 1' do before(:all) do @datahash = get_datahash(path: 'spec/fixtures/files/datahashes/anthro/claim1.json') - @prepper = DataPrepper.new(@datahash, @handler) - @mapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @prepper = CollectionSpace::Mapper::DataPrepper.new(@datahash, @handler) + @mapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) @mapped_doc = remove_namespaces(@mapper.response.doc) @mapped_xpaths = list_xpaths(@mapped_doc) @fixture_doc = get_xml_fixture('anthro/claim1.xml') @@ -52,15 +52,15 @@ context 'collectionobject record' do before(:all) do @collectionobjectmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4_1_0-collectionobject.json') - @handler = DataHandler.new(@collectionobjectmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(@collectionobjectmapper, @client, @cache, @config) end # record 1 was used for testing default value merging, transformations, etc. # we start with record 2 to purely test mapping functionality context 'record 2' do before(:all) do @datahash = get_datahash(path: 'spec/fixtures/files/datahashes/anthro/collectionobject2.json') - @prepper = DataPrepper.new(@datahash, @handler) - @mapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @prepper = CollectionSpace::Mapper::DataPrepper.new(@datahash, @handler) + @mapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) @mapped_doc = remove_namespaces(@mapper.response.doc) @mapped_xpaths = list_xpaths(@mapped_doc) @fixture_doc = get_xml_fixture('anthro/collectionobject1.xml') @@ -84,13 +84,13 @@ context 'osteology record' do before(:all) do @osteologymapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4_1_0-osteology.json') - @handler = DataHandler.new(@osteologymapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(@osteologymapper, @client, @cache, @config) end context 'record 1' do before(:all) do @datahash = get_datahash(path: 'spec/fixtures/files/datahashes/anthro/osteology1.json') - @prepper = DataPrepper.new(@datahash, @handler) - @mapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @prepper = CollectionSpace::Mapper::DataPrepper.new(@datahash, @handler) + @mapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) @mapped_doc = remove_namespaces(@mapper.response.doc) @mapped_xpaths = list_xpaths(@mapped_doc) @fixture_doc = get_xml_fixture('anthro/osteology1.xml') diff --git a/spec/collectionspace/mapper/data_mapper_bonsai_spec.rb b/spec/collectionspace/mapper/data_mapper_bonsai_spec.rb index 646260ca..886131e5 100644 --- a/spec/collectionspace/mapper/data_mapper_bonsai_spec.rb +++ b/spec/collectionspace/mapper/data_mapper_bonsai_spec.rb @@ -17,14 +17,14 @@ context 'objectexit record' do before(:all) do @objectexitmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/bonsai/bonsai_4_1_0-objectexit.json') - @handler = DataHandler.new(@objectexitmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(@objectexitmapper, @client, @cache, @config) end context 'record 1' do before(:all) do @datahash = get_datahash(path: 'spec/fixtures/files/datahashes/bonsai/objectexit1.json') - @prepper = DataPrepper.new(@datahash, @handler) - @mapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @prepper = CollectionSpace::Mapper::DataPrepper.new(@datahash, @handler) + @mapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) @mapped_doc = remove_namespaces(@mapper.response.doc) @mapped_xpaths = list_xpaths(@mapped_doc) @fixture_doc = get_xml_fixture('bonsai/objectexit1.xml') diff --git a/spec/collectionspace/mapper/data_mapper_botgarden_spec.rb b/spec/collectionspace/mapper/data_mapper_botgarden_spec.rb index b78ce9f5..5e4c14a1 100644 --- a/spec/collectionspace/mapper/data_mapper_botgarden_spec.rb +++ b/spec/collectionspace/mapper/data_mapper_botgarden_spec.rb @@ -17,14 +17,14 @@ context 'pottag record' do before(:all) do @pottag_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/botgarden/botgarden_1_1_0-pottag.json') - @pottag_handler = DataHandler.new(@pottag_mapper, @client, @cache, @config) + @pottag_handler = CollectionSpace::Mapper::DataHandler.new(@pottag_mapper, @client, @cache, @config) end context 'record 1' do before(:all) do @datahash = get_datahash(path: 'spec/fixtures/files/datahashes/botgarden/pottag1.json') - @prepper = DataPrepper.new(@datahash, @pottag_handler) - @mapper = DataMapper.new(@prepper.prep, @pottag_handler, @prepper.xphash) + @prepper = CollectionSpace::Mapper::DataPrepper.new(@datahash, @pottag_handler) + @mapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @pottag_handler, @prepper.xphash) @mapped_doc = remove_namespaces(@mapper.response.doc) @mapped_xpaths = list_xpaths(@mapped_doc) @fixture_doc = get_xml_fixture('botgarden/pottag1.xml') @@ -48,14 +48,14 @@ context 'propagation record' do before(:all) do @propagation_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/botgarden/botgarden_1_1_0-propagation.json') - @propagation_handler = DataHandler.new(@propagation_mapper, @client, @cache, @config) + @propagation_handler = CollectionSpace::Mapper::DataHandler.new(@propagation_mapper, @client, @cache, @config) end context 'record 1' do before(:all) do @datahash = get_datahash(path: 'spec/fixtures/files/datahashes/botgarden/propagation1.json') - @prepper = DataPrepper.new(@datahash, @propagation_handler) - @mapper = DataMapper.new(@prepper.prep, @propagation_handler, @prepper.xphash) + @prepper = CollectionSpace::Mapper::DataPrepper.new(@datahash, @propagation_handler) + @mapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @propagation_handler, @prepper.xphash) @mapped_doc = remove_namespaces(@mapper.response.doc) @mapped_xpaths = list_xpaths(@mapped_doc) @fixture_doc = get_xml_fixture('botgarden/propagation1.xml') @@ -80,14 +80,14 @@ context 'taxon record' do before(:all) do @taxon_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/botgarden/botgarden_1_1_0-taxon.json') - @taxon_handler = DataHandler.new(@taxon_mapper, @client, @cache, @config) + @taxon_handler = CollectionSpace::Mapper::DataHandler.new(@taxon_mapper, @client, @cache, @config) end context 'record 1' do before(:all) do @datahash = get_datahash(path: 'spec/fixtures/files/datahashes/botgarden/taxon1.json') - @prepper = DataPrepper.new(@datahash, @taxon_handler) - @mapper = DataMapper.new(@prepper.prep, @taxon_handler, @prepper.xphash) + @prepper = CollectionSpace::Mapper::DataPrepper.new(@datahash, @taxon_handler) + @mapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @taxon_handler, @prepper.xphash) @mapped_doc = remove_namespaces(@mapper.response.doc) @mapped_xpaths = list_xpaths(@mapped_doc) @fixture_doc = get_xml_fixture('botgarden/taxon1.xml') diff --git a/spec/collectionspace/mapper/data_mapper_core_spec.rb b/spec/collectionspace/mapper/data_mapper_core_spec.rb index 0e6e077d..74f46c08 100644 --- a/spec/collectionspace/mapper/data_mapper_core_spec.rb +++ b/spec/collectionspace/mapper/data_mapper_core_spec.rb @@ -17,14 +17,14 @@ context 'acquisition record' do before(:all) do @acquisition_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/core/core_6_1_0-acquisition.json') - @handler = DataHandler.new(@acquisition_mapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(@acquisition_mapper, @client, @cache, @config) end context 'record 1' do before(:all) do @datahash = get_datahash(path: 'spec/fixtures/files/datahashes/core/acquisition1.json') - @prepper = DataPrepper.new(@datahash, @handler) - @mapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @prepper = CollectionSpace::Mapper::DataPrepper.new(@datahash, @handler) + @mapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) @mapped_doc = remove_namespaces(@mapper.response.doc) @mapped_xpaths = list_xpaths(@mapped_doc) @fixture_doc = get_xml_fixture('core/acquisition1.xml') @@ -48,14 +48,14 @@ context 'collectionobject record' do before(:all) do @collectionobject_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/core/core_6_1_0-collectionobject.json') - @handler = DataHandler.new(@collectionobject_mapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(@collectionobject_mapper, @client, @cache, @config) end context 'record 1' do before(:all) do @datahash = get_datahash(path: 'spec/fixtures/files/datahashes/core/collectionobject1.json') - @prepper = DataPrepper.new(@datahash, @handler) - @mapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @prepper = CollectionSpace::Mapper::DataPrepper.new(@datahash, @handler) + @mapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) @mapped_doc = remove_namespaces(@mapper.response.doc) @mapped_xpaths = list_xpaths(@mapped_doc) @fixture_doc = get_xml_fixture('core/collectionobject1.xml') @@ -79,14 +79,14 @@ context 'conditioncheck record' do before(:all) do @conditioncheckmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/core/core_6_1_0-conditioncheck.json') - @handler = DataHandler.new(@conditioncheckmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(@conditioncheckmapper, @client, @cache, @config) end context 'record 1' do before(:all) do @datahash = get_datahash(path: 'spec/fixtures/files/datahashes/core/conditioncheck1.json') - @prepper = DataPrepper.new(@datahash, @handler) - @mapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @prepper = CollectionSpace::Mapper::DataPrepper.new(@datahash, @handler) + @mapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) @mapped_doc = remove_namespaces(@mapper.response.doc) @mapped_xpaths = list_xpaths(@mapped_doc) @fixture_doc = get_xml_fixture('core/conditioncheck1.xml') @@ -111,14 +111,14 @@ context 'conservation record' do before(:all) do @conservationmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/core/core_6_1_0-conservation.json') - @handler = DataHandler.new(@conservationmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(@conservationmapper, @client, @cache, @config) end context 'record 1' do before(:all) do @datahash = get_datahash(path: 'spec/fixtures/files/datahashes/core/conservation1.json') - @prepper = DataPrepper.new(@datahash, @handler) - @mapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @prepper = CollectionSpace::Mapper::DataPrepper.new(@datahash, @handler) + @mapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) @mapped_doc = remove_namespaces(@mapper.response.doc) @mapped_xpaths = list_xpaths(@mapped_doc) @fixture_doc = get_xml_fixture('core/conservation1.xml') @@ -142,14 +142,14 @@ context 'exhibition record' do before(:all) do @exhibitionmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/core/core_6_1_0-exhibition.json') - @handler = DataHandler.new(@exhibitionmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(@exhibitionmapper, @client, @cache, @config) end context 'record 1' do before(:all) do @datahash = get_datahash(path: 'spec/fixtures/files/datahashes/core/exhibition1.json') - @prepper = DataPrepper.new(@datahash, @handler) - @mapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @prepper = CollectionSpace::Mapper::DataPrepper.new(@datahash, @handler) + @mapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) @mapped_doc = remove_namespaces(@mapper.response.doc) @mapped_xpaths = list_xpaths(@mapped_doc) @fixture_doc = get_xml_fixture('core/exhibition1.xml') @@ -173,14 +173,14 @@ context 'group record' do before(:all) do @groupmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/core/core_6_1_0-group.json') - @handler = DataHandler.new(@groupmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(@groupmapper, @client, @cache, @config) end context 'record 1' do before(:all) do @datahash = get_datahash(path: 'spec/fixtures/files/datahashes/core/group1.json') - @prepper = DataPrepper.new(@datahash, @handler) - @mapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @prepper = CollectionSpace::Mapper::DataPrepper.new(@datahash, @handler) + @mapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) @mapped_doc = remove_namespaces(@mapper.response.doc) @mapped_xpaths = list_xpaths(@mapped_doc) @fixture_doc = get_xml_fixture('core/group1.xml') @@ -204,14 +204,14 @@ context 'intake record' do before(:all) do @intakemapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/core/core_6_1_0-intake.json') - @handler = DataHandler.new(@intakemapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(@intakemapper, @client, @cache, @config) end context 'record 1' do before(:all) do @datahash = get_datahash(path: 'spec/fixtures/files/datahashes/core/intake1.json') - @prepper = DataPrepper.new(@datahash, @handler) - @mapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @prepper = CollectionSpace::Mapper::DataPrepper.new(@datahash, @handler) + @mapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) @mapped_doc = remove_namespaces(@mapper.response.doc) @mapped_xpaths = list_xpaths(@mapped_doc) @fixture_doc = get_xml_fixture('core/intake1.xml') @@ -235,14 +235,14 @@ context 'loanin record' do before(:all) do @rm_core_co = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/core/core_6_1_0-loanin.json') - @handler = DataHandler.new(@rm_core_co, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(@rm_core_co, @client, @cache, @config) end context 'record 1' do before(:all) do @datahash = get_datahash(path: 'spec/fixtures/files/datahashes/core/loanin1.json') - @prepper = DataPrepper.new(@datahash, @handler) - @mapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @prepper = CollectionSpace::Mapper::DataPrepper.new(@datahash, @handler) + @mapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) @mapped_doc = remove_namespaces(@mapper.response.doc) @mapped_xpaths = list_xpaths(@mapped_doc) @fixture_doc = get_xml_fixture('core/loanin1.xml') @@ -266,14 +266,14 @@ context 'loanout record' do before(:all) do @loanoutmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/core/core_6_1_0-loanout.json') - @handler = DataHandler.new(@loanoutmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(@loanoutmapper, @client, @cache, @config) end context 'record 1' do before(:all) do @datahash = get_datahash(path: 'spec/fixtures/files/datahashes/core/loanout1.json') - @prepper = DataPrepper.new(@datahash, @handler) - @mapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @prepper = CollectionSpace::Mapper::DataPrepper.new(@datahash, @handler) + @mapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) @mapped_doc = remove_namespaces(@mapper.response.doc) @mapped_xpaths = list_xpaths(@mapped_doc) @fixture_doc = get_xml_fixture('core/loanout1.xml') @@ -296,14 +296,14 @@ context 'movement record' do before(:all) do @movementmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/core/core_6_1_0-movement.json') - @handler = DataHandler.new(@movementmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(@movementmapper, @client, @cache, @config) end context 'record 1' do before(:all) do @datahash = get_datahash(path: 'spec/fixtures/files/datahashes/core/movement1.json') - @prepper = DataPrepper.new(@datahash, @handler) - @mapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @prepper = CollectionSpace::Mapper::DataPrepper.new(@datahash, @handler) + @mapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) @mapped_doc = remove_namespaces(@mapper.response.doc) @mapped_xpaths = list_xpaths(@mapped_doc) @fixture_doc = get_xml_fixture('core/movement1.xml') @@ -327,14 +327,14 @@ context 'media record' do before(:all) do @movementmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/core/core_6_1_0-media.json') - @handler = DataHandler.new(@movementmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(@movementmapper, @client, @cache, @config) end context 'record 1' do before(:all) do @datahash = get_datahash(path: 'spec/fixtures/files/datahashes/core/media1.json') - @prepper = DataPrepper.new(@datahash, @handler) - @mapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @prepper = CollectionSpace::Mapper::DataPrepper.new(@datahash, @handler) + @mapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) @mapped_doc = remove_namespaces(@mapper.response.doc) @mapped_xpaths = list_xpaths(@mapped_doc) @fixture_doc = get_xml_fixture('core/media1.xml') @@ -358,14 +358,14 @@ context 'objectexit record' do before(:all) do @objectexitmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/core/core_6_1_0-objectexit.json') - @handler = DataHandler.new(@objectexitmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(@objectexitmapper, @client, @cache, @config) end context 'record 1' do before(:all) do @datahash = get_datahash(path: 'spec/fixtures/files/datahashes/core/objectexit1.json') - @prepper = DataPrepper.new(@datahash, @handler) - @mapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @prepper = CollectionSpace::Mapper::DataPrepper.new(@datahash, @handler) + @mapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) @mapped_doc = remove_namespaces(@mapper.response.doc) @mapped_xpaths = list_xpaths(@mapped_doc) @fixture_doc = get_xml_fixture('core/objectexit1.xml') @@ -390,14 +390,14 @@ context 'uoc record' do before(:all) do @uocmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/core/core_6_1_0-uoc.json') - @handler = DataHandler.new(@uocmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(@uocmapper, @client, @cache, @config) end context 'record 1' do before(:all) do @datahash = get_datahash(path: 'spec/fixtures/files/datahashes/core/uoc1.json') - @prepper = DataPrepper.new(@datahash, @handler) - @mapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @prepper = CollectionSpace::Mapper::DataPrepper.new(@datahash, @handler) + @mapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) @mapped_doc = remove_namespaces(@mapper.response.doc) @mapped_xpaths = list_xpaths(@mapped_doc) @fixture_doc = get_xml_fixture('core/uoc1.xml') diff --git a/spec/collectionspace/mapper/data_mapper_spec.rb b/spec/collectionspace/mapper/data_mapper_spec.rb index 04b969be..b371dc00 100644 --- a/spec/collectionspace/mapper/data_mapper_spec.rb +++ b/spec/collectionspace/mapper/data_mapper_spec.rb @@ -15,9 +15,9 @@ context 'person record' do before(:all) do @recmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/lhmc/lhmc_3_1_0-person.json') - @handler = DataHandler.new(@recmapper, @client, @cache, @config) - @prepper = DataPrepper.new({'termDisplayName' => 'Xanadu', 'placeNote' => 'note'}, @handler) - @datamapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @handler = CollectionSpace::Mapper::DataHandler.new(@recmapper, @client, @cache, @config) + @prepper = CollectionSpace::Mapper::DataPrepper.new({'termDisplayName' => 'Xanadu', 'placeNote' => 'note'}, @handler) + @datamapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) @mapped_doc = remove_namespaces(@datamapper.response.doc) end @@ -56,9 +56,9 @@ context 'loanout record' do before(:all) do @recmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/botgarden/botgarden_1_1_0-loanout.json') - @handler = DataHandler.new(@recmapper, @client, @cache, @config) - @prepper = DataPrepper.new({'loanOutNumber' => '123', 'sterile' => 'n'}, @handler) - @datamapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @handler = CollectionSpace::Mapper::DataHandler.new(@recmapper, @client, @cache, @config) + @prepper = CollectionSpace::Mapper::DataPrepper.new({'loanOutNumber' => '123', 'sterile' => 'n'}, @handler) + @datamapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) end describe '#set_response_identifier' do @@ -79,9 +79,9 @@ context 'place record' do before(:all) do @recmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4_1_0-place.json') - @handler = DataHandler.new(@recmapper, @client, @cache, @config) - @prepper = DataPrepper.new({'termDisplayName' => 'Xanadu'}, @handler) - @datamapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @handler = CollectionSpace::Mapper::DataHandler.new(@recmapper, @client, @cache, @config) + @prepper = CollectionSpace::Mapper::DataPrepper.new({'termDisplayName' => 'Xanadu'}, @handler) + @datamapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) end describe '#add_short_id' do @@ -115,9 +115,9 @@ }) @recmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4_1_0-collectionobject.json') - @handler = DataHandler.new(@recmapper, @client, @cache, config) - @prepper = DataPrepper.new(anthro_co_1, @handler) - @datamapper = DataMapper.new(@prepper.prep, @handler, @prepper.xphash) + @handler = CollectionSpace::Mapper::DataHandler.new(@recmapper, @client, @cache, config) + @prepper = CollectionSpace::Mapper::DataPrepper.new(anthro_co_1, @handler) + @datamapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) end describe '#doc' do @@ -160,10 +160,10 @@ cache = botgarden_cache populate_botgarden(cache) prop_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/botgarden/botgarden_1_1_0-propagation.json') - prop_handler = DataHandler.new(prop_mapper, client, cache, CollectionSpace::Mapper::DEFAULT_CONFIG) + prop_handler = CollectionSpace::Mapper::DataHandler.new(prop_mapper, client, cache, CollectionSpace::Mapper::DEFAULT_CONFIG) datahash = get_datahash(path: 'spec/fixtures/files/datahashes/botgarden/propagation1.json') - prepper = DataPrepper.new(datahash, prop_handler) - mapper = DataMapper.new(prepper.prep, prop_handler, prepper.xphash) + prepper = CollectionSpace::Mapper::DataPrepper.new(datahash, prop_handler) + mapper = CollectionSpace::Mapper::DataMapper.new(prepper.prep, prop_handler, prepper.xphash) end end end diff --git a/spec/collectionspace/mapper/data_prepper_spec.rb b/spec/collectionspace/mapper/data_prepper_spec.rb index 3aeec11c..f2bd7400 100644 --- a/spec/collectionspace/mapper/data_prepper_spec.rb +++ b/spec/collectionspace/mapper/data_prepper_spec.rb @@ -32,14 +32,14 @@ }) @collectionobject_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4_1_0-collectionobject.json') - @handler = DataHandler.new(@collectionobject_mapper, @client, @cache, @collectionobject_config) - @prepper = DataPrepper.new(anthro_co_1, @handler) + @handler = CollectionSpace::Mapper::DataHandler.new(@collectionobject_mapper, @client, @cache, @collectionobject_config) + @prepper = CollectionSpace::Mapper::DataPrepper.new(anthro_co_1, @handler) end describe '#merge_default_values' do context 'when no default_values specified in config' do it 'does not fall over' do - dp = DataPrepper.new(anthro_co_1, @handler) + dp = CollectionSpace::Mapper::DataPrepper.new(anthro_co_1, @handler) res = dp.prep.merged_data['collection'] ex = 'Permanent Collection' expect(res).to eq(ex) @@ -69,8 +69,8 @@ }, force_defaults: true, }) - dh = DataHandler.new(@collectionobject_mapper, @client, @cache, config) - dp = DataPrepper.new(anthro_co_1, dh) + dh = CollectionSpace::Mapper::DataHandler.new(@collectionobject_mapper, @client, @cache, config) + dp = CollectionSpace::Mapper::DataPrepper.new(anthro_co_1, dh) res = dp.prep.merged_data['collection'] ex = 'library-collection' expect(res).to eq(ex) @@ -90,9 +90,9 @@ context 'when authority record' do before(:all) do @place_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/core/core_6_1_0-place.json') - @place_handler = DataHandler.new(@place_mapper, @cache, @client, @config) + @place_handler = CollectionSpace::Mapper::DataHandler.new(@place_mapper, @cache, @client, @config) data = get_datahash(path: 'spec/fixtures/files/datahashes/core/place001.json') - @place_prepper = DataPrepper.new(data, @place_handler) + @place_prepper = CollectionSpace::Mapper::DataPrepper.new(data, @place_handler) end it 'keeps mapping for shortIdentifier in xphash' do @place_prepper.prep @@ -106,7 +106,7 @@ describe '#handle_term_fields' do before(:all) do - @prepper = DataPrepper.new(anthro_co_1, @handler) + @prepper = CollectionSpace::Mapper::DataPrepper.new(anthro_co_1, @handler) @prepped = @prepper.prep end it 'returns expected result for mapping' do @@ -165,9 +165,9 @@ context 'and one or more combined field values is blank' do before(:all) do @core_conservation_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/core/core_6_1_0-conservation.json') - @handler = DataHandler.new(@core_conservation_mapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(@core_conservation_mapper, @client, @cache, @config) data = get_datahash(path: 'spec/fixtures/files/datahashes/core/conservation0_1.json') - @prepper = DataPrepper.new(data, @handler) + @prepper = CollectionSpace::Mapper::DataPrepper.new(data, @handler) @xpath = 'conservation_common/conservationStatusGroupList/conservationStatusGroup' end it 'removes empty fields from combined data response' do @@ -184,13 +184,13 @@ context 'when multi-authority field is part of repeating field subgroup' do before(:all) do @core_media_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/core/core_6_1_0-media.json') - @handler = DataHandler.new(@core_media_mapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(@core_media_mapper, @client, @cache, @config) end context 'when there is more than one group' do before(:all) do data = get_datahash(path: 'spec/fixtures/files/datahashes/core/media1_1.json') - @prepper = DataPrepper.new(data, @handler) + @prepper = CollectionSpace::Mapper::DataPrepper.new(data, @handler) end it 'combines values properly' do xpath = 'media_common/measuredPartGroupList/measuredPartGroup/dimensionSubGroupList/dimensionSubGroup' @@ -212,7 +212,7 @@ context 'when there is only one group' do before(:all) do data = get_datahash(path: 'spec/fixtures/files/datahashes/core/media1_2.json') - @prepper = DataPrepper.new(data, @handler) + @prepper = CollectionSpace::Mapper::DataPrepper.new(data, @handler) end it 'combines values properly' do xpath = 'media_common/measuredPartGroupList/measuredPartGroup/dimensionSubGroupList/dimensionSubGroup' diff --git a/spec/collectionspace/mapper/data_quality_checker_spec.rb b/spec/collectionspace/mapper/data_quality_checker_spec.rb index e45abd6f..e705c024 100644 --- a/spec/collectionspace/mapper/data_quality_checker_spec.rb +++ b/spec/collectionspace/mapper/data_quality_checker_spec.rb @@ -19,14 +19,14 @@ context 'and value is not in option list' do it 'returns warning' do data = ['Permanent Collection'] - res = DataQualityChecker.new(mapping, data).warnings + res = CollectionSpace::Mapper::DataQualityChecker.new(mapping, data).warnings expect(res.size).to eq(1) end end context 'and value is in option list' do it 'does not return warning' do data = ['permanent-collection'] - res = DataQualityChecker.new(mapping, data).warnings + res = CollectionSpace::Mapper::DataQualityChecker.new(mapping, data).warnings expect(res).to be_empty end end diff --git a/spec/collectionspace/mapper/data_splitter_spec.rb b/spec/collectionspace/mapper/data_splitter_spec.rb index e12d4ac2..74536f6d 100644 --- a/spec/collectionspace/mapper/data_splitter_spec.rb +++ b/spec/collectionspace/mapper/data_splitter_spec.rb @@ -10,37 +10,37 @@ describe '#result' do context 'when "a"' do it 'returns ["a"]' do - s = SimpleSplitter.new('a', @config) + s = CollectionSpace::Mapper::SimpleSplitter.new('a', @config) expect(s.result).to eq(%w[a]) end end context 'when " a"' do it 'returns ["a"]' do - s = SimpleSplitter.new(' a', @config) + s = CollectionSpace::Mapper::SimpleSplitter.new(' a', @config) expect(s.result).to eq(%w[a]) end end context 'when "a;b;c"' do it 'returns ["a", "b", "c"]' do - s = SimpleSplitter.new('a;b;c', @config) + s = CollectionSpace::Mapper::SimpleSplitter.new('a;b;c', @config) expect(s.result).to eq(%w[a b c]) end end context 'when ";b;c"' do it 'returns ["", "b", "c"]' do - s = SimpleSplitter.new(';b;c', @config) + s = CollectionSpace::Mapper::SimpleSplitter.new(';b;c', @config) expect(s.result).to eq(['', 'b', 'c']) end end context 'when "a;b;"' do it 'returns ["a", "b", ""]' do - s = SimpleSplitter.new('a;b;', @config) + s = CollectionSpace::Mapper::SimpleSplitter.new('a;b;', @config) expect(s.result).to eq(['a', 'b', '']) end end context 'when "a;;c"' do it 'returns ["a", "", "c"]' do - s = SimpleSplitter.new('a;;c', @config) + s = CollectionSpace::Mapper::SimpleSplitter.new('a;;c', @config) expect(s.result).to eq(['a', '', 'c']) end end @@ -55,25 +55,25 @@ describe '#result' do context 'when "a^^b;c^^d"' do it 'returns [["a", "b"], ["c", "d"]]' do - s = SubgroupSplitter.new('a^^b;c^^d', @config) + s = CollectionSpace::Mapper::SubgroupSplitter.new('a^^b;c^^d', @config) expect(s.result).to eq([%w[a b], %w[c d]]) end end context 'when "a;c"' do it 'returns [["a"], ["c"]]' do - s = SubgroupSplitter.new('a;c', @config) + s = CollectionSpace::Mapper::SubgroupSplitter.new('a;c', @config) expect(s.result).to eq([%w[a], %w[c]]) end end context 'when "a;c^^d"' do it 'returns [["a"], ["c", "d"]]' do - s = SubgroupSplitter.new('a;c^^d', @config) + s = CollectionSpace::Mapper::SubgroupSplitter.new('a;c^^d', @config) expect(s.result).to eq([%w[a], %w[c d]]) end end context 'when "a^^;c^^d"' do it 'returns [["a", ""], ["c", "d"]]' do - s = SubgroupSplitter.new('a^^;c^^d', @config) + s = CollectionSpace::Mapper::SubgroupSplitter.new('a^^;c^^d', @config) expect(s.result).to eq([['a', ''], %w[c d]]) end end diff --git a/spec/collectionspace/mapper/data_validator_spec.rb b/spec/collectionspace/mapper/data_validator_spec.rb index c7f1811b..a7e609a7 100644 --- a/spec/collectionspace/mapper/data_validator_spec.rb +++ b/spec/collectionspace/mapper/data_validator_spec.rb @@ -5,9 +5,9 @@ RSpec.describe CollectionSpace::Mapper::DataValidator do before(:all) do @anthro_object_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4_1_0-collectionobject.json') - @anthro_dv = DataValidator.new(RecordMapper.convert(@anthro_object_mapper), anthro_cache) + @anthro_dv = CollectionSpace::Mapper::DataValidator.new(CollectionSpace::Mapper::Tools::RecordMapper.convert(@anthro_object_mapper), anthro_cache) @botgarden_loanout_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/botgarden/botgarden_1_1_0-loanout.json') - @botgarden_dv = DataValidator.new(RecordMapper.convert(@botgarden_loanout_mapper), botgarden_cache) + @botgarden_dv = CollectionSpace::Mapper::DataValidator.new(CollectionSpace::Mapper::Tools::RecordMapper.convert(@botgarden_loanout_mapper), botgarden_cache) end it 'gets downcased list of required fields' do diff --git a/spec/collectionspace/mapper/response_spec.rb b/spec/collectionspace/mapper/response_spec.rb index 0f8f3186..4a0eaf4c 100644 --- a/spec/collectionspace/mapper/response_spec.rb +++ b/spec/collectionspace/mapper/response_spec.rb @@ -8,7 +8,7 @@ @cache = botgarden_cache populate_botgarden(@cache) @mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/botgarden/botgarden_1_1_0-taxon.json') - @handler = DataHandler.new(@mapper, @cache, @client, CollectionSpace::Mapper::DEFAULT_CONFIG) + @handler = CollectionSpace::Mapper::DataHandler.new(@mapper, @cache, @client, CollectionSpace::Mapper::DEFAULT_CONFIG) end describe '#valid?' do diff --git a/spec/collectionspace/mapper/term_handler_spec.rb b/spec/collectionspace/mapper/term_handler_spec.rb index f570ffc2..1fe34cdd 100644 --- a/spec/collectionspace/mapper/term_handler_spec.rb +++ b/spec/collectionspace/mapper/term_handler_spec.rb @@ -9,7 +9,7 @@ @cache = core_cache populate_core(@cache) @mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/core/core_6_1_0-collectionobject.json') - @handler = DataHandler.new(@mapper, @client, @cache) + @handler = CollectionSpace::Mapper::DataHandler.new(@mapper, @client, @cache) end @@ -34,7 +34,7 @@ :fullpath=> "collectionobjects_common/titleGroupList/titleGroup/titleTranslationSubGroupList/titleTranslationSubGroup"} data = [['Ancient Greek', 'Swahili'], ['Klingon', 'Spanish']] - @th = TermHandler.new(@mapping, data, @cache) + @th = CollectionSpace::Mapper::TermHandler.new(@mapping, data, @cache) end it 'result is the transformed value for mapping' do expected = [["urn:cspace:core.collectionspace.org:vocabularies:name(languages):item:name(grc)'Ancient Greek'", @@ -63,7 +63,7 @@ :datacolumn=>"referencelocal", :fullpath=>"collectionobjects_common/referenceGroupList/referenceGroup"} data = ['Reference 1', 'Reference 2'] - @th = TermHandler.new(@mapping, data, @cache) + @th = CollectionSpace::Mapper::TermHandler.new(@mapping, data, @cache) end it 'result is the transformed value for mapping' do expected = [ @@ -100,7 +100,7 @@ :fullpath=> "collectionobjects_common/titleGroupList/titleGroup/titleTranslationSubGroupList/titleTranslationSubGroup"} data = [['Ancient Greek', 'Swahili'], ['Klingon', 'Spanish']] - @th = TermHandler.new(@mapping, data, @cache) + @th = CollectionSpace::Mapper::TermHandler.new(@mapping, data, @cache) end it 'contains a term Hash for each value' do expect(@th.terms.length).to eq(4) @@ -130,7 +130,7 @@ :datacolumn=>"referencelocal", :fullpath=>"collectionobjects_common/referenceGroupList/referenceGroup"} data = ['Reference 1', 'Reference 2'] - @th = TermHandler.new(@mapping, data, @cache) + @th = CollectionSpace::Mapper::TermHandler.new(@mapping, data, @cache) end it 'contains a term Hash for each value' do expect(@th.terms.length).to eq(2) diff --git a/spec/collectionspace/mapper/tools/dates_spec.rb b/spec/collectionspace/mapper/tools/dates_spec.rb index 934f876b..61570cda 100644 --- a/spec/collectionspace/mapper/tools/dates_spec.rb +++ b/spec/collectionspace/mapper/tools/dates_spec.rb @@ -9,10 +9,10 @@ @config = CollectionSpace::Mapper::DEFAULT_CONFIG end - describe Dates::CspaceDate do + describe CollectionSpace::Mapper::Tools::Dates::CspaceDate do context 'when date string is Chronic parseable (e.g. 2020-08-14)' do before(:all) do - @res = CspaceDate.new('2020-09-30', @client, @cache, @config) + @res = CollectionSpace::Mapper::Tools::Dates::CspaceDate.new('2020-09-30', @client, @cache, @config) end it 'populates .timestamp' do @@ -62,20 +62,20 @@ context 'when no date_format specified in config' do it 'defaults to M/D/Y interpretation' do - res = CspaceDate.new(@string, @client, @cache, @config).timestamp.to_s + res = CollectionSpace::Mapper::Tools::Dates::CspaceDate.new(@string, @client, @cache, @config).timestamp.to_s expect(res).to start_with('2020-01-02 12:00:00') end end context 'when date_format in config = month day year' do it 'interprets as M/D/Y' do - res = CspaceDate.new(@string, @client, @cache, @config).timestamp.to_s + res = CollectionSpace::Mapper::Tools::Dates::CspaceDate.new(@string, @client, @cache, @config).timestamp.to_s expect(res).to start_with('2020-01-02 12:00:00') end end context 'when date_format in config = day month year' do it 'interprets as D/M/Y' do config = @config.merge({ date_format: 'day month year' }) - res = CspaceDate.new(@string, @client, @cache, config).timestamp.to_s + res = CollectionSpace::Mapper::Tools::Dates::CspaceDate.new(@string, @client, @cache, config).timestamp.to_s expect(res).to start_with('2020-02-01 12:00:00') end end @@ -85,7 +85,7 @@ context 'when date string is not Chronic parseable (e.g. 1/2/2000 - 12/21/2001)' do before(:all) do @string = '1/2/2000 - 12/21/2001' - @res = CspaceDate.new(@string, @client, @cache, @config) + @res = CollectionSpace::Mapper::Tools::Dates::CspaceDate.new(@string, @client, @cache, @config) end it '.timestamp will be nil' do @@ -106,7 +106,7 @@ context 'when date string is not Chronic or services parseable (e.g. VIII.XIV.MMXX)' do before(:all) do @string = 'VIII.XIV.MMXX' - @res = CspaceDate.new(@string, @client, @cache, @config) + @res = CollectionSpace::Mapper::Tools::Dates::CspaceDate.new(@string, @client, @cache, @config) end it '.timestamp will be nil' do diff --git a/spec/collectionspace/mapper/tools/identifiers_spec.rb b/spec/collectionspace/mapper/tools/identifiers_spec.rb index c64fc7e8..2900aced 100644 --- a/spec/collectionspace/mapper/tools/identifiers_spec.rb +++ b/spec/collectionspace/mapper/tools/identifiers_spec.rb @@ -11,7 +11,7 @@ } authorities.each do |term, id| - expect(Identifiers.short_identifier(term, :authority)).to eq(id) + expect(CollectionSpace::Mapper::Tools::Identifiers.short_identifier(term, :authority)).to eq(id) end end it 'generates non-hashed short identifiers for vocabularies' do @@ -21,7 +21,7 @@ } authorities.each do |term, id| - expect(Identifiers.short_identifier(term, :vocabulary)).to eq(id) + expect(CollectionSpace::Mapper::Tools::Identifiers.short_identifier(term, :vocabulary)).to eq(id) end end end diff --git a/spec/collectionspace/mapper/tools/refname_spec.rb b/spec/collectionspace/mapper/tools/refname_spec.rb index da97f6d4..d59f8b41 100644 --- a/spec/collectionspace/mapper/tools/refname_spec.rb +++ b/spec/collectionspace/mapper/tools/refname_spec.rb @@ -14,7 +14,7 @@ subtype = 'person' term = 'Mary Poole' refname = "urn:cspace:anthro.collectionspace.org:personauthorities:name(person):item:name(MaryPoole1796320156)'Mary Poole'" - expect(RefName.build(source_type, type, subtype, term, @cache)).to eq(refname) + expect(CollectionSpace::Mapper::Tools::RefName.build(source_type, type, subtype, term, @cache)).to eq(refname) end it 'builds refname for vocabularies' do source_type = :vocabulary @@ -22,7 +22,7 @@ subtype = 'annotationtype' term = 'another term' refname = "urn:cspace:anthro.collectionspace.org:vocabularies:name(annotationtype):item:name(anotherterm)'another term'" - expect(RefName.build(source_type, type, subtype, term, @cache)).to eq(refname) + expect(CollectionSpace::Mapper::Tools::RefName.build(source_type, type, subtype, term, @cache)).to eq(refname) end end end diff --git a/spec/collectionspace/mapper/value_transformer_spec.rb b/spec/collectionspace/mapper/value_transformer_spec.rb index 8a1b382f..4c7bb0f5 100644 --- a/spec/collectionspace/mapper/value_transformer_spec.rb +++ b/spec/collectionspace/mapper/value_transformer_spec.rb @@ -13,7 +13,7 @@ it 'returns transformed value for retrieving refname' do value = '0' transforms = { vocabulary: 'behrensmeyer', special: %w[behrensmeyer_translate] } - res = ValueTransformer.new(value, transforms, @cache).result + res = CollectionSpace::Mapper::ValueTransformer.new(value, transforms, @cache).result ex = '0 - no cracking or flaking on bone surface' expect(res).to eq(ex) end @@ -28,7 +28,7 @@ { find: ' - ', replace: '-', type: :plain } ] } - res = ValueTransformer.new(value, transforms, @cache).result + res = CollectionSpace::Mapper::ValueTransformer.new(value, transforms, @cache).result ex = 'adolescent 26-75%' expect(res).to eq(ex) end @@ -46,7 +46,7 @@ { find: '(\w)%%(\w)', replace: '\1 \2', type: :regexp } ] } - res = ValueTransformer.new(value, transforms, @cache).result + res = CollectionSpace::Mapper::ValueTransformer.new(value, transforms, @cache).result expect(res).to eq('rycy plynt') end end diff --git a/spec/collectionspace/mapper_spec.rb b/spec/collectionspace/mapper_spec.rb index 352cfa4a..0d6bdc16 100644 --- a/spec/collectionspace/mapper_spec.rb +++ b/spec/collectionspace/mapper_spec.rb @@ -24,7 +24,7 @@ describe '#setup_data' do context 'when passed a CollectionSpace::Mapper::Response' do it 'returns that Response' do - response = Response.new({ 'objectNumber'=>'123' }) + response = CollectionSpace::Mapper::Response.new({ 'objectNumber'=>'123' }) expect(CollectionSpace::Mapper::setup_data(response)).to eq(response) end end