openbel-api 0.6.2-java → 1.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -4,7 +4,6 @@ require 'jwt'
|
|
4
4
|
|
5
5
|
module OpenBEL
|
6
6
|
module JWTMiddleware
|
7
|
-
|
8
7
|
def self.encode(payload, secret)
|
9
8
|
::JWT.encode(payload, secret, 'HS256')
|
10
9
|
end
|
@@ -13,35 +12,32 @@ module OpenBEL
|
|
13
12
|
::JWT.decode(token, secret, verify, options)
|
14
13
|
end
|
15
14
|
|
16
|
-
def self.
|
15
|
+
def self.check_token(env)
|
17
16
|
cookie_hdr = env['HTTP_COOKIE']
|
18
17
|
auth_hdr = env['HTTP_AUTHORIZATION']
|
19
|
-
|
20
|
-
|
18
|
+
req = Rack::Request.new(env)
|
19
|
+
token_param = req.params['token']
|
20
|
+
if cookie_hdr.nil? && auth_hdr.nil? && token_param.nil?
|
21
|
+
raise 'missing authorization cookie, header, or parameter'
|
21
22
|
end
|
22
23
|
|
23
|
-
|
24
|
+
unless cookie_hdr.nil?
|
24
25
|
cookies = cookie_hdr.split('; ')
|
25
|
-
selected = cookies.select {|x| x.start_with?('jwt=') }
|
26
|
-
|
26
|
+
selected = cookies.select { |x| x.start_with?('jwt=') }
|
27
|
+
unless selected.empty?
|
27
28
|
tokens = selected[0].split('=')
|
28
|
-
if tokens.size > 1
|
29
|
-
token = tokens[1]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
if token.nil?
|
33
|
-
raise 'malformed authorization cookie'
|
29
|
+
token = tokens[1] if tokens.size > 1
|
34
30
|
end
|
35
31
|
end
|
36
32
|
|
37
|
-
|
33
|
+
unless auth_hdr.nil?
|
38
34
|
tokens = auth_hdr.split('Bearer ')
|
39
|
-
if tokens.size != 2
|
40
|
-
raise 'malformed authorization header'
|
41
|
-
end
|
35
|
+
raise 'malformed authorization header' if tokens.size != 2
|
42
36
|
token = tokens[1]
|
43
37
|
end
|
44
38
|
|
39
|
+
token = token_param unless token_param.nil?
|
40
|
+
|
45
41
|
secret = OpenBEL::Settings[:auth][:secret]
|
46
42
|
secret = Base64.decode64(secret)
|
47
43
|
# whether we should verify the token
|
@@ -52,6 +48,7 @@ module OpenBEL
|
|
52
48
|
begin
|
53
49
|
decoded_token = decode(token, secret, verify, options)
|
54
50
|
rescue ::JWT::VerificationError => ve
|
51
|
+
puts ve.inspect
|
55
52
|
raise 'invalid authorization token'
|
56
53
|
rescue ::JWT::DecodeError => je
|
57
54
|
puts je.inspect
|
@@ -62,35 +59,31 @@ module OpenBEL
|
|
62
59
|
|
63
60
|
exp = env['jwt.payload']['exp']
|
64
61
|
now = Time.now.to_i
|
65
|
-
if now > exp
|
66
|
-
raise 'token expired'
|
67
|
-
end
|
62
|
+
raise 'token expired' if now > exp
|
68
63
|
|
69
64
|
env['email'] = env['jwt.payload']['email']
|
70
65
|
end
|
71
66
|
|
72
67
|
class Authentication
|
73
68
|
def initialize(app, opts = {})
|
74
|
-
@app
|
75
|
-
@paths
|
69
|
+
@app = app
|
70
|
+
@paths = opts.fetch(:paths, [])
|
76
71
|
end
|
77
72
|
|
78
73
|
def call(env)
|
79
74
|
check = false
|
80
|
-
if @paths.
|
75
|
+
if @paths.empty?
|
81
76
|
# w/out paths, always check for token
|
82
77
|
check = true
|
83
78
|
else
|
84
79
|
path = env['PATH_INFO']
|
85
80
|
# w/ paths, only check for token iff matched
|
86
|
-
if @paths.any? {|x| path.start_with?(x)}
|
87
|
-
check = true
|
88
|
-
end
|
81
|
+
check = true if @paths.any? { |x| path.start_with?(x) }
|
89
82
|
end
|
90
83
|
|
91
84
|
if check
|
92
85
|
begin
|
93
|
-
JWTMiddleware.
|
86
|
+
JWTMiddleware.check_token(env)
|
94
87
|
rescue Exception => e
|
95
88
|
return _401(e.message)
|
96
89
|
end
|
@@ -101,8 +94,8 @@ module OpenBEL
|
|
101
94
|
private
|
102
95
|
|
103
96
|
def _401(message)
|
104
|
-
hdrs = {'Content-Type' => 'application/json'}
|
105
|
-
msg = {error: message }
|
97
|
+
hdrs = { 'Content-Type' => 'application/json' }
|
98
|
+
msg = { error: message }
|
106
99
|
[401, hdrs, [msg.to_json]]
|
107
100
|
end
|
108
101
|
end
|
@@ -22,9 +22,9 @@ module OpenBEL
|
|
22
22
|
schema do
|
23
23
|
type :annotation
|
24
24
|
property :rdf_uri, item.uri.to_s
|
25
|
-
property :name, item.
|
26
|
-
property :prefix, item.prefix
|
27
|
-
property :domain, item.domain
|
25
|
+
property :name, item.pref_label.first
|
26
|
+
property :prefix, item.prefix.first
|
27
|
+
property :domain, item.domain.first
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -85,14 +85,14 @@ module OpenBEL
|
|
85
85
|
type :annotation_value
|
86
86
|
property :rdf_uri, item.uri.to_s
|
87
87
|
property :type, [item.type].flatten.map(&:to_s)
|
88
|
-
property :identifier, item.identifier
|
89
|
-
property :name, item.
|
88
|
+
property :identifier, item.identifier.first
|
89
|
+
property :name, item.pref_label.first
|
90
90
|
entity :annotation, item.annotation, AnnotationSerializer
|
91
91
|
|
92
92
|
# Support inclusion of the matched text when annotation values are filtered by
|
93
93
|
# a full-text search.
|
94
|
-
if item.match_text
|
95
|
-
property :match_text,
|
94
|
+
if item.respond_to?(:match_text) && item.match_text
|
95
|
+
property :match_text, item.match_text
|
96
96
|
end
|
97
97
|
|
98
98
|
setup(item)
|
@@ -11,11 +11,10 @@ module OpenBEL
|
|
11
11
|
schema do
|
12
12
|
type :function
|
13
13
|
properties do |p|
|
14
|
-
p.short_form item
|
15
|
-
p.long_form item
|
16
|
-
p.description item
|
17
|
-
p.return_type item
|
18
|
-
p.signatures item[:signatures]
|
14
|
+
p.short_form item.short
|
15
|
+
p.long_form item.long
|
16
|
+
p.description item.description
|
17
|
+
p.return_type item.return_type.to_sym
|
19
18
|
end
|
20
19
|
end
|
21
20
|
end
|
@@ -26,12 +25,11 @@ module OpenBEL
|
|
26
25
|
schema do
|
27
26
|
type :function
|
28
27
|
properties do |p|
|
29
|
-
p.
|
28
|
+
p.function item
|
30
29
|
end
|
31
30
|
|
32
|
-
link :self,
|
33
|
-
link :
|
34
|
-
link :collection, link_collection
|
31
|
+
link :self, link_self(item[:long_form])
|
32
|
+
link :collection, link_collection
|
35
33
|
end
|
36
34
|
|
37
35
|
private
|
@@ -45,53 +43,32 @@ module OpenBEL
|
|
45
43
|
|
46
44
|
def link_collection
|
47
45
|
{
|
48
|
-
:type => :
|
46
|
+
:type => :function_collection,
|
49
47
|
:href => "#{base_url}/api/functions"
|
50
48
|
}
|
51
49
|
end
|
52
|
-
|
53
|
-
def link_next
|
54
|
-
fx_values = FUNCTIONS.values.uniq.sort_by { |fx|
|
55
|
-
fx[:short_form]
|
56
|
-
}
|
57
|
-
next_fx = fx_values[fx_values.index(item) + 1]
|
58
|
-
{
|
59
|
-
:type => :function,
|
60
|
-
:href => next_fx ?
|
61
|
-
"#{base_url}/api/functions/#{next_fx[:short_form]}" :
|
62
|
-
nil
|
63
|
-
}
|
64
|
-
end
|
65
50
|
end
|
66
51
|
|
67
52
|
class FunctionCollectionSerializer < BaseSerializer
|
68
53
|
adapter Oat::Adapters::HAL
|
69
54
|
|
70
55
|
schema do
|
71
|
-
type :
|
56
|
+
type :function_collection
|
72
57
|
properties do |p|
|
73
|
-
p.
|
58
|
+
p.function_collection item
|
74
59
|
end
|
75
60
|
|
76
|
-
link :self,
|
77
|
-
link :start, link_start(item.first[:short_form])
|
61
|
+
link :self, link_self
|
78
62
|
end
|
79
63
|
|
80
64
|
private
|
81
65
|
|
82
66
|
def link_self
|
83
67
|
{
|
84
|
-
:type => :
|
68
|
+
:type => :function_collection,
|
85
69
|
:href => "#{base_url}/api/functions"
|
86
70
|
}
|
87
71
|
end
|
88
|
-
|
89
|
-
def link_start(first_function)
|
90
|
-
{
|
91
|
-
:type => :function,
|
92
|
-
:href => "#{base_url}/api/functions/#{first_function}"
|
93
|
-
}
|
94
|
-
end
|
95
72
|
end
|
96
73
|
end
|
97
74
|
end
|
@@ -22,9 +22,9 @@ module OpenBEL
|
|
22
22
|
schema do
|
23
23
|
type :namespace
|
24
24
|
property :rdf_uri, item.uri.to_s
|
25
|
-
property :name, item.
|
26
|
-
property :prefix, item.prefix
|
27
|
-
property :domain, item.domain
|
25
|
+
property :name, item.pref_label.first
|
26
|
+
property :prefix, item.prefix.first
|
27
|
+
property :domain, item.domain.first
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -86,16 +86,16 @@ module OpenBEL
|
|
86
86
|
type :namespace_value
|
87
87
|
property :rdf_uri, item.uri.to_s
|
88
88
|
property :type, [item.type].flatten.map(&:to_s)
|
89
|
-
property :identifier, item.identifier
|
90
|
-
property :name, item.
|
91
|
-
property :title, item.title
|
92
|
-
property :species, item.
|
89
|
+
property :identifier, item.identifier.first
|
90
|
+
property :name, item.pref_label.first
|
91
|
+
property :title, item.title.first
|
92
|
+
property :species, item.from_species.first
|
93
93
|
entity :namespace, item.namespace, NamespaceSerializer
|
94
94
|
|
95
95
|
# Support inclusion of the matched text when annotation values are filtered by
|
96
96
|
# a full-text search.
|
97
|
-
if item.match_text
|
98
|
-
property :match_text,
|
97
|
+
if item.respond_to?(:match_text) && item.match_text
|
98
|
+
property :match_text, item.match_text
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
@@ -160,10 +160,10 @@ module OpenBEL
|
|
160
160
|
type :value_equivalence
|
161
161
|
property :value, item.value
|
162
162
|
property :type, item.type ? item.type.sub(VOCABULARY_RDF, '') : nil
|
163
|
-
property :identifier, item.identifier
|
164
|
-
property :title, item.title
|
165
|
-
property :species, item.
|
166
|
-
property :namespace_uri, item.
|
163
|
+
property :identifier, item.identifier.first
|
164
|
+
property :title, item.title.first
|
165
|
+
property :species, item.from_species.first
|
166
|
+
property :namespace_uri, item.in_scheme.first
|
167
167
|
|
168
168
|
property :value_equivalence_collection, item.equivalences, NamespaceValueSerializer
|
169
169
|
end
|
@@ -3,29 +3,29 @@ require_relative 'base'
|
|
3
3
|
|
4
4
|
module OpenBEL
|
5
5
|
module Resource
|
6
|
-
module
|
6
|
+
module Nanopub
|
7
7
|
|
8
|
-
class
|
8
|
+
class NanopubSerializer < BaseSerializer
|
9
9
|
adapter Oat::Adapters::HAL
|
10
10
|
|
11
11
|
schema do
|
12
|
-
type :
|
12
|
+
type :nanopub
|
13
13
|
property :bel_statement, item['bel_statement']
|
14
14
|
property :citation, item['citation']
|
15
|
-
property :
|
15
|
+
property :support, item['support']
|
16
16
|
property :experiment_context, item['experiment_context']
|
17
17
|
property :metadata, item['metadata']
|
18
18
|
property :id, item['_id']
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
class
|
22
|
+
class NanopubResourceSerializer < BaseSerializer
|
23
23
|
adapter Oat::Adapters::HAL
|
24
24
|
|
25
25
|
schema do
|
26
|
-
type :
|
26
|
+
type :nanopub
|
27
27
|
properties do |p|
|
28
|
-
p.
|
28
|
+
p.nanopub item
|
29
29
|
end
|
30
30
|
|
31
31
|
link :self, link_self
|
@@ -38,25 +38,25 @@ module OpenBEL
|
|
38
38
|
id = item[:id] || context[:_id]
|
39
39
|
item.delete(:id)
|
40
40
|
{
|
41
|
-
:type => :
|
42
|
-
:href => "#{base_url}/api/
|
41
|
+
:type => :nanopub,
|
42
|
+
:href => "#{base_url}/api/nanopubs/#{id}"
|
43
43
|
}
|
44
44
|
end
|
45
45
|
|
46
46
|
def link_collection
|
47
47
|
{
|
48
|
-
:type => :
|
49
|
-
:href => "#{base_url}/api/
|
48
|
+
:type => :nanopub_collection,
|
49
|
+
:href => "#{base_url}/api/nanopubs"
|
50
50
|
}
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
class
|
54
|
+
class NanopubCollectionSerializer < BaseSerializer
|
55
55
|
adapter Oat::Adapters::HAL
|
56
56
|
|
57
57
|
schema do
|
58
|
-
type :
|
59
|
-
property :
|
58
|
+
type :nanopub_collection
|
59
|
+
property :nanopub_collection, item
|
60
60
|
property :facets, context[:facets]
|
61
61
|
property :metadata, context[:metadata]
|
62
62
|
link :self, link_self
|
@@ -71,16 +71,16 @@ module OpenBEL
|
|
71
71
|
start = context[:start]
|
72
72
|
size = context[:size]
|
73
73
|
{
|
74
|
-
:type => :
|
75
|
-
:href => "#{base_url}/api/
|
74
|
+
:type => :nanopub_collection,
|
75
|
+
:href => "#{base_url}/api/nanopubs?start=#{start}&size=#{size}&#{filter_query_params.join('&')}"
|
76
76
|
}
|
77
77
|
end
|
78
78
|
|
79
79
|
def link_start
|
80
80
|
size = context[:size]
|
81
81
|
{
|
82
|
-
:type => :
|
83
|
-
:href => "#{base_url}/api/
|
82
|
+
:type => :nanopub_collection,
|
83
|
+
:href => "#{base_url}/api/nanopubs?start=0&size=#{size}&#{filter_query_params.join('&')}"
|
84
84
|
}
|
85
85
|
end
|
86
86
|
|
@@ -89,8 +89,8 @@ module OpenBEL
|
|
89
89
|
return {} unless previous_page
|
90
90
|
|
91
91
|
{
|
92
|
-
:type => :
|
93
|
-
:href => "#{base_url}/api/
|
92
|
+
:type => :nanopub_collection,
|
93
|
+
:href => "#{base_url}/api/nanopubs?start=#{previous_page.start_offset}&size=#{previous_page.page_size}&#{filter_query_params.join('&')}"
|
94
94
|
}
|
95
95
|
end
|
96
96
|
|
@@ -99,14 +99,14 @@ module OpenBEL
|
|
99
99
|
return {} unless next_page
|
100
100
|
|
101
101
|
{
|
102
|
-
:type => :
|
103
|
-
:href => "#{base_url}/api/
|
102
|
+
:type => :nanopub_collection,
|
103
|
+
:href => "#{base_url}/api/nanopubs?start=#{next_page.start_offset}&size=#{next_page.page_size}&#{filter_query_params.join('&')}"
|
104
104
|
}
|
105
105
|
end
|
106
106
|
|
107
107
|
def filter_query_params
|
108
108
|
context[:filters].map { |filter|
|
109
|
-
"filter=#{filter}"
|
109
|
+
"filter=#{MultiJson.dump(filter)}"
|
110
110
|
}
|
111
111
|
end
|
112
112
|
end
|
@@ -2,7 +2,7 @@ require 'bel'
|
|
2
2
|
|
3
3
|
module OpenBEL
|
4
4
|
module Resource
|
5
|
-
module
|
5
|
+
module Nanopub
|
6
6
|
|
7
7
|
class AnnotationTransform
|
8
8
|
|
@@ -18,9 +18,9 @@ module OpenBEL
|
|
18
18
|
@annotations = annotations
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
if
|
23
|
-
experiment_context =
|
21
|
+
def transform_nanopub!(nanopub, base_url)
|
22
|
+
if nanopub
|
23
|
+
experiment_context = nanopub.experiment_context
|
24
24
|
if experiment_context != nil
|
25
25
|
experiment_context.values.map! { |annotation|
|
26
26
|
transform_annotation(annotation, base_url)
|
@@ -103,12 +103,12 @@ module OpenBEL
|
|
103
103
|
|
104
104
|
class AnnotationGroupingTransform
|
105
105
|
|
106
|
-
ExperimentContext = ::BEL::
|
106
|
+
ExperimentContext = ::BEL::Nanopub::ExperimentContext
|
107
107
|
|
108
|
-
def
|
109
|
-
experiment_context =
|
108
|
+
def transform_nanopub!(nanopub)
|
109
|
+
experiment_context = nanopub.experiment_context
|
110
110
|
if experiment_context != nil
|
111
|
-
|
111
|
+
nanopub.experiment_context = ExperimentContext.new(
|
112
112
|
experiment_context.group_by { |annotation|
|
113
113
|
annotation[:name]
|
114
114
|
}.values.map do |grouped_annotation|
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'bel'
|
2
|
+
require_relative 'base'
|
3
|
+
|
4
|
+
module OpenBEL
|
5
|
+
module Resource
|
6
|
+
module Relationships
|
7
|
+
|
8
|
+
class RelationshipSerializer < BaseSerializer
|
9
|
+
adapter Oat::Adapters::HAL
|
10
|
+
|
11
|
+
schema do
|
12
|
+
type :relationship
|
13
|
+
properties do |p|
|
14
|
+
p.short_form item.short
|
15
|
+
p.long_form item.long
|
16
|
+
p.description item.description
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class RelationshipResourceSerializer < BaseSerializer
|
22
|
+
adapter Oat::Adapters::HAL
|
23
|
+
|
24
|
+
schema do
|
25
|
+
type :relationship
|
26
|
+
properties do |p|
|
27
|
+
p.relation item
|
28
|
+
end
|
29
|
+
|
30
|
+
link :self, link_self(item[:long_form])
|
31
|
+
link :collection, link_collection
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def link_self(id)
|
37
|
+
{
|
38
|
+
:type => :relationship,
|
39
|
+
:href => "#{base_url}/api/relationships/#{id}"
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def link_collection
|
44
|
+
{
|
45
|
+
:type => :relationship_collection,
|
46
|
+
:href => "#{base_url}/api/relationships"
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class RelationshipCollectionSerializer < BaseSerializer
|
52
|
+
adapter Oat::Adapters::HAL
|
53
|
+
|
54
|
+
schema do
|
55
|
+
type :relationship_collection
|
56
|
+
properties do |p|
|
57
|
+
p.relationship_collection item
|
58
|
+
end
|
59
|
+
|
60
|
+
link :self, link_self
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def link_self
|
66
|
+
{
|
67
|
+
:type => :relationship_collection,
|
68
|
+
:href => "#{base_url}/api/relationships"
|
69
|
+
}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|