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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf3299ac7ab5dfacd5f34d68f94f58985126cc1a
4
- data.tar.gz: 199ad43c3ff3149474c5fa96096afa9b7aac6715
3
+ metadata.gz: f0929e76df292579509bd760cc6906f3886b1474
4
+ data.tar.gz: ddbafc67e4487606a13aee6116f0dad9e68371e8
5
5
  SHA512:
6
- metadata.gz: d3810a1472c76152187acaa66e9b2c294c324deb3ccd3a40361b772d10492cfc22a54bb7ae0be10565220b6f8b4d568e947325f757e824df5613d6f86bcc70bd
7
- data.tar.gz: ee05c454262f4ce76e86ef138a8243374fb03a52587f97f4e1cab2e863d858e26ea655c3bbdacccca63836406a8fb63f40dbcc4a1b56fde65fbd5291b7da5510
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:, url_helpers:)
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 ensure_identifier
16
- identifier_str = resource.identifier_str
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
 
@@ -4,7 +4,7 @@ module Stash
4
4
  NAME = 'stash-merritt'.freeze
5
5
 
6
6
  # The version of this gem
7
- VERSION = '0.0.1'.freeze
7
+ VERSION = '0.1.0'.freeze
8
8
 
9
9
  # The copyright notice for this gem
10
10
  COPYRIGHT = 'Copyright (c) 2017 The Regents of the University of California'.freeze
@@ -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, url_helpers: url_helpers)
60
+ @ezid_helper ||= EzidHelper.new(resource: resource)
50
61
  end
51
62
 
52
63
  def ensure_identifier
53
- log.info("#{Time.now.xmlschema} #{self.class}: ensuring identifier for resource #{resource_id} (#{resource.identifier_str})")
54
- ezid_helper.ensure_identifier
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) { |path| "https://stash-dev.example.edu/#{path}" }
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
- @landing_page_url = "http://stash.example.edu/stash/#{identifier_str}"
23
- allow(url_helpers).to receive(:show_path).with(identifier_str).and_return(landing_page_url)
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, url_helpers: url_helpers)
40
+ @helper = EzidHelper.new(resource: resource)
38
41
  end
39
42
 
40
- describe :ensure_identifier do
41
- it 'returns an existing identifier without bothering EZID' do
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
- expect(resource).to receive(:ensure_identifier).with(identifier_str)
61
- expect(helper.ensure_identifier).to eq(identifier_str)
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)) { |identifier| identifier }
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, url_helpers: url_helpers).and_return(ezid_helper)
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 'ensures an identifier' do
69
- expect(ezid_helper).to receive(:ensure_identifier)
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(ezid_helper).to receive(:ensure_identifier).and_raise(Ezid::NotAllowedError)
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" />
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stash-merritt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Moles