matterhorn_whymper 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/matterhorn/acl.rb +93 -0
- data/lib/matterhorn/dublin_core.rb +171 -0
- data/lib/matterhorn/endpoint/ingest.rb +60 -68
- data/lib/matterhorn/endpoint/series.rb +177 -0
- data/lib/matterhorn/endpoint/workflow.rb +36 -51
- data/lib/matterhorn/endpoint.rb +113 -40
- data/lib/matterhorn/error.rb +17 -21
- data/lib/matterhorn/http_client.rb +4 -2
- data/lib/matterhorn_whymper/version.rb +1 -1
- data/lib/matterhorn_whymper.rb +10 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjliZDhiZTllYjViZDZlMDRlNDBkMDk2Y2NjZDJlYjE2ODU3OTlmNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODkzN2MzZjJmYzc3YjJhMTc0M2UzZTg0ZWVmYTRmZGY5ZDJmNTYwMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDM4YzBhODU2MmU3YTdhNzFjM2Y2NDdjYzYyNjg4ZjAwZmZlNTllYTYwMTM3
|
10
|
+
YzNjM2FkOTdjNjFhZWNiOWRhOTdkZDJmYWUwNDNjZjc2ZDhmOTM5MzU2MDlm
|
11
|
+
MTA0ZTdhMDRmODBjMDYxNmU1MWQxYzVlZjQxYWYwMmQwNDhmNWY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGY2ZjhjYmQ4MDljZGQyYTEzMTAwMTdjY2Y4OWFiY2ZjOTBkMGIzYTg0OGJk
|
14
|
+
Mzg5MDg5NzI0NTA1MWUzNmRlNzBlZmMwYjQ0YThhZjUxNTJkNWJkMDM4NTMx
|
15
|
+
NWEzMDM4YWRhZmE3OTI5ZjZkMWNiYzdkMzliODEzNzdlZjA0ZTc=
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
|
4
|
+
# ============================================================================== Matterhorn::Acl ===
|
5
|
+
|
6
|
+
# <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
7
|
+
# <acl xmlns="http://org.opencastproject.security">
|
8
|
+
# <ace>
|
9
|
+
# <role>admin</role>
|
10
|
+
# <action>delete</action>
|
11
|
+
# <allow>true</allow>
|
12
|
+
# </ace>
|
13
|
+
# </acl>
|
14
|
+
#
|
15
|
+
#
|
16
|
+
class Matterhorn::Acl
|
17
|
+
|
18
|
+
attr_accessor :aces
|
19
|
+
|
20
|
+
|
21
|
+
# ======================================================================= Matterhorn::Acl::Ace ===
|
22
|
+
|
23
|
+
class Ace
|
24
|
+
|
25
|
+
attr_accessor :role, :action, :allow
|
26
|
+
|
27
|
+
def initialize(role = nil, action = nil, allow = true)
|
28
|
+
@role = role
|
29
|
+
@action = action
|
30
|
+
@allow = allow
|
31
|
+
end
|
32
|
+
|
33
|
+
end # --------------------------------------------------------------- end Matterhorn::Acl::Ace ---
|
34
|
+
|
35
|
+
|
36
|
+
# -------------------------------------------------------------------------- const definitions ---
|
37
|
+
|
38
|
+
NS = {
|
39
|
+
'xmlns' => "http://org.opencastproject.security",
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
# ----------------------------------------------------------------------------- initialization ---
|
44
|
+
|
45
|
+
def initialize(xml = nil)
|
46
|
+
if !xml.nil?
|
47
|
+
doc = Nokogiri::XML(xml)
|
48
|
+
@aces = []
|
49
|
+
doc.xpath("/xmlns:acl/xmlns:ace").each do |ace_elem|
|
50
|
+
ace = Ace.new
|
51
|
+
ace.role = ace_elem.at_xpath("xmlns:role").content
|
52
|
+
ace.action = ace_elem.at_xpath("xmlns:action").content
|
53
|
+
ace.allow = ace_elem.at_xpath("xmlns:allow").content
|
54
|
+
@aces << ace
|
55
|
+
end
|
56
|
+
else
|
57
|
+
@aces = []
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
# ----------------------------------------------------------------------------------- methodes ---
|
63
|
+
|
64
|
+
def save(file)
|
65
|
+
File.open(file, 'w') do |file|
|
66
|
+
file.write(to_xml)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def to_xml
|
72
|
+
Nokogiri::XML::Builder.new do |xml|
|
73
|
+
xml.acl(NS) do
|
74
|
+
@aces.each do |ace|
|
75
|
+
xml.ace do
|
76
|
+
xml.role(ace.role)
|
77
|
+
xml.action(ace.action)
|
78
|
+
xml.allow(ace.allow)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end.doc.to_xml
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
# ------------------------------------------------------------------------------------ helpers ---
|
87
|
+
|
88
|
+
def inspect
|
89
|
+
to_xml.to_s
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
end # ---------------------------------------------------------------------- end Matterhorn::Acl ---
|
@@ -0,0 +1,171 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
|
4
|
+
# ======================================================================= Matterhorn::DublinCore ===
|
5
|
+
|
6
|
+
|
7
|
+
# <?xml version="1.0"?>
|
8
|
+
# <dublincore xmlns="http://www.opencastproject.org/xsd/1.0/dublincore/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
9
|
+
# xsi:schemaLocation="http://www.opencastproject.org http://www.opencastproject.org/schema.xsd" xmlns:dc="http://purl.org/dc/elements/1.1/"
|
10
|
+
# xmlns:dcterms="http://purl.org/dc/terms/" xmlns:oc="http://www.opencastproject.org/matterhorn/">
|
11
|
+
# <dcterms:title xml:lang="en">
|
12
|
+
# Land and Vegetation: Key players on the Climate Scene
|
13
|
+
# </dcterms:title>
|
14
|
+
# <dcterms:subject>
|
15
|
+
# climate, land, vegetation
|
16
|
+
# </dcterms:subject>
|
17
|
+
# <dcterms:description xml:lang="en">
|
18
|
+
# Introduction lecture from the Institute for
|
19
|
+
# Atmospheric and Climate Science.
|
20
|
+
# </dcterms:description>
|
21
|
+
# <dcterms:publisher>
|
22
|
+
# ETH Zurich, Switzerland
|
23
|
+
# </dcterms:publisher>
|
24
|
+
# <dcterms:identifier>
|
25
|
+
# 10.0000/5819
|
26
|
+
# </dcterms:identifier>
|
27
|
+
# <dcterms:modified xsi:type="dcterms:W3CDTF">
|
28
|
+
# 2007-12-05
|
29
|
+
# </dcterms:modified>
|
30
|
+
# <dcterms:format xsi:type="dcterms:IMT">
|
31
|
+
# video/x-dv
|
32
|
+
# </dcterms:format>
|
33
|
+
# <oc:promoted>
|
34
|
+
# true
|
35
|
+
# </oc:promoted>
|
36
|
+
# </dublincore>
|
37
|
+
#
|
38
|
+
#
|
39
|
+
class Matterhorn::DublinCore
|
40
|
+
|
41
|
+
# -------------------------------------------------------------------------- const definitions ---
|
42
|
+
|
43
|
+
NS = {
|
44
|
+
'xmlns' => "http://www.opencastproject.org/xsd/1.0/dublincore/",
|
45
|
+
'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
|
46
|
+
'xsi:schemaLocation' => "http://www.opencastproject.org http://www.opencastproject.org/schema.xsd",
|
47
|
+
'xmlns:dc' => "http://purl.org/dc/elements/1.1/",
|
48
|
+
'xmlns:dcterms' => "http://purl.org/dc/terms/",
|
49
|
+
'xmlns:oc' => "http://www.opencastproject.org/matterhorn/"
|
50
|
+
}
|
51
|
+
|
52
|
+
|
53
|
+
# ----------------------------------------------------------------------------- initialization ---
|
54
|
+
|
55
|
+
def initialize(xml = nil)
|
56
|
+
if !xml.nil?
|
57
|
+
@document = Nokogiri::XML(xml)
|
58
|
+
else
|
59
|
+
@document = Nokogiri::XML::Builder.new do |xml|
|
60
|
+
xml.dublincore(NS) do
|
61
|
+
end
|
62
|
+
end
|
63
|
+
.doc
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
# ----------------------------------------------------------------------------------- methodes ---
|
69
|
+
|
70
|
+
def document
|
71
|
+
@document
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def save(file)
|
76
|
+
File.open(file, 'w') do |file|
|
77
|
+
file.write(@document.to_xml)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def to_xml
|
83
|
+
@document.to_xml
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
def inspect
|
88
|
+
to_xml.to_s
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
def method_missing(method, *args, &block)
|
93
|
+
# analyse mehtod
|
94
|
+
splitted_method = method.to_s.split('_')
|
95
|
+
if splitted_method.first == 'add'
|
96
|
+
method_name = :add_value
|
97
|
+
splitted_method.shift
|
98
|
+
elsif splitted_method.first == 'list'
|
99
|
+
method_name = :list_value
|
100
|
+
splitted_method.shift
|
101
|
+
elsif splitted_method.last.end_with?('=')
|
102
|
+
method_name = :set_value
|
103
|
+
splitted_method.last.chop!
|
104
|
+
else
|
105
|
+
method_name = :get_value
|
106
|
+
end
|
107
|
+
|
108
|
+
# namespace, key and value
|
109
|
+
namespace = if !get_ns(splitted_method.first).nil?
|
110
|
+
splitted_method.shift
|
111
|
+
else
|
112
|
+
'xmlns'
|
113
|
+
end
|
114
|
+
key = splitted_method.join('_')
|
115
|
+
value = args[0]
|
116
|
+
MatterhornWhymper.logger.debug { "#{self.class.name}#method_missing | " +
|
117
|
+
"method: #{method_name.to_s}; namespace: #{namespace}; " +
|
118
|
+
"key: #{key}; value: #{value.to_s}" }
|
119
|
+
|
120
|
+
# call method
|
121
|
+
params = case method_name
|
122
|
+
when :get_value then [namespace, key]
|
123
|
+
when :set_value then [namespace, key, args[0].to_s]
|
124
|
+
when :add_value then [namespace, key, args[0].to_s]
|
125
|
+
end
|
126
|
+
send(method_name, *params)
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
# ------------------------------------------------------------------------------------ helpers ---
|
131
|
+
|
132
|
+
def get_ns(ns)
|
133
|
+
@document.root.namespace_definitions.find { |n| n.prefix == ns }
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
def get_value(ns, key)
|
138
|
+
elem = @document.xpath("/xmlns:dublincore/#{ns}:#{key}").first
|
139
|
+
return nil if elem.nil?
|
140
|
+
elem.content
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
def set_value(ns, key, value)
|
145
|
+
if !(elem = @document.at_xpath("/xmlns:dublincore/#{ns}:#{key}")).nil?
|
146
|
+
elem.content = value
|
147
|
+
else
|
148
|
+
elem = Nokogiri::XML::Element.new(key, @document)
|
149
|
+
elem.content = value
|
150
|
+
elem.namespace = get_ns(ns) unless ns.nil?
|
151
|
+
@document.root << elem
|
152
|
+
end
|
153
|
+
elem.content
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
def add_value(ns, key, value)
|
158
|
+
sibling = @document.xpath("/xmlns:dublincore/#{ns}:#{key}").last
|
159
|
+
elem = Nokogiri::XML::Element.new(key, @document)
|
160
|
+
elem.content = value
|
161
|
+
elem.namespace = get_ns(ns) unless ns.nil?
|
162
|
+
if !sibling.nil?
|
163
|
+
sibling.after(elem)
|
164
|
+
else
|
165
|
+
@document.root << elem
|
166
|
+
end
|
167
|
+
elem.content
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
end # --------------------------------------------------------------- end Matterhorn::DublinCore ---
|
@@ -9,20 +9,19 @@ class Matterhorn::Endpoint::Ingest < Matterhorn::Endpoint
|
|
9
9
|
unless @media_pkg_remote then raise(Matterhorn::Error, "No media package is available!"); end
|
10
10
|
@media_pkg_local.add_attachment(file, flavor) if @media_pkg_local
|
11
11
|
begin
|
12
|
-
|
12
|
+
spit_response http_client.post(
|
13
13
|
"ingest/addAttachment",
|
14
14
|
{ 'flavor' => flavor,
|
15
15
|
'mediaPackage' => @media_pkg_remote,
|
16
16
|
'BODY' => file
|
17
17
|
}
|
18
|
-
)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
"Internal server error on Matterhorn!" }
|
18
|
+
)
|
19
|
+
@media_pkg_remote = response_body
|
20
|
+
rescue => ex
|
21
|
+
exception_handler('addAttachment', ex, {
|
22
|
+
400 => "Media package not valid! / media package:\n#{@media_pkg_remote}"
|
23
|
+
}
|
24
|
+
)
|
26
25
|
raise ex
|
27
26
|
end
|
28
27
|
@media_pkg_remote
|
@@ -33,20 +32,19 @@ class Matterhorn::Endpoint::Ingest < Matterhorn::Endpoint
|
|
33
32
|
unless @media_pkg_remote then raise(Matterhorn::Error, "No media package is available!"); end
|
34
33
|
@media_pkg_local.add_catalog(file, flavor) if @media_pkg_local
|
35
34
|
begin
|
36
|
-
|
35
|
+
split_response http_client.post(
|
37
36
|
"ingest/addCatalog",
|
38
37
|
{ 'flavor' => flavor,
|
39
38
|
'mediaPackage' => @media_pkg_remote,
|
40
39
|
'BODY' => file
|
41
40
|
}
|
42
|
-
)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
"Internal server error on Matterhorn!" }
|
41
|
+
)
|
42
|
+
@media_pkg_remote = response_body
|
43
|
+
rescue => ex
|
44
|
+
exception_handler('addCatalog', ex, {
|
45
|
+
400 => "Media package not valid! / media package:\n#{@media_pkg_remote}"
|
46
|
+
}
|
47
|
+
)
|
50
48
|
raise ex
|
51
49
|
end
|
52
50
|
@media_pkg_remote
|
@@ -57,20 +55,19 @@ class Matterhorn::Endpoint::Ingest < Matterhorn::Endpoint
|
|
57
55
|
unless @media_pkg_remote then raise(Matterhorn::Error, "No media package is available!"); end
|
58
56
|
@media_pkg_local.add_dc_catalog(dublin_core) if @media_pkg_local
|
59
57
|
begin
|
60
|
-
|
58
|
+
split_response http_client.post(
|
61
59
|
"ingest/addDCCatalog",
|
62
60
|
{ 'flavor' => 'dublincore/episode',
|
63
61
|
'mediaPackage' => @media_pkg_remote,
|
64
62
|
'dublinCore' => dublin_core
|
65
63
|
}
|
66
|
-
)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
"Internal server error on Matterhorn!" }
|
64
|
+
)
|
65
|
+
@media_pkg_remote = response_body
|
66
|
+
rescue => ex
|
67
|
+
exception_handler('create', ex, {
|
68
|
+
400 => "Media package not valid! / media package:\n#{@media_pkg_remote}"
|
69
|
+
}
|
70
|
+
)
|
74
71
|
raise ex
|
75
72
|
end
|
76
73
|
@media_pkg_remote
|
@@ -82,33 +79,29 @@ class Matterhorn::Endpoint::Ingest < Matterhorn::Endpoint
|
|
82
79
|
unless @media_pkg_remote then raise(Matterhorn::Error, "No media package is available!"); end
|
83
80
|
@media_pkg_local.add_track(file_or_url, flavor) if @media_pkg_local
|
84
81
|
begin
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
raise ex
|
109
|
-
rescue Matterhorn::HttpServerError => ex
|
110
|
-
MatterhornWhymper.logger.error { "#{self.class.name}::addTrack | " +
|
111
|
-
"Internal server error on Matterhorn!" }
|
82
|
+
if HTTP_PROTOCOL_RE =~ file_or_url
|
83
|
+
split_response http_client.post(
|
84
|
+
"ingest/addTrack",
|
85
|
+
{ 'flavor' => flavor,
|
86
|
+
'mediaPackage' => @media_pkg_remote,
|
87
|
+
'url' => file_or_url
|
88
|
+
}
|
89
|
+
)
|
90
|
+
else
|
91
|
+
split_response http_client.post(
|
92
|
+
"ingest/addTrack",
|
93
|
+
{ 'flavor' => flavor,
|
94
|
+
'mediaPackage' => @media_pkg_remote,
|
95
|
+
'BODY' => file_or_url
|
96
|
+
}
|
97
|
+
)
|
98
|
+
end
|
99
|
+
@media_pkg_remote = response_body
|
100
|
+
rescue => ex
|
101
|
+
exception_handler('addTrack', ex, {
|
102
|
+
400 => "Media package not valid! / media package:\n#{@media_pkg_remote}"
|
103
|
+
}
|
104
|
+
)
|
112
105
|
raise ex
|
113
106
|
end
|
114
107
|
@media_pkg_remote
|
@@ -123,12 +116,12 @@ class Matterhorn::Endpoint::Ingest < Matterhorn::Endpoint
|
|
123
116
|
if @media_pkg_remote then raise(Matterhorn::Error, "A media package is allready created!"); end
|
124
117
|
@media_pkg_local = source_path ? Matterhorn::MediaPackage.new(source_path) : nil
|
125
118
|
begin
|
126
|
-
|
119
|
+
split_response http_client.get(
|
127
120
|
"ingest/createMediaPackage"
|
128
|
-
)
|
129
|
-
|
130
|
-
|
131
|
-
|
121
|
+
)
|
122
|
+
@media_pkg_remote = response_body
|
123
|
+
rescue => ex
|
124
|
+
exception_handler('createMediaPackage', ex, {})
|
132
125
|
raise ex
|
133
126
|
end
|
134
127
|
@media_pkg_remote
|
@@ -140,17 +133,16 @@ class Matterhorn::Endpoint::Ingest < Matterhorn::Endpoint
|
|
140
133
|
@media_pkg_local.save if @media_pkg_local
|
141
134
|
options['mediaPackage'] = @media_pkg_remote
|
142
135
|
begin
|
143
|
-
|
136
|
+
split_response http_client.post(
|
144
137
|
"ingest/ingest/#{wdID}",
|
145
138
|
options
|
146
|
-
)
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
"Internal server error on Matterhorn!" }
|
139
|
+
)
|
140
|
+
@workflow_inst = response_body
|
141
|
+
rescue => ex
|
142
|
+
exception_handler('create', ex, {
|
143
|
+
400 => "Media package not valid! / media package:\n#{@media_pkg_remote}"
|
144
|
+
}
|
145
|
+
)
|
154
146
|
raise ex
|
155
147
|
end
|
156
148
|
workflow_instance
|
@@ -0,0 +1,177 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
|
4
|
+
# ================================================================= Matterhorn::Endpoint::Series ===
|
5
|
+
|
6
|
+
class Matterhorn::Endpoint::Series < Matterhorn::Endpoint
|
7
|
+
|
8
|
+
|
9
|
+
# -------------------------------------------------------------------------- endpoint methodes ---
|
10
|
+
|
11
|
+
# ------------------------------------------------------------------------------------- create ---
|
12
|
+
|
13
|
+
# Create a new Series on Mattherhorn.
|
14
|
+
# Return the dublin core of the created Series.
|
15
|
+
# In the property dcterms:identifier is written the Matterhorn Series Id.
|
16
|
+
#
|
17
|
+
def create(dublin_core, acl = nil)
|
18
|
+
dc = nil
|
19
|
+
begin
|
20
|
+
split_response http_client.post(
|
21
|
+
"series",
|
22
|
+
{ 'series' => dublin_core.to_xml, 'acl' => acl ? acl.to_xml : '' }
|
23
|
+
)
|
24
|
+
dc = Matterhorn::DublinCore.new(response_body)
|
25
|
+
rescue => ex
|
26
|
+
exception_handler('create', ex, {
|
27
|
+
400 => "The required form params were missing to create the series!\n" +
|
28
|
+
" dubline_core:\n#{dublin_core.inspect}\n acl:\n#{acl.inspect}",
|
29
|
+
401 => "Unauthorized. It is required to authenticate first, before create a series!"
|
30
|
+
}
|
31
|
+
)
|
32
|
+
end
|
33
|
+
dc
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
# --------------------------------------------------------------------------------------- read ---
|
38
|
+
|
39
|
+
def read(series_id)
|
40
|
+
dc_model = nil
|
41
|
+
begin
|
42
|
+
split_response http_client.get(
|
43
|
+
"series/#{series_id}.xml"
|
44
|
+
)
|
45
|
+
dc_model = Matterhorn::DublinCore.new(response_body)
|
46
|
+
rescue => ex
|
47
|
+
exception_handler('read', ex, {
|
48
|
+
401 => "Unauthorized. It is required to authenticate first, " +
|
49
|
+
"before get the content of series #{series_id}.",
|
50
|
+
403 => "It is forbidden to get the content of series #{series_id}.",
|
51
|
+
404 => "The content of series #{series_id} could not be get."
|
52
|
+
}
|
53
|
+
)
|
54
|
+
end
|
55
|
+
dc_model
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def read_acl(series_id)
|
60
|
+
acl_model = nil
|
61
|
+
begin
|
62
|
+
split_response http_client.get(
|
63
|
+
"series/#{series_id}/acl.xml"
|
64
|
+
)
|
65
|
+
acl_model = Matterhorn::Acl.new(response_body)
|
66
|
+
rescue => ex
|
67
|
+
exception_handler('acl', ex, {
|
68
|
+
404 => "The acl of series #{series_id} could not be found."
|
69
|
+
}
|
70
|
+
)
|
71
|
+
end
|
72
|
+
acl_model
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
def find(options)
|
77
|
+
dc_models = []
|
78
|
+
begin
|
79
|
+
split_response http_client.get(
|
80
|
+
"series/series.xml#{build_query_str(options)}"
|
81
|
+
)
|
82
|
+
Nokogiri::XML(response_body).
|
83
|
+
xpath("/dublincorelist/xmlns:dublincore", Matterhorn::DublinCore::NS).each do |dc_elem|
|
84
|
+
dc_models << Matterhorn::DublinCore.new(dc_elem.to_xml)
|
85
|
+
end
|
86
|
+
rescue => ex
|
87
|
+
exception_handler('filter', ex, {
|
88
|
+
401 => "Unauthorized. It is required to authenticate first, " +
|
89
|
+
"before filter series."
|
90
|
+
}
|
91
|
+
)
|
92
|
+
end
|
93
|
+
dc_models
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
def count
|
98
|
+
count = 0
|
99
|
+
begin
|
100
|
+
split_response http_client.get(
|
101
|
+
"series/count"
|
102
|
+
)
|
103
|
+
count = response_body.to_i
|
104
|
+
rescue => ex
|
105
|
+
exception_handler('count', ex, {})
|
106
|
+
end
|
107
|
+
count
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
# ------------------------------------------------------------------------------------- update ---
|
112
|
+
|
113
|
+
# Updates a given Series on Mattherhorn.
|
114
|
+
# In the property dcterms:identifier must be written the Matterhorn Series Id of the Series
|
115
|
+
# which should be updated.
|
116
|
+
# Return the dublin core of the updated Series.
|
117
|
+
#
|
118
|
+
def update(dublin_core, acl = nil)
|
119
|
+
series_id = dublin_core.dcterms_identifier
|
120
|
+
dc_to_update = read(dublin_core.dcterms_identifier)
|
121
|
+
if dc_to_update.nil?
|
122
|
+
raise(Matterhorn::Matterhorn::Error.new("Series[#{series_id}] was not found on Matterhorn"))
|
123
|
+
end
|
124
|
+
dc = create(dublin_core, acl)
|
125
|
+
if response_code == 204
|
126
|
+
dc = read(series_id)
|
127
|
+
end
|
128
|
+
dc
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
def update_acl(series_id, acl)
|
133
|
+
acl_updated = false
|
134
|
+
begin
|
135
|
+
split_response http_client.post(
|
136
|
+
"series/#{series_id}/accesscontrol", { 'acl' => acl.to_xml }
|
137
|
+
)
|
138
|
+
acl_updated = true
|
139
|
+
rescue => ex
|
140
|
+
exception_handler('update_acl', ex, {
|
141
|
+
400 => "Bad request. The required param acl was missing. acl: #{acl.inspect}",
|
142
|
+
401 => "Unauthorized. It is required to authenticate first, " +
|
143
|
+
"before update the acl of series #{series_id}.",
|
144
|
+
404 => "The series #{series_id} could not be found."
|
145
|
+
}
|
146
|
+
)
|
147
|
+
end
|
148
|
+
acl_updated
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
# ------------------------------------------------------------------------------------- delete ---
|
153
|
+
|
154
|
+
def delete(series_id)
|
155
|
+
deleted = false
|
156
|
+
begin
|
157
|
+
split_response http_client.delete(
|
158
|
+
"series/#{series_id}"
|
159
|
+
)
|
160
|
+
deleted = true
|
161
|
+
rescue => ex
|
162
|
+
exception_handler('delete', ex, {
|
163
|
+
401 => "Unauthorized. It is required to authenticate first, " +
|
164
|
+
"before delete series #{series_id}.",
|
165
|
+
404 => "The series #{series_id} could not be found."
|
166
|
+
}
|
167
|
+
)
|
168
|
+
end
|
169
|
+
deleted
|
170
|
+
end
|
171
|
+
|
172
|
+
|
173
|
+
# ---------------------------------------------------------------------------- private section ---
|
174
|
+
private
|
175
|
+
|
176
|
+
|
177
|
+
end # --------------------------------------------------------- end Matterhorn::Endpoint::Series --
|
@@ -6,87 +6,72 @@ class Matterhorn::Endpoint::Workflow < Matterhorn::Endpoint
|
|
6
6
|
# -------------------------------------------------------------------------- endpoint methodes ---
|
7
7
|
|
8
8
|
def instance(wi_id)
|
9
|
+
wi = nil
|
9
10
|
begin
|
10
|
-
|
11
|
+
split_response http_client.get(
|
11
12
|
"workflow/instance/#{wi_id}.xml"
|
12
|
-
)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
MatterhornWhymper.logger.error { "#{self.class.name}::instance | " +
|
20
|
-
"WorkflowInstance[#{wi_id}]: Internal server error on Matterhorn!" }
|
21
|
-
|
22
|
-
raise ex
|
23
|
-
end
|
13
|
+
)
|
14
|
+
wi = response_body
|
15
|
+
rescue => ex
|
16
|
+
exception_handler('instance', ex, {
|
17
|
+
404 => "WorkflowInstance[#{wi_id}]: No workflow instance with that identifier exists."
|
18
|
+
}
|
19
|
+
)
|
24
20
|
end
|
25
21
|
wi ? Matterhorn::WorkflowInstance.new(wi) : nil
|
26
22
|
end
|
27
23
|
|
28
24
|
|
29
25
|
def remove(wi_id)
|
26
|
+
wi_removed = false
|
30
27
|
begin
|
31
|
-
http_client.delete(
|
28
|
+
split_response http_client.delete(
|
32
29
|
"workflow/remove/#{wi_id}"
|
33
30
|
)
|
34
31
|
wi_removed = true
|
35
|
-
rescue
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
else
|
41
|
-
MatterhornWhymper.logger.error { "#{self.class.name}::remove | " +
|
42
|
-
"WorkflowInstance[#{wi_id}]: Internal server error on Matterhorn!" }
|
43
|
-
|
44
|
-
raise ex
|
45
|
-
end
|
32
|
+
rescue => ex
|
33
|
+
exception_handler('remove', ex, {
|
34
|
+
404 => "WorkflowInstance[#{wi_id}]: No workflow instance with that identifier exists."
|
35
|
+
}
|
36
|
+
)
|
46
37
|
end
|
47
38
|
wi_removed
|
48
39
|
end
|
49
40
|
|
50
41
|
|
51
42
|
def resume(wi_id)
|
43
|
+
wi = nil
|
52
44
|
begin
|
53
|
-
|
45
|
+
split_response http_client.post(
|
54
46
|
"workflow/resume",
|
55
47
|
{ 'id' => wi_id }
|
56
|
-
)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
"WorkflowInstance[#{wi_id}]: Internal server error on Matterhorn!" }
|
65
|
-
|
66
|
-
raise ex
|
67
|
-
end
|
48
|
+
)
|
49
|
+
wi = response_body
|
50
|
+
rescue => ex
|
51
|
+
exception_handler('resume', ex, {
|
52
|
+
404 => "WorkflowInstance[#{wi_id}]: No suspended workflow instance " +
|
53
|
+
"with that identifier exists."
|
54
|
+
}
|
55
|
+
)
|
68
56
|
end
|
69
57
|
wi ? Matterhorn::WorkflowInstance.new(wi) : nil
|
70
58
|
end
|
71
59
|
|
72
60
|
|
73
61
|
def stop(wi_id)
|
62
|
+
wi = nil
|
74
63
|
begin
|
75
|
-
|
64
|
+
split_response http_client.post(
|
76
65
|
"workflow/stop",
|
77
66
|
{ 'id' => wi_id }
|
78
|
-
)
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
"WorkflowInstance[#{wi_id}]: Internal server error on Matterhorn!" }
|
87
|
-
|
88
|
-
raise ex
|
89
|
-
end
|
67
|
+
)
|
68
|
+
wi = response_body
|
69
|
+
rescue => ex
|
70
|
+
exception_handler('stop', ex, {
|
71
|
+
404 => "WorkflowInstance[#{wi_id}]: No running workflow instance " +
|
72
|
+
"with that identifier exists."
|
73
|
+
}
|
74
|
+
)
|
90
75
|
end
|
91
76
|
wi ? Matterhorn::WorkflowInstance.new(wi) : nil
|
92
77
|
end
|
data/lib/matterhorn/endpoint.rb
CHANGED
@@ -1,56 +1,129 @@
|
|
1
|
-
#
|
1
|
+
# ========================================================================= Matterhorn::Endpoint ===
|
2
2
|
|
3
|
-
|
3
|
+
class Matterhorn::Endpoint
|
4
4
|
|
5
|
+
# --------------------------------------------------------------------------------- attributes ---
|
5
6
|
|
6
|
-
|
7
|
+
attr_reader :response_code, :response_body
|
7
8
|
|
8
|
-
class Endpoint
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
# ----------------------------------------------------------------------------- initialization ---
|
11
|
+
|
12
|
+
def self.create(endpoint)
|
13
|
+
if endpoint.respond_to? 'to_s'
|
14
|
+
endpoint = endpoint.to_s.capitalize
|
15
|
+
else
|
16
|
+
raise(Matterhorn::Error, "Matterhorn::Endpoint::open | " +
|
17
|
+
"#{endpoint.inspect} does not respond to 'to_s'")
|
18
|
+
end
|
19
|
+
endpoint = Object.const_get('Matterhorn').const_get('Endpoint').const_get(endpoint).new
|
20
|
+
if endpoint.nil? || !endpoint.kind_of?(Matterhorn::Endpoint)
|
21
|
+
raise(Matterhorn::Error, "Matterhorn::Endpoint::open | " +
|
22
|
+
"#{endpoint ? endpoint.class.name : 'nil'} is not a sub class " +
|
23
|
+
"of 'Matterhorn::Endpoint'!")
|
24
|
+
end
|
25
|
+
endpoint
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def self.open(endpoint)
|
30
|
+
endpoint = create(endpoint)
|
31
|
+
begin
|
32
|
+
yield endpoint
|
33
|
+
ensure
|
34
|
+
endpoint.close
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def initialize
|
40
|
+
@http_client = Matterhorn::HttpClient.new(
|
41
|
+
MatterhornWhymper.configuration.uri,
|
42
|
+
MatterhornWhymper.configuration.http_timeout,
|
43
|
+
MatterhornWhymper.configuration.ssl_dont_verify_cert
|
44
|
+
)
|
45
|
+
@response_code = 200
|
46
|
+
@response_body = nil
|
47
|
+
@error_msg = ''
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
# ----------------------------------------------------------------------------------- methodes ---
|
52
|
+
|
53
|
+
def error_occurred?
|
54
|
+
response_code >= 400
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def error_code
|
59
|
+
error_occurred? ? response_code : nil
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def error_msg
|
64
|
+
error_occurred? ? @error_msg : ''
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def close
|
69
|
+
http_client.close
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
# ---------------------------------------------------------------------- *** protected section ***
|
74
|
+
protected
|
13
75
|
|
76
|
+
def http_client
|
77
|
+
@http_client
|
78
|
+
end
|
79
|
+
|
14
80
|
|
15
|
-
|
81
|
+
def split_response(response)
|
82
|
+
@response_code = response.code.to_i
|
83
|
+
@response_body = response.body
|
84
|
+
end
|
16
85
|
|
17
|
-
|
18
|
-
|
19
|
-
|
86
|
+
|
87
|
+
def exception_handler(method, exception, code_error_msg_hash)
|
88
|
+
res_code = 0
|
89
|
+
error_msg = ''
|
90
|
+
case exception
|
91
|
+
when Matterhorn::HttpClientError
|
92
|
+
res_code = exception.code
|
93
|
+
error_msg = if (msg = code_error_msg_hash[res_code]).nil?
|
94
|
+
"An unspezified error (#{res_code}) has occurred!"
|
20
95
|
else
|
21
|
-
|
22
|
-
"#{endpoint.inspect} does not respond to 'to_s'")
|
23
|
-
end
|
24
|
-
endpoint = Object.const_get('Matterhorn').const_get('Endpoint').const_get(endpoint).new
|
25
|
-
if endpoint.nil? || !endpoint.kind_of?(Matterhorn::Endpoint)
|
26
|
-
raise(Matterhorn::Error, "Matterhorn::Endpoint::open | " +
|
27
|
-
"#{endpoint ? endpoint.class.name : 'nil'} is not a sub class " +
|
28
|
-
"of 'Matterhorn::Endpoint'!")
|
29
|
-
end
|
30
|
-
begin
|
31
|
-
yield endpoint
|
32
|
-
ensure
|
33
|
-
endpoint.close
|
96
|
+
msg
|
34
97
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
98
|
+
log_warn_with_res_code_and_error_msg(method, res_code, error_msg)
|
99
|
+
when Matterhorn::HttpServerError
|
100
|
+
res_code = exception.code
|
101
|
+
log_error_with_res_code(method, res_code)
|
102
|
+
raise exception
|
103
|
+
else
|
104
|
+
log_fatal_with_backtrace(method, exception)
|
105
|
+
raise exception
|
43
106
|
end
|
44
|
-
|
45
|
-
|
46
|
-
|
107
|
+
@response_code = res_code
|
108
|
+
@error_msg = error_msg
|
109
|
+
end
|
47
110
|
|
48
|
-
|
49
|
-
|
50
|
-
|
111
|
+
|
112
|
+
def log_warn_with_res_code_and_error_msg(method, code, error_msg)
|
113
|
+
MatterhornWhymper.logger.warn { "#{self.class.name}##{method} | #{code}: #{error_msg}" }
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
def log_error_with_res_code(method, code)
|
118
|
+
MatterhornWhymper.logger.error { "#{self.class.name}##{method} | #{code}: " +
|
119
|
+
"An internal server error has occurred on Matterhorn!" }
|
120
|
+
end
|
51
121
|
|
52
122
|
|
53
|
-
|
123
|
+
def log_fatal_with_backtrace(method, ex)
|
124
|
+
MatterhornWhymper.logger.fatal { Matterhorn::Error.format_message(
|
125
|
+
"#{self.class.name}##{method} | A general error has occurred!", ex) }
|
126
|
+
end
|
54
127
|
|
55
128
|
|
56
|
-
end #
|
129
|
+
end # ----------------------------------------------------------------- end Matterhorn::Endpoint ---
|
data/lib/matterhorn/error.rb
CHANGED
@@ -1,33 +1,29 @@
|
|
1
|
-
#
|
1
|
+
# ====================================================================== several error classes ===
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
class Error < StandardError
|
3
|
+
class Matterhorn::Error < StandardError
|
4
|
+
def self.format_message(msg, ex)
|
5
|
+
"#{msg}\n" +
|
6
|
+
"#{ex.class.name}: #{ex.to_s}\n backtrace:\n #{ex.backtrace.join("\n ")}"
|
9
7
|
end
|
10
|
-
|
8
|
+
end
|
11
9
|
|
12
|
-
class HttpGeneralError < Matterhorn::Error
|
13
10
|
|
14
|
-
|
11
|
+
class Matterhorn::HttpGeneralError < Matterhorn::Error
|
15
12
|
|
16
|
-
|
17
|
-
@request = request
|
18
|
-
@response = response
|
19
|
-
@code = response.code.to_i
|
20
|
-
end
|
13
|
+
attr_reader :request, :response, :code
|
21
14
|
|
15
|
+
def initialize(request, response)
|
16
|
+
@request = request
|
17
|
+
@response = response
|
18
|
+
@code = response.code.to_i
|
22
19
|
end
|
23
20
|
|
21
|
+
end
|
24
22
|
|
25
|
-
class HttpClientError < Matterhorn::HttpGeneralError
|
26
|
-
end
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
end
|
24
|
+
class Matterhorn::HttpClientError < Matterhorn::HttpGeneralError
|
25
|
+
end
|
31
26
|
|
32
27
|
|
33
|
-
|
28
|
+
class Matterhorn::HttpServerError < Matterhorn::HttpGeneralError
|
29
|
+
end
|
@@ -13,17 +13,18 @@ module Matterhorn
|
|
13
13
|
|
14
14
|
# ------------------------------------------------------------------------------- attributes ---
|
15
15
|
|
16
|
-
attr_reader :base_uri, :host, :port, :ssl, :timeout
|
16
|
+
attr_reader :base_uri, :host, :port, :ssl, :ssl_dont_verify_cert, :timeout
|
17
17
|
|
18
18
|
|
19
19
|
# --------------------------------------------------------------------------- initialization ---
|
20
20
|
|
21
|
-
def initialize(base_uri, http_timeout = nil)
|
21
|
+
def initialize(base_uri, http_timeout = nil, ssl_dont_verify_cert = false)
|
22
22
|
@base_uri = URI.parse(base_uri)
|
23
23
|
@host = @base_uri.host
|
24
24
|
@port = @base_uri.port
|
25
25
|
@ssl = @port == 443 ? true : false
|
26
26
|
@timeout = http_timeout
|
27
|
+
@ssl_dont_verify_cert = ssl_dont_verify_cert
|
27
28
|
end
|
28
29
|
|
29
30
|
|
@@ -63,6 +64,7 @@ module Matterhorn
|
|
63
64
|
return @http_socket if !@http_socket.nil? && @http_socket.started?
|
64
65
|
@http_socket = Net::HTTP.new(host, port)
|
65
66
|
@http_socket.use_ssl = ssl
|
67
|
+
@http_socket.verify_mode = OpenSSL::SSL::VERIFY_NONE if ssl && ssl_dont_verify_cert
|
66
68
|
if !timeout.nil?
|
67
69
|
@http_socket.open_timeout = timeout
|
68
70
|
@http_socket.read_timeout = timeout
|
@@ -5,7 +5,7 @@ module MatterhornWhymper
|
|
5
5
|
|
6
6
|
# -------------------------------------------------------------------------- const definitions ---
|
7
7
|
|
8
|
-
VERSION = "0.
|
8
|
+
VERSION = "0.5.0"
|
9
9
|
|
10
10
|
|
11
11
|
end # -------------------------------------------------------------------- end MatterhornWhymper ---
|
data/lib/matterhorn_whymper.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
|
+
# Define Matterhorn Namespace
|
2
|
+
#
|
3
|
+
module Matterhorn
|
4
|
+
end
|
5
|
+
|
6
|
+
|
1
7
|
require 'matterhorn_whymper/version'
|
8
|
+
require 'matterhorn/acl'
|
9
|
+
require 'matterhorn/dublin_core'
|
2
10
|
require 'matterhorn/endpoint'
|
3
11
|
require 'matterhorn/endpoint/ingest'
|
12
|
+
require 'matterhorn/endpoint/series'
|
4
13
|
require 'matterhorn/endpoint/workflow'
|
5
14
|
require 'matterhorn/error'
|
6
15
|
require 'matterhorn/http_client'
|
@@ -49,7 +58,7 @@ module MatterhornWhymper
|
|
49
58
|
# ------------------------------------------------------------------------------- attributes ---
|
50
59
|
|
51
60
|
attr_accessor :system_account_user, :system_account_password, :system_domain, :system_protocol,
|
52
|
-
:http_timeout
|
61
|
+
:http_timeout, :ssl_dont_verify_cert
|
53
62
|
|
54
63
|
|
55
64
|
# --------------------------------------------------------------------------------- methodes ---
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matterhorn_whymper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Fritschi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multipart-post
|
@@ -137,8 +137,11 @@ files:
|
|
137
137
|
- LICENSE.txt
|
138
138
|
- README.md
|
139
139
|
- Rakefile
|
140
|
+
- lib/matterhorn/acl.rb
|
141
|
+
- lib/matterhorn/dublin_core.rb
|
140
142
|
- lib/matterhorn/endpoint.rb
|
141
143
|
- lib/matterhorn/endpoint/ingest.rb
|
144
|
+
- lib/matterhorn/endpoint/series.rb
|
142
145
|
- lib/matterhorn/endpoint/workflow.rb
|
143
146
|
- lib/matterhorn/error.rb
|
144
147
|
- lib/matterhorn/http_client.rb
|
@@ -178,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
181
|
version: '0'
|
179
182
|
requirements: []
|
180
183
|
rubyforge_project:
|
181
|
-
rubygems_version: 2.
|
184
|
+
rubygems_version: 2.4.6
|
182
185
|
signing_key:
|
183
186
|
specification_version: 4
|
184
187
|
summary: Ruby wrapper around the Matterhorn Endpoint API
|