Skip to content

Commit

Permalink
Merge pull request #125 from collectionspace/gh-importer-110-obj-hier…
Browse files Browse the repository at this point in the history
…-debug

Gh importer 110 obj hier debug
  • Loading branch information
kspurgin authored Sep 3, 2021
2 parents ff839d0 + d165313 commit 1ea749b
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 45 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ name: Ruby

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

jobs:
test:
Expand All @@ -25,7 +25,7 @@ jobs:
# change this to (see https://github.com/ruby/setup-ruby#versioning):
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
ruby-version: 2.7.3
- name: Install dependencies
run: bundle install
- name: Run tests
Expand Down
14 changes: 11 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ This project bumps the version number for any changes (including documentation u

## [Unreleased]

## [2.4.8] - 2021-09-03
### Changed
- Bugfix for [collectionspace-csv-importer#110](https://github.com/collectionspace/collectionspace-csv-importer/issues/110)
- Re-set up running tests automatically on PR creation
- Use `collectionspace-client` v0.10.0 and the `find_relation` method added to it
- Use `collectionspace-refcache` v0.7.7
- Add tests for methods in `TermSearchable` module

## [2.4.7] - 2021-07-14
### Changed
- use ruby v2.7.3
- use `collectionspace-client` v0.9.0
- use `collectionspace-refcache` v0.7.6
- Use ruby v2.7.3
- Use `collectionspace-client` v0.9.0
- Use `collectionspace-refcache` v0.7.6

## [2.4.6] - 2021-07-13
### Changed
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ ruby '2.7.3'
gem 'facets', require: false

# Specify your gem's dependencies in collectionspace-mapper.gemspec
gem 'collectionspace-client', tag: 'v0.9.0', git: 'https://github.com/collectionspace/collectionspace-client.git'
gem 'collectionspace-refcache', tag: 'v0.7.6', git: 'https://github.com/collectionspace/collectionspace-refcache.git'
gem 'collectionspace-client', tag: 'v0.10.0', git: 'https://github.com/collectionspace/collectionspace-client.git'
gem 'collectionspace-refcache', tag: 'v0.7.7', git: 'https://github.com/collectionspace/collectionspace-refcache.git'
gemspec
8 changes: 0 additions & 8 deletions lib/collectionspace/mapper/term_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,6 @@ def handle_term(val)
refname_urn
end

def in_cache?(val)
@cache.exists?(type, subtype, val)
end

def cached_term(val)
@cache.get(type, subtype, val, search: false)
end

def add_found_term(refname_urn, term_report)
refname_obj = CollectionSpace::Mapper::Tools::RefName.new(urn: refname_urn)
found = @config.check_terms ? true : false
Expand Down
13 changes: 11 additions & 2 deletions lib/collectionspace/mapper/term_searchable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ def searched_term(val)

def obj_csid(objnum, type)
csid = @cache.get(type, '', objnum)
return csid unless csid.nil?
csid ? extract_refname_csid(csid) : lookup_obj_csid(objnum, type)
end

def extract_refname_csid(urn)
urn.match(/:id\((.*?)\)/)[1]
end

def lookup_obj_csid(objnum, type)
response = @client.find(type: type, value: objnum)
if response.result.success?
result = response.parsed['abstract_common_list']
Expand Down Expand Up @@ -84,8 +90,8 @@ def obj_csid(objnum, type)
errors << {
category: :unsuccessful_csid_lookup_for_objnum,
field: '',
type: type,
subtype: '',
type: type,
value: objnum,
message: "Problem with search for #{objnum}."
}
Expand All @@ -94,6 +100,9 @@ def obj_csid(objnum, type)
end

def term_csid(term)
# This is currently working though it returns the cached refname urn instead of CSID
# if a term is cached. There's a lot of stuff to clean up/fix/test better here so
# I'm leaving this for now to get the bugfix in
csid = cached_term(term)
return csid unless csid.nil?

Expand Down
8 changes: 1 addition & 7 deletions lib/collectionspace/mapper/tools/record_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def initialize(client, mapper)
# Tests in examples/search.rb
def lookup(value)
if @ns_prefix == 'relations'
response = lookup_relationship(value)
response = @client.find_relation(subject_csid: value[:sub], object_csid: value[:obj])
else
response = lookup_non_relationship(value)
end
Expand All @@ -53,12 +53,6 @@ def lookup(value)
end

private

def lookup_relationship(value)
@client.get(
@path, query: { 'sbj' => value[:sub], 'obj' => value[:obj] }
)
end

def lookup_non_relationship(value)
@client.find(
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.4.7"
VERSION = '2.4.8'
end
end
35 changes: 17 additions & 18 deletions spec/collectionspace/mapper/data_mapper_core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,25 @@
end

context 'object hierarchy record', services_call: true do
let(:mapper) { get_json_record_mapper('spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_objecthierarchy.json') }

context 'record 1' do
let(:hashpath) { 'spec/fixtures/files/datahashes/core/objectHierarchy1.json' }
let(:fixturepath) { 'core/objectHierarchy1.xml' }
let(:mapper) do
get_json_record_mapper('spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_objecthierarchy.json')
end
let(:hashpath) { 'spec/fixtures/files/datahashes/core/objectHierarchy1.json' }
let(:fixturepath) { 'core/objectHierarchy1.xml' }

it 'sets response id field as expected' do
expect(response.identifier).to eq('2020.1.105 > 2020.1.1055')
end
it 'does not map unexpected fields' do
expect(diff).to eq([])
end
it 'sets response id field as expected' do
expect(response.identifier).to eq('2020.1.105 > 2020.1.1055')
end

it 'does not map unexpected fields' do
expect(diff).to eq([])
end

it 'maps as expected' do
fixture_xpaths.each do |xpath|
fixture_node = standardize_value(fixture_doc.xpath(xpath).text)
mapped_node = standardize_value(mapped_doc.xpath(xpath).text)
expect(mapped_node).to eq(fixture_node)
end
it 'maps as expected' do
fixture_xpaths.each do |xpath|
fixture_node = standardize_value(fixture_doc.xpath(xpath).text)
mapped_node = standardize_value(mapped_doc.xpath(xpath).text)
expect(mapped_node).to eq(fixture_node)
end
end
end
Expand Down
100 changes: 100 additions & 0 deletions spec/collectionspace/mapper/term_searchable_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# frozen_string_literal: true

require 'spec_helper'

class TermClass
attr_reader :cache, :client
attr_accessor :type, :subtype, :errors
include CS::Mapper::TermSearchable

def initialize(cache, client)
@cache = cache
@client = client
@type = 'conceptauthorities'
@subtype = 'concept'
@errors = []
end

end

RSpec.describe CollectionSpace::Mapper::TermSearchable do
before(:context) do
@cache = core_cache
populate_core(@cache)
end

let(:term){ TermClass.new(@cache, core_client) }

describe '#in_cache?' do
let(:result){ term.in_cache?(val) }
context 'when not in cache' do
let(:val){ 'Tiresias' }
it 'returns false' do
expect(result).to be false
end
end

context 'when in cache' do
let(:val){ 'Test' }
it 'returns true' do
expect(result).to be true
end
end
end

describe '#cached_term' do
let(:result){ term.cached_term(val) }
context 'when not in cache' do
let(:val){ 'Tiresias' }
it 'returns nil' do
expect(result).to be_nil
end
end

context 'when in cache' do
let(:val){ 'Test' }
it 'returns refname urn' do
expected = "urn:cspace:core.collectionspace.org:conceptauthorities:name(concept):item:name(Test1599650854716)'Test'"
expect(result).to eq(expected)
end
end
end

# also covers extract_refname_csid and lookup_obj_csid
describe '#obj_csid' do
let(:result){ term.obj_csid(objnum, type) }
let(:type){ 'collectionobjects' }
context 'when in cache' do
let(:objnum){ 'Hierarchy Test 001' }

it 'returns csid' do
expect(result).to eq('16161bff-b01a-4b55-95aa')
end
end

context 'when not in cache' do
let(:objnum){ 'QA TEST 001' }
it 'returns csid' do
expect(result).to eq('56c04f5f-32b9-4f1d-8a4b')
end
end
end

describe '#term_csid' do
let(:result){ term.term_csid(val) }
context 'when in cache' do
let(:val){ 'Sample Concept 1' }

it 'returns csid', :skip => 'does not cause mapping to fail, so we live with technical incorrectness for now' do
expect(result).to eq('c119ed04-d99d-4ea2-bbda')
end
end

context 'when not in cache' do
let(:val){ 'QA TEST Concept 2' }
it 'returns csid' do
expect(result).to eq('8a76c4d7-d66d-451c-abee')
end
end
end
end
11 changes: 11 additions & 0 deletions spec/collectionspace/mapper/tools/record_status_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,16 @@
expect(res[:status]).to eq(:existing)
end
end

context 'when mapper is for a relationship' do
let(:mapper) { CollectionSpace::Mapper::RecordMapper.new(mapper: get_json_record_mapper(
'spec/fixtures/files/mappers/release_6_1/core/core_6-1-0_objecthierarchy.json'
)) }

it 'works the same' do
res = service.lookup({sub: '56c04f5f-32b9-4f1d-8a4b', obj: '6f0ce7b3-0130-444d-8633'})
expect(res[:status]).to eq(:existing)
end
end
end
end
2 changes: 1 addition & 1 deletion spec/collectionspace/mapper/tools/refname_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'spec_helper'

RSpec.describe CollectionSpace::Mapper::Tools::RefName do
before(:all) do
before(:context) do
@cache = anthro_cache
populate_anthro(@cache)
end
Expand Down
2 changes: 2 additions & 0 deletions spec/core_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def populate_core(cache)
['citationauthorities', 'citation', 'makasi', "urn:cspace:core.collectionspace.org:citationauthorities:name(citation):item:name(makasi1599645537547)'makasi'"],
['citationauthorities', 'worldcat', 'Chelse', "urn:cspace:core.collectionspace.org:citationauthorities:name(worldcat):item:name(Chelse1599645525740)'Chelse'"],
['citationauthorities', 'worldcat', 'Patiently', "urn:cspace:core.collectionspace.org:citationauthorities:name(worldcat):item:name(Patiently1599559993332)'Patiently'"],
['collectionobjects', '', 'Hierarchy Test 001', "urn:cspace:core.collectionspace.org:collectionobjects:id(16161bff-b01a-4b55-95aa)'Hierarchy Test 001'"],
['conceptauthorities', 'concept', 'Test', "urn:cspace:core.collectionspace.org:conceptauthorities:name(concept):item:name(Test1599650854716)'Test'"],
['conceptauthorities', 'concept', 'Sample Concept 1', "urn:cspace:core.collectionspace.org:conceptauthorities:name(concept):item:name(SampleConcept11581354228875)'Sample Concept 1'"],
['conceptauthorities', 'concept', 'Uno', "urn:cspace:core.collectionspace.org:conceptauthorities:name(concept):item:name(Uno1599645111177)'Uno'"],
['conceptauthorities', 'occasion', 'Computer', "urn:cspace:core.collectionspace.org:conceptauthorities:name(occasion):item:name(Computer1599734104251)'Computer'"],
['locationauthorities', 'indeterminate', '~Indeterminate Location~', "urn:cspace:indeterminate:locationauthorities:name(indeterminate):item:name(indeterminate)'~Indeterminate Location~'"],
Expand Down

0 comments on commit 1ea749b

Please sign in to comment.