Skip to content

Commit

Permalink
Merge pull request #125 from collectionspace/fix-comparison
Browse files Browse the repository at this point in the history
Bugfix for profile comparison
  • Loading branch information
kspurgin authored Sep 19, 2023
2 parents 6b25b63 + c54dd5d commit 9f5e184
Show file tree
Hide file tree
Showing 14 changed files with 270,140 additions and 206 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ These changes are merged into the `main` branch, but have not been released. Aft

== Releases

=== 2.0.1 - 2023-09-19
==== Bugfixes
* Fix failure in `ProfileComparison` class and add integration test

=== 2.0.0 - 2023-08-16
==== Breaking
* `ccu fields csv` command no longer allows you to specify record types to include. All record types from the given profiles are included in the output, which you can easily filter to the record type(s) of interest.
Expand Down
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
source "https://rubygems.org"

group :test do
gem "rspec-custom", github: "kspurgin/rspec-custom", branch: "main"
end

# Specify your gem's dependencies in cspace_config_untangler.gemspec
gemspec
43 changes: 27 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
GIT
remote: https://github.com/kspurgin/rspec-custom.git
revision: 074dcc0a4ffeccd1cebcd8654e13724117bc8b4f
branch: main
specs:
rspec-custom (0.1.0)
rspec-core

PATH
remote: .
specs:
Expand Down Expand Up @@ -40,27 +48,29 @@ GEM
http-parser (1.2.3)
ffi-compiler (>= 1.0, < 2.0)
method_source (1.0.0)
nokogiri (1.14.3-x86_64-darwin)
mini_portile2 (2.8.4)
nokogiri (1.14.3)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
pry (0.13.1)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (5.0.3)
racc (1.7.1)
rake (13.0.6)
rspec (3.11.0)
rspec-core (~> 3.11.0)
rspec-expectations (~> 3.11.0)
rspec-mocks (~> 3.11.0)
rspec-core (3.11.0)
rspec-support (~> 3.11.0)
rspec-expectations (3.11.0)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-mocks (3.11.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-support (3.11.1)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
thor (1.2.2)
unf (0.1.4)
unf_ext
Expand All @@ -71,11 +81,12 @@ PLATFORMS
ruby

DEPENDENCIES
bundler (~> 2.3.9)
bundler
cspace_config_untangler!
pry (~> 0.13.0)
rake (~> 13.0.6)
rspec (~> 3.11)
pry
rake
rspec
rspec-custom!

BUNDLED WITH
2.3.9
36 changes: 18 additions & 18 deletions cspace_config_untangler.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "cspace_config_untangler/version"

Gem::Specification.new do |spec|
spec.name = "cspace_config_untangler"
spec.version = CspaceConfigUntangler::VERSION
spec.authors = ["Kristina Spurgin"]
spec.email = ["[email protected]"]
spec.name = "cspace_config_untangler"
spec.version = CspaceConfigUntangler::VERSION
spec.authors = ["Kristina Spurgin"]
spec.email = ["[email protected]"]

spec.summary = "Generate data dictionary info from CSpace configs"
spec.homepage = "https://github.com/lyrasis/cspace_config_untangler"
spec.license = "MIT"
spec.summary = "Generate data dictionary info from CSpace configs"
spec.homepage = "https://github.com/lyrasis/cspace_config_untangler"
spec.license = "MIT"

spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"

Expand All @@ -20,19 +20,19 @@ Gem::Specification.new do |spec|

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
`git ls-files -z`.split("\x0").reject { |f|
f.match(%r{^(test|spec|features)/})
}
end
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}){ |f| File.basename(f) }
spec.require_paths = ['lib']
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 2.3.9"
spec.add_development_dependency "pry", "~> 0.13.0"
# spec.add_development_dependency "byebug"
# spec.add_development_dependency "pry-byebug"
spec.add_development_dependency "rake", "~> 13.0.6"
spec.add_development_dependency "rspec", "~> 3.11"
spec.add_development_dependency "bundler"
spec.add_development_dependency "pry"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"

spec.add_runtime_dependency "dry-configurable", "~> 0.12"
spec.add_runtime_dependency "facets", "~> 3.1.0"
Expand Down
85 changes: 43 additions & 42 deletions lib/cspace_config_untangler/fields/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initialize(rectype_obj, form_field)
@fid = "#{@profile.name} #{rectype.name} #{@ns_for_id} #{@name}"
end

def csv_header(mode=:expert)
def csv_header(mode = :expert)
case mode
when :expert then expert_csv_row.keys.map(&:to_s)
when :friendly then friendly_csv_row.keys.map(&:to_s)
Expand All @@ -32,11 +32,7 @@ def csv_header(mode=:expert)
end

def structured_date?
if @data_type == 'structured date group'
return true
else
return false
end
@data_type == "structured date group"
end

def freetext?
Expand All @@ -52,24 +48,24 @@ def controlled?

def authority_controlled?
controlled? &&
value_source.any?{ |src| src.source_type == "authority" }
value_source.any? { |src| src.source_type == "authority" }
end

def vocabulary_controlled?
controlled? &&
value_source.any?{ |src| src.source_type == "vocabulary" }
value_source.any? { |src| src.source_type == "vocabulary" }
end

