pushmi_pullyu 1.0.5 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/CODEOWNERS +2 -0
- data/.github/PULL_REQUEST_TEMPLATE +11 -0
- data/.github/dependabot.yml +12 -0
- data/.github/workflows/ruby.yml +31 -0
- data/.rubocop.yml +21 -1
- data/CHANGELOG.md +25 -0
- data/Dangerfile +7 -3
- data/README.md +4 -5
- data/examples/pushmi_pullyu.yml +6 -6
- data/lib/pushmi_pullyu/aip/downloader.rb +133 -180
- data/lib/pushmi_pullyu/aip.rb +9 -6
- data/lib/pushmi_pullyu/cli.rb +30 -25
- data/lib/pushmi_pullyu/logging.rb +6 -6
- data/lib/pushmi_pullyu/swift_depositer.rb +1 -1
- data/lib/pushmi_pullyu/version.rb +1 -1
- data/lib/pushmi_pullyu.rb +10 -17
- data/pushmi_pullyu.gemspec +18 -14
- metadata +69 -47
- data/.travis.yml +0 -16
- data/lib/pushmi_pullyu/aip/fedora_fetcher.rb +0 -66
- data/lib/pushmi_pullyu/aip/file_list_creator.rb +0 -121
- data/lib/pushmi_pullyu/aip/owner_email_editor.rb +0 -50
- data/lib/pushmi_pullyu/aip/user.rb +0 -2
@@ -1,121 +0,0 @@
|
|
1
|
-
require 'rdf'
|
2
|
-
require 'rdf/n3'
|
3
|
-
require 'rest-client'
|
4
|
-
|
5
|
-
class PushmiPullyu::AIP::FileListCreator
|
6
|
-
|
7
|
-
IANA = 'http://www.iana.org/assignments/relation/'.freeze
|
8
|
-
PREDICATES = {
|
9
|
-
proxy_for: RDF::URI('http://www.openarchives.org/ore/terms/proxyFor'),
|
10
|
-
first: RDF::URI(IANA + 'first'),
|
11
|
-
last: RDF::URI(IANA + 'last'),
|
12
|
-
prev: RDF::URI(IANA + 'prev'),
|
13
|
-
next: RDF::URI(IANA + 'next'),
|
14
|
-
has_part: RDF::URI('http://purl.org/dc/terms/hasPart')
|
15
|
-
}.freeze
|
16
|
-
|
17
|
-
class NoProxyURIFound < StandardError; end
|
18
|
-
class NoFirstProxyFound < StandardError; end
|
19
|
-
class FirstProxyHasPrev < StandardError; end
|
20
|
-
class ListSourceFileSetMismatch < StandardError; end
|
21
|
-
|
22
|
-
def initialize(list_source_uri, output_xml_file, file_set_uuids)
|
23
|
-
@uri = RDF::URI(list_source_uri)
|
24
|
-
@auth_uri = RDF::URI(list_source_uri)
|
25
|
-
@auth_uri.user = PushmiPullyu.options[:fedora][:user]
|
26
|
-
@auth_uri.password = PushmiPullyu.options[:fedora][:password]
|
27
|
-
@output_file = output_xml_file
|
28
|
-
|
29
|
-
# These are the known fileset uuids, used for validation
|
30
|
-
@file_set_uuids = file_set_uuids
|
31
|
-
end
|
32
|
-
|
33
|
-
def run
|
34
|
-
extract_list_source_uuids
|
35
|
-
raise ListSourceFileSetMismatch, @uri.to_s if @list_source_uuids.sort != @file_set_uuids.sort
|
36
|
-
|
37
|
-
write_output_file
|
38
|
-
end
|
39
|
-
|
40
|
-
def extract_list_source_uuids
|
41
|
-
# Note: raises IOError if can't find
|
42
|
-
# raises RDF::ReaderError if can't parse
|
43
|
-
@graph = RDF::Graph.load(@auth_uri, validate: true)
|
44
|
-
@list_source_uuids = []
|
45
|
-
|
46
|
-
# Fetch first FileSet in list source
|
47
|
-
this_proxy = find_first_proxy
|
48
|
-
|
49
|
-
while @list_source_uuids.count <= num_proxies
|
50
|
-
@list_source_uuids << uuid_from_proxy(this_proxy)
|
51
|
-
next_proxy = find_next_proxy(this_proxy)
|
52
|
-
|
53
|
-
break if next_proxy.nil?
|
54
|
-
|
55
|
-
raise NextPreviousProxyMismatch if this_proxy != find_prev_proxy(next_proxy)
|
56
|
-
|
57
|
-
this_proxy = next_proxy
|
58
|
-
end
|
59
|
-
|
60
|
-
raise ProxyCountIncorrect if @list_source_uuids.count != num_proxies
|
61
|
-
raise LastProxyFailsValidation if this_proxy != find_last_proxy
|
62
|
-
end
|
63
|
-
|
64
|
-
def num_proxies
|
65
|
-
@num_proxies ||= @graph.query(subject: @uri, predicate: PREDICATES[:has_part]).count
|
66
|
-
end
|
67
|
-
|
68
|
-
def uuid_from_proxy(proxy_uri)
|
69
|
-
@graph.query(subject: proxy_uri, predicate: PREDICATES[:proxy_for]) do |statement|
|
70
|
-
return statement.object.to_s.split('/').last
|
71
|
-
end
|
72
|
-
raise NoProxyURIFound, proxy_uri.to_s
|
73
|
-
end
|
74
|
-
|
75
|
-
def find_first_proxy
|
76
|
-
@graph.query(subject: @uri, predicate: PREDICATES[:first]) do |statement|
|
77
|
-
first_uri = statement.object
|
78
|
-
# Validate that the first proxy doesn't have a previous one
|
79
|
-
raise FirstProxyHasPrev, @uri.to_s if find_prev_proxy(first_uri)
|
80
|
-
|
81
|
-
return first_uri
|
82
|
-
end
|
83
|
-
raise NoFirstProxyFound, @uri.to_s
|
84
|
-
end
|
85
|
-
|
86
|
-
def find_last_proxy
|
87
|
-
@graph.query(subject: @uri, predicate: PREDICATES[:last]) do |statement|
|
88
|
-
last_uri = statement.object
|
89
|
-
# Validate that the last proxy doesn't have a next one
|
90
|
-
raise LastProxyHasNext, @uri.to_s if find_next_proxy(last_uri)
|
91
|
-
|
92
|
-
return last_uri
|
93
|
-
end
|
94
|
-
raise LastProxyFound, @uri.to_s
|
95
|
-
end
|
96
|
-
|
97
|
-
def find_next_proxy(proxy_uri)
|
98
|
-
@graph.query(subject: proxy_uri, predicate: PREDICATES[:next]) do |statement|
|
99
|
-
return statement.object
|
100
|
-
end
|
101
|
-
nil
|
102
|
-
end
|
103
|
-
|
104
|
-
def find_prev_proxy(proxy_uri)
|
105
|
-
@graph.query(subject: proxy_uri, predicate: PREDICATES[:prev]) do |statement|
|
106
|
-
return statement.object
|
107
|
-
end
|
108
|
-
nil
|
109
|
-
end
|
110
|
-
|
111
|
-
def write_output_file
|
112
|
-
File.open(@output_file, 'w') do |file|
|
113
|
-
file.write("<file_order>\n")
|
114
|
-
@list_source_uuids.each do |uuid|
|
115
|
-
file.write(" <uuid>#{uuid}</uuid>\n")
|
116
|
-
end
|
117
|
-
file.write("</file_order>\n")
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
|
3
|
-
class PushmiPullyu::AIP::OwnerEmailEditor
|
4
|
-
|
5
|
-
OWNER_PREDICATE = RDF::URI('http://purl.org/ontology/bibo/owner').freeze
|
6
|
-
|
7
|
-
class NoOwnerPredicate < StandardError; end
|
8
|
-
|
9
|
-
def initialize(rdf_string)
|
10
|
-
@document = rdf_string
|
11
|
-
end
|
12
|
-
|
13
|
-
def run
|
14
|
-
setup_db_connection
|
15
|
-
is_modified = false
|
16
|
-
prefixes = nil
|
17
|
-
# Read once to load prefixes (the @things at the top of an n3 file)
|
18
|
-
RDF::N3::Reader.new(input = @document) do |reader|
|
19
|
-
reader.each_statement { |_statement| }
|
20
|
-
prefixes = reader.prefixes
|
21
|
-
end
|
22
|
-
new_body = RDF::N3::Writer.buffer(prefixes: prefixes) do |writer|
|
23
|
-
RDF::N3::Reader.new(input = @document) do |reader|
|
24
|
-
reader.each_statement do |statement|
|
25
|
-
if statement.predicate == OWNER_PREDICATE
|
26
|
-
user = PushmiPullyu::AIP::User.find(statement.object.to_i)
|
27
|
-
writer << [statement.subject, statement.predicate, user.email]
|
28
|
-
is_modified = true
|
29
|
-
else
|
30
|
-
writer << statement
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
return new_body if is_modified
|
36
|
-
|
37
|
-
raise NoOwnerPredicate
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def setup_db_connection
|
43
|
-
ActiveRecord::Base.establish_connection(database_configuration)
|
44
|
-
end
|
45
|
-
|
46
|
-
def database_configuration
|
47
|
-
PushmiPullyu.options[:database][:url]
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|