opentox-client 0.0.2pre → 1.0.0pre1

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,14 +17,14 @@ module OpenTox
17
17
 
18
18
  # check input
19
19
  @subjectid = headers[:subjectid] ? headers[:subjectid] : nil
20
- bad_request_error "Invalid URI: '#{uri}'" unless URI.valid? uri
21
- not_found_error "URI '#{uri}' not found." unless URI.accessible?(uri, @subjectid) unless URI.ssl?(uri)
22
- bad_request_error "Headers are not a hash: #{headers.inspect}" unless headers==nil or headers.is_a?(Hash)
20
+ bad_request_error "Invalid URI: '#{uri}'", uri unless URI.valid? uri
21
+ #resource_not_found_error "URI '#{uri}' not found.", uri unless URI.accessible?(uri, @subjectid) unless URI.ssl?(uri)
22
+ bad_request_error "Headers are not a hash: #{headers.inspect}", uri unless headers==nil or headers.is_a?(Hash)
23
23
  # make sure that no header parameters are set in the payload
24
24
  [:accept,:content_type,:subjectid].each do |header|
25
25
  if defined? $aa || URI(uri).host == URI($aa[:uri]).host
26
26
  else
27
- bad_request_error "#{header} should be submitted in the headers" if payload and payload.is_a?(Hash) and payload[header]
27
+ bad_request_error "#{header} should be submitted in the headers", uri if payload and payload.is_a?(Hash) and payload[header]
28
28
  end
29
29
  end
30
30
 
@@ -42,13 +42,32 @@ module OpenTox
42
42
  @response = @request.execute do |response, request, result|
43
43
  if [301, 302, 307].include? response.code and request.method == :get
44
44
  response.follow_redirection(request, result)
45
+ elsif response.code >= 400 and !URI.task?(uri)
46
+ message = response.to_s
47
+ parameters = request.args
48
+ parameters[:headers][:subjectid] = "REMOVED" if parameters[:headers] and parameters[:headers][:subjectid]
49
+ message += "\nREST paramenters:\n#{parameters.inspect}"
50
+ error = known_errors.collect{|e| e if e[:code] == response.code}.compact.first
51
+ Object.method(error[:method]).call message, uri # call error method
45
52
  else
46
- raise OpenTox::RestCallError.new response.to_s, request, uri unless response.code < 400 or URI.task? uri
47
53
  response
48
54
  end
49
55
  end
50
56
  end
51
57
  end
52
58
 