def optionlist_controlled?
controlled? &&
value_source.any?{ |src| src.source_type == "optionlist" }
value_source.any? { |src| src.source_type == "optionlist" }
end

# @param name [String]
def controlled_by?(name)
return false unless controlled?

value_source.map{ |src| src.name }
value_source.map { |src| src.name }
.include?(name)
end

Expand All @@ -81,14 +77,18 @@ def to_user_csv
format_csv(friendly_csv_row)
end

def to_h
expert_csv_row
end

private

def formatted_ui_path(orig)
return [] unless orig
return [] if orig.empty?

orig.compact
.map{ |segment| lookup_display_name(segment) }
.map { |segment| lookup_display_name(segment) }
.compact
end

Expand All @@ -103,14 +103,14 @@ def expert_csv_row
ui_info_group: get_ui_info_group,
ui_path: get_ui_path,
ui_field_label: label,
xml_path: @schema_path.join(' > '),
xml_path: @schema_path.join(" > "),
xml_field_name: @name,
data_type: @data_type,
required: @required,
repeats: @repeats,
group_repeats: @in_repeating_group,
data_source: @value_source.map(&:fields_csv_label).compact.join('; '),
option_list_values: @value_list.join(', ')
data_source: @value_source.map(&:fields_csv_label).compact.join("; "),
option_list_values: @value_list.join(", ")
}
end

Expand All @@ -125,16 +125,16 @@ def friendly_csv_row
required: @required,
repeats: @repeats,
group_repeats: @in_repeating_group,
data_source: @value_source.map(&:fields_csv_label).compact.join('; '),
option_list_values: @value_list.join(', '),
data_source: @value_source.map(&:fields_csv_label).compact.join("; "),
option_list_values: @value_list.join(", "),
record_type_machine_name: @rectype.name,
field_machine_name: @name
}
end

def format_csv(source)
source.values
.map{ |val| val.nil? ? "" : val }
.map { |val| val.nil? ? "" : val }
end

def get_ui_info_group
Expand All @@ -157,28 +157,28 @@ def merge_field_defs
def find_field_def
fd = @profile.field_defs.dig(@id)
if fd.nil?
return find_field_def_alt
find_field_def_alt
elsif fd.length == 1
return fd.first
fd.first
else
return fd.select{ |f| f.ns == @ns }.first
fd.select { |f| f.ns == @ns }.first
end
end

def find_field_def_alt
if @ns == 'ns2:conservation_livingplant'
try_id = @id.sub('ext.', 'conservation_')
try_id = if @ns == "ns2:conservation_livingplant"
@id.sub("ext.", "conservation_")
else
try_id = "#{@ns.sub('ns2:', '')}.#{@name}"
"#{@ns.sub("ns2:", "")}.#{@name}"
end

fd = @profile.field_defs.dig(try_id)
if fd.nil?
return nil
nil
elsif fd.length == 1
return fd.first
fd.first
else
return fd.select{ |f| f.ns == @ns }.first
fd.select { |f| f.ns == @ns }.first
end
end

Expand All @@ -198,20 +198,20 @@ def lookup_display_name(val)

msgs = @profile.messages

if val.start_with?('panel.')
if msgs.dig(val, 'name')
msgs[val]['name']
if val.start_with?("panel.")
if msgs.dig(val, "name")
msgs[val]["name"]
else
alt_panel_lookup(val)
end
elsif val.start_with?('inputTable.')
msgs.dig(val, 'name') ? msgs[val]['name'] : val
elsif val.start_with?("inputTable.")
msgs.dig(val, "name") ? msgs[val]["name"] : val
else
fieldid = "field.#{val}"
if msgs.dig(fieldid, 'fullName')
msgs[fieldid]['fullName']
elsif msgs.dig(fieldid, 'name')
msgs[fieldid]['name']
if msgs.dig(fieldid, "fullName")
msgs[fieldid]["fullName"]
elsif msgs.dig(fieldid, "name")
msgs[fieldid]["name"]
elsif val == "uoc_common.useDateHoursSpent"
CCU.warn_on_upgrade(binding.source_location, "DRYD-1269")
alt_fieldname_lookup(val.sub("useDateHoursSpent", "hoursSpent"))
Expand Down Expand Up @@ -254,18 +254,19 @@ def alt_fieldname_lookup(val)

def alt_panel_lookup(val)
trunc_lookup = {}
@profile.messages.select{ |id, h| id.start_with?('panel.') }.each{ |id, h|
name = id.split('.').last
@profile.messages.select { |id, h|
id.start_with?("panel.")
}.each { |id, h|
name = id.split(".").last
trunc_lookup[name] = h
}
trunc_val = val.split('.').last
trunc_val = val.split(".").last

if trunc_lookup.dig(trunc_val, 'name')
new = trunc_lookup[trunc_val]['name']
if trunc_lookup.dig(trunc_val, "name")
trunc_lookup[trunc_val]["name"]
else
new = val
val
end
return new
end

def fix_museum_records
Expand Down
Loading

0 comments on commit 9f5e184

Please sign in to comment.