From 02f3f94ed15a09e34dd730cf9a305b4a00bcdcf4 Mon Sep 17 00:00:00 2001 From: Kristina Spurgin Date: Thu, 24 Dec 2020 17:00:37 -0500 Subject: [PATCH 1/5] debug --- lib/collectionspace/mapper/tools/refname.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/collectionspace/mapper/tools/refname.rb b/lib/collectionspace/mapper/tools/refname.rb index 74517cbc..b0241edc 100644 --- a/lib/collectionspace/mapper/tools/refname.rb +++ b/lib/collectionspace/mapper/tools/refname.rb @@ -39,6 +39,7 @@ def new_from_term(source_type) def new_from_urn parts = @urn.match(/^urn:cspace:([^:]+):([^:]+):name\(([^\)]+)\):item:name\(([^\)]+)\)'/) +binding.pry if parts.nil? @domain = parts[1] @type = parts[2] @subtype = parts[3] From 9d8b7c0da7f680bbc3ae0d9fe88c9bffc1e13cce Mon Sep 17 00:00:00 2001 From: Kristina Spurgin Date: Mon, 4 Jan 2021 10:50:49 -0500 Subject: [PATCH 2/5] testing to try to find bug --- .../mapper/data_handler_spec.rb | 34 +++++++++++++++++++ spec/core_helpers.rb | 9 +++++ 2 files changed, 43 insertions(+) diff --git a/spec/collectionspace/mapper/data_handler_spec.rb b/spec/collectionspace/mapper/data_handler_spec.rb index 063ff3f2..e3ebf535 100644 --- a/spec/collectionspace/mapper/data_handler_spec.rb +++ b/spec/collectionspace/mapper/data_handler_spec.rb @@ -18,6 +18,40 @@ @bonsai_conservation_handler = CollectionSpace::Mapper::DataHandler.new(@bonsai_conservation_mapper, @bonsai_client, @bonsai_cache) end + context 'when config has check_terms = false' do + before(:all) do + @client = core_client + @cache = core_cache_search + @mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/core/core_6_1_0-collectionobject.json') + @config = '{"check_terms": false}' + @handler = CollectionSpace::Mapper::DataHandler.new(@mapper, @client, @cache, @config) + @data = {"objectNumber"=>"20CS.001.0002", + "numberOfObjects"=>"1", + "title"=>"Rainbow", + "titleLanguage"=>"English", + "namedCollection"=>"Test Collection", + "collection"=>"rando"} + @data2 = {"objectNumber"=>"20CS.001.0001", + "numberOfObjects"=>"1", + "numberValue"=>"123456|98765", + "numberType"=>"lender|obsolete", + "title"=>"A Man| A Woman", + "titleLanguage"=>"English| Klingon", + "namedCollection"=>"Test collection", + "collection"=>"permanent collection"} + end + it 'returns found = false for all terms, even if they exist in client' do + res = @handler.process(@data) + not_found = res.terms.reject{ |t| t[:found] } + expect(not_found.length).to eq(2) + end + it 'returns found = false for all terms, even if they exist in client' do + res = @handler.process(@data2) + not_found = res.terms.reject{ |t| t[:found] } + expect(not_found.length).to eq(3) + end + end + context 'when no config is passed at initialization' do it 'uses default config' do expect(@anthro_place_handler.config).to eq(CollectionSpace::Mapper::DEFAULT_CONFIG) diff --git a/spec/core_helpers.rb b/spec/core_helpers.rb index 61484202..b76cb358 100644 --- a/spec/core_helpers.rb +++ b/spec/core_helpers.rb @@ -22,6 +22,15 @@ def core_cache CollectionSpace::RefCache.new(config: cache_config, client: core_client) end + def core_cache_search + cache_config = { + domain: 'core.collectionspace.org', + search_enabled: true, + search_identifiers: false + } + CollectionSpace::RefCache.new(config: cache_config, client: core_client) + end + def populate_core(cache) terms = [ ['citationauthorities', 'citation', 'Wanting', "urn:cspace:core.collectionspace.org:citationauthorities:name(citation):item:name(Wanting1599560009399)'Wanting'"], From f3359eb6ef73edf0e61172a9eed0142ac367b5e1 Mon Sep 17 00:00:00 2001 From: Kristina Spurgin Date: Mon, 4 Jan 2021 11:41:57 -0500 Subject: [PATCH 3/5] init DataHandler with keywords --- lib/collectionspace/mapper/data_handler.rb | 4 +- lib/collectionspace/mapper/term_handler.rb | 2 +- lib/collectionspace/mapper/tools/refname.rb | 4 +- .../mapper/data_handler_spec.rb | 43 ++++++++++++++----- .../mapper/data_mapper_anthro_spec.rb | 15 +++++-- .../mapper/data_mapper_bonsai_spec.rb | 5 ++- .../mapper/data_mapper_botgarden_spec.rb | 8 +++- .../mapper/data_mapper_core_spec.rb | 26 +++++------ .../mapper/data_mapper_spec.rb | 13 +++--- .../mapper/data_mapper_ucb_spec.rb | 5 ++- .../mapper/data_prepper_spec.rb | 13 +++--- spec/collectionspace/mapper/response_spec.rb | 5 ++- .../mapper/term_handler_spec.rb | 5 ++- .../tools/record_status_service_spec.rb | 2 +- 14 files changed, 103 insertions(+), 47 deletions(-) diff --git a/lib/collectionspace/mapper/data_handler.rb b/lib/collectionspace/mapper/data_handler.rb index a919f0de..2c10f2b1 100644 --- a/lib/collectionspace/mapper/data_handler.rb +++ b/lib/collectionspace/mapper/data_handler.rb @@ -8,8 +8,8 @@ class DataHandler attr_reader :mapper, :client, :cache, :config, :blankdoc, :defaults, :validator, :is_authority, :known_fields - def initialize(record_mapper, client, cache = nil, - config = CollectionSpace::Mapper::DEFAULT_CONFIG + def initialize(record_mapper:, client:, cache: nil, + config: CollectionSpace::Mapper::DEFAULT_CONFIG ) @mapper = CollectionSpace::Mapper::Tools::RecordMapper.convert(record_mapper) @is_authority = get_is_authority diff --git a/lib/collectionspace/mapper/term_handler.rb b/lib/collectionspace/mapper/term_handler.rb index fd1d8395..a94c376f 100644 --- a/lib/collectionspace/mapper/term_handler.rb +++ b/lib/collectionspace/mapper/term_handler.rb @@ -41,7 +41,7 @@ def handle_term(val) term_report = { category: @source_type, - field: @column, + field: @column } if in_cache?(val) diff --git a/lib/collectionspace/mapper/tools/refname.rb b/lib/collectionspace/mapper/tools/refname.rb index b0241edc..049917dd 100644 --- a/lib/collectionspace/mapper/tools/refname.rb +++ b/lib/collectionspace/mapper/tools/refname.rb @@ -17,6 +17,9 @@ def initialize(args) urn_args = %i[urn] args_given = args.keys.sort + pp(args) + puts '' + if args_given == urn_args @urn = args[:urn] new_from_urn @@ -39,7 +42,6 @@ def new_from_term(source_type) def new_from_urn parts = @urn.match(/^urn:cspace:([^:]+):([^:]+):name\(([^\)]+)\):item:name\(([^\)]+)\)'/) -binding.pry if parts.nil? @domain = parts[1] @type = parts[2] @subtype = parts[3] diff --git a/spec/collectionspace/mapper/data_handler_spec.rb b/spec/collectionspace/mapper/data_handler_spec.rb index e3ebf535..59ccac50 100644 --- a/spec/collectionspace/mapper/data_handler_spec.rb +++ b/spec/collectionspace/mapper/data_handler_spec.rb @@ -8,14 +8,20 @@ @anthro_cache = anthro_cache populate_anthro(@anthro_cache) @anthro_object_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4_1_2-collectionobject.json') - @anthro_object_handler = CollectionSpace::Mapper::DataHandler.new(@anthro_object_mapper, @anthro_client, @anthro_cache) + @anthro_object_handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @anthro_object_mapper, + client: @anthro_client, + cache: @anthro_cache) @anthro_place_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4_1_2-place-local.json') - @anthro_place_handler = CollectionSpace::Mapper::DataHandler.new(@anthro_place_mapper, @anthro_client, @anthro_cache) + @anthro_place_handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @anthro_place_mapper, + client: @anthro_client, + cache: @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_1-conservation.json') - @bonsai_conservation_handler = CollectionSpace::Mapper::DataHandler.new(@bonsai_conservation_mapper, @bonsai_client, @bonsai_cache) + @bonsai_conservation_handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @bonsai_conservation_mapper, + client: @bonsai_client, + cache: @bonsai_cache) end context 'when config has check_terms = false' do @@ -24,7 +30,10 @@ @cache = core_cache_search @mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/core/core_6_1_0-collectionobject.json') @config = '{"check_terms": false}' - @handler = CollectionSpace::Mapper::DataHandler.new(@mapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @mapper, + client: @client, + cache: @cache, + config: @config) @data = {"objectNumber"=>"20CS.001.0002", "numberOfObjects"=>"1", "title"=>"Rainbow", @@ -62,13 +71,15 @@ context 'when mapping an authority' do it 'cache.search_identifiers = false' do mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4_1_2-place-local.json') - dh = CollectionSpace::Mapper::DataHandler.new(mapper, @anthro_client) + dh = CollectionSpace::Mapper::DataHandler.new(record_mapper: mapper, + client: @anthro_client) expect(dh.cache.inspect).to include('@search_identifiers=false') end end context 'when mapping a non-authority' do it 'cache.search_identifiers = true' do - dh = CollectionSpace::Mapper::DataHandler.new(@anthro_object_mapper, @anthro_client) + dh = CollectionSpace::Mapper::DataHandler.new(record_mapper: @anthro_object_mapper, + client: @anthro_client) expect(dh.cache.inspect).to include('@search_identifiers=true') end end @@ -131,7 +142,10 @@ end context 'collection data field' do it 'merges data field specific transforms' do - handler = CollectionSpace::Mapper::DataHandler.new(@anthro_object_mapper, @anthro_client, @anthro_cache, @config) + handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @anthro_object_mapper, + client: @anthro_client, + cache: @anthro_cache, + config: @config) fieldmap = handler.mapper[:mappings].select{ |m| m[:fieldname] == 'collection' }.first xforms = { special: %w[downcase_value], @@ -266,7 +280,10 @@ 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 = CollectionSpace::Mapper::DataHandler.new(@anthro_object_mapper, @anthro_client, @anthro_cache, config) + handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @anthro_object_mapper, + client: @anthro_client, + cache: @anthro_cache, + config: config) result = handler.prep(@data) expect(result.transformed_data).not_to be_empty end @@ -295,7 +312,10 @@ 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 = CollectionSpace::Mapper::DataHandler.new(@anthro_object_mapper, @anthro_client, @anthro_cache, config) + handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @anthro_object_mapper, + client: @anthro_client, + cache: @anthro_cache, + config: config) result = handler.process(@data) expect(result.transformed_data).not_to be_empty end @@ -325,7 +345,10 @@ 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 = CollectionSpace::Mapper::DataHandler.new(@anthro_object_mapper, @anthro_client, @anthro_cache, config) + handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @anthro_object_mapper, + client: @anthro_client, + cache: @anthro_cache, + config: config) prepper = CollectionSpace::Mapper::DataPrepper.new(@data, handler) result = handler.map(handler.prep(@data), prepper.xphash) expect(result.transformed_data).not_to be_empty diff --git a/spec/collectionspace/mapper/data_mapper_anthro_spec.rb b/spec/collectionspace/mapper/data_mapper_anthro_spec.rb index 7017bd03..f960eab7 100644 --- a/spec/collectionspace/mapper/data_mapper_anthro_spec.rb +++ b/spec/collectionspace/mapper/data_mapper_anthro_spec.rb @@ -21,7 +21,10 @@ # Problem in claimantGroupList before(:all) do @claimmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4_1_2-claim.json') - @handler = CollectionSpace::Mapper::DataHandler.new(@claimmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @claimmapper, + client: @client, + cache: @cache, + config: @config) end context 'record 1' do before(:all) do @@ -52,7 +55,10 @@ context 'collectionobject record' do before(:all) do @collectionobjectmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4_1_2-collectionobject.json') - @handler = CollectionSpace::Mapper::DataHandler.new(@collectionobjectmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @collectionobjectmapper, + client: @client, + cache: @cache, + config: @config) end # record 1 was used for testing default value merging, transformations, etc. # we start with record 2 to purely test mapping functionality @@ -84,7 +90,10 @@ context 'osteology record' do before(:all) do @osteologymapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4_1_2-osteology.json') - @handler = CollectionSpace::Mapper::DataHandler.new(@osteologymapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @osteologymapper, + client: @client, + cache: @cache, + config: @config) end context 'record 1' do # before(:all) do diff --git a/spec/collectionspace/mapper/data_mapper_bonsai_spec.rb b/spec/collectionspace/mapper/data_mapper_bonsai_spec.rb index b54f35a5..21216101 100644 --- a/spec/collectionspace/mapper/data_mapper_bonsai_spec.rb +++ b/spec/collectionspace/mapper/data_mapper_bonsai_spec.rb @@ -17,7 +17,10 @@ context 'objectexit record' do before(:all) do @objectexitmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/bonsai/bonsai_4_1_1-objectexit.json') - @handler = CollectionSpace::Mapper::DataHandler.new(@objectexitmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @objectexitmapper, + client: @client, + cache: @cache, + config: @config) end context 'record 1' do diff --git a/spec/collectionspace/mapper/data_mapper_botgarden_spec.rb b/spec/collectionspace/mapper/data_mapper_botgarden_spec.rb index bd066339..2d6cc5db 100644 --- a/spec/collectionspace/mapper/data_mapper_botgarden_spec.rb +++ b/spec/collectionspace/mapper/data_mapper_botgarden_spec.rb @@ -17,7 +17,8 @@ context 'pottag record' do # before(:all) do # @pottag_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/botgarden/botgarden_2_0_1-pottag.json') - # @pottag_handler = CollectionSpace::Mapper::DataHandler.new(@pottag_mapper, @client, @cache, @config) + # @pottag_handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @pottag_mapper, + # client: @client, cache: @cache, config: @config) # end context 'record 1' do @@ -84,7 +85,10 @@ context 'taxon record' do before(:all) do @taxon_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/botgarden/botgarden_2_0_1-taxon-local.json') - @taxon_handler = CollectionSpace::Mapper::DataHandler.new(@taxon_mapper, @client, @cache, @config) + @taxon_handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @taxon_mapper, + client: @client, + cache: @cache, + config: @config) end context 'record 1' do diff --git a/spec/collectionspace/mapper/data_mapper_core_spec.rb b/spec/collectionspace/mapper/data_mapper_core_spec.rb index d6aa8a1b..00bdc146 100644 --- a/spec/collectionspace/mapper/data_mapper_core_spec.rb +++ b/spec/collectionspace/mapper/data_mapper_core_spec.rb @@ -17,7 +17,7 @@ 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 = CollectionSpace::Mapper::DataHandler.new(@acquisition_mapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @acquisition_mapper, client: @client, cache: @cache, config: @config) end context 'record 1' do @@ -48,7 +48,7 @@ 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 = CollectionSpace::Mapper::DataHandler.new(@collectionobject_mapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @collectionobject_mapper, client: @client, cache: @cache, config: @config) end context 'record 1' do @@ -79,7 +79,7 @@ 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 = CollectionSpace::Mapper::DataHandler.new(@conditioncheckmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @conditioncheckmapper, client: @client, cache: @cache, config: @config) end context 'record 1' do @@ -110,7 +110,7 @@ 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 = CollectionSpace::Mapper::DataHandler.new(@conservationmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @conservationmapper, client: @client, cache: @cache, config: @config) end context 'record 1' do @@ -141,7 +141,7 @@ 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 = CollectionSpace::Mapper::DataHandler.new(@exhibitionmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @exhibitionmapper, client: @client, cache: @cache, config: @config) end context 'record 1' do @@ -172,7 +172,7 @@ 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 = CollectionSpace::Mapper::DataHandler.new(@groupmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @groupmapper, client: @client, cache: @cache, config: @config) end context 'record 1' do @@ -203,7 +203,7 @@ 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 = CollectionSpace::Mapper::DataHandler.new(@intakemapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @intakemapper, client: @client, cache: @cache, config: @config) end context 'record 1' do @@ -234,7 +234,7 @@ 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 = CollectionSpace::Mapper::DataHandler.new(@rm_core_co, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @rm_core_co, client: @client, cache: @cache, config: @config) end context 'record 1' do @@ -265,7 +265,7 @@ 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 = CollectionSpace::Mapper::DataHandler.new(@loanoutmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @loanoutmapper, client: @client, cache: @cache, config: @config) end context 'record 1' do @@ -295,7 +295,7 @@ 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 = CollectionSpace::Mapper::DataHandler.new(@movementmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @movementmapper, client: @client, cache: @cache, config: @config) end context 'record 1' do @@ -326,7 +326,7 @@ 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 = CollectionSpace::Mapper::DataHandler.new(@movementmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @movementmapper, client: @client, cache: @cache, config: @config) end context 'record 1' do @@ -357,7 +357,7 @@ 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 = CollectionSpace::Mapper::DataHandler.new(@objectexitmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @objectexitmapper, client: @client, cache: @cache, config: @config) end context 'record 1' do @@ -389,7 +389,7 @@ 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 = CollectionSpace::Mapper::DataHandler.new(@uocmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @uocmapper, client: @client, cache: @cache, config: @config) end context 'record 1' do diff --git a/spec/collectionspace/mapper/data_mapper_spec.rb b/spec/collectionspace/mapper/data_mapper_spec.rb index 22a5285f..58005637 100644 --- a/spec/collectionspace/mapper/data_mapper_spec.rb +++ b/spec/collectionspace/mapper/data_mapper_spec.rb @@ -15,7 +15,7 @@ context 'person record' do before(:all) do @recmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/lhmc/lhmc_3_1_1-person-local.json') - @handler = CollectionSpace::Mapper::DataHandler.new(@recmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @recmapper, client: @client, cache: @cache, config: @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) @@ -56,7 +56,7 @@ context 'loanout record' do before(:all) do @recmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/botgarden/botgarden_2_0_1-loanout.json') - @handler = CollectionSpace::Mapper::DataHandler.new(@recmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @recmapper, client: @client, cache: @cache, config: @config) @prepper = CollectionSpace::Mapper::DataPrepper.new({'loanOutNumber' => '123', 'sterile' => 'n'}, @handler) @datamapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) end @@ -79,7 +79,7 @@ context 'place record' do before(:all) do @recmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4_1_2-place-local.json') - @handler = CollectionSpace::Mapper::DataHandler.new(@recmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @recmapper, client: @client, cache: @cache, config: @config) @prepper = CollectionSpace::Mapper::DataPrepper.new({'termDisplayName' => 'Xanadu'}, @handler) @datamapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) end @@ -115,7 +115,7 @@ }) @recmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4_1_2-collectionobject.json') - @handler = CollectionSpace::Mapper::DataHandler.new(@recmapper, @client, @cache, config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @recmapper, client: @client, cache: @cache, config: config) @prepper = CollectionSpace::Mapper::DataPrepper.new(anthro_co_1, @handler) @datamapper = CollectionSpace::Mapper::DataMapper.new(@prepper.prep, @handler, @prepper.xphash) end @@ -160,7 +160,10 @@ cache = botgarden_cache populate_botgarden(cache) prop_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/botgarden/botgarden_2_0_1-propagation.json') - prop_handler = CollectionSpace::Mapper::DataHandler.new(prop_mapper, client, cache, CollectionSpace::Mapper::DEFAULT_CONFIG) + prop_handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: prop_mapper, + client: client, + cache: cache, + config: CollectionSpace::Mapper::DEFAULT_CONFIG) datahash = get_datahash(path: 'spec/fixtures/files/datahashes/botgarden/propagation1.json') prepper = CollectionSpace::Mapper::DataPrepper.new(datahash, prop_handler) mapper = CollectionSpace::Mapper::DataMapper.new(prepper.prep, prop_handler, prepper.xphash) diff --git a/spec/collectionspace/mapper/data_mapper_ucb_spec.rb b/spec/collectionspace/mapper/data_mapper_ucb_spec.rb index 5d3243ff..62f93b67 100644 --- a/spec/collectionspace/mapper/data_mapper_ucb_spec.rb +++ b/spec/collectionspace/mapper/data_mapper_ucb_spec.rb @@ -36,7 +36,10 @@ context 'collectionobject record' do before(:all) do @objmapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/ucb_pahma_nagpra-collectionobject.json') - @handler = CollectionSpace::Mapper::DataHandler.new(@objmapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @objmapper, + client: @client, + cache: @cache, + config: @config) end context 'record 2' do before(:all) do diff --git a/spec/collectionspace/mapper/data_prepper_spec.rb b/spec/collectionspace/mapper/data_prepper_spec.rb index f5695d95..e2154337 100644 --- a/spec/collectionspace/mapper/data_prepper_spec.rb +++ b/spec/collectionspace/mapper/data_prepper_spec.rb @@ -32,7 +32,10 @@ }) @collectionobject_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/anthro/anthro_4_1_2-collectionobject.json') - @handler = CollectionSpace::Mapper::DataHandler.new(@collectionobject_mapper, @client, @cache, @collectionobject_config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @collectionobject_mapper, + client: @client, + cache: @cache, + config: @collectionobject_config) @prepper = CollectionSpace::Mapper::DataPrepper.new(anthro_co_1, @handler) end @@ -69,7 +72,7 @@ }, force_defaults: true, }) - dh = CollectionSpace::Mapper::DataHandler.new(@collectionobject_mapper, @client, @cache, config) + dh = CollectionSpace::Mapper::DataHandler.new(record_mapper: @collectionobject_mapper, client: @client, cache: @cache, config: config) dp = CollectionSpace::Mapper::DataPrepper.new(anthro_co_1, dh) res = dp.prep.merged_data['collection'] ex = 'library-collection' @@ -90,7 +93,7 @@ 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-local.json') - @place_handler = CollectionSpace::Mapper::DataHandler.new(@place_mapper, @client, @cache, @config) + @place_handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @place_mapper, client: @client, cache: @cache, config: @config) data = get_datahash(path: 'spec/fixtures/files/datahashes/core/place001.json') @place_prepper = CollectionSpace::Mapper::DataPrepper.new(data, @place_handler) end @@ -165,7 +168,7 @@ 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 = CollectionSpace::Mapper::DataHandler.new(@core_conservation_mapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @core_conservation_mapper, client: @client, cache: @cache, config: @config) data = get_datahash(path: 'spec/fixtures/files/datahashes/core/conservation0_1.json') @prepper = CollectionSpace::Mapper::DataPrepper.new(data, @handler) @xpath = 'conservation_common/conservationStatusGroupList/conservationStatusGroup' @@ -184,7 +187,7 @@ 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 = CollectionSpace::Mapper::DataHandler.new(@core_media_mapper, @client, @cache, @config) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @core_media_mapper, client: @client, cache: @cache, config: @config) end context 'when there is more than one group' do diff --git a/spec/collectionspace/mapper/response_spec.rb b/spec/collectionspace/mapper/response_spec.rb index 49defc17..a919d5a7 100644 --- a/spec/collectionspace/mapper/response_spec.rb +++ b/spec/collectionspace/mapper/response_spec.rb @@ -8,7 +8,10 @@ @cache = botgarden_cache populate_botgarden(@cache) @mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/botgarden/botgarden_2_0_1-taxon-local.json') - @handler = CollectionSpace::Mapper::DataHandler.new(@mapper, @client, @cache, CollectionSpace::Mapper::DEFAULT_CONFIG) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @mapper, + client: @client, + cache: @cache, + config: 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 35620e84..dbee22fc 100644 --- a/spec/collectionspace/mapper/term_handler_spec.rb +++ b/spec/collectionspace/mapper/term_handler_spec.rb @@ -9,7 +9,10 @@ @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 = CollectionSpace::Mapper::DataHandler.new(@mapper, @client, @cache) + @handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @mapper, + client: @client, + cache: @cache, + config: @config) @ref_mapping = { :fieldname=>"reference", :transforms=>{:authority=>["citationauthorities", "citation"]}, diff --git a/spec/collectionspace/mapper/tools/record_status_service_spec.rb b/spec/collectionspace/mapper/tools/record_status_service_spec.rb index b39bc4a6..bb973472 100644 --- a/spec/collectionspace/mapper/tools/record_status_service_spec.rb +++ b/spec/collectionspace/mapper/tools/record_status_service_spec.rb @@ -60,7 +60,7 @@ @service = CollectionSpace::Mapper::Tools::RecordStatusService.new(@core_client, @core_co_mapper) end it 'works the same' do - res = @service.lookup('20CS.1980-32-1194') + res = @service.lookup('2000.1') expect(res[:status]).to eq(:existing) end end From ecf017a08eaf9cb8bf095068df77e0abfe081270 Mon Sep 17 00:00:00 2001 From: Kristina Spurgin Date: Mon, 4 Jan 2021 11:44:25 -0500 Subject: [PATCH 4/5] remove stdout debugging --- lib/collectionspace/mapper/tools/refname.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/collectionspace/mapper/tools/refname.rb b/lib/collectionspace/mapper/tools/refname.rb index 049917dd..74517cbc 100644 --- a/lib/collectionspace/mapper/tools/refname.rb +++ b/lib/collectionspace/mapper/tools/refname.rb @@ -17,9 +17,6 @@ def initialize(args) urn_args = %i[urn] args_given = args.keys.sort - pp(args) - puts '' - if args_given == urn_args @urn = args[:urn] new_from_urn From 65e92a6df0268da0454a058fe9f338d581ca88d8 Mon Sep 17 00:00:00 2001 From: Kristina Spurgin Date: Mon, 4 Jan 2021 12:07:13 -0500 Subject: [PATCH 5/5] bump version, update documentation --- doc/usage.adoc | 37 +++++++++++---------------- lib/collectionspace/mapper/version.rb | 2 +- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/doc/usage.adoc b/doc/usage.adoc index bd34d86e..a699659e 100644 --- a/doc/usage.adoc +++ b/doc/usage.adoc @@ -52,36 +52,29 @@ The DataHandler object sets up all the stuff that only needs to be done once per You also send each row/record through DataHandler methods for processing. -=== DataHandler config parameter - -A dataset-specific configuration hash may be passed in when creating a new DataHandler. This hash contains settings that control how the Mapper will parsed and transform the data. - -Details on available config options and how to format them are in the **Config options** section below. - -If no config parameter is passed in, the following minimum required default configuration will be applied: - -.Default config [source,ruby] +.Creating a DataHandler with default config ---- -{ delimiter: ';', - subgroup_delimiter: '^^', - response_mode: 'normal', - force_defaults: false, - date_format: 'month day year' -} +handler = DataHandler.new(record_mapper: mapper_json, client: cs_client_object, cache: cs_refcache_object) ---- -[NOTE] -==== -Default delimiter `;` will be replaced with `|` after DDD are finished contributing to test coverage. -==== +If you do not initialize new `DataHandler` with a specific, pre-created `collectionspace-refcache` object, one will be generated from the settings in the required `collectionspace-client`. [source,ruby] -.Creating a DataHandler with default config +.Creating a DataHandler without pre-created cache ---- -handler = DataHandler.new(record_mapper, client, cache) +handler = DataHandler.new(record_mapper: mapper_json, client: cs_client_object) ---- +=== DataHandler config parameter + +A dataset-specific configuration hash may be passed in when creating a new DataHandler. This hash contains settings that control how the Mapper will parsed and transform the data. + +Details on available config options and how to format them are in the https://github.com/collectionspace/collectionspace-mapper/blob/master/doc/batch_configuration.adoc[batch configuration documentation]. + +If no config parameter is passed in, the following minimum required default configuration from https://github.com/collectionspace/collectionspace-mapper/blob/master/lib/collectionspace/mapper.rb[`mapper.rb`] will be applied: + + [source,ruby] .Creating a DataHandler with custom batch config ---- @@ -90,7 +83,7 @@ config = { subgroup_delimiter: '~' } -handler = DataHandler.new(record_mapper, client, cache, config) +handler = DataHandler.new(record_mapper: mapper_json, client: cs_client_object, cache: cs_refcache_object, config: config) ---- diff --git a/lib/collectionspace/mapper/version.rb b/lib/collectionspace/mapper/version.rb index 4495d5ec..caae4952 100644 --- a/lib/collectionspace/mapper/version.rb +++ b/lib/collectionspace/mapper/version.rb @@ -1,5 +1,5 @@ module CollectionSpace module Mapper - VERSION = "1.6.0" + VERSION = "2.0.0" end end