stash-merritt 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +193 -0
- data/.rubocop.yml +32 -0
- data/.ruby-version +1 -0
- data/.travis.yml +12 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +326 -0
- data/LICENSE.md +22 -0
- data/README.md +53 -0
- data/Rakefile +49 -0
- data/lib/datacite/mapping/datacite_xml_factory.rb +212 -0
- data/lib/stash/merritt/ezid_helper.rb +50 -0
- data/lib/stash/merritt/module_info.rb +12 -0
- data/lib/stash/merritt/repository.rb +17 -0
- data/lib/stash/merritt/submission_job.rb +90 -0
- data/lib/stash/merritt/submission_package/data_one_manifest_builder.rb +41 -0
- data/lib/stash/merritt/submission_package/merritt_datacite_builder.rb +22 -0
- data/lib/stash/merritt/submission_package/merritt_delete_builder.rb +25 -0
- data/lib/stash/merritt/submission_package/merritt_oaidc_builder.rb +130 -0
- data/lib/stash/merritt/submission_package/stash_wrapper_builder.rb +59 -0
- data/lib/stash/merritt/submission_package.rb +125 -0
- data/lib/stash/merritt/sword_helper.rb +58 -0
- data/lib/stash/merritt.rb +5 -0
- data/lib/stash.rb +5 -0
- data/spec/.rubocop.yml +10 -0
- data/spec/config/app_config.yml +3 -0
- data/spec/config/database.yml +7 -0
- data/spec/config/licenses.yml +18 -0
- data/spec/data/archive/mrt-datacite.xml +121 -0
- data/spec/data/archive/mrt-dataone-manifest.txt +32 -0
- data/spec/data/archive/mrt-oaidc.xml +38 -0
- data/spec/data/archive/stash-wrapper.xml +213 -0
- data/spec/data/archive.zip +0 -0
- data/spec/data/dc4-with-funding-references.xml +123 -0
- data/spec/db/datacite/mapping/datacite_xml_factory_spec.rb +56 -0
- data/spec/db/stash/merritt/merritt_oaidc_builder_spec.rb +72 -0
- data/spec/db/stash/merritt/submission_package_spec.rb +174 -0
- data/spec/db/stash/merritt/sword_helper_spec.rb +162 -0
- data/spec/db_spec_helper.rb +31 -0
- data/spec/rspec_custom_matchers.rb +92 -0
- data/spec/spec_helper.rb +86 -0
- data/spec/unit/stash/merritt/ezid_helper_spec.rb +88 -0
- data/spec/unit/stash/merritt/repository_spec.rb +19 -0
- data/spec/unit/stash/merritt/submission_job_spec.rb +127 -0
- data/spec/util/resource_builder.rb +333 -0
- data/stash-merritt.gemspec +48 -0
- data/stash-merritt.iml +147 -0
- data/stash-merritt.ipr +127 -0
- data/travis-local-deps.sh +43 -0
- metadata +337 -0
@@ -0,0 +1,123 @@
|
|
1
|
+
<resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://datacite.org/schema/kernel-4" xsi:schemaLocation="http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4/metadata.xsd">
|
2
|
+
<identifier identifierType="DOI">10.15146/R3RG6G</identifier>
|
3
|
+
<creators>
|
4
|
+
<creator>
|
5
|
+
<creatorName>Chen, Hao</creatorName>
|
6
|
+
<nameIdentifier nameIdentifierScheme="ORCID" schemeURI="http://orcid.org/">0123-4567-8910-1112</nameIdentifier>
|
7
|
+
<affiliation>North Carolina Central University</affiliation>
|
8
|
+
</creator>
|
9
|
+
</creators>
|
10
|
+
<titles>
|
11
|
+
<title>A Zebrafish Model for Studies on Esophageal Epithelial Biology</title>
|
12
|
+
<title titleType="Subtitle">
|
13
|
+
Characterizing a region of stratified squamous epithelium in the zebrafish
|
14
|
+
upper digestive tract
|
15
|
+
</title>
|
16
|
+
</titles>
|
17
|
+
<publisher>DataONE</publisher>
|
18
|
+
<publicationYear>2016</publicationYear>
|
19
|
+
<subjects>
|
20
|
+
<subject>Zebrafish</subject>
|
21
|
+
<subject>Epithelium</subject>
|
22
|
+
<subject>Barrett's esophagus</subject>
|
23
|
+
</subjects>
|
24
|
+
<fundingReferences>
|
25
|
+
<fundingReference>
|
26
|
+
<funderName>U.S. Environmental Protection Agency</funderName>
|
27
|
+
<awardNumber>EPA STAR Fellowship 2011</awardNumber>
|
28
|
+
</fundingReference>
|
29
|
+
<fundingReference>
|
30
|
+
<funderName>CYBER-ShARE Center of Excellence National Science Foundation (NSF) CREST grants</funderName>
|
31
|
+
<awardNumber>HRD-0734825 and HRD-1242122</awardNumber>
|
32
|
+
</fundingReference>
|
33
|
+
<fundingReference>
|
34
|
+
<funderName>CI-Team Grant</funderName>
|
35
|
+
<awardNumber>OCI-1135525</awardNumber>
|
36
|
+
</fundingReference>
|
37
|
+
</fundingReferences>
|
38
|
+
<contributors>
|
39
|
+
<contributor contributorType="ProjectMember">
|
40
|
+
<contributorName>Chen, Xiaoxin</contributorName>
|
41
|
+
<nameIdentifier nameIdentifierScheme="ORCID" schemeURI="http://orcid.org/">1234-5678-9101-1121</nameIdentifier>
|
42
|
+
<affiliation>University of North Carolina at Chapel Hill</affiliation>
|
43
|
+
</contributor>
|
44
|
+
<contributor contributorType="DataManager">
|
45
|
+
<contributorName>Wilson, James</contributorName>
|
46
|
+
</contributor>
|
47
|
+
</contributors>
|
48
|
+
<dates>
|
49
|
+
<date dateType="Available">2015-12-02</date>
|
50
|
+
<date dateType="Collected">2009/2011</date>
|
51
|
+
</dates>
|
52
|
+
<language>en</language>
|
53
|
+
<resourceType resourceTypeGeneral="Dataset">application/octet-stream</resourceType>
|
54
|
+
<alternateIdentifiers>
|
55
|
+
<alternateIdentifier alternateIdentifierType="URL">
|
56
|
+
https://oneshare.cdlib.org/xtf/view?docId=dataone/ark%2B%3Dc5146%3Dr3rg6g/mrt-datacite.xml
|
57
|
+
</alternateIdentifier>
|
58
|
+
</alternateIdentifiers>
|
59
|
+
<relatedIdentifiers>
|
60
|
+
<relatedIdentifier relationType="IsCitedBy" relatedIdentifierType="DOI">10.1371/journal.pone.0143878</relatedIdentifier>
|
61
|
+
<relatedIdentifier relationType="IsDocumentedBy" relatedIdentifierType="URL">http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0143878</relatedIdentifier>
|
62
|
+
</relatedIdentifiers>
|
63
|
+
<sizes>
|
64
|
+
<size>3286679 bytes</size>
|
65
|
+
</sizes>
|
66
|
+
<formats>
|
67
|
+
<format>text/plain</format>
|
68
|
+
<format>text/application/vnd.openxmlformats-officedocument.wordprocessingml.document</format>
|
69
|
+
<format>application/xml</format>
|
70
|
+
<format>application/pdf</format>
|
71
|
+
</formats>
|
72
|
+
<version>1</version>
|
73
|
+
<rightsList>
|
74
|
+
<rights rightsURI="https://creativecommons.org/publicdomain/zero/1.0/">CC0 1.0 Universal (CC0 1.0) Public Domain Dedication</rights>
|
75
|
+
</rightsList>
|
76
|
+
<descriptions>
|
77
|
+
<description descriptionType="Abstract">
|
78
|
+
Mammalian esophagus exhibits a remarkable change in epithelial structure
|
79
|
+
during the transition from embryo to adult. However, the molecular
|
80
|
+
mechanisms of esophageal epithelial development are not well understood.
|
81
|
+
Zebrafish (Danio rerio), a common model organism for vertebrate
|
82
|
+
development and gene function, has not previously been characterized as a
|
83
|
+
model system for esophageal epithelial development. In this study, we
|
84
|
+
characterized a piece of non-keratinized stratified squamous epithelium
|
85
|
+
similar to human esophageal epithelium in the upper digestive tract of
|
86
|
+
developing zebrafish. Under the microscope, this piece was detectable at
|
87
|
+
5dpf and became stratified at 7dpf. Expression of esophageal epithelial
|
88
|
+
marker genes (Krt5, P63, Sox2 and Pax9) was detected by
|
89
|
+
immunohistochemistry and in situ hybridization. Knockdown of P63, a gene
|
90
|
+
known to be critical for esophageal epithelium, disrupted the development
|
91
|
+
of this epithelium. With this model system, we found that Pax9 knockdown
|
92
|
+
resulted in loss or disorganization of the squamous epithelium, as well as
|
93
|
+
down-regulation of the differentiation markers Krt4 and Krt5. In summary,
|
94
|
+
we characterized a region of stratified squamous epithelium in the
|
95
|
+
zebrafish upper digestive tract which can be used for functional studies
|
96
|
+
of candidate genes involved in esophageal epithelial biology.
|
97
|
+
</description>
|
98
|
+
</descriptions>
|
99
|
+
<geoLocations>
|
100
|
+
<geoLocation>
|
101
|
+
<geoLocationBox>
|
102
|
+
<westBoundLongitude>-119.211</westBoundLongitude>
|
103
|
+
<eastBoundLongitude>-119.182</eastBoundLongitude>
|
104
|
+
<southBoundLatitude>37.046</southBoundLatitude>
|
105
|
+
<northBoundLatitude>37.075</northBoundLatitude>
|
106
|
+
</geoLocationBox>
|
107
|
+
<geoLocationPlace>Providence Creek (Lower, Upper and P301)</geoLocationPlace>
|
108
|
+
</geoLocation>
|
109
|
+
<geoLocation>
|
110
|
+
<geoLocationPoint>
|
111
|
+
<pointLatitude>31.233</pointLatitude>
|
112
|
+
<pointLongitude>-67.302</pointLongitude>
|
113
|
+
</geoLocationPoint>
|
114
|
+
<geoLocationBox>
|
115
|
+
<westBoundLongitude>-71.032</westBoundLongitude>
|
116
|
+
<eastBoundLongitude>-68.211</eastBoundLongitude>
|
117
|
+
<southBoundLatitude>41.09</southBoundLatitude>
|
118
|
+
<northBoundLatitude>42.893</northBoundLatitude>
|
119
|
+
</geoLocationBox>
|
120
|
+
<geoLocationPlace>Atlantic Ocean</geoLocationPlace>
|
121
|
+
</geoLocation>
|
122
|
+
</geoLocations>
|
123
|
+
</resource>
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'db_spec_helper'
|
2
|
+
require 'datacite/mapping/datacite_xml_factory'
|
3
|
+
|
4
|
+
module Datacite
|
5
|
+
module Mapping
|
6
|
+
describe DataciteXMLFactory do
|
7
|
+
attr_reader :dc3_xml
|
8
|
+
attr_reader :dcs_resource
|
9
|
+
attr_reader :xml_factory
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
stash_wrapper_xml = File.read('spec/data/archive/stash-wrapper.xml')
|
13
|
+
stash_wrapper = Stash::Wrapper::StashWrapper.parse_xml(stash_wrapper_xml)
|
14
|
+
|
15
|
+
doi_value = '10.15146/R3RG6G'
|
16
|
+
total_size_bytes = 3_286_679
|
17
|
+
|
18
|
+
@dc3_xml = File.read('spec/data/archive/mrt-datacite.xml')
|
19
|
+
@dcs_resource = Datacite::Mapping::Resource.parse_xml(dc3_xml)
|
20
|
+
|
21
|
+
user = StashEngine::User.create(
|
22
|
+
uid: 'lmuckenhaupt-example@example.edu',
|
23
|
+
first_name: 'Lisa',
|
24
|
+
last_name: 'Muckenhaupt',
|
25
|
+
email: 'lmuckenhaupt@example.edu',
|
26
|
+
provider: 'developer',
|
27
|
+
tenant_id: 'dataone'
|
28
|
+
)
|
29
|
+
resource = StashDatacite::ResourceBuilder.new(
|
30
|
+
user_id: user.id,
|
31
|
+
dcs_resource: dcs_resource,
|
32
|
+
stash_files: stash_wrapper.inventory.files,
|
33
|
+
upload_date: stash_wrapper.version_date
|
34
|
+
).build
|
35
|
+
|
36
|
+
@xml_factory = DataciteXMLFactory.new(
|
37
|
+
doi_value: doi_value,
|
38
|
+
se_resource_id: resource.id,
|
39
|
+
total_size_bytes: total_size_bytes,
|
40
|
+
version: 1
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'generates DC3' do
|
45
|
+
actual = xml_factory.build_datacite_xml(datacite_3: true)
|
46
|
+
expect(actual).to be_xml(dc3_xml)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'generates DC4' do
|
50
|
+
expected = File.read('spec/data/dc4-with-funding-references.xml')
|
51
|
+
actual = xml_factory.build_datacite_xml
|
52
|
+
expect(actual).to be_xml(expected)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'db_spec_helper'
|
2
|
+
|
3
|
+
module Stash
|
4
|
+
module Merritt
|
5
|
+
class SubmissionPackage
|
6
|
+
describe MerrittOAIDCBuilder do
|
7
|
+
attr_reader :resource
|
8
|
+
attr_reader :tenant
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
user = StashEngine::User.create(
|
12
|
+
uid: 'lmuckenhaupt-example@example.edu',
|
13
|
+
email: 'lmuckenhaupt@example.edu',
|
14
|
+
tenant_id: 'dataone'
|
15
|
+
)
|
16
|
+
|
17
|
+
dc3_xml = File.read('spec/data/archive/mrt-datacite.xml')
|
18
|
+
dcs_resource = Datacite::Mapping::Resource.parse_xml(dc3_xml)
|
19
|
+
stash_wrapper_xml = File.read('spec/data/archive/stash-wrapper.xml')
|
20
|
+
stash_wrapper = Stash::Wrapper::StashWrapper.parse_xml(stash_wrapper_xml)
|
21
|
+
|
22
|
+
@tenant = double(StashEngine::Tenant)
|
23
|
+
allow(tenant).to receive(:short_name).and_return('DataONE')
|
24
|
+
allow(StashEngine::Tenant).to receive(:find).with('dataone').and_return(tenant)
|
25
|
+
|
26
|
+
@resource = StashDatacite::ResourceBuilder.new(
|
27
|
+
user_id: user.id,
|
28
|
+
dcs_resource: dcs_resource,
|
29
|
+
stash_files: stash_wrapper.inventory.files,
|
30
|
+
upload_date: stash_wrapper.version_date
|
31
|
+
).build
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#build_xml_string' do
|
35
|
+
it 'includes related identifiers' do
|
36
|
+
rel_ids = StashDatacite::RelatedIdentifier::RelationTypesLimited.values.map do |rel_type|
|
37
|
+
related_doi_value = "10.5555/#{Time.now.nsec}"
|
38
|
+
StashDatacite::RelatedIdentifier.create(
|
39
|
+
resource_id: resource.id,
|
40
|
+
relation_type: rel_type,
|
41
|
+
related_identifier_type: 'doi',
|
42
|
+
related_identifier: related_doi_value
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
expected = {
|
47
|
+
'IsPartOf' => 'isPartOf',
|
48
|
+
'HasPart' => 'hasPart',
|
49
|
+
'IsCitedBy' => 'isReferencedBy',
|
50
|
+
'Cites' => 'references',
|
51
|
+
'IsReferencedBy' => 'isReferencedBy',
|
52
|
+
'References' => 'references',
|
53
|
+
'IsNewVersionOf' => 'isVersionOf',
|
54
|
+
'IsPreviousVersionOf' => 'hasVersion',
|
55
|
+
'IsVariantFormOf' => 'isVersionOf',
|
56
|
+
'IsOriginalFormOf' => 'hasVersion'
|
57
|
+
}
|
58
|
+
|
59
|
+
dc_builder = MerrittOAIDCBuilder.new(resource_id: resource.id)
|
60
|
+
xml_string = dc_builder.contents
|
61
|
+
rel_ids.each do |rel_id|
|
62
|
+
predicate = expected[rel_id.relation_type_friendly] || 'relation'
|
63
|
+
dc_tag = "dcterms:#{predicate}"
|
64
|
+
id_value = "#{rel_id.related_identifier_type_friendly}: #{rel_id.related_identifier}"
|
65
|
+
expect(xml_string).to include("<#{dc_tag}>#{id_value}</#{dc_tag}>")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
require 'db_spec_helper'
|
2
|
+
|
3
|
+
module Stash
|
4
|
+
module Merritt
|
5
|
+
describe SubmissionPackage do
|
6
|
+
attr_reader :rails_root
|
7
|
+
attr_reader :user
|
8
|
+
attr_reader :tenant
|
9
|
+
attr_reader :datacite_xml
|
10
|
+
attr_reader :stash_wrapper_xml
|
11
|
+
attr_reader :resource
|
12
|
+
attr_reader :target_url
|
13
|
+
attr_reader :zipfile_path
|
14
|
+
attr_reader :url_helpers
|
15
|
+
|
16
|
+
before(:each) do
|
17
|
+
@rails_root = Dir.mktmpdir('rails_root')
|
18
|
+
FileUtils.mkdir_p("#{rails_root}/tmp")
|
19
|
+
allow(Rails).to receive(:root).and_return(rails_root)
|
20
|
+
|
21
|
+
@user = StashEngine::User.create(
|
22
|
+
uid: 'lmuckenhaupt-example@example.edu',
|
23
|
+
first_name: 'Lisa',
|
24
|
+
last_name: 'Muckenhaupt',
|
25
|
+
email: 'lmuckenhaupt@example.edu',
|
26
|
+
provider: 'developer',
|
27
|
+
tenant_id: 'dataone'
|
28
|
+
)
|
29
|
+
@tenant = double(StashEngine::Tenant)
|
30
|
+
allow(tenant).to receive(:identifier_service).and_return(shoulder: 'doi:10.15146/R3',
|
31
|
+
account: 'stash',
|
32
|
+
password: 'stash',
|
33
|
+
id_scheme: 'doi')
|
34
|
+
allow(tenant).to receive(:tenant_id).and_return('dataone')
|
35
|
+
allow(tenant).to receive(:short_name).and_return('DataONE')
|
36
|
+
allow(tenant).to receive(:landing_url) { |path| "https://stash-dev.example.edu/#{path}" }
|
37
|
+
allow(tenant).to receive(:sword_params).and_return(collection_uri: 'http://sword.example.edu/stash-dev')
|
38
|
+
allow(StashEngine::Tenant).to receive(:find).with('dataone').and_return(tenant)
|
39
|
+
|
40
|
+
@stash_wrapper_xml = File.read('spec/data/archive/stash-wrapper.xml')
|
41
|
+
stash_wrapper = Stash::Wrapper::StashWrapper.parse_xml(stash_wrapper_xml)
|
42
|
+
|
43
|
+
@datacite_xml = File.read('spec/data/archive/mrt-datacite.xml')
|
44
|
+
dcs_resource = Datacite::Mapping::Resource.parse_xml(datacite_xml)
|
45
|
+
|
46
|
+
@resource = StashDatacite::ResourceBuilder.new(
|
47
|
+
user_id: user.id,
|
48
|
+
dcs_resource: dcs_resource,
|
49
|
+
stash_files: stash_wrapper.inventory.files,
|
50
|
+
upload_date: stash_wrapper.version_date
|
51
|
+
).build
|
52
|
+
|
53
|
+
@url_helpers = double(Module) # yes, apparently URL helpers are an anonymous module
|
54
|
+
allow(url_helpers).to(receive(:show_path)) { |identifier| identifier }
|
55
|
+
|
56
|
+
# TODO: move this to ResourceBuilder
|
57
|
+
stash_wrapper.inventory.files.each do |stash_file|
|
58
|
+
data_file = stash_file.pathname
|
59
|
+
placeholder_file = "#{resource.upload_dir}/#{data_file}"
|
60
|
+
parent = File.dirname(placeholder_file)
|
61
|
+
FileUtils.mkdir_p(parent) unless File.directory?(parent)
|
62
|
+
File.open(placeholder_file, 'w') do |f|
|
63
|
+
f.puts("#{data_file}\t#{stash_file.size_bytes}\t#{stash_file.mime_type}\t(placeholder)")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
after(:each) do
|
69
|
+
FileUtils.remove_dir(rails_root)
|
70
|
+
end
|
71
|
+
|
72
|
+
def zipfile
|
73
|
+
@zipfile ||= ::Zip::File.open(zipfile_path)
|
74
|
+
end
|
75
|
+
|
76
|
+
def zip_entry(path)
|
77
|
+
@zip_entries ||= {}
|
78
|
+
@zip_entries[path] ||= begin
|
79
|
+
entry = zipfile.find_entry(path)
|
80
|
+
entry_io = entry.get_input_stream
|
81
|
+
entry_io.read
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe :initialize do
|
86
|
+
it 'fails if the resource doesn\'t have an identifier' do
|
87
|
+
resource.identifier = nil
|
88
|
+
resource.save!
|
89
|
+
expect { SubmissionPackage.new(resource: resource) }.to raise_error(ArgumentError)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'sets publication year if needed'
|
93
|
+
end
|
94
|
+
|
95
|
+
describe :zipfile do
|
96
|
+
it 'builds a zipfile' do
|
97
|
+
expected_metadata = Dir.glob('spec/data/archive/*').map do |path|
|
98
|
+
[File.basename(path), File.read(path)]
|
99
|
+
end.to_h
|
100
|
+
|
101
|
+
package = SubmissionPackage.new(resource: resource)
|
102
|
+
@zipfile_path = package.zipfile
|
103
|
+
|
104
|
+
expected_metadata.each do |path, content|
|
105
|
+
if path.end_with?('xml')
|
106
|
+
actual = zip_entry(path).gsub(/20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]Z/, '')
|
107
|
+
expected = content.gsub(/20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]Z/, '')
|
108
|
+
expect(actual).to be_xml(expected, path)
|
109
|
+
else
|
110
|
+
actual = zip_entry(path).strip
|
111
|
+
expected = content.strip
|
112
|
+
if actual != expected
|
113
|
+
now = Time.now.to_i
|
114
|
+
FileUtils.mkdir('tmp') unless File.directory?('tmp')
|
115
|
+
File.open("tmp/#{now}-expected-#{path}", 'w') { |f| f.write(expected) }
|
116
|
+
File.open("tmp/#{now}-actual-#{path}", 'w') { |f| f.write(actual) }
|
117
|
+
end
|
118
|
+
expect(actual).to eq(expected)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'includes a delete list' do
|
124
|
+
deleted = []
|
125
|
+
resource.file_uploads.each_with_index do |upload, index|
|
126
|
+
next unless index.even?
|
127
|
+
upload.file_state = 'deleted'
|
128
|
+
upload.save
|
129
|
+
deleted << upload.upload_file_name
|
130
|
+
end
|
131
|
+
|
132
|
+
package = SubmissionPackage.new(resource: resource)
|
133
|
+
@zipfile_path = package.zipfile
|
134
|
+
mrt_delete = zip_entry('mrt-delete.txt')
|
135
|
+
deleted.each do |filename|
|
136
|
+
expect(mrt_delete).to include(filename)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe :dc3_xml do
|
142
|
+
it 'builds Datacite 3 XML' do
|
143
|
+
package = SubmissionPackage.new(resource: resource)
|
144
|
+
expect(package.dc3_xml).to be_xml(datacite_xml)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe :cleanup! do
|
149
|
+
it 'removes the working directory' do
|
150
|
+
package = SubmissionPackage.new(resource: resource)
|
151
|
+
@zipfile_path = package.zipfile
|
152
|
+
workdir = File.dirname(zipfile_path)
|
153
|
+
package.cleanup!
|
154
|
+
expect(File.exist?(workdir)).to eq(false)
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
describe :to_s do
|
160
|
+
attr_reader :package_str
|
161
|
+
before(:each) do
|
162
|
+
package = SubmissionPackage.new(resource: resource)
|
163
|
+
@package_str = package.to_s
|
164
|
+
end
|
165
|
+
it 'includes the class name' do
|
166
|
+
expect(package_str).to include('SubmissionPackage')
|
167
|
+
end
|
168
|
+
it 'includes the resource ID' do
|
169
|
+
expect(package_str).to include(resource.id.to_s)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'db_spec_helper'
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'pathname'
|
5
|
+
require 'webmock'
|
6
|
+
|
7
|
+
module Stash
|
8
|
+
module Merritt
|
9
|
+
describe SwordHelper do
|
10
|
+
attr_reader :title
|
11
|
+
attr_reader :doi
|
12
|
+
attr_reader :update_uri
|
13
|
+
attr_reader :download_uri
|
14
|
+
attr_reader :request_host
|
15
|
+
attr_reader :request_port
|
16
|
+
attr_reader :sword_params
|
17
|
+
attr_reader :rails_root
|
18
|
+
attr_reader :user
|
19
|
+
attr_reader :tenant
|
20
|
+
attr_reader :resource
|
21
|
+
attr_reader :sword_client
|
22
|
+
attr_reader :receipt
|
23
|
+
|
24
|
+
before(:all) do
|
25
|
+
WebMock.disable_net_connect!
|
26
|
+
|
27
|
+
@title = 'A Zebrafish Model for Studies on Esophageal Epithelial Biology'
|
28
|
+
@doi = 'doi:10.15146/R3RG6G'
|
29
|
+
@update_uri = "http://example.org/#{doi}/edit"
|
30
|
+
@download_uri = "http://example.org/#{doi}/em"
|
31
|
+
@request_host = 'example.org'
|
32
|
+
@request_port = 80
|
33
|
+
|
34
|
+
@sword_params = {
|
35
|
+
collection_uri: 'http://example.org/sword/my_collection',
|
36
|
+
username: 'elvis',
|
37
|
+
password: 'presley'
|
38
|
+
}.freeze
|
39
|
+
end
|
40
|
+
|
41
|
+
before(:each) do
|
42
|
+
@rails_root = Dir.mktmpdir('rails_root')
|
43
|
+
FileUtils.mkdir_p("#{rails_root}/tmp")
|
44
|
+
allow(Rails).to receive(:root).and_return(rails_root)
|
45
|
+
|
46
|
+
@user = StashEngine::User.create(
|
47
|
+
uid: 'lmuckenhaupt-example@example.edu',
|
48
|
+
first_name: 'Lisa',
|
49
|
+
last_name: 'Muckenhaupt',
|
50
|
+
email: 'lmuckenhaupt@example.edu',
|
51
|
+
provider: 'developer',
|
52
|
+
tenant_id: 'dataone'
|
53
|
+
)
|
54
|
+
@tenant = double(StashEngine::Tenant)
|
55
|
+
allow(tenant).to receive(:identifier_service).and_return(shoulder: 'doi:10.15146/R3',
|
56
|
+
id_scheme: 'doi')
|
57
|
+
allow(tenant).to receive(:tenant_id).and_return('dataone')
|
58
|
+
allow(tenant).to receive(:short_name).and_return('DataONE')
|
59
|
+
allow(tenant).to receive(:landing_url) { |path| "https://stash-dev.example.edu/#{path}" }
|
60
|
+
allow(tenant).to receive(:sword_params).and_return(sword_params)
|
61
|
+
allow(StashEngine::Tenant).to receive(:find).with('dataone').and_return(tenant)
|
62
|
+
|
63
|
+
stash_wrapper = Stash::Wrapper::StashWrapper.parse_xml(File.read('spec/data/archive/stash-wrapper.xml'))
|
64
|
+
@resource = StashDatacite::ResourceBuilder.new(
|
65
|
+
user_id: user.id,
|
66
|
+
dcs_resource: Datacite::Mapping::Resource.parse_xml(File.read('spec/data/archive/mrt-datacite.xml')),
|
67
|
+
stash_files: stash_wrapper.inventory.files,
|
68
|
+
upload_date: stash_wrapper.version_date
|
69
|
+
).build
|
70
|
+
|
71
|
+
# TODO: move this to ResourceBuilder
|
72
|
+
stash_wrapper.inventory.files.each do |stash_file|
|
73
|
+
data_file = stash_file.pathname
|
74
|
+
placeholder_file = "#{resource.upload_dir}/#{data_file}"
|
75
|
+
parent = File.dirname(placeholder_file)
|
76
|
+
FileUtils.mkdir_p(parent) unless File.directory?(parent)
|
77
|
+
File.open(placeholder_file, 'w') do |f|
|
78
|
+
f.puts("#{data_file}\t#{stash_file.size_bytes}\t#{stash_file.mime_type}\t(placeholder)")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
@receipt = instance_double(Stash::Sword::DepositReceipt)
|
83
|
+
allow(receipt).to(receive(:em_iri)).and_return(download_uri)
|
84
|
+
allow(receipt).to(receive(:edit_iri)).and_return(update_uri)
|
85
|
+
|
86
|
+
@sword_client = instance_double(Stash::Sword::Client)
|
87
|
+
allow(sword_client).to receive(:update).and_return(200)
|
88
|
+
allow(sword_client).to receive(:create).and_return(receipt)
|
89
|
+
allow(Stash::Sword::Client).to receive(:new).and_return(sword_client)
|
90
|
+
end
|
91
|
+
|
92
|
+
after(:each) do
|
93
|
+
FileUtils.remove_entry_secure rails_root
|
94
|
+
end
|
95
|
+
|
96
|
+
describe :submit! do
|
97
|
+
describe 'create' do
|
98
|
+
it 'submits the zipfile' do
|
99
|
+
package = Stash::Merritt::SubmissionPackage.new(resource: resource)
|
100
|
+
helper = SwordHelper.new(package: package)
|
101
|
+
expect(sword_client).to receive(:create).with(doi: doi, zipfile: package.zipfile)
|
102
|
+
helper.submit!
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'sets the update and download URIs' do
|
106
|
+
package = Stash::Merritt::SubmissionPackage.new(resource: resource)
|
107
|
+
helper = SwordHelper.new(package: package)
|
108
|
+
expect(sword_client).to receive(:create).with(doi: doi, zipfile: package.zipfile).and_return(receipt)
|
109
|
+
helper.submit!
|
110
|
+
expect(resource.download_uri).to eq(download_uri)
|
111
|
+
expect(resource.update_uri).to eq(update_uri)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'sets the version zipfile' do
|
115
|
+
package = Stash::Merritt::SubmissionPackage.new(resource: resource)
|
116
|
+
SwordHelper.new(package: package).submit!
|
117
|
+
version = resource.stash_version
|
118
|
+
zipfile = File.basename(package.zipfile)
|
119
|
+
expect(version.zip_filename).to eq(zipfile)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'forwards errors' do
|
123
|
+
package = Stash::Merritt::SubmissionPackage.new(resource: resource)
|
124
|
+
helper = SwordHelper.new(package: package)
|
125
|
+
expect(sword_client).to receive(:create).and_raise(RestClient::RequestFailed)
|
126
|
+
expect { helper.submit! }.to raise_error(RestClient::RequestFailed)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe 'update' do
|
131
|
+
before(:each) do
|
132
|
+
resource.update_uri = update_uri
|
133
|
+
resource.download_uri = download_uri
|
134
|
+
resource.save
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'submits the zipfile' do
|
138
|
+
package = Stash::Merritt::SubmissionPackage.new(resource: resource)
|
139
|
+
helper = SwordHelper.new(package: package)
|
140
|
+
expect(sword_client).to receive(:update).with(edit_iri: update_uri, zipfile: package.zipfile).and_return(200)
|
141
|
+
helper.submit!
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'sets the version zipfile' do
|
145
|
+
package = Stash::Merritt::SubmissionPackage.new(resource: resource)
|
146
|
+
SwordHelper.new(package: package).submit!
|
147
|
+
version = resource.stash_version
|
148
|
+
zipfile = File.basename(package.zipfile)
|
149
|
+
expect(version.zip_filename).to eq(zipfile)
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'forwards errors' do
|
153
|
+
package = Stash::Merritt::SubmissionPackage.new(resource: resource)
|
154
|
+
helper = SwordHelper.new(package: package)
|
155
|
+
expect(sword_client).to receive(:update).and_raise(RestClient::RequestFailed)
|
156
|
+
expect { helper.submit! }.to raise_error(RestClient::RequestFailed)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'database_cleaner'
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
db_config = YAML.load_file('spec/config/database.yml')['test']
|
6
|
+
|
7
|
+
host = db_config['host']
|
8
|
+
raise("Can't run destructive tests against non-local database #{host}") unless host == 'localhost'
|
9
|
+
puts "Using database #{db_config['database']} on host #{db_config['host']} with username #{db_config['username']}"
|
10
|
+
|
11
|
+
stash_engine_path = Gem::Specification.find_by_name('stash_engine').gem_dir
|
12
|
+
stash_datacite_path = Gem::Specification.find_by_name('stash_datacite').gem_dir
|
13
|
+
migration_paths = %W(#{stash_engine_path}/db/migrate #{stash_datacite_path}/db/migrate)
|
14
|
+
|
15
|
+
ActiveRecord::Base.establish_connection(db_config)
|
16
|
+
ActiveRecord::Migration.verbose = true
|
17
|
+
puts "Executing migrations from #{migration_paths.join(':')}"
|
18
|
+
ActiveRecord::Migrator.up migration_paths
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
config.before(:suite) do
|
22
|
+
DatabaseCleaner.strategy = :deletion
|
23
|
+
end
|
24
|
+
config.after(:each) do
|
25
|
+
DatabaseCleaner.clean
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Helpers
|
30
|
+
|
31
|
+
require 'util/resource_builder'
|