59
+ def self.known_errors
60
+ errors = []
61
+ RestClient::STATUSES.each do |code,k|
62
+ if code >= 400
63
+ method = k.underscore.gsub(/ |'/,'_')
64
+ method += "_error" unless method.match(/_error$/)
65
+ klass = method.split("_").collect{|s| s.capitalize}.join("")
66
+ errors << {:code => code, :method => method.to_sym, :class => klass}
67
+ end
68
+ end
69
+ errors
70
+ end
71
+
53
72
  end
54
73
  end
@@ -6,15 +6,23 @@ module OpenTox
6
6
 
7
7
  attr_accessor :pid, :observer_pid
8
8
 
9
- def self.create service_uri, params={}
9
+ def self.create service_uri, subjectid=nil, params={}
10
10
 
11
- task = Task.new RestClientWrapper.post(service_uri,params).chomp
11
+ uri = File.join(service_uri,SecureRandom.uuid)
12
+ task = Task.new uri, subjectid
13
+ task[RDF::OT.hasStatus] = "Running"
14
+ params.each { |k,v| task[k] = v }
15
+ task.put false
12
16
  pid = fork do
13
17
  begin
14
18
  result_uri = yield
15
19
  task.completed result_uri
16
20
  rescue
17
- RestClientWrapper.put(File.join(task.uri,'Error'),{:errorReport => $!.report.to_yaml}) if $!.respond_to? :report
21
+ if $!.respond_to? :to_ntriples
22
+ RestClientWrapper.put(File.join(task.uri,'Error'),:errorReport => $!.to_ntriples,:content_type => 'text/plain')
23
+ else
24
+ RestClientWrapper.put(File.join(task.uri,'Error'))
25
+ end
18
26
  task.kill
19
27
  end
20
28
  end
@@ -39,27 +47,27 @@ module OpenTox
39
47
  def kill
40
48
  Process.kill(9,@pid)
41
49
  Process.kill(9,@observer_pid)
42
- rescue # no need to raise an exeption if processes are not running
50
+ rescue # no need to raise an exception if processes are not running
43
51
  end
44
52
 
45
53
  def description
46
- pull
47
- self.[](RDF::DC.description).uniq.first
54
+ self.[](RDF::DC.description)
48
55
  end
49
56
 
50
57
  def creator
51
- pull
52
- self.[](RDF::DC.creator).uniq.first
58
+ self.[](RDF::DC.creator)
53
59
  end
54
60
 
55
61
  def cancel
56
62
  kill
57
- RestClientWrapper.put(File.join(@uri,'Cancelled'),{})
63
+ self.[]=(RDF::OT.hasStatus, "Cancelled")
64
+ put false
58
65
  end
59
66
 
60
67
  def completed(uri)
61
- #not_found_error "Result URI \"#{uri}\" does not exist." unless URI.accessible? uri
62
- RestClientWrapper.put(File.join(@uri,'Completed'),{:resultURI => uri})
68
+ self.[]=(RDF::OT.resultURI, uri)
69
+ self.[]=(RDF::OT.hasStatus, "Completed")
70
+ put false
63
71
  end
64
72
 
65
73
  # waits for a task, unless time exceeds or state is no longer running
@@ -68,7 +76,7 @@ module OpenTox
68
76
  def wait
69
77
  start_time = Time.new
70
78
  due_to_time = start_time + DEFAULT_TASK_MAX_DURATION
71
- dur = 0
79
+ dur = 0.3
72
80
  while running?
73
81
  sleep dur
74
82
  dur = [[(Time.new - start_time)/20.0,0.3].max,300.0].min
@@ -96,19 +104,29 @@ module OpenTox
96
104
  code >= 400 and code != 503
97
105
  end
98
106
 
99
- def errorReport
100
- # TODO: fix rdf output at task service
101
- not_implemented_error "RDF output of errorReports has to be fixed at task service"
102
- end
103
-
104
- [:hasStatus, :resultURI].each do |method|
107
+ [:hasStatus, :resultURI, :finished_at].each do |method|
105
108
  define_method method do
109
+ get
106
110
  response = self.[](RDF::OT[method])
107
111
  response = self.[](RDF::OT1[method]) unless response # API 1.1 compatibility
108
112
  response
109
113
  end
110
114
  end
111
115
 
116
+ def error_report
117
+ report = {}
118
+ query = RDF::Query.new({
119
+ :report => {
120
+ RDF.type => RDF::OT.ErrorReport,
121
+ :property => :value,
122
+ }
123
+ })
124
+ query.execute(@rdf).each do |solution|
125
+ report[solution.property] = solution.value.to_s
126
+ end
127
+ report
128
+ end
129
+
112
130
  #TODO: subtasks (only for progress)
113
131
 
114
132
  end
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "opentox-client"
6
- s.version = "0.0.2pre"
6
+ s.version = File.read("./VERSION").strip
7
7
  s.authors = ["Christoph Helma, Martin Guetlein, Andreas Maunz, Micha Rautenberg, David Vorgrimmler"]
8
8
  s.email = ["helma@in-silico.ch"]
9
9
  s.homepage = "http://github.com/opentox/opentox-client"
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_runtime_dependency "rest-client"
24
24
  s.add_runtime_dependency "rdf"
25
25
  s.add_runtime_dependency "rdf-raptor"
26
+ s.add_runtime_dependency 'rdf-n3'
26
27
  s.add_runtime_dependency "open4"
27
28
 
28
29
  # external requirements
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentox-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2pre
4
+ version: 1.0.0pre1
5
5
  prerelease: 5
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-02 00:00:00.000000000 Z
12
+ date: 2012-08-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &76175050 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *76175050
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rest-client
27
- requirement: &76185830 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *76185830
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rdf
38
- requirement: &76706430 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,31 @@ dependencies:
43
53
  version: '0'
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *76706430
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rdf-raptor
49
- requirement: &76705970 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rdf-n3
80
+ requirement: !ruby/object:Gem::Requirement
50
81
  none: false
51
82
  requirements:
52
83
  - - ! '>='
@@ -54,10 +85,15 @@ dependencies:
54
85
  version: '0'
55
86
  type: :runtime
56
87
  prerelease: false
57
- version_requirements: *76705970
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
58
94
  - !ruby/object:Gem::Dependency
59
95
  name: open4
60
- requirement: &76705540 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
61
97
  none: false
62
98
  requirements:
63
99
  - - ! '>='
@@ -65,19 +101,29 @@ dependencies:
65
101
  version: '0'
66
102
  type: :runtime
67
103
  prerelease: false
68
- version_requirements: *76705540
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
69
110
  description: Ruby wrapper for the OpenTox REST API (http://www.opentox.org)
70
111
  email:
71
112
  - helma@in-silico.ch
72
- executables: []
113
+ executables:
114
+ - opentox-client-install
73
115
  extensions: []
74
116
  extra_rdoc_files: []
75
117
  files:
76
118
  - .gitignore
119
+ - ChangeLog
77
120
  - Gemfile
121
+ - Gemfile.lock
78
122
  - LICENSE
79
123
  - README.markdown
80
124
  - Rakefile
125
+ - VERSION
126
+ - bin/opentox-client-install
81
127
  - lib/algorithm.rb
82
128
  - lib/authorization.rb
83
129
  - lib/compound.rb
@@ -94,27 +140,6 @@ files:
94
140
  - lib/templates/default_guest_policy.xml
95
141
  - lib/templates/default_policy.xml
96
142
  - opentox-client.gemspec
97
- - test/authorization.rb
98
- - test/compound.rb
99
- - test/data/CPDBAS_v5c_1547_29Apr2008part.sdf
100
- - test/data/EPAFHM.csv
101
- - test/data/EPAFHM.mini.csv
102
- - test/data/ISSCAN-multi.csv
103
- - test/data/cpdb_100.csv
104
- - test/data/hamster_carcinogenicity.csv
105
- - test/data/hamster_carcinogenicity.mini.csv
106
- - test/data/hamster_carcinogenicity.sdf
107
- - test/data/hamster_carcinogenicity.xls
108
- - test/data/hamster_carcinogenicity.yaml
109
- - test/data/hamster_carcinogenicity_with_errors.csv
110
- - test/data/kazius.csv
111
- - test/data/multi_cell_call.csv
112
- - test/data/multicolumn.csv
113
- - test/dataset.rb
114
- - test/error.rb
115
- - test/feature.rb
116
- - test/policy.rb
117
- - test/task.rb
118
143
  homepage: http://github.com/opentox/opentox-client
119
144
  licenses:
120
145
  - GPL-3
@@ -129,9 +154,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
154
  - - ! '>='
130
155
  - !ruby/object:Gem::Version
131
156
  version: '0'
132
- segments:
133
- - 0
134
- hash: -571051053
135
157
  required_rubygems_version: !ruby/object:Gem::Requirement
136
158
  none: false
137
159
  requirements:
@@ -141,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
163
  requirements:
142
164
  - libraptor-dev
143
165
  rubyforge_project: opentox-client
144
- rubygems_version: 1.8.11
166
+ rubygems_version: 1.8.18
145
167
  signing_key:
146
168
  specification_version: 3
147
169
  summary: Ruby wrapper for the OpenTox REST API
@@ -1,107 +0,0 @@
1
- require 'test/unit'
2
- $LOAD_PATH << File.join(File.dirname(__FILE__),'..','lib')
3
- require File.expand_path(File.join(File.dirname(__FILE__),'..','lib','opentox-client.rb'))
4
- TEST_URI = "http://only_a_test/test/" + rand(1000000).to_s
5
- AA ||= "https://opensso.in-silico.ch"
6
- AA_USER = "guest"
7
- AA_PASS = "guest"
8
- @@subjectid = OpenTox::Authorization.authenticate(AA_USER,AA_PASS)
9
-
10
- class TestOpenToxAuthorizationBasic < Test::Unit::TestCase
11
-
12
- def test_01_server
13
- assert_equal(AA, OpenTox::Authorization.server)
14
- end
15
-
16
- def test_02_get_token
17
- assert_not_nil @@subjectid
18
- end
19
-
20
- def test_03_is_valid_token
21
- tok = login
22
- assert_not_nil tok
23
- assert OpenTox::Authorization.is_token_valid(tok)
24
- logout(tok)
25
- end
26
-
27
- def test_04_logout
28
- tok = login
29
- assert logout(tok)
30
- assert_equal false, OpenTox::Authorization.is_token_valid(tok)
31
- end
32
-
33
- def test_05_list_policies
34
- assert_kind_of Array, OpenTox::Authorization.list_policies(@@subjectid)
35
- end
36
-
37
- end
38
-
39
- class TestOpenToxAuthorizationLDAP < Test::Unit::TestCase
40
-
41
- def test_01_list_user_groups
42
- assert_kind_of Array, OpenTox::Authorization.list_user_groups(AA_USER, @@subjectid)
43
- end
44
-
45
- def test_02_get_user
46
- assert_equal AA_USER, OpenTox::Authorization.get_user(@@subjectid)
47
- end
48
-
49
- end
50
-
51
- class TestOpenToxAuthorizationLDAP < Test::Unit::TestCase
52
-
53
- def test_01_create_check_delete_default_policies
54
- res = OpenTox::Authorization.send_policy(TEST_URI, @@subjectid)
55
- assert res
56
- assert OpenTox::Authorization.uri_has_policy(TEST_URI, @@subjectid)
57
- policies = OpenTox::Authorization.list_uri_policies(TEST_URI, @@subjectid)
58
- assert_kind_of Array, policies
59
- policies.each do |policy|
60
- assert OpenTox::Authorization.delete_policy(policy, @@subjectid)
61
- end
62
- assert_equal false, OpenTox::Authorization.uri_has_policy(TEST_URI, @@subjectid)
63
- end
64
-
65
- def test_02_check_policy_rules
66
- tok_anonymous = OpenTox::Authorization.authenticate("anonymous","anonymous")
67
- assert_not_nil tok_anonymous
68
- res = OpenTox::Authorization.send_policy(TEST_URI, @@subjectid)
69
- assert res
70
- assert OpenTox::Authorization.uri_has_policy(TEST_URI, @@subjectid)
71
- owner_rights = {"GET" => true, "POST" => true, "PUT" => true, "DELETE" => true}
72
- groupmember_rights = {"GET" => true, "POST" => nil, "PUT" => nil, "DELETE" => nil}
73
- owner_rights.each do |request, right|
74
- assert_equal right, OpenTox::Authorization.authorize(TEST_URI, request, @@subjectid), "#{AA_USER} requests #{request} to #{TEST_URI}"
75
- end
76
- groupmember_rights.each do |request, r|
77
- assert_equal r, OpenTox::Authorization.authorize(TEST_URI, request, tok_anonymous), "anonymous requests #{request} to #{TEST_URI}"
78
- end
79
-
80
- policies = OpenTox::Authorization.list_uri_policies(TEST_URI, @@subjectid)
81
- assert_kind_of Array, policies
82
- policies.each do |policy|
83
- assert OpenTox::Authorization.delete_policy(policy, @@subjectid)
84
- end
85
- logout(tok_anonymous)
86
- end
87
-
88
- def test_03_check_different_uris
89
- res = OpenTox::Authorization.send_policy(TEST_URI, @@subjectid)
90
- assert OpenTox::Authorization.uri_has_policy(TEST_URI, @@subjectid)
91
- assert OpenTox::Authorization.authorize(TEST_URI, "GET", @@subjectid), "GET request"
92
- policies = OpenTox::Authorization.list_uri_policies(TEST_URI, @@subjectid)
93
- policies.each do |policy|
94
- assert OpenTox::Authorization.delete_policy(policy, @@subjectid)
95
- end
96
-
97
- end
98
- end
99
-
100
-
101
- def logout (token)
102
- OpenTox::Authorization.logout(token)
103
- end
104
-
105
- def login
106
- OpenTox::Authorization.authenticate(AA_USER,AA_PASS)
107
- end