Skip to content

Commit

Permalink
Merge pull request #106 from collectionspace/debug
Browse files Browse the repository at this point in the history
Bugfix mapping multiple records on same `DataHandler`; add Changelog; changes to tests
  • Loading branch information
kspurgin authored Apr 22, 2021
2 parents e6e65d6 + 93bb67d commit 3f6d7dd
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 107 deletions.
20 changes: 15 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
This project bumps the version number for any changes (including documentation updates and refactorings). Versions with only documentation or refactoring changes may not be released. Versions with bugfixes will be released. Changes made to unreleased versions will be indicated by version number under each release that includes those changes.

## [Unreleased]
### Changed
- Refactoring

## [2.2.5] - 2021-04-22
### Added
#### [2.2.4]
- CHANGELOG.md

### Changed
#### [2.2.5]
- Refactoring
#### [2.2.4]
- BUGFIX: Fixes an issue where, when many records are mapped using the same `DataHandler`, some XML records were missing expected elements.

### Deleted
- Tests for UCB-specific mapping. These tests had served their purpose, were no longer needed, and were not worth fixing when they started to fail because the dev instance on UCB's end changed or went away.

Details: https://github.com/collectionspace/collectionspace-mapper/compare/v2.2.3...v2.2.5

## [2.2.4 (Unreleased)] - 2021-03-25

- Updated values in fixtures causing test failures due to records being deleted from CollectionSpace dev instance

## [2.2.3] - 2021-03-09
### Changed
- BUGFIX: Spurious warnings about subgroup overflows are no longer emitted

https://github.com/collectionspace/collectionspace-mapper/compare/v2.2.2...v2.2.3
Details: https://github.com/collectionspace/collectionspace-mapper/compare/v2.2.2...v2.2.3
8 changes: 7 additions & 1 deletion lib/collectionspace/mapper/data_prepper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def initialize(data, handler)
@cache = @handler.cache
@client = @handler.client
@response = CollectionSpace::Mapper::setup_data(data, @handler.defaults, @config)
drop_empty_fields
if @response.valid?
process_xpaths
end
Expand Down Expand Up @@ -62,15 +63,20 @@ def combine_data_fields

private

def drop_empty_fields
@response.merged_data = @response.merged_data.delete_if{ |k, v| v.blank? }
end

def process_xpaths
# keep only mappings for datacolumns present in data hash
mappings = @handler.mapper[:mappings].select do |m|
m[:fieldname] == 'shortIdentifier' || @response.merged_data.key?(m[:datacolumn])
end

# create xpaths for remaining mappings...
@xphash = mappings.map{ |m| m[:fullpath] }.uniq
# hash with xpath as key and xpath info hash from DataHandler as value
@xphash = @xphash.map{ |xpath| [xpath, @handler.mapper[:xpath][xpath]] }.to_h
@xphash = @xphash.map{ |xpath| [xpath, @handler.mapper[:xpath][xpath].clone] }.to_h
@xphash.each do |xpath, hash|
hash[:mappings] = hash[:mappings].select do |m|
m[:fieldname] == 'shortIdentifier' || @response.merged_data.key?(m[:datacolumn])
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 = "2.2.4"
VERSION = "2.2.5"
end
end
33 changes: 33 additions & 0 deletions spec/collectionspace/mapper/data_mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,39 @@
before(:all) do
@config = CollectionSpace::Mapper::DEFAULT_CONFIG
end

context 'fcart profile' do
before(:all) do
@client = fcart_client
@cache = fcart_cache
populate_fcart(@cache)
end

context 'acquisition record' do
before(:all) do
@acq_mapper = get_json_record_mapper(path: 'spec/fixtures/files/mappers/release_6_1/fcart/fcart_3_0_1-acquisition.json')
@handler = CollectionSpace::Mapper::DataHandler.new(record_mapper: @acq_mapper, client: @client, cache: @cache, config: @config)
end

it 'maps records as expected in sequence' do
data1 = JSON.parse("{\"creditline\":\"Gift of Frances, 1985\",\"accessiondategroup\":\"1985\",\"acquisitionmethod\":\"unknown-provenance\",\"acquisitionreferencenumber\":\"ACC216 (migrated accession)\",\"acquisitionsourceperson\":\"\",\"acquisitionsourceorganization\":\"\",\"acquisitionauthorizer\":\"\",\"acquisitionnote\":\"\"}")
data2 = JSON.parse("{\"creditline\":\"\",\"accessiondategroup\":\"\",\"acquisitionmethod\":\"unknown-provenance\",\"acquisitionreferencenumber\":\"ACC215 (migrated accession)\",\"acquisitionsourceperson\":\"\",\"acquisitionsourceorganization\":\"\",\"acquisitionauthorizer\":\"\",\"acquisitionnote\":\"\"}")
data3 = JSON.parse("{\"creditline\":\"Gift of Elizabeth, 1985\",\"accessiondategroup\":\"1985\",\"acquisitionmethod\":\"gift\",\"acquisitionreferencenumber\":\"ACC208 (migrated accession)\",\"acquisitionsourceperson\":\"Elizabeth\",\"acquisitionsourceorganization\":\"\",\"acquisitionauthorizer\":\"\",\"acquisitionnote\":\"Acquisition source role(s): Donor\"}")
data = [data1, data2, data3]
preppers = data.map{ |d| CollectionSpace::Mapper::DataPrepper.new(d, @handler) }
mappers = preppers.map{ |prepper| CollectionSpace::Mapper::DataMapper.new(prepper.prep, @handler, prepper.xphash) }
docs = mappers.map{ |mapper| remove_namespaces(mapper.response.doc) }
docxpaths = docs.map{ |doc| list_xpaths(doc) }

