stash-merritt 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stash/merritt/ezid_helper.rb +4 -12
- data/lib/stash/merritt/module_info.rb +1 -1
- data/lib/stash/merritt/submission_job.rb +17 -5
- data/spec/db/stash/merritt/submission_package_spec.rb +2 -2
- data/spec/unit/stash/merritt/ezid_helper_spec.rb +11 -15
- data/spec/unit/stash/merritt/submission_job_spec.rb +16 -7
- data/stash-merritt.iml +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0929e76df292579509bd760cc6906f3886b1474
|
4
|
+
data.tar.gz: ddbafc67e4487606a13aee6116f0dad9e68371e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23e692e54ed88c08abdd8ec2b67c942913e4b37e10186a4b208714c06fe5becb56f32594944e5e49469052c0bd7e48361abeba2704df0f3eca5f25070fc9f6ee
|
7
|
+
data.tar.gz: 8ef7aaa13b2fdd46602150e35feb45379ee1616a87b03f9d892bcf0521c26742efb0556037197028095039f71b488403b25a4282e3d52eea12610e498156a73a
|
@@ -4,26 +4,18 @@ module Stash
|
|
4
4
|
module Merritt
|
5
5
|
class EzidHelper
|
6
6
|
attr_reader :resource
|
7
|
-
attr_reader :url_helpers
|
8
7
|
|
9
|
-
def initialize(resource
|
8
|
+
def initialize(resource:)
|
10
9
|
@resource = resource
|
11
|
-
@url_helpers = url_helpers
|
12
10
|
end
|
13
11
|
|
14
12
|
# @return [String] the identifier (DOI, ARK, or URN)
|
15
|
-
def
|
16
|
-
|
17
|
-
return identifier_str if identifier_str
|
18
|
-
|
19
|
-
new_identifier_str = ezid_client.mint_id
|
20
|
-
resource.ensure_identifier(new_identifier_str)
|
21
|
-
new_identifier_str
|
13
|
+
def mint_id
|
14
|
+
ezid_client.mint_id
|
22
15
|
end
|
23
16
|
|
24
|
-
def update_metadata(dc3_xml:)
|
17
|
+
def update_metadata(dc3_xml:, landing_page_url:)
|
25
18
|
identifier_str = resource.identifier_str
|
26
|
-
landing_page_url = url_helpers.show_path(identifier_str)
|
27
19
|
ezid_client.update_metadata(identifier_str, dc3_xml, landing_page_url)
|
28
20
|
end
|
29
21
|
|
@@ -45,13 +45,25 @@ module Stash
|
|
45
45
|
@resource ||= StashEngine::Resource.find(resource_id)
|
46
46
|
end
|
47
47
|
|
48
|
+
def tenant
|
49
|
+
@tenant ||= resource.tenant
|
50
|
+
end
|
51
|
+
|
52
|
+
def landing_page_url
|
53
|
+
@landing_page_url ||= begin
|
54
|
+
path_to_landing = url_helpers.show_path(resource.identifier_str)
|
55
|
+
tenant.landing_url(path_to_landing)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
48
59
|
def ezid_helper
|
49
|
-
@ezid_helper ||= EzidHelper.new(resource: resource
|
60
|
+
@ezid_helper ||= EzidHelper.new(resource: resource)
|
50
61
|
end
|
51
62
|
|
52
63
|
def ensure_identifier
|
53
|
-
|
54
|
-
|
64
|
+
return if resource.identifier
|
65
|
+
log.info("#{Time.now.xmlschema} #{self.class}: minting new identifier for resource #{resource_id}")
|
66
|
+
resource.ensure_identifier(ezid_helper.mint_id)
|
55
67
|
end
|
56
68
|
|
57
69
|
def create_package
|
@@ -67,8 +79,8 @@ module Stash
|
|
67
79
|
end
|
68
80
|
|
69
81
|
def update_metadata(dc3_xml)
|
70
|
-
log.info("#{Time.now.xmlschema} #{self.class}: updating identifier metadata for resource #{resource_id} (#{resource.identifier_str})")
|
71
|
-
ezid_helper.update_metadata(dc3_xml: dc3_xml)
|
82
|
+
log.info("#{Time.now.xmlschema} #{self.class}: updating identifier landing page (#{landing_page_url}) and metadata for resource #{resource_id} (#{resource.identifier_str})")
|
83
|
+
ezid_helper.update_metadata(dc3_xml: dc3_xml, landing_page_url: landing_page_url)
|
72
84
|
end
|
73
85
|
|
74
86
|
def cleanup(package)
|
@@ -33,7 +33,7 @@ module Stash
|
|
33
33
|
id_scheme: 'doi')
|
34
34
|
allow(tenant).to receive(:tenant_id).and_return('dataone')
|
35
35
|
allow(tenant).to receive(:short_name).and_return('DataONE')
|
36
|
-
allow(tenant).to receive(:landing_url) { |
|
36
|
+
allow(tenant).to receive(:landing_url) { |path_to_landing| URI::HTTPS.build(host: 'stash.example.edu', path: path_to_landing).to_s }
|
37
37
|
allow(tenant).to receive(:sword_params).and_return(collection_uri: 'http://sword.example.edu/stash-dev')
|
38
38
|
allow(StashEngine::Tenant).to receive(:find).with('dataone').and_return(tenant)
|
39
39
|
|
@@ -51,7 +51,7 @@ module Stash
|
|
51
51
|
).build
|
52
52
|
|
53
53
|
@url_helpers = double(Module) # yes, apparently URL helpers are an anonymous module
|
54
|
-
allow(url_helpers).to(receive(:show_path)) { |identifier| identifier }
|
54
|
+
allow(url_helpers).to(receive(:show_path)) { |identifier| "/stash/#{identifier}" }
|
55
55
|
|
56
56
|
# TODO: move this to ResourceBuilder
|
57
57
|
stash_wrapper.inventory.files.each do |stash_file|
|
@@ -19,8 +19,10 @@ module Stash
|
|
19
19
|
|
20
20
|
@identifier_str = 'doi:10.15146/R38675309'
|
21
21
|
@url_helpers = double(Module)
|
22
|
-
|
23
|
-
|
22
|
+
|
23
|
+
path_to_landing = "/stash/#{identifier_str}"
|
24
|
+
@landing_page_url = URI::HTTPS.build(host: 'stash.example.edu', path: path_to_landing).to_s
|
25
|
+
allow(url_helpers).to receive(:show_path).with(identifier_str).and_return(path_to_landing)
|
24
26
|
|
25
27
|
@tenant = double(StashEngine::Tenant)
|
26
28
|
id_params = {
|
@@ -32,19 +34,14 @@ module Stash
|
|
32
34
|
}
|
33
35
|
allow(tenant).to receive(:identifier_service).and_return(OpenStruct.new(id_params))
|
34
36
|
allow(tenant).to receive(:tenant_id).and_return('dataone')
|
37
|
+
allow(tenant).to receive(:landing_url).with(path_to_landing).and_return(landing_page_url)
|
35
38
|
allow(resource).to receive(:tenant).and_return(tenant)
|
36
39
|
|
37
|
-
@helper = EzidHelper.new(resource: resource
|
40
|
+
@helper = EzidHelper.new(resource: resource)
|
38
41
|
end
|
39
42
|
|
40
|
-
describe :
|
41
|
-
it '
|
42
|
-
expect(resource).to receive(:identifier_str).and_return(identifier_str)
|
43
|
-
expect(::Ezid::Client).not_to receive(:new)
|
44
|
-
expect(helper.ensure_identifier).to eq(identifier_str)
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'mints and assigns a new identifier if none is present' do
|
43
|
+
describe :mint_id do
|
44
|
+
it 'mints a new identifier' do
|
48
45
|
identifier = instance_double(::Ezid::MintIdentifierResponse)
|
49
46
|
allow(identifier).to receive(:id).and_return(identifier_str)
|
50
47
|
|
@@ -53,12 +50,11 @@ module Stash
|
|
53
50
|
.with(user: 'stash', password: '3cc9d3fbd9788148c6a32a1415fa673a')
|
54
51
|
.and_return(ezid_client)
|
55
52
|
|
56
|
-
expect(resource).to receive(:identifier_str).and_return(nil)
|
57
53
|
expect(ezid_client).to receive(:mint_identifier)
|
58
54
|
.with('doi:10.15146/R3', status: 'reserved', profile: 'datacite')
|
59
55
|
.and_return(identifier)
|
60
|
-
|
61
|
-
expect(helper.
|
56
|
+
|
57
|
+
expect(helper.mint_id).to eq(identifier_str)
|
62
58
|
end
|
63
59
|
end
|
64
60
|
|
@@ -80,7 +76,7 @@ module Stash
|
|
80
76
|
)
|
81
77
|
|
82
78
|
expect(resource).to receive(:identifier_str).and_return(identifier_str)
|
83
|
-
helper.update_metadata(dc3_xml: dc3_xml)
|
79
|
+
helper.update_metadata(dc3_xml: dc3_xml, landing_page_url: landing_page_url)
|
84
80
|
end
|
85
81
|
end
|
86
82
|
end
|
@@ -4,6 +4,7 @@ module Stash
|
|
4
4
|
module Merritt
|
5
5
|
describe SubmissionJob do
|
6
6
|
attr_reader :logger
|
7
|
+
attr_reader :landing_page_url
|
7
8
|
attr_reader :tenant
|
8
9
|
attr_reader :resource_id
|
9
10
|
attr_reader :resource
|
@@ -23,6 +24,8 @@ module Stash
|
|
23
24
|
@rails_logger = Rails.logger
|
24
25
|
Rails.logger = logger
|
25
26
|
|
27
|
+
@landing_page_url = URI::HTTPS.build(host: 'stash.example.edu', path: '/stash/doi:10.123/456').to_s
|
28
|
+
|
26
29
|
@tenant = double(StashEngine::Tenant)
|
27
30
|
sword_params = {
|
28
31
|
collection_uri: 'http://example.edu/sword/example',
|
@@ -31,6 +34,7 @@ module Stash
|
|
31
34
|
}.freeze
|
32
35
|
allow(tenant).to receive(:sword_params).and_return(sword_params)
|
33
36
|
allow(tenant).to receive(:id).and_return('example_u')
|
37
|
+
allow(tenant).to receive(:landing_url) { |path_to_landing| URI::HTTPS.build(host: 'stash.example.edu', path: path_to_landing).to_s }
|
34
38
|
|
35
39
|
@resource_id = 37
|
36
40
|
@resource = double(StashEngine::Resource)
|
@@ -40,12 +44,14 @@ module Stash
|
|
40
44
|
allow(resource).to receive(:tenant).and_return(tenant)
|
41
45
|
allow(resource).to receive(:tenant_id).and_return('example_u')
|
42
46
|
|
47
|
+
identifier = double(StashEngine::Identifier)
|
48
|
+
allow(resource).to receive(:identifier).and_return(identifier)
|
49
|
+
|
43
50
|
@url_helpers = double(Module) # yes, apparently URL helpers are an anonymous module
|
44
|
-
allow(url_helpers).to(receive(:show_path)) { |
|
51
|
+
allow(url_helpers).to(receive(:show_path)) { |identifier_str| "/stash/#{identifier_str}" }
|
45
52
|
|
46
53
|
@ezid_helper = instance_double(EzidHelper)
|
47
|
-
allow(EzidHelper).to receive(:new).with(resource: resource
|
48
|
-
allow(ezid_helper).to receive(:ensure_identifier)
|
54
|
+
allow(EzidHelper).to receive(:new).with(resource: resource).and_return(ezid_helper)
|
49
55
|
allow(ezid_helper).to receive(:update_metadata)
|
50
56
|
|
51
57
|
@package = instance_double(SubmissionPackage)
|
@@ -65,8 +71,10 @@ module Stash
|
|
65
71
|
end
|
66
72
|
|
67
73
|
describe :submit! do
|
68
|
-
it '
|
69
|
-
expect(
|
74
|
+
it 'mints an ID if needed' do
|
75
|
+
expect(resource).to receive(:identifier).and_return(nil)
|
76
|
+
expect(ezid_helper).to receive(:mint_id).and_return('doi:10.123/456')
|
77
|
+
expect(resource).to receive(:ensure_identifier).with('doi:10.123/456')
|
70
78
|
job.submit!
|
71
79
|
end
|
72
80
|
|
@@ -78,7 +86,7 @@ module Stash
|
|
78
86
|
it 'updates the metadata' do
|
79
87
|
dc3_xml = '<resource/>'
|
80
88
|
expect(package).to receive(:dc3_xml).and_return(dc3_xml)
|
81
|
-
expect(ezid_helper).to receive(:update_metadata).with(dc3_xml: dc3_xml)
|
89
|
+
expect(ezid_helper).to receive(:update_metadata).with(dc3_xml: dc3_xml, landing_page_url: landing_page_url)
|
82
90
|
job.submit!
|
83
91
|
end
|
84
92
|
|
@@ -102,7 +110,8 @@ module Stash
|
|
102
110
|
end
|
103
111
|
|
104
112
|
it 'fails on an ID minting error' do
|
105
|
-
expect(
|
113
|
+
expect(resource).to receive(:identifier).and_return(nil)
|
114
|
+
expect(ezid_helper).to receive(:mint_id).and_raise(Ezid::NotAllowedError)
|
106
115
|
expect(job.submit!.error).to be_a(Ezid::NotAllowedError)
|
107
116
|
end
|
108
117
|
|
data/stash-merritt.iml
CHANGED
@@ -41,6 +41,7 @@
|
|
41
41
|
<orderEntry type="library" scope="PROVIDED" name="arel (v6.0.4, ruby-2.2.5-p319) [gem]" level="application" />
|
42
42
|
<orderEntry type="library" scope="PROVIDED" name="ast (v2.3.0, ruby-2.2.5-p319) [gem]" level="application" />
|
43
43
|
<orderEntry type="library" scope="PROVIDED" name="builder (v3.2.3, ruby-2.2.5-p319) [gem]" level="application" />
|
44
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.13.7, ruby-2.2.5-p319) [gem]" level="application" />
|
44
45
|
<orderEntry type="library" scope="PROVIDED" name="carrierwave (v0.10.0, ruby-2.2.5-p319) [gem]" level="application" />
|
45
46
|
<orderEntry type="library" scope="PROVIDED" name="colorize (v0.8.1, ruby-2.2.5-p319) [gem]" level="application" />
|
46
47
|
<orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.0.4, ruby-2.2.5-p319) [gem]" level="application" />
|