Skip to content

Commit

Permalink
Add RightsStatements service
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Aug 24, 2016
1 parent bf708eb commit 638cfc2
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 12 deletions.
8 changes: 8 additions & 0 deletions app/services/curation_concerns/license_service.rb
@@ -0,0 +1,8 @@
module CurationConcerns
# Provide select options for the license (dcterms:rights) field
class LicenseService < QaSelectService
def initialize
super('licenses')
end
end
end
33 changes: 33 additions & 0 deletions app/services/curation_concerns/qa_select_service.rb
@@ -0,0 +1,33 @@
module CurationConcerns
# This is an abstract class to provide select options from a
# questioning authority backed authority
class QaSelectService
attr_reader :authority

def initialize(authority_name)
@authority = Qa::Authorities::Local.subauthority_for(authority_name)
end

def select_all_options
authority.all.map do |element|
[element[:label], element[:id]]
end
end

def select_active_options
active_elements.map { |e| [e[:label], e[:id]] }
end

def active?(id)
authority.find(id).fetch('active')
end

def label(id)
authority.find(id).fetch('term')
end

def active_elements
authority.all.select { |e| active?(e.fetch('id')) }
end
end
end
8 changes: 8 additions & 0 deletions app/services/curation_concerns/rights_statements.rb
@@ -0,0 +1,8 @@
module CurationConcerns
# Provide select options for the copyright status (edm:rights) field
class RightsStatements < QaSelectService
def initialize
super('rights_statements')
end
end
end
11 changes: 9 additions & 2 deletions app/services/rights_service.rb
@@ -1,8 +1,15 @@
module RightsService
extend Deprecation
mattr_accessor :authority
self.authority = Qa::Authorities::Local.subauthority_for('rights')
begin
self.authority = Qa::Authorities::Local.subauthority_for('rights')
rescue Qa::InvalidSubAuthority
Deprecation.warn(RightsService, "You are using the deprecated RightsService module, but you do not have 'rights.yml'. Switch to CurationConcerns::LicenseService instead")
self.authority = Qa::Authorities::Local.subauthority_for('licenses')
end

def self.select_all_options
Deprecation.warn(RightsService, "RightsService is deprecated. Use CurationConcerns::LicenseService instead. This will be removed in curation_concerns 2.0")
authority.all.map do |element|
[element[:label], element[:id]]
end
Expand All @@ -21,6 +28,6 @@ def self.label(id)
end

def self.active_elements
authority.all.select { |e| authority.find(e[:id])[:active] }
authority.all.select { |e| active?(e[:id]) }
end
end
2 changes: 1 addition & 1 deletion app/views/curation_concerns/base/_form_rights.html.erb
Expand Up @@ -10,7 +10,7 @@
</p>

<%= f.input :rights, as: :multi_value_select,
collection: RightsService.select_active_options,
collection: CurationConcerns::LicenseService.new.select_active_options,
include_blank: true,
item_helper: method(:include_current_value),
input_html: { class: 'form-control' } %>
Expand Down
15 changes: 6 additions & 9 deletions lib/generators/curation_concerns/install_generator.rb
Expand Up @@ -15,9 +15,8 @@ class Install < Rails::Generators::Base
5. Adds CurationConcerns abilities into the Ability class
6. Copies the catalog controller into the local app
7. Adds CurationConcerns::SolrDocumentBehavior to app/models/solr_document.rb
8. Adds config/authorities/rights.yml to the application
9. Adds config/authorities/resource_types.yml to the application
10. Copies modified simple_form initializers
8. Adds local authority files to the application
9. Copies modified simple_form initializers
'

def run_required_generators
Expand Down Expand Up @@ -93,12 +92,10 @@ def add_helper
copy_file 'curation_concerns_helper.rb', 'app/helpers/curation_concerns_helper.rb'
end

def rights_config
copy_file "config/authorities/rights.yml", "config/authorities/rights.yml"
end

def resource_types_config
copy_file "config/authorities/resource_types.yml", "config/authorities/resource_types.yml"
def local_authorities
copy_file "config/authorities/licenses.yml"
copy_file "config/authorities/rights_statements.yml"
copy_file "config/authorities/resource_types.yml"
end