fixpaths = ['fcart/acqseq1.xml', 'fcart/acqseq2.xml', 'fcart/acqseq3.xml']
fixdocs = fixpaths.map{ |path| get_xml_fixture(path) }
fixxpaths = fixdocs.map{ |doc| list_xpaths(doc) }

expect(docxpaths).to eq(fixxpaths)
end

end
end

context 'core profile' do
before(:all) do
Expand Down
75 changes: 0 additions & 75 deletions spec/collectionspace/mapper/data_mapper_ucb_spec.rb

This file was deleted.

31 changes: 31 additions & 0 deletions spec/fcart_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

module Helpers
extend self

def fcart_client
CollectionSpace::Client.new(
CollectionSpace::Configuration.new(
base_uri: 'https://fcart.dev.collectionspace.org/cspace-services',
username: '[email protected]',
password: 'Administrator'
)
)
end

def fcart_cache
cache_config = {
domain: 'fcart.collectionspace.org',
search_enabled: false,
search_identifiers: false
}
CollectionSpace::RefCache.new(config: cache_config, client: fcart_client)
end

def populate_fcart(cache)
terms = [
['personauthorities', 'person', 'Elizabeth', "urn:cspace:fcart.collectionspace.org:personauthorities:name(person):item:name(Elizabeth123)'Elizabeth'"] ]
populate(cache, terms)
end

end
22 changes: 22 additions & 0 deletions spec/fixtures/files/xml/fcart/acqseq1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<document>
<acquisitions_common>
<acquisitionReferenceNumber>ACC216 (migrated accession)</acquisitionReferenceNumber>
<accessionDateGroup>
<dateDisplayDate>1985</dateDisplayDate>
<dateEarliestSingleYear>1985</dateEarliestSingleYear>
<dateEarliestSingleMonth>1</dateEarliestSingleMonth>
<dateEarliestSingleDay>1</dateEarliestSingleDay>
<dateEarliestSingleEra>urn:cspace:fcart.collectionspace.org:vocabularies:name(dateera):item:name(ce)'CE'</dateEarliestSingleEra>
<dateLatestYear>1985</dateLatestYear>
<dateLatestMonth>12</dateLatestMonth>
<dateLatestDay>31</dateLatestDay>
<dateLatestEra>urn:cspace:fcart.collectionspace.org:vocabularies:name(dateera):item:name(ce)'CE'</dateLatestEra>
<dateEarliestScalarValue>1985-01-01T00:00:00.000Z</dateEarliestScalarValue>
<dateLatestScalarValue>1986-01-01T00:00:00.000Z</dateLatestScalarValue>
<scalarValuesComputed>true</scalarValuesComputed>
</accessionDateGroup>
<acquisitionMethod>unknown-provenance</acquisitionMethod>
<creditLine>Gift of Frances, 1985</creditLine>
</acquisitions_common>
</document>
7 changes: 7 additions & 0 deletions spec/fixtures/files/xml/fcart/acqseq2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<document>
<acquisitions_common>
<acquisitionReferenceNumber>ACC215 (migrated accession)</acquisitionReferenceNumber>
<acquisitionMethod>unknown-provenance</acquisitionMethod>
</acquisitions_common>
</document>
26 changes: 26 additions & 0 deletions spec/fixtures/files/xml/fcart/acqseq3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0"?>
<document>
<acquisitions_common>
<acquisitionSources>
<acquisitionSource>urn:cspace:fcart.collectionspace.org:personauthorities:name(person):item:name(Elizabeth123)'Elizabeth'</acquisitionSource>
</acquisitionSources>
<acquisitionReferenceNumber>ACC208 (migrated accession)</acquisitionReferenceNumber>
<accessionDateGroup>
<dateDisplayDate>1985</dateDisplayDate>
<dateEarliestSingleYear>1985</dateEarliestSingleYear>
<dateEarliestSingleMonth>1</dateEarliestSingleMonth>
<dateEarliestSingleDay>1</dateEarliestSingleDay>
<dateEarliestSingleEra>urn:cspace:fcart.collectionspace.org:vocabularies:name(dateera):item:name(ce)'CE'</dateEarliestSingleEra>
<dateLatestYear>1985</dateLatestYear>
<dateLatestMonth>12</dateLatestMonth>
<dateLatestDay>31</dateLatestDay>
<dateLatestEra>urn:cspace:fcart.collectionspace.org:vocabularies:name(dateera):item:name(ce)'CE'</dateLatestEra>
<dateEarliestScalarValue>1985-01-01T00:00:00.000Z</dateEarliestScalarValue>
<dateLatestScalarValue>1986-01-01T00:00:00.000Z</dateLatestScalarValue>
<scalarValuesComputed>true</scalarValuesComputed>
</accessionDateGroup>
<acquisitionMethod>gift</acquisitionMethod>
<acquisitionNote>Acquisition source role(s): Donor</acquisitionNote>
<creditLine>Gift of Elizabeth, 1985</creditLine>
</acquisitions_common>
</document>
2 changes: 1 addition & 1 deletion spec/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
require_relative './bonsai_helpers'
require_relative './botgarden_helpers'
require_relative './core_helpers'
require_relative './fcart_helpers'
require_relative './lhmc_helpers'
require_relative './ucb_helpers'

module Helpers
extend self
Expand Down
24 changes: 0 additions & 24 deletions spec/ucb_helpers.rb

This file was deleted.

0 comments on commit 3f6d7dd

Please sign in to comment.