openbel-api 0.6.2-java → 1.0.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gemspec +11 -14
- data/CHANGELOG.md +18 -12
- data/README.md +25 -36
- data/VERSION +1 -1
- data/app/openbel/api/app.rb +13 -12
- data/app/openbel/api/config.rb +53 -11
- data/app/openbel/api/helpers/{evidence.rb → nanopub.rb} +13 -14
- data/app/openbel/api/middleware/auth.rb +22 -29
- data/app/openbel/api/resources/annotation.rb +7 -7
- data/app/openbel/api/resources/function.rb +12 -35
- data/app/openbel/api/resources/namespace.rb +13 -13
- data/app/openbel/api/resources/{evidence.rb → nanopub.rb} +23 -23
- data/app/openbel/api/resources/{evidence_transform.rb → nanopub_transform.rb} +8 -8
- data/app/openbel/api/resources/relationship.rb +74 -0
- data/app/openbel/api/routes/annotations.rb +1 -1
- data/app/openbel/api/routes/base.rb +11 -7
- data/app/openbel/api/routes/datasets.rb +74 -84
- data/app/openbel/api/routes/expressions.rb +86 -396
- data/app/openbel/api/routes/language.rb +118 -0
- data/app/openbel/api/routes/namespaces.rb +2 -2
- data/app/openbel/api/routes/{evidence.rb → nanopubs.rb} +68 -69
- data/app/openbel/api/routes/root.rb +2 -2
- data/app/openbel/api/routes/version.rb +37 -23
- data/app/openbel/api/schemas/annotation_resource.schema.json +1 -1
- data/app/openbel/api/schemas/{evidence.schema.json → nanopub.schema.json} +10 -10
- data/app/openbel/api/schemas/{evidence_collection.schema.json → nanopub_collection.schema.json} +5 -5
- data/app/openbel/api/schemas/{evidence_resource.schema.json → nanopub_resource.schema.json} +4 -4
- data/config/config.yml +15 -5
- data/lib/openbel/api/helpers/uuid_generator.rb +22 -0
- data/lib/openbel/api/{evidence → nanopub}/api.rb +9 -9
- data/lib/openbel/api/{evidence → nanopub}/facet_api.rb +2 -2
- data/lib/openbel/api/{evidence → nanopub}/facet_filter.rb +6 -6
- data/lib/openbel/api/{evidence → nanopub}/mongo.rb +54 -52
- data/lib/openbel/api/{evidence → nanopub}/mongo_facet.rb +17 -28
- data/lib/openbel/api/plugin/{evidence/evidence.rb → nanopub/nanopub.rb} +7 -7
- metadata +44 -56
- data/app/openbel/api/routes/functions.rb +0 -41
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'bel'
|
2
|
+
require 'bel_parser'
|
3
|
+
|
4
|
+
module OpenBEL
|
5
|
+
module Routes
|
6
|
+
# Language defines and implements the _/api/language_ routes to expose
|
7
|
+
# BEL functions, relationships, and version configured for the API.
|
8
|
+
class Language < Base
|
9
|
+
|
10
|
+
JSON = Rack::Mime.mime_type('.json')
|
11
|
+
TEXT = Rack::Mime.mime_type('.txt')
|
12
|
+
ACCEPTED_TYPES = {'json' => JSON, 'text' => TEXT}
|
13
|
+
DEFAULT_TYPE = TEXT
|
14
|
+
|
15
|
+
def initialize(app)
|
16
|
+
super
|
17
|
+
bel_version = OpenBEL::Settings[:bel][:version]
|
18
|
+
@spec = BELParser::Language.specification(bel_version)
|
19
|
+
end
|
20
|
+
|
21
|
+
options '/api/language' do
|
22
|
+
response.headers['Allow'] = 'OPTIONS,GET'
|
23
|
+
status 200
|
24
|
+
end
|
25
|
+
|
26
|
+
options '/api/language/functions' do
|
27
|
+
response.headers['Allow'] = 'OPTIONS,GET'
|
28
|
+
status 200
|
29
|
+
end
|
30
|
+
|
31
|
+
options '/api/language/functions/:fx' do
|
32
|
+
response.headers['Allow'] = 'OPTIONS,GET'
|
33
|
+
status 200
|
34
|
+
end
|
35
|
+
|
36
|
+
options '/api/language/relationships' do
|
37
|
+
response.headers['Allow'] = 'OPTIONS,GET'
|
38
|
+
status 200
|
39
|
+
end
|
40
|
+
|
41
|
+
options '/api/language/relationships/:rel' do
|
42
|
+
response.headers['Allow'] = 'OPTIONS,GET'
|
43
|
+
status 200
|
44
|
+
end
|
45
|
+
|
46
|
+
options '/api/language/version' do
|
47
|
+
response.headers['Allow'] = 'OPTIONS,GET'
|
48
|
+
status 200
|
49
|
+
end
|
50
|
+
|
51
|
+
get '/api/language' do
|
52
|
+
response.headers['Content-Type'] = 'application/hal+json'
|
53
|
+
MultiJson.dump({
|
54
|
+
:_links => {
|
55
|
+
:item => [
|
56
|
+
{
|
57
|
+
:href => "#{base_url}/api/language/functions"
|
58
|
+
},
|
59
|
+
{
|
60
|
+
:href => "#{base_url}/api/language/relationships"
|
61
|
+
},
|
62
|
+
{
|
63
|
+
:href => "#{base_url}/api/language/version"
|
64
|
+
}
|
65
|
+
]
|
66
|
+
}
|
67
|
+
})
|
68
|
+
end
|
69
|
+
|
70
|
+
get '/api/language/functions' do
|
71
|
+
render_collection(
|
72
|
+
@spec.functions.sort_by(&:long),
|
73
|
+
:function)
|
74
|
+
end
|
75
|
+
|
76
|
+
get '/api/language/functions/:fx' do
|
77
|
+
function = @spec.function(params[:fx].to_sym)
|
78
|
+
halt 404 unless function
|
79
|
+
render_resource(function, :function)
|
80
|
+
end
|
81
|
+
|
82
|
+
get '/api/language/relationships' do
|
83
|
+
render_collection(
|
84
|
+
@spec.relationships.sort_by(&:long),
|
85
|
+
:relationship)
|
86
|
+
end
|
87
|
+
|
88
|
+
get '/api/language/relationships/:rel' do
|
89
|
+
relationship = @spec.relationship(params[:rel].to_sym)
|
90
|
+
halt 404 unless relationship
|
91
|
+
render_resource(relationship, :relationship)
|
92
|
+
end
|
93
|
+
|
94
|
+
get '/api/language/version' do
|
95
|
+
accept_type = request.accept.find { |accept_entry|
|
96
|
+
ACCEPTED_TYPES.values.include?(accept_entry.to_s)
|
97
|
+
}
|
98
|
+
accept_type ||= DEFAULT_TYPE
|
99
|
+
|
100
|
+
format = params[:format]
|
101
|
+
if format
|
102
|
+
accept_type = ACCEPTED_TYPES[format]
|
103
|
+
halt 406 unless accept_type
|
104
|
+
end
|
105
|
+
|
106
|
+
render_json(
|
107
|
+
{
|
108
|
+
:bel_version => {
|
109
|
+
:string => OpenBEL::Settings[:bel][:version].to_s
|
110
|
+
}
|
111
|
+
}
|
112
|
+
)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
# vim: ts=2 sw=2:
|
118
|
+
# encoding: utf-8
|
@@ -18,7 +18,7 @@ module OpenBEL
|
|
18
18
|
|
19
19
|
RESULT_TYPES = {
|
20
20
|
:resource => :all,
|
21
|
-
:name => :
|
21
|
+
:name => :pref_label,
|
22
22
|
:identifier => :identifier,
|
23
23
|
:title => :title
|
24
24
|
}
|
@@ -92,7 +92,7 @@ module OpenBEL
|
|
92
92
|
|
93
93
|
render_collection(
|
94
94
|
namespaces.sort { |x,y|
|
95
|
-
x.
|
95
|
+
x.pref_label.to_s <=> y.pref_label.to_s
|
96
96
|
},
|
97
97
|
:namespace
|
98
98
|
)
|
@@ -1,25 +1,25 @@
|
|
1
1
|
require 'bel'
|
2
2
|
require 'cgi'
|
3
|
-
require 'openbel/api/
|
4
|
-
require 'openbel/api/
|
5
|
-
require_relative '../resources/
|
6
|
-
require_relative '../helpers/
|
3
|
+
require 'openbel/api/nanopub/mongo'
|
4
|
+
require 'openbel/api/nanopub/facet_filter'
|
5
|
+
require_relative '../resources/nanopub_transform'
|
6
|
+
require_relative '../helpers/nanopub'
|
7
7
|
require_relative '../helpers/filters'
|
8
8
|
require_relative '../helpers/pager'
|
9
9
|
|
10
10
|
module OpenBEL
|
11
11
|
module Routes
|
12
12
|
|
13
|
-
class
|
14
|
-
include OpenBEL::
|
15
|
-
include OpenBEL::Resource::
|
13
|
+
class Nanopubs < Base
|
14
|
+
include OpenBEL::Nanopub::FacetFilter
|
15
|
+
include OpenBEL::Resource::Nanopub
|
16
16
|
include OpenBEL::Helpers
|
17
17
|
|
18
18
|
def initialize(app)
|
19
19
|
super
|
20
20
|
|
21
|
-
mongo = OpenBEL::Settings[:
|
22
|
-
@api = OpenBEL::
|
21
|
+
mongo = OpenBEL::Settings[:nanopub_store][:mongo]
|
22
|
+
@api = OpenBEL::Nanopub::Nanopub.new(mongo)
|
23
23
|
|
24
24
|
# RdfRepository using Jena
|
25
25
|
@rr = BEL::RdfRepository.plugins[:jena].create_repository(
|
@@ -27,31 +27,30 @@ module OpenBEL
|
|
27
27
|
)
|
28
28
|
|
29
29
|
# Annotations using RdfRepository
|
30
|
-
annotations
|
31
|
-
|
32
|
-
@annotation_transform = AnnotationTransform.new(annotations)
|
30
|
+
annotations = BEL::Resource::Annotations.new(@rr)
|
31
|
+
@annotation_transform = AnnotationTransform.new(annotations)
|
33
32
|
@annotation_grouping_transform = AnnotationGroupingTransform.new
|
34
33
|
end
|
35
34
|
|
36
35
|
helpers do
|
37
36
|
|
38
|
-
def
|
37
|
+
def stream_nanopub_objects(cursor)
|
39
38
|
|
40
39
|
stream :keep_open do |response|
|
41
|
-
cursor.each do |
|
42
|
-
|
40
|
+
cursor.each do |nanopub|
|
41
|
+
nanopub.delete('facets')
|
43
42
|
|
44
43
|
response << render_resource(
|
45
|
-
|
46
|
-
:
|
44
|
+
nanopub,
|
45
|
+
:nanopub,
|
47
46
|
:as_array => false,
|
48
|
-
:_id =>
|
47
|
+
:_id => nanopub['_id'].to_s
|
49
48
|
)
|
50
49
|
end
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
54
|
-
def
|
53
|
+
def stream_nanopub_array(cursor)
|
55
54
|
stream :keep_open do |response|
|
56
55
|
current = 0
|
57
56
|
|
@@ -63,14 +62,14 @@ module OpenBEL
|
|
63
62
|
end
|
64
63
|
|
65
64
|
response << '['
|
66
|
-
cursor.each do |
|
67
|
-
|
65
|
+
cursor.each do |nanopub|
|
66
|
+
nanopub.delete('facets')
|
68
67
|
|
69
68
|
response << render_resource(
|
70
|
-
|
71
|
-
:
|
69
|
+
nanopub,
|
70
|
+
:nanopub,
|
72
71
|
:as_array => false,
|
73
|
-
:_id =>
|
72
|
+
:_id => nanopub['_id'].to_s
|
74
73
|
)
|
75
74
|
current += 1
|
76
75
|
response << ',' if current < total
|
@@ -98,22 +97,22 @@ module OpenBEL
|
|
98
97
|
end
|
99
98
|
end
|
100
99
|
|
101
|
-
options '/api/
|
100
|
+
options '/api/nanopubs' do
|
102
101
|
response.headers['Allow'] = 'OPTIONS,POST,GET'
|
103
102
|
status 200
|
104
103
|
end
|
105
104
|
|
106
|
-
options '/api/
|
105
|
+
options '/api/nanopubs/:id' do
|
107
106
|
response.headers['Allow'] = 'OPTIONS,GET,PUT,DELETE'
|
108
107
|
status 200
|
109
108
|
end
|
110
109
|
|
111
|
-
post '/api/
|
112
|
-
# Validate
|
110
|
+
post '/api/nanopubs' do
|
111
|
+
# Validate BNJ.
|
113
112
|
validate_media_type! "application/json"
|
114
|
-
|
113
|
+
nanopub_obj = read_json
|
115
114
|
|
116
|
-
schema_validation = validate_schema(keys_to_s_deep(
|
115
|
+
schema_validation = validate_schema(keys_to_s_deep(nanopub_obj), :nanopub)
|
117
116
|
unless schema_validation[0]
|
118
117
|
halt(
|
119
118
|
400,
|
@@ -122,39 +121,39 @@ module OpenBEL
|
|
122
121
|
)
|
123
122
|
end
|
124
123
|
|
125
|
-
|
124
|
+
nanopub = ::BEL::Nanopub::Nanopub.create(nanopub_obj[:nanopub])
|
126
125
|
|
127
126
|
# Standardize annotations.
|
128
|
-
@annotation_transform.
|
127
|
+
@annotation_transform.transform_nanopub!(nanopub, base_url)
|
129
128
|
|
130
129
|
# Build facets.
|
131
|
-
facets =
|
132
|
-
hash =
|
130
|
+
facets = map_nanopub_facets(nanopub)
|
131
|
+
hash = nanopub.to_h
|
133
132
|
hash[:bel_statement] = hash.fetch(:bel_statement, nil).to_s
|
134
133
|
hash[:facets] = facets
|
135
|
-
_id
|
134
|
+
_id = @api.create_nanopub(hash)
|
136
135
|
|
137
136
|
# Return Location information (201).
|
138
137
|
status 201
|
139
|
-
headers "Location" => "#{base_url}/api/
|
138
|
+
headers "Location" => "#{base_url}/api/nanopubs/#{_id}"
|
140
139
|
end
|
141
140
|
|
142
|
-
get '/api/
|
141
|
+
get '/api/nanopubs-stream', provides: 'application/json' do
|
143
142
|
start = (params[:start] || 0).to_i
|
144
143
|
size = (params[:size] || 0).to_i
|
145
144
|
group_as_array = as_bool(params[:group_as_array])
|
146
145
|
|
147
146
|
filters = validate_filters!
|
148
147
|
|
149
|
-
cursor = @api.
|
148
|
+
cursor = @api.find_nanopub(filters, start, size, false)[:cursor]
|
150
149
|
if group_as_array
|
151
|
-
|
150
|
+
stream_nanopub_array(cursor)
|
152
151
|
else
|
153
|
-
|
152
|
+
stream_nanopub_objects(cursor)
|
154
153
|
end
|
155
154
|
end
|
156
155
|
|
157
|
-
get '/api/
|
156
|
+
get '/api/nanopubs' do
|
158
157
|
start = (params[:start] || 0).to_i
|
159
158
|
size = (params[:size] || 0).to_i
|
160
159
|
faceted = as_bool(params[:faceted])
|
@@ -162,46 +161,46 @@ module OpenBEL
|
|
162
161
|
|
163
162
|
filters = validate_filters!
|
164
163
|
|
165
|
-
collection_total = @api.
|
166
|
-
filtered_total = @api.
|
167
|
-
page_results = @api.
|
164
|
+
collection_total = @api.count_nanopub()
|
165
|
+
filtered_total = @api.count_nanopub(filters)
|
166
|
+
page_results = @api.find_nanopub(filters, start, size, faceted, max_values_per_facet)
|
168
167
|
|
169
|
-
|
170
|
-
'
|
168
|
+
render_nanopub_collection(
|
169
|
+
'nanopub-export', page_results, start, size, filters,
|
171
170
|
filtered_total, collection_total, @api
|
172
171
|
)
|
173
172
|
end
|
174
173
|
|
175
|
-
get '/api/
|
174
|
+
get '/api/nanopubs/:id' do
|
176
175
|
object_id = params[:id]
|
177
176
|
halt 404 unless BSON::ObjectId.legal?(object_id)
|
178
177
|
|
179
|
-
|
180
|
-
halt 404 unless
|
178
|
+
nanopub = @api.find_nanopub_by_id(object_id)
|
179
|
+
halt 404 unless nanopub
|
181
180
|
|
182
|
-
|
181
|
+
nanopub.delete('facets')
|
183
182
|
|
184
183
|
# XXX Hack to return single resource wrapped as json array
|
185
|
-
# XXX Need to better support
|
184
|
+
# XXX Need to better support nanopub resource arrays in base.rb
|
186
185
|
render_resource(
|
187
|
-
|
188
|
-
:
|
186
|
+
nanopub,
|
187
|
+
:nanopub,
|
189
188
|
:as_array => false,
|
190
189
|
:_id => object_id
|
191
190
|
)
|
192
191
|
end
|
193
192
|
|
194
|
-
put '/api/
|
193
|
+
put '/api/nanopubs/:id' do
|
195
194
|
object_id = params[:id]
|
196
195
|
halt 404 unless BSON::ObjectId.legal?(object_id)
|
197
196
|
|
198
197
|
validate_media_type! "application/json"
|
199
198
|
|
200
|
-
ev = @api.
|
199
|
+
ev = @api.find_nanopub_by_id(object_id)
|
201
200
|
halt 404 unless ev
|
202
201
|
|
203
|
-
|
204
|
-
schema_validation = validate_schema(keys_to_s_deep(
|
202
|
+
nanopub_obj = read_json
|
203
|
+
schema_validation = validate_schema(keys_to_s_deep(nanopub_obj), :nanopub)
|
205
204
|
unless schema_validation[0]
|
206
205
|
halt(
|
207
206
|
400,
|
@@ -211,30 +210,30 @@ module OpenBEL
|
|
211
210
|
end
|
212
211
|
|
213
212
|
# transformation
|
214
|
-
|
215
|
-
|
216
|
-
@annotation_transform.
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
213
|
+
nanopub = nanopub_obj[:nanopub]
|
214
|
+
nanopub = ::BEL::Nanopub::Nanopub.create(nanopub)
|
215
|
+
@annotation_transform.transform_nanopub!(nanopub, base_url)
|
216
|
+
|
217
|
+
facets = map_nanopub_facets(nanopub)
|
218
|
+
nanopub = nanopub.to_h
|
219
|
+
nanopub[:bel_statement] = nanopub.fetch(:bel_statement, nil).to_s
|
220
|
+
nanopub[:facets] = facets
|
221
221
|
|
222
|
-
@api.
|
222
|
+
@api.update_nanopub_by_id(object_id, nanopub)
|
223
223
|
|
224
224
|
status 202
|
225
225
|
end
|
226
226
|
|
227
|
-
delete '/api/
|
227
|
+
delete '/api/nanopubs/:id' do
|
228
228
|
object_id = params[:id]
|
229
229
|
halt 404 unless BSON::ObjectId.legal?(object_id)
|
230
230
|
|
231
|
-
ev = @api.
|
231
|
+
ev = @api.find_nanopub_by_id(object_id)
|
232
232
|
halt 404 unless ev
|
233
233
|
|
234
|
-
@api.
|
234
|
+
@api.delete_nanopub_by_id(object_id)
|
235
235
|
status 202
|
236
236
|
end
|
237
|
-
|
238
237
|
end
|
239
238
|
end
|
240
239
|
end
|
@@ -17,13 +17,13 @@ module OpenBEL
|
|
17
17
|
:href => "#{base_url}/api/annotations"
|
18
18
|
},
|
19
19
|
{
|
20
|
-
:href => "#{base_url}/api/
|
20
|
+
:href => "#{base_url}/api/nanopub"
|
21
21
|
},
|
22
22
|
{
|
23
23
|
:href => "#{base_url}/api/expressions"
|
24
24
|
},
|
25
25
|
{
|
26
|
-
:href => "#{base_url}/api/
|
26
|
+
:href => "#{base_url}/api/language"
|
27
27
|
},
|
28
28
|
{
|
29
29
|
:href => "#{base_url}/api/namespaces"
|
@@ -1,45 +1,59 @@
|
|
1
|
-
|
2
|
-
require 'rack/mime'
|
1
|
+
require 'openbel/api/version'
|
3
2
|
|
4
3
|
module OpenBEL
|
5
4
|
module Routes
|
6
|
-
|
5
|
+
# Version defines and implements the _/api/version_ route that exposes
|
6
|
+
# the semantic version of the OpenBEL API.
|
7
7
|
class Version < Base
|
8
8
|
|
9
9
|
JSON = Rack::Mime.mime_type('.json')
|
10
|
+
HAL = 'application/hal+json'
|
10
11
|
TEXT = Rack::Mime.mime_type('.txt')
|
11
|
-
ACCEPTED_TYPES = {
|
12
|
+
ACCEPTED_TYPES = {
|
13
|
+
'hal' => HAL,
|
14
|
+
'json' => JSON,
|
15
|
+
'text' => TEXT
|
16
|
+
}
|
12
17
|
DEFAULT_TYPE = TEXT
|
13
18
|
|
19
|
+
helpers do
|
20
|
+
def requested_media_type
|
21
|
+
if params && params[:format]
|
22
|
+
ACCEPTED_TYPES[params[:format]]
|
23
|
+
else
|
24
|
+
request.accept.flat_map { |accept_entry|
|
25
|
+
ACCEPTED_TYPES.values.find { |type| type == accept_entry.entry }
|
26
|
+
}.compact.first
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
14
31
|
options '/api/version' do
|
15
32
|
response.headers['Allow'] = 'OPTIONS,GET'
|
16
33
|
status 200
|
17
34
|
end
|
18
35
|
|
19
36
|
get '/api/version' do
|
20
|
-
accept_type =
|
21
|
-
ACCEPTED_TYPES.values.include?(accept_entry.to_s)
|
22
|
-
}
|
23
|
-
accept_type ||= DEFAULT_TYPE
|
24
|
-
|
25
|
-
format = params[:format]
|
26
|
-
if format
|
27
|
-
accept_type = ACCEPTED_TYPES[format]
|
28
|
-
halt 406 unless accept_type
|
29
|
-
end
|
37
|
+
accept_type = requested_media_type || DEFAULT_TYPE
|
30
38
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
39
|
+
case accept_type
|
40
|
+
when TEXT
|
41
|
+
response.headers['Content-Type'] = 'text/plain'
|
42
|
+
OpenBEL::Version.to_s
|
43
|
+
when HAL, JSON
|
44
|
+
response.headers['Content-Type'] = 'application/hal+json'
|
45
|
+
MultiJson.dump({
|
46
|
+
:version => {
|
47
|
+
:string => OpenBEL::Version.to_s,
|
48
|
+
:semantic_version => {
|
49
|
+
:major => OpenBEL::Version::MAJOR,
|
50
|
+
:minor => OpenBEL::Version::MINOR,
|
51
|
+
:patch => OpenBEL::Version::PATCH
|
37
52
|
}
|
38
53
|
}
|
39
|
-
)
|
54
|
+
})
|
40
55
|
else
|
41
|
-
|
42
|
-
OpenBEL::Version.to_s
|
56
|
+
halt 406
|
43
57
|
end
|
44
58
|
end
|
45
59
|
end
|