hydra-ezid 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CONTRIBUTORS.md +1 -0
- data/Gemfile +0 -13
- data/{LICENSE → LICENSE.txt} +0 -0
- data/README.md +38 -19
- data/Rakefile +15 -5
- data/config/ezid.yml +13 -0
- data/config/ezid_override.yml +6 -0
- data/config/jetty.yml +6 -0
- data/hydra-ezid.gemspec +7 -8
- data/lib/hydra/ezid.rb +15 -4
- data/lib/hydra/ezid/identifiable.rb +75 -0
- data/lib/hydra/ezid/mint_error.rb +6 -0
- data/lib/hydra/ezid/version.rb +1 -1
- data/spec/spec_helper.rb +3 -27
- data/spec/units/ezid_spec.rb +105 -0
- metadata +26 -64
- data/.gitmodules +0 -4
- data/app/assets/images/hydra_ezid/.keep +0 -0
- data/app/assets/javascripts/hydra_ezid/.keep +0 -0
- data/app/assets/stylesheets/hydra_ezid/.keep +0 -0
- data/app/controllers/.keep +0 -0
- data/app/controllers/ezid_controller.rb +0 -3
- data/app/helpers/.keep +0 -0
- data/app/helpers/ezid_helper.rb +0 -3
- data/app/mailers/.keep +0 -0
- data/app/models/.keep +0 -0
- data/app/views/.keep +0 -0
- data/app/views/ezid/_button_to_mint_ezid.html.erb +0 -1
- data/config/routes.rb +0 -3
- data/fedora_conf/conf/development/fedora.fcfg +0 -946
- data/fedora_conf/conf/test/fedora.fcfg +0 -946
- data/gemfiles/rails3.gemfile +0 -6
- data/gemfiles/rails4.gemfile +0 -6
- data/lib/hydra-ezid.rb +0 -6
- data/lib/hydra/ezid/controller_behavior.rb +0 -27
- data/lib/hydra/ezid/model_methods.rb +0 -10
- data/solr_conf/conf/schema.xml +0 -372
- data/solr_conf/conf/solrconfig.xml +0 -164
- data/solr_conf/solr.xml +0 -35
- data/spec/controllers/ezid_controller_spec.rb +0 -4
- data/spec/factories.rb +0 -3
- data/spec/factories/.keep +0 -0
- data/spec/helpers/ezid_helper_spec.rb +0 -6
- data/spec/models/ezid_spec.rb +0 -4
- data/spec/support/app/models/sample.rb +0 -36
- data/spec/support/app/views/catalog/_sort_and_per_page.html.erb +0 -10
- data/spec/support/db/migrate/20111101221803_create_searches.rb +0 -16
- data/spec/support/lib/generators/test_app_generator.rb +0 -56
- data/spec/support/lib/tasks/rspec.rake +0 -8
- data/tasks/hydra-ezid-dev.rake +0 -68
- data/tasks/jetty.rake +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 057f939ebe9d09e72b871c309aaf46069a950b0b
|
4
|
+
data.tar.gz: ff9d5a5c602c89ae7cb1e994b6c40d995411830b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 717e05c76340bccb043baa60b08f462910a8111bd9d4ce7ab4c0ed75431c63316bdf09a5a29871a84308a1253605b4430c89480579fce22fd27b067d46b98adf
|
7
|
+
data.tar.gz: cc82e1054392701c1ca5a77c0fa0f54df9cff16485a6756a3d47dd979d47139586646e6cb175be16ebdc2286cdd5d0a6055c8eb085900762acda86231747561a
|
data/.gitignore
CHANGED
data/CONTRIBUTORS.md
CHANGED
data/Gemfile
CHANGED
@@ -2,16 +2,3 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in hydra-ezid.gemspec
|
4
4
|
gemspec
|
5
|
-
|
6
|
-
# To use debugger
|
7
|
-
# gem 'debugger'
|
8
|
-
|
9
|
-
gem 'blacklight'
|
10
|
-
|
11
|
-
group :development, :test do
|
12
|
-
gem 'sqlite3'
|
13
|
-
gem "factory_girl_rails", "~> 4.1.0"
|
14
|
-
gem 'devise'
|
15
|
-
gem 'capybara', '~>1.1.3'
|
16
|
-
gem 'jettywrapper'
|
17
|
-
end
|
data/{LICENSE → LICENSE.txt}
RENAMED
File without changes
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Hydra::Ezid [![Version](https://badge.fury.io/rb/hydra-ezid.png)](http://badge.fury.io/rb/hydra-ezid) [![Build Status](https://travis-ci.org/psu-stewardship/hydra-ezid.png?branch=master)](https://travis-ci.org/psu-stewardship/hydra-ezid) [![Dependency Status](https://gemnasium.com/psu-stewardship/hydra-ezid.png)](https://gemnasium.com/psu-stewardship/hydra-ezid)
|
2
2
|
|
3
|
-
A
|
3
|
+
A Ruby gem providing EZID services for Hydra applications
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,35 +18,54 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
###
|
21
|
+
### Make your Models Identifiable by EZID
|
22
22
|
|
23
|
-
|
23
|
+
First, add a config file to your app in `config/ezid.yml` that looks like the following:
|
24
24
|
|
25
|
-
|
25
|
+
```yaml
|
26
|
+
doi:
|
27
|
+
user: "foo"
|
28
|
+
pass: "bar"
|
29
|
+
scheme: "doi"
|
30
|
+
shoulder: "sldr1"
|
31
|
+
naa: "10.1000"
|
26
32
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
ark:
|
34
|
+
user: "foo"
|
35
|
+
pass: "quux"
|
36
|
+
scheme: "ark"
|
37
|
+
shoulder: "sldr2"
|
38
|
+
naa: "98765"
|
32
39
|
```
|
33
40
|
|
34
|
-
|
35
|
-
|
36
|
-
ezid.new_ezid_path
|
37
|
-
|
38
|
-
### Make your Models Ezid-able
|
39
|
-
|
40
|
-
Add `include Hydra::Ezid::ModelMethods` to the models for anything that you want to be able to mint EZIDs for.
|
41
|
+
Add `include Hydra::Ezid::Identifiable` to the models you want EZIDs for.
|
41
42
|
|
42
43
|
Example:
|
43
44
|
```ruby
|
44
45
|
class GenericFile < ActiveFedora::Base
|
45
|
-
include Hydra::Ezid::
|
46
|
-
|
46
|
+
include Hydra::Ezid::Identifiable
|
47
|
+
ezid_config do
|
48
|
+
store_doi at: :descMetadata, in: :my_doi
|
49
|
+
store_ark at: :properties, in: :some_ark
|
50
|
+
find_creator at: :descMetadata, in: :author
|
51
|
+
find_title at: :properties
|
52
|
+
find_publisher at: :properties
|
53
|
+
find_publication_year at: :descMetadata, in: :pubYear
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
And then you can mint EZIDs on your model instances:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
gf = GenericFile.find('id:123')
|
61
|
+
gf.mint_ezid # will mint both a DOI and an ARK per the snippet above
|
62
|
+
gf.mint_ezid(Hydra::Ezid.config(except_keys: :doi)) # will mint only an ARK
|
63
|
+
gf.mint_doi # shortcut version of prior method
|
64
|
+
gf.mint_ezid(Hydra::Ezid.config(except_keys: :ark)) # will mint only a DOI
|
65
|
+
gf.mint_ark # shortcut version of prior method
|
47
66
|
```
|
48
67
|
|
49
|
-
|
68
|
+
## Developers
|
50
69
|
|
51
70
|
In order to make modifications to the gem code and run the tests, clone the repository then
|
52
71
|
|
data/Rakefile
CHANGED
@@ -5,12 +5,22 @@ rescue LoadError
|
|
5
5
|
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
6
|
end
|
7
7
|
|
8
|
-
|
8
|
+
require 'rspec/core'
|
9
|
+
require 'rspec/core/rake_task'
|
10
|
+
APP_ROOT="." # for jettywrapper
|
11
|
+
require 'jettywrapper'
|
9
12
|
|
10
|
-
|
13
|
+
RSpec::Core::RakeTask.new(:spec)
|
11
14
|
|
12
|
-
desc '
|
13
|
-
task :
|
15
|
+
desc 'Spin up jetty and run specs'
|
16
|
+
task :ci => ['jetty:unzip'] do
|
17
|
+
puts 'running continuous integration'
|
18
|
+
jetty_params = Jettywrapper.load_config
|
19
|
+
error = Jettywrapper.wrap(jetty_params) do
|
20
|
+
Rake::Task['spec'].invoke
|
21
|
+
end
|
22
|
+
raise "test failures: #{error}" if error
|
23
|
+
end
|
14
24
|
|
15
25
|
desc 'Default: run CI'
|
16
|
-
task :default =>
|
26
|
+
task :default => :ci
|
data/config/ezid.yml
ADDED
data/config/jetty.yml
ADDED
data/hydra-ezid.gemspec
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
lib = File.expand_path('../lib', __FILE__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'hydra/ezid/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
@@ -8,8 +7,8 @@ Gem::Specification.new do |s|
|
|
8
7
|
s.version = Hydra::Ezid::VERSION
|
9
8
|
s.authors = ['Michael J. Giarlo']
|
10
9
|
s.email = ['leftwing@alumni.rutgers.edu']
|
11
|
-
s.summary = 'A
|
12
|
-
s.description = 'A
|
10
|
+
s.summary = 'A Ruby gem providing EZID services for Hydra applications'
|
11
|
+
s.description = 'A Ruby gem providing EZID services for Hydra applications'
|
13
12
|
s.homepage = 'https://github.com/psu-stewardship/hydra-ezid'
|
14
13
|
s.license = 'APACHE2'
|
15
14
|
|
@@ -18,12 +17,12 @@ Gem::Specification.new do |s|
|
|
18
17
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
19
18
|
s.require_paths = ['lib']
|
20
19
|
|
21
|
-
s.add_dependency '
|
22
|
-
s.add_dependency '
|
20
|
+
s.add_dependency 'activesupport', '>= 3.2.13', '< 5.0'
|
21
|
+
s.add_dependency 'active-fedora'
|
23
22
|
s.add_dependency 'ezid'
|
24
23
|
|
25
24
|
s.add_development_dependency 'bundler', '~> 1.3'
|
26
25
|
s.add_development_dependency 'rake'
|
27
|
-
s.add_development_dependency '
|
28
|
-
s.add_development_dependency '
|
26
|
+
s.add_development_dependency 'jettywrapper'
|
27
|
+
s.add_development_dependency 'rspec'
|
29
28
|
end
|
data/lib/hydra/ezid.rb
CHANGED
@@ -1,11 +1,22 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active-fedora'
|
3
|
+
require 'yaml'
|
1
4
|
module Hydra
|
2
5
|
module Ezid
|
3
6
|
extend ActiveSupport::Autoload
|
4
7
|
autoload :Version
|
5
|
-
autoload :
|
6
|
-
autoload :
|
7
|
-
|
8
|
-
|
8
|
+
autoload :MintError
|
9
|
+
autoload :Identifiable
|
10
|
+
|
11
|
+
def self.config(options = {}.with_indifferent_access)
|
12
|
+
from_file = options.fetch(:from_file, default_file)
|
13
|
+
except_keys = Array(options[:except_keys])
|
14
|
+
from_file.to_hash.with_indifferent_access.delete_if { |k, v| except_keys.include? k.to_sym }
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def self.default_file
|
19
|
+
YAML::load(ERB.new(IO.read(File.join('config', 'ezid.yml'))).result)
|
9
20
|
end
|
10
21
|
end
|
11
22
|
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Hydra
|
2
|
+
module Ezid
|
3
|
+
module Identifiable
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
def self.ezid_registry
|
8
|
+
@@ezid_registry ||= {}
|
9
|
+
end
|
10
|
+
def self.ezid_config(&block)
|
11
|
+
block.call
|
12
|
+
end
|
13
|
+
def self.store_doi(options)
|
14
|
+
ezid_register(options, :doi)
|
15
|
+
end
|
16
|
+
def self.store_ark(options)
|
17
|
+
ezid_register(options, :ark)
|
18
|
+
end
|
19
|
+
def self.find_creator(options)
|
20
|
+
# TODO: unstub
|
21
|
+
end
|
22
|
+
def self.find_title(options)
|
23
|
+
# TODO: unstub
|
24
|
+
end
|
25
|
+
def self.find_publisher(options)
|
26
|
+
# TODO: unstub
|
27
|
+
end
|
28
|
+
def self.find_publication_year(options)
|
29
|
+
# TODO: unstub
|
30
|
+
end
|
31
|
+
|
32
|
+
# TODO: include stuff such as AF callbacks and validations
|
33
|
+
|
34
|
+
private
|
35
|
+
def self.ezid_register(options, scheme)
|
36
|
+
datastream = options[:at]
|
37
|
+
field = options.fetch(:in, scheme)
|
38
|
+
ezid_registry[scheme] = {datastream: datastream, field: field}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# TODO: This will be done by ezid gem, THROW AWAY
|
43
|
+
def idify(*ary)
|
44
|
+
"#{ary[0]}:/#{ary[1]}/#{ary[2]}#{ary[3]}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def mint_ezid(conf = Hydra::Ezid.config)
|
48
|
+
raise Hydra::Ezid::MintError.new("Cannot mint EZID until object is saved") unless self.persisted?
|
49
|
+
self.class.ezid_registry.each_pair do |scheme, opts|
|
50
|
+
scheme_conf = conf.values.find { |subkeys| subkeys['scheme'] == scheme.to_s }
|
51
|
+
next unless scheme_conf
|
52
|
+
id = idify(scheme_conf['scheme'], scheme_conf['naa'], scheme_conf['shoulder'], self.pid)
|
53
|
+
datastreams["#{opts[:datastream]}"].send("#{opts[:field]}=", id)
|
54
|
+
end
|
55
|
+
# TODO: When generate_ezid is ready, fix me with something like:
|
56
|
+
# session = ::Ezid::ApiSession.new(
|
57
|
+
# conf.doi.user,
|
58
|
+
# conf.doi.pass,
|
59
|
+
# conf.doi.scheme,
|
60
|
+
# conf.doi.naa
|
61
|
+
# )
|
62
|
+
# @ezid = session.generate_ezid(conf.doi.shoulder + self.pid)
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
|
66
|
+
def mint_doi
|
67
|
+
mint_ezid(Hydra::Ezid.config(except_keys: :ark))
|
68
|
+
end
|
69
|
+
|
70
|
+
def mint_ark
|
71
|
+
mint_ezid(Hydra::Ezid.config(except_keys: :doi))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/hydra/ezid/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,30 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
require File.expand_path("config/environment", ENV['RAILS_ROOT'] || File.expand_path("../internal", __FILE__))
|
6
|
-
require 'rspec/rails'
|
7
|
-
require 'hydra-ezid'
|
8
|
-
|
9
|
-
FactoryGirl.definition_file_paths = [File.expand_path("../factories", __FILE__)]
|
10
|
-
FactoryGirl.find_definitions
|
11
|
-
|
12
|
-
module EngineRoutes
|
13
|
-
def self.included(base)
|
14
|
-
base.routes { Hydra::Ezid::Engine.routes }
|
15
|
-
end
|
16
|
-
end
|
1
|
+
require 'rspec/autorun'
|
2
|
+
ENV['environment'] ||= 'test'
|
3
|
+
require 'hydra/ezid'
|
17
4
|
|
18
5
|
RSpec.configure do |config|
|
19
|
-
config.use_transactional_fixtures = true
|
20
|
-
config.include Devise::TestHelpers, :type => :controller
|
21
|
-
config.before(:each, :type=>"controller") { @routes = Hydra::Ezid::Engine.routes }
|
22
|
-
config.include EngineRoutes, :type => :controller
|
23
|
-
end
|
24
|
-
|
25
|
-
module FactoryGirl
|
26
|
-
def self.find_or_create(handle, by=:email)
|
27
|
-
tmpl = FactoryGirl.build(handle)
|
28
|
-
tmpl.class.send("find_by_#{by}".to_sym, tmpl.send(by)) || FactoryGirl.create(handle)
|
29
|
-
end
|
30
6
|
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::Ezid do
|
4
|
+
before(:all) do
|
5
|
+
class FedoraModel < ActiveFedora::Base
|
6
|
+
include Hydra::Ezid::Identifiable
|
7
|
+
has_metadata :name => 'properties', :type => ActiveFedora::SimpleDatastream do |m|
|
8
|
+
m.field 'some_ark', :string
|
9
|
+
end
|
10
|
+
has_metadata :name => 'descMetadata', :type => ActiveFedora::SimpleDatastream do |m|
|
11
|
+
m.field 'doi', :string
|
12
|
+
end
|
13
|
+
delegate_to :properties, [:some_ark], unique: true
|
14
|
+
delegate_to :descMetadata, [:doi], unique: true
|
15
|
+
ezid_config do
|
16
|
+
store_doi at: :descMetadata
|
17
|
+
store_ark at: :properties, in: :some_ark
|
18
|
+
find_creator at: :descMetadata, in: :author
|
19
|
+
find_title at: :properties
|
20
|
+
find_publisher at: :properties
|
21
|
+
find_publication_year at: :descMetadata, in: :pubYear
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
after(:all) do
|
27
|
+
Object.send(:remove_const, :FedoraModel)
|
28
|
+
end
|
29
|
+
|
30
|
+
subject(:item) { FedoraModel.new }
|
31
|
+
|
32
|
+
describe "#mint_ezid" do
|
33
|
+
before(:each) do
|
34
|
+
item.stub(:persisted? => true)
|
35
|
+
item.stub(:pid => 'sufia:xz67gt83a')
|
36
|
+
end
|
37
|
+
|
38
|
+
it { should respond_to(:mint_ezid) }
|
39
|
+
|
40
|
+
it "mints a valid ezid" do
|
41
|
+
item.mint_ezid.should be_nil
|
42
|
+
end
|
43
|
+
|
44
|
+
it "uses a configurator for account details" do
|
45
|
+
Hydra::Ezid.config['doi']['user'].should == ''
|
46
|
+
end
|
47
|
+
|
48
|
+
it "calls Ezid.generate_ezid" do
|
49
|
+
pending "*** WE NEED TO IMPLEMENT THIS ***"
|
50
|
+
Ezid::ApiSession.any_instance.should_receive(:generate_ezid).once
|
51
|
+
item.mint_ezid
|
52
|
+
end
|
53
|
+
|
54
|
+
it "raises an error when minting against an unsaved object" do
|
55
|
+
item.stub(:persisted? => false)
|
56
|
+
expect { item.mint_ezid }.to raise_error(Hydra::Ezid::MintError)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "respects the configurator when keys are passed in - doi" do
|
60
|
+
item.mint_ezid(Hydra::Ezid.config(except_keys: :doi))
|
61
|
+
item.some_ark.should == "ark:/98765/sldr2sufia:xz67gt83a"
|
62
|
+
item.doi.should be_nil
|
63
|
+
end
|
64
|
+
|
65
|
+
it "respects the configurator when keys are passed in - ark" do
|
66
|
+
item.mint_ezid(Hydra::Ezid.config(except_keys: :ark))
|
67
|
+
item.some_ark.should be_nil
|
68
|
+
item.doi.should == "doi:/10.1000/sldr1sufia:xz67gt83a"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "provides a convenience method for minting only ARKs" do
|
72
|
+
item.mint_ark
|
73
|
+
item.some_ark.should == "ark:/98765/sldr2sufia:xz67gt83a"
|
74
|
+
item.doi.should be_nil
|
75
|
+
end
|
76
|
+
|
77
|
+
it "provides a convenience method for minting only DOIs" do
|
78
|
+
item.mint_doi
|
79
|
+
item.some_ark.should be_nil
|
80
|
+
item.doi.should == "doi:/10.1000/sldr1sufia:xz67gt83a"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "respects a config from a file" do
|
84
|
+
f = YAML::load(ERB.new(IO.read(File.join('config', 'ezid_override.yml'))).result)
|
85
|
+
item.mint_ezid(Hydra::Ezid.config(from_file: f))
|
86
|
+
item.some_ark.should be_nil
|
87
|
+
item.doi.should == "doi:/10.2000/sldr3sufia:xz67gt83a"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "stores an id in a configurable location by scheme" do
|
91
|
+
item.mint_ezid
|
92
|
+
item.some_ark.should == "ark:/98765/sldr2sufia:xz67gt83a"
|
93
|
+
item.doi.should == "doi:/10.1000/sldr1sufia:xz67gt83a"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
it "disallows repeat settings of a scheme"
|
98
|
+
it "disallows setting of the ezid manually"
|
99
|
+
it "updates/saves when changed"
|
100
|
+
it "crosswalks metadata"
|
101
|
+
it "sends crosswalked metadata to the ezid service"
|
102
|
+
it "allows specification of DOI or ARK"
|
103
|
+
it "allows multiple accounts"
|
104
|
+
it "allows management of status (public, private, etc.)"
|
105
|
+
end
|