def simple_form_initializers
Expand Down
@@ -0,0 +1,37 @@
terms:
- id: http://rightsstatements.org/vocab/InC/1.0/
term: "In Copyright"
active: true
- id: http://rightsstatements.org/vocab/InC-OW-EU/1.0/
term: "In Copyright - EU Orphan Work"
active: true
- id: http://rightsstatements.org/vocab/InC-EDU/1.0/
term: "In Copyright - Educational Use Permitted"
active: true
- id: http://rightsstatements.org/vocab/InC-NC/1.0/
term: "In Copyright - Non-Commercial Use Permitted"
active: true
- id: http://rightsstatements.org/vocab/InC-RUU/1.0/
term: "In Copyright - Rights-holder(s) Unlocatable or Unidentifiable"
active: true
- id: http://rightsstatements.org/vocab/NoC-CR/1.0/
term: "No Copyright - Contractual Restrictions"
active: true
- id: http://rightsstatements.org/vocab/NoC-NC/1.0/
term: "No Copyright - Non-Commercial Use Only "
active: true
- id: http://rightsstatements.org/vocab/NoC-OKLR/1.0/
term: "No Copyright - Other Known Legal Restrictions"
active: true
- id: http://rightsstatements.org/vocab/NoC-US/1.0/
term: "No Copyright - United States"
active: true
- id: http://rightsstatements.org/vocab/CNE/1.0/
term: "Copyright Not Evaluated"
active: true
- id: http://rightsstatements.org/vocab/UND/1.0/
term: "Copyright Undetermined"
active: true
- id: http://rightsstatements.org/vocab/NKC/1.0/
term: "No Known Copyright"
active: true
File renamed without changes.
36 changes: 36 additions & 0 deletions spec/services/curation_concerns/license_service_spec.rb
@@ -0,0 +1,36 @@
require 'spec_helper'

describe CurationConcerns::LicenseService do
before do
# Configure QA to use fixtures
qa_fixtures = { local_path: File.expand_path('spec/fixtures/authorities') }
allow(Qa::Authorities::Local).to receive(:config).and_return(qa_fixtures)
end
let(:service) { described_class.new }

describe "#select_active_options" do
it "returns active terms" do
expect(service.select_active_options).to include(["First Active Term", "demo_id_01"], ["Second Active Term", "demo_id_02"])
end

it "does not return inactive terms" do
expect(service.select_active_options).not_to include(["Third is an Inactive Term", "demo_id_03"], ["Fourth is an Inactive Term", "demo_id_04"])
end
end

describe "#select_all_options" do
it "returns both active and inactive terms" do
expect(service.select_all_options).to include(["Fourth is an Inactive Term", "demo_id_04"], ["First Active Term", "demo_id_01"])
end
end

describe "#label" do
it "resolves for ids of active terms" do
expect(service.label('demo_id_01')).to eq("First Active Term")
end

it "resolves for ids of inactive terms" do
expect(service.label('demo_id_03')).to eq("Third is an Inactive Term")
end
end
end
11 changes: 11 additions & 0 deletions spec/services/curation_concerns/rights_statements_spec.rb
@@ -0,0 +1,11 @@
require 'spec_helper'

describe CurationConcerns::RightsStatements do
let(:service) { described_class.new }

describe "#select_active_options" do
it "returns active terms" do
expect(service.select_active_options).to include(["In Copyright", "http://rightsstatements.org/vocab/InC/1.0/"], ["No Known Copyright", "http://rightsstatements.org/vocab/NKC/1.0/"])
end
end
end
2 changes: 2 additions & 0 deletions spec/services/rights_service_spec.rb
@@ -1,5 +1,6 @@
require 'spec_helper'

Deprecation.default_deprecation_behavior = :silence
describe RightsService do
before do
# Configure QA to use fixtures
Expand Down Expand Up @@ -33,3 +34,4 @@
end
end
end
Deprecation.default_deprecation_behavior = :stderr

0 comments on commit 638cfc2

Please sign in to comment.