Skip to content

Commit

Permalink
Merge pull request #88 from collectionspace/bugfix
Browse files Browse the repository at this point in the history
debug
  • Loading branch information
kspurgin authored Jan 4, 2021
2 parents 367336b + 65e92a6 commit f8b1209
Show file tree
Hide file tree
Showing 16 changed files with 158 additions and 68 deletions.
37 changes: 15 additions & 22 deletions doc/usage.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
----
Expand All @@ -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)
----


Expand Down
4 changes: 2 additions & 2 deletions lib/collectionspace/mapper/data_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/collectionspace/mapper/term_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def handle_term(val)

term_report = {
category: @source_type,
field: @column,
field: @column
}

if in_cache?(val)
Expand Down
2 changes: 1 addition & 1 deletion lib/collectionspace/mapper/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module CollectionSpace
module Mapper
VERSION = "1.6.0"
VERSION = "2.0.0"
end
end
75 changes: 66 additions & 9 deletions spec/collectionspace/mapper/data_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,59 @@
@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
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(record_mapper: @mapper,
client: @client,
cache: @cache,
config: @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)
Expand All @@ -28,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
Expand Down Expand Up @@ -97,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],
Expand Down Expand Up @@ -232,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
Expand Down Expand Up @@ -261,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
Expand Down Expand Up @@ -291,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
Expand Down
15 changes: 12 additions & 3 deletions spec/collectionspace/mapper/data_mapper_anthro_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion spec/collectionspace/mapper/data_mapper_bonsai_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions spec/collectionspace/mapper/data_mapper_botgarden_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit f8b1209

Please sign in to comment.