toxbank-investigation 0.0.2pre → 1.0.0pre1

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.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ Gemfile.lock
1
2
  *.gem
2
3
  .bundle
3
4
  pkg/*
@@ -0,0 +1,26 @@
1
+ v0.0.4 2012-07-
2
+ - Address and IDs changed
3
+ - Service URI https://INVESTIGATIONSERVICE is now https://INVESTIGATIONSERVICE/investigation
4
+ - IDs changed to UUIDs e.G.: https://INVESTIGATIONSERVICE/123 changed to https://INVESTIGATIONSERVICE/investigation/1f6d584a-53aa-4c59-bae3-8c7ac9cb82ff
5
+ UUID is a v4 random UUID (Universally Unique IDentifier).
6
+ - Policy/Access management
7
+ - allowReadByUser and allowReadByGroup parameters added to POST and PUT request (POST to service and PUT to a specific investigation).
8
+ both values are optional and can be empty or contain single or comma separated URIs of an existing ToxBank user or group (e.G.: allowReadByUser=http://USERSERVICE/toxbank/user/U2,http://USERSERVICE/toxbank/user/U124 )
9
+ as described here: http://api.toxbank.net/index.php/Protocol#Security.
10
+ Every user or group get read access to the specific investigation.
11
+ - The creator of a new investigation gets full REST access (GET/POST/PUT/DELETE). Creator is identified by its subjectid from login and should be member of the LDAP Public Investigator group (cn=PI_GROUP,ou=groups,dc=DOMAIN,dc=TLD).
12
+ - isPublished flag
13
+ - New investigations get http://onto.toxbank.net/api/isPublished = false to its metadata RDF representation:
14
+ e.G.:
15
+ <rdf:Description rdf:about="https://INVESTIGATIONSERVICE/investigation/f0154c33-e27a-4683-b9cd-94473beccae3/">
16
+ <ns0:isPublished xmlns:ns0="http://onto.toxbank.net/api/" rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">false</ns0:isPublished>
17
+ </rdf:Description>
18
+ - published parameter added to PUT request to set isPublished in metadata to true:
19
+ curl -Lk -X PUT -i -H "subjectid:MYTOKEN" -d "published=true" https://INVESTIGATIONSERVICE/investigation/UUID
20
+ - isSummarySearchable flag
21
+ summarySearchable parameter added to POST and PUT request to set isSummarySearchable flag in metadata.
22
+ - Add studies, assays or data to an investigation / Updating an investigation
23
+ - additions to or updating an investigation will be handled via PUT request
24
+
25
+ v0.0.3 2012-05-07
26
+ * switch from v0.0.2pre to v0.0.3
data/Gemfile CHANGED
@@ -7,6 +7,6 @@ gemspec
7
7
  #gem 'rake', '~> 0.9.3.beta.1'
8
8
  gem 'opentox-server', :path => "~/opentox-server"
9
9
  gem "opentox-client", :path => "~/opentox-client"
10
- group :test do
11
- gem "rack-test", :require => "rack/test"
12
- end
10
+ #group :test do
11
+ #gem "rack-test", :require => "rack/test"
12
+ #end
data/Rakefile CHANGED
@@ -1,14 +1 @@
1
1
  require "bundler/gem_tasks"
2
- require 'bundler'
3
- Bundler.require
4
- Bundler.setup
5
-
6
- require 'rake/testtask'
7
- Rake::TestTask.new do |t|
8
- t.libs << 'test'
9
- t.test_files = FileList['test/*.rb'] - FileList["test/setup.rb"]
10
- t.verbose = true
11
- end
12
-
13
- desc "Run tests"
14
- task :default => :test
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0pre1
@@ -1,19 +1,21 @@
1
- require "opentox-server"
2
- require File.join(ENV["HOME"],".opentox","config","toxbank-investigation.rb")
1
+ require 'opentox-server'
2
+ require "#{File.dirname(__FILE__)}/tbaccount.rb"
3
+ require "#{File.dirname(__FILE__)}/pirewriter.rb"
3
4
 
4
5
  module OpenTox
5
6
  class Application < Service
6
7
 
7
8
  helpers do
8
9
 
9
- def uri
10
- params[:id] ? url_for("/#{params[:id]}", :full).sub("http://","https://") : "https://#{request.env['HTTP_HOST']}"
10
+ def investigation_uri
11
+ to("/investigation/#{params[:id]}") # new in Sinatra, replaces url_for
11
12
  end
12
13
 
13
14
  def uri_list
14
15
  params[:id] ? d = "./investigation/#{params[:id]}/*" : d = "./investigation/*"
15
- uris = Dir[d].collect{|f| url_for(f.sub(/\.\/investigation/,''), :full).sub("http://","https://") }
16
+ uris = Dir[d].collect{|f| to(f.sub(/\.\//,'')) }
16
17
  uris.collect!{|u| u.sub(/(\/#{params[:id]}\/)/,'\1isatab/')} if params[:id]
18
+ uris.delete_if{|u| u.match(/_policies$/)}
17
19
  uris.compact.sort.join("\n") + "\n"
18
20
  end
19
21
 
@@ -33,22 +35,17 @@ module OpenTox
33
35
  "#{params[:id]}.n3"
34
36
  end
35
37
 
36
- def next_id
37
- id = Dir["./investigation/*"].collect{|f| File.basename(f).to_i}.sort.last
38
- id ? id + 1 : 0
39
- end
40
-
41
38
  def prepare_upload
42
39
  # remove stale directories from failed tests
43
- stale_files = `cd #{File.dirname(__FILE__)}/investigation && git ls-files --others --exclude-standard --directory`.chomp
44
- `cd #{File.dirname(__FILE__)}/investigation && rm -rf #{stale_files}` unless stale_files.empty?
40
+ #stale_files = `cd #{File.dirname(__FILE__)}/investigation && git ls-files --others --exclude-standard --directory`.chomp
41
+ #`cd #{File.dirname(__FILE__)}/investigation && rm -rf #{stale_files}` unless stale_files.empty?
45
42
  # lock tmp dir
46
43
  locked_error "Processing investigation #{params[:id]}. Please try again later." if File.exists? tmp
47
44
  bad_request_error "Please submit data as multipart/form-data" unless request.form_data?
48
45
  # move existing ISA-TAB files to tmp
49
46
  FileUtils.mkdir_p tmp
50
47
  FileUtils.cp Dir[File.join(dir,"*.txt")], tmp
51
- File.open(File.join(tmp, params[:file][:filename]), "w+"){|f| f.puts params[:file][:tempfile].read}
48
+ FileUtils.cp params[:file][:tempfile], File.join(tmp, params[:file][:filename])
52
49
  end
53
50
 
54
51
  def extract_zip
@@ -58,6 +55,7 @@ module OpenTox
58
55
  `mv #{d}/* #{tmp}`
59
56
  `rmdir #{d}`
60
57
  end
58
+ replace_pi @subjectid
61
59
  end
62
60
 
63
61
  def extract_xls
@@ -83,95 +81,135 @@ module OpenTox
83
81
 
84
82
  def isa2rdf
85
83
  begin # isa2rdf returns correct exit code
86
- `cd #{File.dirname(__FILE__)}/java && java -jar isa2rdf-0.0.1-SNAPSHOT.jar -d #{tmp} -o #{File.join tmp,n3} &> #{File.join tmp,'log'}`
84
+ `cd #{File.dirname(__FILE__)}/java && java -jar isa2rdf-0.0.3-SNAPSHOT.jar -d #{tmp} -o #{File.join tmp,n3} &> #{File.join tmp,'log'}`
87
85
  rescue
88
86
  log = File.read File.join(tmp,"log")
89
87
  FileUtils.remove_entry dir
90
- bad_request_error "ISA-TAB validation failed:\n#{log}", uri
88
+ bad_request_error "ISA-TAB validation failed:\n#{log}", investigation_uri
91
89
  end
92
90
  # rewrite default prefix
93
- `sed -i 's;http://onto.toxbank.net/isa/tmp/;#{uri}/;' #{File.join tmp,n3}`
91
+ `sed -i 's;http://onto.toxbank.net/isa/tmp/;#{investigation_uri}/;' #{File.join tmp,n3}`
94
92
  # add owl:sameAs to identify investigation later
95
93
  investigation_id = `grep ":I[0-9]" #{File.join tmp,n3}|cut -f1 -d ' '`.strip
96
- `echo "\n: owl:sameAs #{investigation_id} ." >> #{File.join tmp,n3}`
94
+ `sed -i 's;#{investigation_id};:;' #{File.join tmp,n3}`
95
+ `echo "\n: a <#{RDF::OT.Investigation}> ." >> #{File.join tmp,n3}`
96
+ #`echo "\n: owl:sameAs #{investigation_id} ." >> #{File.join tmp,n3}`
97
97
  FileUtils.rm Dir[File.join(tmp,"*.zip")]
98
98
  # if everything is fine move ISA-TAB files back to original dir
99
99
  FileUtils.cp Dir[File.join(tmp,"*")], dir
100
- # git commit
101
- newfiles = `cd #{File.dirname(__FILE__)}/investigation; git ls-files --others --exclude-standard --directory`
102
- `cd #{File.dirname(__FILE__)}/investigation && git add #{newfiles}`
103
- ['application/zip', 'application/vnd.ms-excel'].include?(params[:file][:type]) ? action = "created" : action = "modified"
104
- `cd #{File.dirname(__FILE__)}/investigation && git commit -am "investigation #{params[:id]} #{action} by #{request.ip}"`
105
100
  # create new zipfile
106
101
  zipfile = File.join dir, "investigation_#{params[:id]}.zip"
107
102
  `zip -j #{zipfile} #{dir}/*.txt`
108
103
  # store RDF
109
- length = File.size(File.join dir,n3)
110
- file = File.join(dir,n3)
111
- `curl -0 -k -u #{$four_store[:user]}:#{$four_store[:password]} -T #{file} -H 'Content_Length => #{length}' '#{$four_store[:uri]}/data/?graph=#{$four_store[:uri]}/data/#{$four_store[:user]}/investigation#{n3}'`
104
+ c_length = File.size(File.join dir,n3)
105
+ RestClient.put File.join(FourStore.four_store_uri,"data",investigation_uri), File.read(File.join(dir,n3)), {:content_type => "application/x-turtle", :content_length => c_length} # content-type not very consistent in 4store
112
106
  FileUtils.remove_entry tmp # unlocks tmp
113
- OpenTox::Authorization.check_policy(uri, @subjectid)
114
- uri
107
+ # git commit
108
+ newfiles = `cd #{File.dirname(__FILE__)}/investigation; git ls-files --others --exclude-standard --directory #{params[:id]}`
109
+ `cd #{File.dirname(__FILE__)}/investigation && git add #{newfiles}`
110
+ ['application/zip', 'application/vnd.ms-excel'].include?(params[:file][:type]) ? action = "created" : action = "modified"
111
+ `cd #{File.dirname(__FILE__)}/investigation && git commit -am "investigation #{params[:id]} #{action} by #{request.ip}"`
112
+ investigation_uri
113
+ end
114
+
115
+ def create_policy ldaptype, uristring
116
+ begin
117
+ filename = File.join(dir, "#{ldaptype}_policies")
118
+ policyfile = File.open(filename,"w")
119
+ uriarray = uristring.split(",")
120
+ uriarray.each do |u|
121
+ tbaccount = OpenTox::TBAccount.new(u, @subjectid)
122
+ policyfile.puts tbaccount.get_policy(investigation_uri)
123
+ end
124
+ policyfile.close
125
+ policytext = File.read filename
126
+ replace = policytext.gsub!("</Policies>\n<!DOCTYPE Policies PUBLIC \"-//Sun Java System Access Manager7.1 2006Q3 Admin CLI DTD//EN\" \"jar://com/sun/identity/policy/policyAdmin.dtd\">\n<Policies>\n", "")
127
+ File.open(filename, "w") { |file| file.puts replace } if replace
128
+ Authorization.reset_policies investigation_uri, ldaptype, @subjectid
129
+ ret = Authorization.create_policy(File.read(policyfile), @subjectid)
130
+ File.delete policyfile if ret
131
+ rescue
132
+ $logger.warn "create policies error for Investigation URI: #{investigation_uri} for user/group uris: #{uristring}"
133
+ end
134
+ end
135
+
136
+ def set_flag flag, value, type = ""
137
+ flagtype = type == "boolean" ? "^^<#{RDF::XSD.boolean}>" : ""
138
+ FourStore.update "DELETE DATA { GRAPH <#{investigation_uri}> {<#{investigation_uri}/> <#{flag}> \"#{!value}\"#{flagtype}}}"
139
+ FourStore.update "INSERT DATA { GRAPH <#{investigation_uri}> {<#{investigation_uri}/> <#{flag}> \"#{value}\"#{flagtype}}}"
115
140
  end
116
141
 
117
- def query sparql
118
- if @accept.match(/turtle/) and sparql.match(/CONSTRUCT/)
119
- response['Content-type'] = @accept
120
- elsif sparql.match(/CONSTRUCT/)
121
- response['Content-type'] = 'application/rdf+xml'
142
+ def qfilter(flag, uri)
143
+ qfilter = FourStore.query "SELECT ?s FROM <#{uri}> WHERE {?s <#{RDF::TB}#{flag}> ?o FILTER regex(?o, 'true', 'i')}", "application/sparql-results+xml"
144
+ qfilter.split("\n")[7].gsub(/<binding name="s"><uri>|\/<\/uri><\/binding>/, '').strip
145
+ end
146
+
147
+ def protected!(subjectid)
148
+ if !env["session"] && subjectid
149
+ unless authorized?(subjectid) || get_permission
150
+ $logger.debug ">-get_permission failed"
151
+ $logger.debug "URI not authorized: clean: " + clean_uri("#{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}#{request.env['REQUEST_URI']}").sub("http://","https://").to_s + " full: #{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}#{request.env['REQUEST_URI']} with request: #{request.env['REQUEST_METHOD']}"
152
+ unauthorized_error "Not authorized: #{request.env['REQUEST_URI']}"
153
+ end
122
154
  else
123
- response['Content-type'] = "application/sparql-results+xml"
155
+ unauthorized_error "Not authorized: #{request.env['REQUEST_URI']}"
124
156
  end
125
- `curl -H 'Accept:#{@accept}' -k -u #{$four_store[:user]}:#{$four_store[:password]} -d 'query=#{sparql}' '#{$four_store[:uri]}/sparql/'`
126
157
  end
127
158
 
159
+ def get_permission
160
+ # only for GET
161
+ return false if request.env['REQUEST_METHOD'] != "GET"
162
+ if request.env['REQUEST_URI'] =~ /metadata/
163
+ ruri = request.env['REQUEST_URI'].chomp("/metadata")
164
+ return true if qfilter("isSummarySearchable", to(ruri)) =~ /#{to(ruri)}/
165
+ return false
166
+ else
167
+ ruri = request.env['REQUEST_URI'].gsub(/\/isatab\/.*/,'')
168
+ return true if qfilter("isPublished", to(ruri)) =~ /#{to(ruri)}/
169
+ return false
170
+ end
171
+ end
172
+
173
+ def qlist
174
+ list = FourStore.list(to("/investigation"), "text/uri-list")
175
+ list.split.keep_if{|v| v =~ /#{$investigation[:uri]}/ || qfilter("isSummarySearchable", v)}.join("\n")
176
+ end
177
+
128
178
  end
129
179
 
130
180
  before do
131
- not_found_error "Directory #{dir} does not exist." unless File.exist? dir
181
+ resource_not_found_error "Directory #{dir} does not exist." unless File.exist? dir
182
+ parse_input if request.request_method =~ /POST|PUT/
132
183
  @accept = request.env['HTTP_ACCEPT']
133
184
  response['Content-Type'] = @accept
134
- # TODO: A+A
135
185
  end
136
186
 
137
- # Query all investigations or get a list of all investigations
138
- # Requests with a query parameter will perform a SPARQL query on all investigations
139
- # @return [application/sparql-results+json] Query result
187
+ # uri-list of all investigations
140
188
  # @return [text/uri-list] List of investigations
141
- get '/?' do
142
- if params[:query] # pass SPARQL query to 4store
143
- query params[:query]
144
- else
145
- # Requests without a query parameter return a list of all investigations
146
- case @accept
147
- when 'text/uri-list'
148
- uri_list
149
- else
150
- response['Content-Type'] = 'application/rdf+xml'
151
- response['Content-Type'] = @accept if @accept == 'text/turtle'
152
- query "
153
- PREFIX isa: <http://onto.toxbank.net/isa/>
154
- CONSTRUCT { ?s ?p ?o . }
155
- WHERE {
156
- ?s a isa:Investigation ;
157
- ?p ?o .
158
- }
159
- "
160
- end
161
- end
189
+ # include own and searchable
190
+ # TODO handle published for uri-list
191
+ get '/investigation/?' do
192
+ bad_request_error "Mime type #{@accept} not supported here. Please expect data as text/uri-list." unless @accept.to_s == "text/uri-list"
193
+ qlist
162
194
  end
163
195
 
164
196
  # Create a new investigation from ISA-TAB files
165
197
  # @param [Header] Content-type: multipart/form-data
166
198
  # @param file Zipped investigation files in ISA-TAB format
167
- # @return [text/uri-list] Investigation URI
168
- post '/?' do
169
- params[:id] = next_id
170
- mime_types = ['application/zip','text/tab-separated-values', "application/vnd.ms-excel"]
199
+ # @return [text/uri-list] Task URI
200
+ post '/investigation/?' do
201
+ params[:id] = SecureRandom.uuid
202
+ mime_types = ['application/zip','text/tab-separated-values', 'application/vnd.ms-excel']
171
203
  bad_request_error "No file uploaded." unless params[:file]
172
204
  bad_request_error "Mime type #{params[:file][:type]} not supported. Please submit data as zip archive (application/zip), Excel file (application/vnd.ms-excel) or as tab separated text (text/tab-separated-values)" unless mime_types.include? params[:file][:type]
173
- task = OpenTox::Task.create($task[:uri], :description => "#{params[:file][:filename]}: Uploding, validating and converting to RDF") do
205
+ if params[:file]
206
+ if params[:file][:type] == "application/zip"
207
+ bad_request_error "The zip #{params[:file][:filename]} contains no investigation file.", investigation_uri unless `unzip -Z -1 #{File.join(params[:file][:tempfile])}`.match('.txt')
208
+ end
209
+ end
210
+ task = OpenTox::Task.create($task[:uri], @subjectid, RDF::DC.description => "#{params[:file][:filename]}: Uploading, validating and converting to RDF") do
174
211
  prepare_upload
212
+ OpenTox::Authorization.create_pi_policy(investigation_uri, @subjectid)
175
213
  case params[:file][:type]
176
214
  when "application/vnd.ms-excel"
177
215
  extract_xls
@@ -182,6 +220,14 @@ module OpenTox
182
220
  #when 'text/tab-separated-values' # do nothing, file is already in tmp
183
221
  end
184
222
  isa2rdf
223
+ set_flag(RDF::TB.isPublished, false, "boolean")
224
+ set_flag(RDF::TB.isSummarySearchable, (params[:summarySearchable].to_s == "true" ? true : false), "boolean")
225
+ #set_flag(RDF.Type, RDF::OT.Investigation)
226
+ create_policy "user", params[:allowReadByUser] if params[:allowReadByUser]
227
+ create_policy "group", params[:allowReadByGroup] if params[:allowReadByGroup]
228
+ # TODO send notification to UI
229
+ # OpenTox::RestClientWrapper.put "https://www.leadscope.com/dev-toxbank-search/search/index/investigation?resourceUri=#{CGI.escape(investigation_uri)}",{},{:subjectid => @subjectid}
230
+ investigation_uri
185
231
  end
186
232
  response['Content-Type'] = 'text/uri-list'
187
233
  halt 202,task.uri+"\n"
@@ -190,8 +236,9 @@ module OpenTox
190
236
  # Get an investigation representation
191
237
  # @param [Header] Accept: one of text/tab-separated-values, text/uri-list, application/zip, application/sparql-results+json
192
238
  # @return [text/tab-separated-values, text/uri-list, application/zip, application/sparql-results+json] Investigation in the requested format
193
- get '/:id' do
194
- not_found_error "Investigation #{uri} does not exist." unless File.exist? dir # not called in before filter???
239
+ # include own and published
240
+ get '/investigation/:id' do
241
+ resource_not_found_error "Investigation #{investigation_uri} does not exist." unless File.exist? dir # not called in before filter???
195
242
  case @accept
196
243
  when "text/tab-separated-values"
197
244
  send_file Dir["./investigation/#{params[:id]}/i_*txt"].first, :type => @accept
@@ -199,82 +246,96 @@ module OpenTox
199
246
  uri_list
200
247
  when "application/zip"
201
248
  send_file File.join dir, "investigation_#{params[:id]}.zip"
202
- when "application/rdf+xml"
203
- query "CONSTRUCT { ?s ?p ?o } FROM <#{$four_store[:uri]}/data/#{$four_store[:user]}/investigation#{n3}> WHERE {?s ?p ?o } LIMIT 15000"
204
249
  else
205
- #$logger.debug request.to_yaml
206
- #bad_request_error "Accept header #{@accept} not supported for #{uri}"
207
- $logger.warn "Accept header #{@accept} not supported for #{uri}" # do not halt: strange requests from test, TODO: identify and fix
250
+ FourStore.query "CONSTRUCT { ?s ?p ?o } FROM <#{investigation_uri}> WHERE {?s ?p ?o}", @accept
208
251
  end
209
252
  end
210
253
 
211
254
  # Get investigation metadata in RDF
212
- get '/:id/metadata' do
213
- not_found_error "Investigation #{uri} does not exist." unless File.exist? dir # not called in before filter???
214
- query "
215
- PREFIX : <#{uri}/>
216
- PREFIX owl: <http://www.w3.org/2002/07/owl#>
217
- CONSTRUCT { ?s ?p ?o. }
218
- WHERE {
219
- : owl:sameAs ?s .
220
- ?s ?p ?o .
221
- }
222
- "
255
+ # include own, pulished and searchable
256
+ get '/investigation/:id/metadata' do
257
+ resource_not_found_error "Investigation #{investigation_uri} does not exist." unless File.exist? dir # not called in before filter???
258
+ FourStore.query "CONSTRUCT { ?s ?p ?o. } FROM <#{investigation_uri}> WHERE { ?s <#{RDF.type}> <http://onto.toxbank.net/isa/Investigation>. ?s ?p ?o . } ", @accept
223
259
  end
224
260
 
225
261
  # Get a study, assay, data representation
226
262
  # @param [Header] one of text/tab-separated-values, application/sparql-results+json
227
263
  # @return [text/tab-separated-values, application/sparql-results+json] Study, assay, data representation in ISA-TAB or RDF format
228
- get '/:id/isatab/:filename' do
229
- not_found_error "File #{File.join uri,"isatab",params[:filename]} does not exist." unless File.exist? file
264
+ # include own and published
265
+ get '/investigation/:id/isatab/:filename' do
266
+ resource_not_found_error "File #{File.join investigation_uri,"isatab",params[:filename]} does not exist." unless File.exist? file
230
267
  # TODO: returns text/plain content type for tab separated files
231
268
  send_file file, :type => File.new(file).mime_type
232
269
  end
233
270
 
234
271
  # Get RDF for an investigation resource
235
- get '/:id/:resource' do
236
- query "
237
- PREFIX : <#{uri}/>
238
- PREFIX owl: <http://www.w3.org/2002/07/owl#>
239
- CONSTRUCT { :#{params[:resource]} ?p ?o. }
240
- WHERE {
241
- :#{params[:resource]} ?p ?o .
242
- }
243
- "
272
+ # include own and published
273
+ get '/investigation/:id/:resource' do
274
+ FourStore.query " CONSTRUCT { <#{File.join(investigation_uri,params[:resource])}> ?p ?o. } FROM <#{investigation_uri}> WHERE { <#{File.join(investigation_uri,params[:resource])}> ?p ?o . } ", @accept
244
275
  end
245
276
 
246
277
  # Add studies, assays or data to an investigation
247
278
  # @param [Header] Content-type: multipart/form-data
248
279
  # @param file Study, assay and data file (zip archive of ISA-TAB files or individual ISA-TAB files)
249
- post '/:id' do
250
- mime_types = ['application/zip','text/tab-separated-values', "application/vnd.ms-excel"]
251
- bad_request_error "Mime type #{params[:file][:type]} not supported. Please submit data as zip archive (application/zip), Excel file (application/vnd.ms-excel) or as tab separated text (text/tab-separated-values)" unless mime_types.include? params[:file][:type]
252
- task = OpenTox::Task.create($task[:uri], :description => "#{params[:file][:filename]}: Uploding, validationg and converting to RDF") do
253
- prepare_upload
254
- isa2rdf
280
+ # @return [text/uri-list] Task URI
281
+ put '/investigation/:id' do
282
+ mime_types = ['application/zip','text/tab-separated-values', 'application/vnd.ms-excel']
283
+ bad_request_error "Mime type #{params[:file][:type]} not supported. Please submit data as zip archive (application/zip), Excel file (application/vnd.ms-excel) or as tab separated text (text/tab-separated-values)" unless mime_types.include?(params[:file][:type]) if params[:file]
284
+ task = OpenTox::Task.create($task[:uri], @subjectid, RDF::DC.description => "#{investigation_uri}: Add studies, assays or data.") do
285
+ if params[:file]
286
+ prepare_upload
287
+ case params[:file][:type]
288
+ when 'application/zip'
289
+ extract_zip
290
+ end
291
+ isa2rdf
292
+ end
293
+ set_flag(RDF::TB.isPublished, (params[:published].to_s == "true" ? true : false), "boolean") if params[:file] || (!params[:file] && params[:published])
294
+ set_flag(RDF::TB.isSummarySearchable, (params[:summarySearchable].to_s == "true" ? true : false), "boolean") if params[:file] || (!params[:file] && params[:summarySearchable])
295
+ create_policy "user", params[:allowReadByUser] if params[:allowReadByUser]
296
+ create_policy "group", params[:allowReadByGroup] if params[:allowReadByGroup]
297
+ # TODO send notification to UI
298
+ # OpenTox::RestClientWrapper.put "https://www.leadscope.com/dev-toxbank-search/search/index/investigation?resourceUri=#{CGI.escape(investigation_uri)}",{},{:subjectid => @subjectid}
299
+ investigation_uri
255
300
  end
256
301
  response['Content-Type'] = 'text/uri-list'
257
302
  halt 202,task.uri+"\n"
258
303
  end
259
304
 
260
305
  # Delete an investigation
261
- delete '/:id' do
306
+ delete '/investigation/:id' do
262
307
  FileUtils.remove_entry dir
263
308
  # git commit
264
309
  `cd #{File.dirname(__FILE__)}/investigation; git commit -am "#{dir} deleted by #{request.ip}"`
265
310
  # updata RDF
266
- `curl -i -k -u #{$four_store[:user]}:#{$four_store[:password]} -X DELETE '#{$four_store[:uri]}/data/#{$four_store[:user]}/investigation#{n3}'`
311
+ FourStore.delete investigation_uri
312
+ if @subjectid and !File.exists?(dir) and investigation_uri
313
+ begin
314
+ res = OpenTox::Authorization.delete_policies_from_uri(investigation_uri, @subjectid)
315
+ $logger.debug "Policy deleted for Investigation URI: #{investigation_uri} with result: #{res}"
316
+ rescue
317
+ $logger.warn "Policy delete error for Investigation URI: #{investigation_uri}"
318
+ end
319
+ end
320
+ # TODO send notification to UI
321
+ # OpenTox::RestClientWrapper.delete "https://www.leadscope.com/dev-toxbank-search/search/index/investigation?resourceUri=#{CGI.escape(investigation_uri)}",{},{:subjectid => @subjectid}
267
322
  response['Content-Type'] = 'text/plain'
268
323
  "Investigation #{params[:id]} deleted"
269
324
  end
270
325
 
271
326
  # Delete an individual study, assay or data file
272
- delete '/:id/:filename' do
273
- task = OpenTox::Task.create($task[:uri], :description => "Deleting #{params[:file][:filename]} from investigation #{params[:id]}.") do
274
- prepare_upload
275
- File.delete File.join(tmp,params[:filename])
276
- isa2rdf
277
- "#{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}"
327
+ delete '/investigation/:id/:filename' do
328
+ if is_pi?(@subjectid)
329
+ task = OpenTox::Task.create($task[:uri], @subjectid, RDF::DC.description => "Deleting #{params[:file][:filename]} from investigation #{params[:id]}.") do
330
+ prepare_upload
331
+ File.delete File.join(tmp,params[:filename])
332
+ isa2rdf
333
+ # TODO send notification to UI (TO CHECK: if files will be indexed?)
334
+ # OpenTox::RestClientWrapper.put "https://www.leadscope.com/dev-toxbank-search/search/index/investigation?resourceUri=#{CGI.escape(investigation_uri)}",{},{:subjectid => @subjectid}
335
+ "#{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}"
336
+ end
337
+ else
338
+ unauthorized_error "not authorized: #{investigation_uri}"
278
339
  end
279
340
  response['Content-Type'] = 'text/uri-list'
280
341
  halt 202,task.uri+"\n"
@@ -2,7 +2,7 @@
2
2
  # Main ToxBank-investigation install script
3
3
  # Author: Christoph Helma, Andreas Maunz, Denis Gebele.
4
4
 
5
- ISA2RDF=isa2rdf-0.0.1-SNAPSHOT.jar
5
+ ISA2RDF=isa2rdf-0.0.3-SNAPSHOT.jar
6
6
 
7
7
  echo
8
8
  echo "This script will setup and configure the toxbank-investigation service."
@@ -32,6 +32,8 @@ then
32
32
  git init
33
33
  echo "*/*.zip" > .gitignore
34
34
  echo "*/tmp" >> .gitignore
35
+ echo "user_policies" >> .gitignore
36
+ echo "group_policies" >> .gitignore
35
37
  git add .gitignore
36
38
  git commit -am "Initial commit: .gitignore added"
37
39
  fi
@@ -39,11 +41,11 @@ cd $TB_HOME
39
41
 
40
42
  echo "Installing configuration files"
41
43
 
42
- mkdir -p "$HOME/.opentox/config/toxbank-investigation"
44
+ mkdir -p "$HOME/.opentox/config"
43
45
  mkdir -p "$HOME/.opentox/log"
44
46
  mkdir -p "$HOME/.opentox/tmp"
45
47
 
46
- config="$HOME/.opentox/config/toxbank-investigation/production.rb"
48
+ config="$HOME/.opentox/config/investigation.rb"
47
49
 
48
50
  if [ -f $config ]
49
51
  then
data/config.ru CHANGED
@@ -1,3 +1,4 @@
1
+ SERVICE = "investigation"
1
2
  require 'bundler'
2
3
  Bundler.require
3
4
  #Encoding.default_external = Encoding::UTF_8
@@ -0,0 +1,277 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <isatab-config-file xmlns="http://www.ebi.ac.uk/bii/isatab_configuration#">
3
+ <isatab-configuration table-name="investigation" isatab-assay-type="generic_assay" isatab-conversion-target="generic">
4
+ <measurement term-label="[investigation]" term-accession="" source-abbreviation="" />
5
+ <technology term-label="" term-accession="" source-abbreviation="" />
6
+ <field header="Investigation Identifier" data-type="String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION">
7
+ <description><![CDATA[A user defined identifier for the investigation.]]></description>
8
+ <default-value><![CDATA[]]></default-value>
9
+ </field>
10
+ <field header="Investigation Title" data-type="String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION">
11
+ <description><![CDATA[A title for the Investigation.]]></description>
12
+ <default-value><![CDATA[]]></default-value>
13
+ </field>
14
+ <field header="Investigation Description" data-type="Long String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION">
15
+ <description><![CDATA[A brief description of the investigation aims.]]></description>
16
+ <default-value><![CDATA[]]></default-value>
17
+ </field>
18
+ <field header="Investigation Submission Date" data-type="Date" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION">
19
+ <description><![CDATA[The date the investigation was submitted.]]></description>
20
+ <default-value><![CDATA[]]></default-value>
21
+ </field>
22
+ <field header="Investigation Public Release Date" data-type="Date" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION">
23
+ <description><![CDATA[The date the investigation was release publicly.]]></description>
24
+ <default-value><![CDATA[]]></default-value>
25
+ </field>
26
+ <field header="Comment [Created with configuration]" data-type="String" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="true" is-forced-ontology="false" section="INVESTIGATION">
27
+ <description><![CDATA[A field indicating which ISA configuration was used to create the ISAtab file.]]></description>
28
+ <default-value><![CDATA[]]></default-value>
29
+ </field>
30
+ <field header="Comment [Last Opened With Configuration]" data-type="String" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="true" is-forced-ontology="false" section="INVESTIGATION">
31
+ <description><![CDATA[A field indicating which ISA configuration was last used to open the ISAtab file.]]></description>
32
+ <default-value><![CDATA[]]></default-value>
33
+ </field>
34
+ <field header="Comment [Owning Organisation URI]" data-type="Ontology term" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION">
35
+ <description><![CDATA[Owning Organisation URI]]></description>
36
+ <default-value><![CDATA[]]></default-value>
37
+ <recommended-ontologies>
38
+ <ontology id="TBO" abbreviation="TBO" name="ToxBank organisation" version="0.1" />
39
+ </recommended-ontologies>
40
+ </field>
41
+ <field header="Comment [Consortium URI]" data-type="Ontology term" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION">
42
+ <description><![CDATA[Consortium URI]]></description>
43
+ <default-value><![CDATA[]]></default-value>
44
+ <recommended-ontologies>
45
+ <ontology id="TBC" abbreviation="TBC" name="ToxBank consortium" version="0.1" />
46
+ </recommended-ontologies>
47
+ </field>
48
+ <field header="Comment [Principal Investigator URI]" data-type="Ontology term" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION">
49
+ <description><![CDATA[Toxbank user URI]]></description>
50
+ <default-value><![CDATA[]]></default-value>
51
+ <recommended-ontologies>
52
+ <ontology id="TBU" abbreviation="TBU" name="ToxBank users" version="0.1" />
53
+ </recommended-ontologies>
54
+ </field>
55
+ <field header="Comment [Investigation keywords]" data-type="Ontology term" is-file-field="false" is-multiple-value="true" is-required="true" is-hidden="false" is-forced-ontology="true" section="INVESTIGATION">
56
+ <description><![CDATA[Investigation keywords.]]></description>
57
+ <default-value><![CDATA[]]></default-value>
58
+ <recommended-ontologies>
59
+ <ontology id="TBK" abbreviation="TBK" name="ToxBank keywords" version="0.1" />
60
+ </recommended-ontologies>
61
+ </field>
62
+ <field header="Investigation PubMed ID" data-type="String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION PUBLICATIONS">
63
+ <description><![CDATA[The PubMed ID related to this publication (if available).]]></description>
64
+ <default-value><![CDATA[]]></default-value>
65
+ </field>
66
+ <field header="Investigation Publication DOI" data-type="String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION PUBLICATIONS">
67
+ <description><![CDATA[The DOI related to this publication (if available).]]></description>
68
+ <default-value><![CDATA[]]></default-value>
69
+ </field>
70
+ <field header="Investigation Publication Author List" data-type="Long String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION PUBLICATIONS">
71
+ <description><![CDATA[The authors who contributed to this publication.]]></description>
72
+ <default-value><![CDATA[]]></default-value>
73
+ </field>
74
+ <field header="Investigation Publication Title" data-type="Long String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION PUBLICATIONS">
75
+ <description><![CDATA[The title of the publication.]]></description>
76
+ <default-value><![CDATA[]]></default-value>
77
+ </field>
78
+ <field header="Investigation Publication Status" data-type="Ontology term" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION PUBLICATIONS">
79
+ <description><![CDATA[The status of this publication, e.g. Published, Submitted, etc.]]></description>
80
+ <default-value><![CDATA[]]></default-value>
81
+ </field>
82
+ <field header="Investigation Person Last Name" data-type="String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION CONTACTS">
83
+ <description><![CDATA[The last name/surname of the contact.]]></description>
84
+ <default-value><![CDATA[]]></default-value>
85
+ </field>
86
+ <field header="Investigation Person First Name" data-type="String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION CONTACTS">
87
+ <description><![CDATA[The first name/forename of the contact.]]></description>
88
+ <default-value><![CDATA[]]></default-value>
89
+ </field>
90
+ <field header="Investigation Person Mid Initials" data-type="String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION CONTACTS">
91
+ <description><![CDATA[The mid initial of the contact.]]></description>
92
+ <default-value><![CDATA[]]></default-value>
93
+ </field>
94
+ <field header="Investigation Person Email" data-type="Long String" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION CONTACTS">
95
+ <description><![CDATA[The email corresponding to this contact.]]></description>
96
+ <default-value><![CDATA[]]></default-value>
97
+ </field>
98
+ <field header="Investigation Person Phone" data-type="String" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION CONTACTS">
99
+ <description><![CDATA[A phone number for this contact, if available.]]></description>
100
+ <default-value><![CDATA[]]></default-value>
101
+ </field>
102
+ <field header="Investigation Person Fax" data-type="String" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION CONTACTS">
103
+ <description><![CDATA[A fax number for this contact, if available.]]></description>
104
+ <default-value><![CDATA[]]></default-value>
105
+ </field>
106
+ <field header="Investigation Person Address" data-type="Long String" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION CONTACTS">
107
+ <description><![CDATA[The address for this contact, preferably, their institution.]]></description>
108
+ <default-value><![CDATA[]]></default-value>
109
+ </field>
110
+ <field header="Investigation Person Affiliation" data-type="String" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION CONTACTS">
111
+ <description><![CDATA[The affiliation for this contact.]]></description>
112
+ <default-value><![CDATA[]]></default-value>
113
+ </field>
114
+ <field header="Investigation Person Roles" data-type="Ontology term" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="INVESTIGATION CONTACTS">
115
+ <description><![CDATA[The role of the person in this investigation.]]></description>
116
+ <default-value><![CDATA[]]></default-value>
117
+ </field>
118
+ <field header="Comment [Investigation Person URI]" data-type="Ontology term" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="true" section="INVESTIGATION CONTACTS">
119
+ <description><![CDATA[Toxbank User URI]]></description>
120
+ <default-value><![CDATA[]]></default-value>
121
+ <recommended-ontologies>
122
+ <ontology id="TBU" abbreviation="TBU" name="ToxBank users" version="0.1" />
123
+ </recommended-ontologies>
124
+ </field>
125
+ <field header="Study Identifier" data-type="String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="STUDY">
126
+ <description><![CDATA[A user defined identifier for the study.]]></description>
127
+ <default-value><![CDATA[]]></default-value>
128
+ </field>
129
+ <field header="Study Title" data-type="String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="STUDY">
130
+ <description><![CDATA[A title for the Study.]]></description>
131
+ <default-value><![CDATA[]]></default-value>
132
+ </field>
133
+ <field header="Study Description" data-type="Long String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="STUDY">
134
+ <description><![CDATA[A brief description of the study aims.]]></description>
135
+ <default-value><![CDATA[]]></default-value>
136
+ </field>
137
+ <field header="Study Submission Date" data-type="Date" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY">
138
+ <description><![CDATA[The date the study was submitted.]]></description>
139
+ <default-value><![CDATA[]]></default-value>
140
+ </field>
141
+ <field header="Study Public Release Date" data-type="Date" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY">
142
+ <description><![CDATA[The date the study was released publicly.]]></description>
143
+ <default-value><![CDATA[]]></default-value>
144
+ </field>
145
+ <field header="Study File Name" data-type="String" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="true" is-forced-ontology="false" section="STUDY">
146
+ <description><![CDATA[The name of the study sample file linked to this Study]]></description>
147
+ <default-value><![CDATA[]]></default-value>
148
+ </field>
149
+ <field header="Study PubMed ID" data-type="String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="STUDY PUBLICATIONS">
150
+ <description><![CDATA[The PubMed ID related to this publication (if available).]]></description>
151
+ <default-value><![CDATA[]]></default-value>
152
+ </field>
153
+ <field header="Study Publication DOI" data-type="String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="STUDY PUBLICATIONS">
154
+ <description><![CDATA[The DOI related to this publication (if available).]]></description>
155
+ <default-value><![CDATA[]]></default-value>
156
+ </field>
157
+ <field header="Study Publication Author List" data-type="Long String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="STUDY PUBLICATIONS">
158
+ <description><![CDATA[The authors who contributed to this publication.]]></description>
159
+ <default-value><![CDATA[]]></default-value>
160
+ </field>
161
+ <field header="Study Publication Title" data-type="Long String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="STUDY PUBLICATIONS">
162
+ <description><![CDATA[The title of the publication.]]></description>
163
+ <default-value><![CDATA[]]></default-value>
164
+ </field>
165
+ <field header="Study Publication Status" data-type="Ontology term" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="STUDY PUBLICATIONS">
166
+ <description><![CDATA[The status of this publication, e.g. Published, Submitted, etc.]]></description>
167
+ <default-value><![CDATA[]]></default-value>
168
+ </field>
169
+ <field header="Study Person Last Name" data-type="String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="STUDY CONTACTS">
170
+ <description><![CDATA[The last name/surname of the contact.]]></description>
171
+ <default-value><![CDATA[]]></default-value>
172
+ </field>
173
+ <field header="Study Person First Name" data-type="String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="STUDY CONTACTS">
174
+ <description><![CDATA[The first name/forename of the contact.]]></description>
175
+ <default-value><![CDATA[]]></default-value>
176
+ </field>
177
+ <field header="Study Person Mid Initials" data-type="String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="STUDY CONTACTS">
178
+ <description><![CDATA[The mid initial of the contact.]]></description>
179
+ <default-value><![CDATA[]]></default-value>
180
+ </field>
181
+ <field header="Study Person Email" data-type="Long String" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY CONTACTS">
182
+ <description><![CDATA[The email corresponding to this contact.]]></description>
183
+ <default-value><![CDATA[]]></default-value>
184
+ </field>
185
+ <field header="Study Person Phone" data-type="String" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY CONTACTS">
186
+ <description><![CDATA[A phone number for this contact, if available.]]></description>
187
+ <default-value><![CDATA[]]></default-value>
188
+ </field>
189
+ <field header="Study Person Fax" data-type="String" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY CONTACTS">
190
+ <description><![CDATA[A fax number for this contact, if available.]]></description>
191
+ <default-value><![CDATA[]]></default-value>
192
+ </field>
193
+ <field header="Study Person Address" data-type="Long String" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY CONTACTS">
194
+ <description><![CDATA[The address for this contact, preferably, their institution.]]></description>
195
+ <default-value><![CDATA[]]></default-value>
196
+ </field>
197
+ <field header="Study Person Affiliation" data-type="String" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY CONTACTS">
198
+ <description><![CDATA[The affiliation for this contact.]]></description>
199
+ <default-value><![CDATA[]]></default-value>
200
+ </field>
201
+ <field header="Study Person Roles" data-type="Ontology term" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY CONTACTS">
202
+ <description><![CDATA[The role of the person in this Study.]]></description>
203
+ <default-value><![CDATA[]]></default-value>
204
+ </field>
205
+ <field header="Study Factor Name" data-type="String" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY FACTORS">
206
+ <description><![CDATA[The name of the Factor driving this study, e.g. Dose, Collection Time Point, Compound, and so forth]]></description>
207
+ <default-value><![CDATA[]]></default-value>
208
+ </field>
209
+ <field header="Study Factor Type" data-type="Ontology term" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY FACTORS">
210
+ <description><![CDATA[The type of the Factor driving this study, e.g. EFO:Dose (from Ontology), or Dose if the Factor name is something related to Dose as well, etc.]]></description>
211
+ <default-value><![CDATA[]]></default-value>
212
+ </field>
213
+ <field header="Study Design Type" data-type="Ontology term" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY DESIGN DESCRIPTORS">
214
+ <description><![CDATA[The type of study design being employed, e.g. Observation, Intervention, Cross-Over, etc.]]></description>
215
+ <default-value><![CDATA[]]></default-value>
216
+ </field>
217
+ <field header="Study Assay Measurement Type" data-type="List" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY ASSAYS">
218
+ <description><![CDATA[The measurement being observed in this assay, e.g. Transcription Profiling, Metabolite Profiling]]></description>
219
+ <default-value><![CDATA[]]></default-value>
220
+ </field>
221
+ <field header="Study Assay Technology Type" data-type="List" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY ASSAYS">
222
+ <description><![CDATA[The technology being employed to observe this measurement, e.g. DNA microarray, NMR, Mass Spectrometry and so forth]]></description>
223
+ <default-value><![CDATA[]]></default-value>
224
+ </field>
225
+ <field header="Study Assay Technology Platform" data-type="String" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY ASSAYS">
226
+ <description><![CDATA[The technology platform used, e.g. Affymetrix, Illumina, Solexa, SOLiD, Bruker, etc.]]></description>
227
+ <default-value><![CDATA[]]></default-value>
228
+ </field>
229
+ <field header="Study Assay File Name" data-type="String" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY ASSAYS">
230
+ <description><![CDATA[The name of the file which contains the information about this assay, the samples and pipeline used.]]></description>
231
+ <default-value><![CDATA[]]></default-value>
232
+ </field>
233
+ <field header="Study Protocol Name" data-type="String" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY PROTOCOLS">
234
+ <description><![CDATA[The name of the protocol, e.g. RNA Extraction Protocol]]></description>
235
+ <default-value><![CDATA[]]></default-value>
236
+ </field>
237
+ <field header="Study Protocol Type" data-type="Ontology term" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="true" section="STUDY PROTOCOLS">
238
+ <description><![CDATA[The type of the protocol, preferably coming from an Ontology, e.g. Extraction Protocol]]></description>
239
+ <default-value><![CDATA[]]></default-value>
240
+ <recommended-ontologies>
241
+ <ontology id="TBP" abbreviation="TBP" name="ToxBank protocols" version="0.1" />
242
+ </recommended-ontologies>
243
+ </field>
244
+ <field header="Study Protocol Description" data-type="Long String" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY PROTOCOLS">
245
+ <description><![CDATA[A description of the Protocol.]]></description>
246
+ <default-value><![CDATA[]]></default-value>
247
+ </field>
248
+ <field header="Study Protocol URI" data-type="Long String" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="false" section="STUDY PROTOCOLS">
249
+ <description><![CDATA[A URI to link out to a publication, web page, etc. describing the protocol.]]></description>
250
+ <default-value><![CDATA[]]></default-value>
251
+ </field>
252
+ <field header="Study Protocol Version" data-type="String" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY PROTOCOLS">
253
+ <description><![CDATA[The version of the protocol used, where applicable.]]></description>
254
+ <default-value><![CDATA[]]></default-value>
255
+ </field>
256
+ <field header="Study Protocol Parameters Name" data-type="Ontology term" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY PROTOCOLS">
257
+ <description><![CDATA[The parameters used when executing this protocol.]]></description>
258
+ <default-value><![CDATA[]]></default-value>
259
+ </field>
260
+ <field header="Study Protocol Components Name" data-type="String" is-file-field="false" is-multiple-value="true" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY PROTOCOLS">
261
+ <description><![CDATA[The components used when carrying out this protocol.]]></description>
262
+ <default-value><![CDATA[]]></default-value>
263
+ </field>
264
+ <field header="Study Protocol Components Type" data-type="Ontology term" is-file-field="false" is-multiple-value="false" is-required="false" is-hidden="false" is-forced-ontology="false" section="STUDY PROTOCOLS">
265
+ <description><![CDATA[The type of Components used in this Protocol.]]></description>
266
+ <default-value><![CDATA[]]></default-value>
267
+ </field>
268
+ <field header="Comment [Protocol URI]" data-type="Ontology term" is-file-field="false" is-multiple-value="false" is-required="true" is-hidden="false" is-forced-ontology="true" section="STUDY PROTOCOLS">
269
+ <description><![CDATA[Toxbank Protocol URI]]></description>
270
+ <default-value><![CDATA[]]></default-value>
271
+ <recommended-ontologies>
272
+ <ontology id="TBP" abbreviation="TBP" name="ToxBank protocols" version="0.1" />
273
+ </recommended-ontologies>
274
+ </field>
275
+ <structured-field name="factors" />
276
+ </isatab-configuration>
277
+ </isatab-config-file>
@@ -0,0 +1,15 @@
1
+ def replace_pi subjectid
2
+ begin
3
+ user = OpenTox::Authorization.get_user(subjectid)
4
+ accounturi = OpenTox::RestClientWrapper.get("http://toxbanktest1.opentox.org:8080/toxbank/user?username=#{user}", nil, {:Accept => "text/uri-list", :subjectid => subjectid}).sub("\n","")
5
+ account = OpenTox::TBAccount.new(accounturi, subjectid)
6
+ investigation_file = Dir["#{tmp}/i_*vestigation.txt"]
7
+ investigation_file.each do |inv_file|
8
+ text = File.read(inv_file, :encoding => "BINARY")
9
+ replace = text.gsub!(/TBU:U\d+/, account.ns_uri)
10
+ File.open(inv_file, "wb") { |file| file.puts replace } if replace
11
+ end
12
+ rescue
13
+ $logger.error "can not replace Principal Investigator to user: #{user} with subjectid: #{subjectid}"
14
+ end
15
+ end
@@ -0,0 +1,153 @@
1
+ module OpenTox
2
+
3
+ # define RDF vocabularies
4
+ RDF::TB = RDF::Vocabulary.new "http://onto.toxbank.net/api/"
5
+ RDF::TBU = RDF::Vocabulary.new "http://toxbanktest1.opentox.org:8080/toxbank/user/"
6
+ RDF::TBO = RDF::Vocabulary.new "http://toxbanktest1.opentox.org:8080/toxbank/organisation/"
7
+ RDF::TBPT = RDF::Vocabulary.new "http://toxbanktest1.opentox.org:8080/toxbank/project/"
8
+
9
+ CLASSES << "TBAccount"
10
+
11
+ =begin
12
+ # TODO: this should not be necessary, class in initialized below
13
+ # add new OpenTox class
14
+ c = Class.new do
15
+ include OpenTox
16
+ #extend OpenTox::ClassMethods
17
+ end
18
+ OpenTox.const_set "TBAccount",c
19
+ =end
20
+
21
+ # Get rdf representation for a user, organisation or project from the ToxBank service
22
+ # @see http://api.toxbank.net/index.php/User ToxBank API User
23
+ # @see http://api.toxbank.net/index.php/Organisation ToxBank API Organisation
24
+ # @see http://api.toxbank.net/index.php/Project ToxBank API Project
25
+ # @see http://api.toxbank.net/index.php/Protocol#Security ToxBank API Security
26
+ # @example TBAccount
27
+ # require "opentox-server"
28
+ # User1 = OpenTox::TBAccount.new("http://uri_to_toxbankservice/toxbank/user/U123", subjectid)
29
+ # puts User1.ldap_dn #=> "uid=username,ou=people,dc=opentox,dc=org"
30
+ # User1.send_policy("http://uri_toprotect/bla/foo") #=> creates new read policy for http://uri_toprotect/bla/foo
31
+ class TBAccount
32
+ include OpenTox
33
+
34
+ # Get hasAccount value of a user,organisation or project from ToxBank service
35
+ # @return [String] username
36
+ def account
37
+ @account ||= get_account
38
+ end
39
+
40
+ # Generates LDAP Distinguished Name (DN)
41
+ # @return [String] LDAP Distinguished Name (DN)
42
+ def ldap_dn
43
+ @uri.match(RDF::TBU.to_s) ? "uid=#{self.account},ou=people,dc=opentox,dc=org" : "cn=#{self.account},ou=groups,dc=opentox,dc=org"
44
+ end
45
+
46
+ # Get LDAP type - returns 'LDAPUsers' if the TBAccount.uri is a user URI
47
+ # @return [String] 'LDAPUsers' or 'LDAPGroups'
48
+ def ldap_type
49
+ @uri.match(RDF::TBU.to_s) ? "LDAPUsers" : "LDAPGroups"
50
+ end
51
+
52
+ # GET policy XML
53
+ # @param [String,String] URI,Type URI to protect, Access-rights < "all", "readwrite", "read" (default) >
54
+ # @return [String] policy in XML
55
+ def get_policy uri, type="read"
56
+ policy(uri, type)
57
+ end
58
+
59
+ # sends policy to opensso server
60
+ # @param (see #get_policy)
61
+ def send_policy uri, type="read"
62
+ OpenTox::Authorization.create_policy(policy(uri, type), @subjectid)
63
+ end
64
+
65
+ # Change account URI into RDF prefixed Version e.G.: "http://toxbanktest1.opentox.org:8080/toxbank/user/U2" becomes "TBU:U2"
66
+ # @example
67
+ # user = OpenTox::TBAccount.new("http://uri_to_toxbankservice/toxbank/user/U2", subjectid)
68
+ # puts user.ns_uri #=> "RDF::TBU:U2"
69
+ # @return [String] prefixed URI of a user/organisation/project
70
+ def ns_uri
71
+ out = "TBU:#{@uri.split('/')[-1]}" if @uri.match(RDF::TBU.to_s)
72
+ out = "TBO:#{@uri.split('/')[-1]}" if @uri.match(RDF::TBO.to_s)
73
+ out = "TBPT:#{@uri.split('/')[-1]}" if @uri.match(RDF::TBPT.to_s)
74
+ out
75
+ end
76
+
77
+ private
78
+
79
+ # Get rdf from user service and returns username
80
+ # @private
81
+ def get_account
82
+ get "application/rdf+xml" # get rdfxml instead of ntriples
83
+ # do not catch errors as this will lead do follow up problems
84
+ # error handling is implemented at a lower level in opentox-client
85
+ self[RDF::TB.hasAccount]
86
+ end
87
+
88
+ # creates policy
89
+ def policy uri, type="read"
90
+ return <<-EOS
91
+ <!DOCTYPE Policies PUBLIC "-//Sun Java System Access Manager7.1 2006Q3 Admin CLI DTD//EN" "jar://com/sun/identity/policy/policyAdmin.dtd">
92
+ <Policies>
93
+ <Policy name="tbi-#{self.account}-#{self.ldap_type[4,6].downcase}-#{Time.now.strftime("%Y-%m-%d-%H-%M-%S-x") + rand(1000).to_s}" referralPolicy="false" active="true">
94
+ <Rule name="rule_name">
95
+ <ServiceName name="iPlanetAMWebAgentService" />
96
+ <ResourceName name="#{uri}"/>
97
+ #{get_permissions(type)}
98
+ </Rule>
99
+ <Subjects name="subjects_name" description="">
100
+ <Subject name="subject_name" type="#{self.ldap_type}" includeType="inclusive">
101
+ <AttributeValuePair>
102
+ <Attribute name="Values"/>
103
+ <Value>#{self.ldap_dn}</Value>
104
+ </AttributeValuePair>
105
+ </Subject>
106
+ </Subjects>
107
+ </Policy>
108
+ </Policies>
109
+ EOS
110
+ end
111
+
112
+ # creates permission part of policy
113
+ def get_permissions type
114
+ requests = case type
115
+ when "all"
116
+ ["GET", "POST", "PUT", "DELETE"]
117
+ when "readwrite"
118
+ ["GET", "POST", "PUT"]
119
+ else
120
+ ["GET"]
121
+ end
122
+ out=""
123
+ requests.each{|r| out = "#{out}<AttributeValuePair><Attribute name=\"#{r}\" /><Value>allow</Value></AttributeValuePair>\n"}
124
+ return out
125
+ end
126
+
127
+ end
128
+
129
+ # ToxBank-investigation specific extension to OpenTox::Authorization in opentox-client
130
+ # @see http://rubydoc.info/gems/opentox-client/frames opentox-client documentation
131
+ module Authorization
132
+
133
+ # Create policy for PI-user (owner of subjectid)
134
+ # @param [String, String] URI,subjectid URI to create a policy for, subjectid
135
+ def self.create_pi_policy uri, subjectid
136
+ user = get_user(subjectid)
137
+ piuri = RestClientWrapper.get("http://toxbanktest1.opentox.org:8080/toxbank/user?username=#{user}", nil, {:Accept => "text/uri-list", :subjectid => subjectid}).sub("\n","")
138
+ piaccount = TBAccount.new(piuri, subjectid)
139
+ piaccount.send_policy(uri, "all")
140
+ end
141
+
142
+ # Delete all policies for Users or Groups of an investigation except the policy of the PI (Principal Investigator) user.
143
+ # @param [String, String, String] URI,LDAPtype,subjectid URI to protect, LDAPUsers or LDAPGroups, subjectid
144
+ def self.reset_policies uri, type, subjectid
145
+ policies = self.list_uri_policies(uri, subjectid)
146
+ user = get_user(subjectid)
147
+ policies.keep_if{|policy| policy =~ /^tbi-\w+-#{type}-*/ }
148
+ policies.delete_if{|policy| policy =~ /^tbi-#{user}-users-*/ }
149
+ policies.each{|policy| self.delete_policy(policy, subjectid) }
150
+ end
151
+
152
+ end
153
+ end
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "toxbank-investigation"
6
- s.version = "0.0.2pre"
6
+ s.version = File.read("./VERSION")
7
7
  s.authors = ["Christoph Helma","Denis Gebele","Micha Rautenberg"]
8
8
  s.email = ["helma@in-silico.ch","gebele@in-silico.ch","rautenenberg@in-silico.ch"]
9
9
  s.homepage = "http://github.com/ToxBank/toxbank-investigation"
@@ -15,13 +15,11 @@ Gem::Specification.new do |s|
15
15
  s.rubyforge_project = "toxbank-investigation"
16
16
 
17
17
  s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
- #s.require_paths = ["lib"]
21
18
  s.required_ruby_version = '>= 1.9.2'
22
19
 
23
20
  # specify any dependencies here; for example:
24
21
  s.add_runtime_dependency "opentox-server"
22
+ s.add_runtime_dependency 'roo'
25
23
 
26
24
  # external requirements
27
25
  ["git", "zip", "java", "curl", "wget"].each{|r| s.requirements << r}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toxbank-investigation
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:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-04-02 00:00:00.000000000 Z
14
+ date: 2012-08-23 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: opentox-server
18
- requirement: &78865690 !ruby/object:Gem::Requirement
18
+ requirement: !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,23 +23,44 @@ dependencies:
23
23
  version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *78865690
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: roo
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
27
48
  description: Toxbank investigation service
28
49
  email:
29
50
  - helma@in-silico.ch
30
51
  - gebele@in-silico.ch
31
52
  - rautenenberg@in-silico.ch
32
- executables:
33
- - toxbank-investigation-install
53
+ executables: []
34
54
  extensions: []
35
55
  extra_rdoc_files: []
36
56
  files:
37
57
  - .gitignore
58
+ - ChangeLog
38
59
  - Gemfile
39
- - Gemfile.lock
40
60
  - LICENSE
41
61
  - README
42
62
  - Rakefile
63
+ - VERSION
43
64
  - application.rb
44
65
  - bin/toxbank-investigation-install
45
66
  - config.ru
@@ -56,6 +77,7 @@ files:
56
77
  - java/config/isa_configurator/heterozygosity_micro.xml
57
78
  - java/config/isa_configurator/histology.xml
58
79
  - java/config/isa_configurator/histonemodification_seq.xml
80
+ - java/config/isa_configurator/investigation.xml
59
81
  - java/config/isa_configurator/metaboliteprofiling_ms.xml
60
82
  - java/config/isa_configurator/metaboliteprofiling_nmr.xml
61
83
  - java/config/isa_configurator/metagenome_seq.xml
@@ -74,6 +96,8 @@ files:
74
96
  - java/config/isa_configurator/transcription_micro.xml
75
97
  - java/config/isa_configurator/transcription_rtpcr.xml
76
98
  - java/config/isa_configurator/transcription_seq.xml
99
+ - pirewriter.rb
100
+ - tbaccount.rb
77
101
  - toxbank-investigation.gemspec
78
102
  homepage: http://github.com/ToxBank/toxbank-investigation
79
103
  licenses:
@@ -101,7 +125,7 @@ requirements:
101
125
  - curl
102
126
  - wget
103
127
  rubyforge_project: toxbank-investigation
104
- rubygems_version: 1.8.11
128
+ rubygems_version: 1.8.18
105
129
  signing_key:
106
130
  specification_version: 3
107
131
  summary: Toxbank investigation service
@@ -1,111 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- toxbank-investigation (0.0.2pre)
5
- opentox-server
6
-
7
- PATH
8
- remote: ~/opentox-client
9
- specs:
10
- opentox-client (0.0.2pre)
11
- bundler
12
- open4
13
- rdf
14
- rdf-raptor
15
- rest-client
16
-
17
- PATH
18
- remote: ~/opentox-server
19
- specs:
20
- opentox-server (0.0.2pre)
21
- emk-sinatra-url-for
22
- opentox-client
23
- rack
24
- rack-contrib
25
- roo
26
- sinatra
27
- sinatra-contrib
28
- unicorn
29
-
30
- GEM
31
- remote: http://rubygems.org/
32
- specs:
33
- addressable (2.2.7)
34
- backports (2.3.0)
35
- choice (0.1.5)
36
- emk-sinatra-url-for (0.2.1)
37
- sinatra (>= 0.9.1.1)
38
- eventmachine (0.12.10)
39
- faraday (0.7.6)
40
- addressable (~> 2.2)
41
- multipart-post (~> 1.1)
42
- rack (~> 1.1)
43
- ffi (1.0.11)
44
- google-spreadsheet-ruby (0.1.8)
45
- nokogiri (>= 1.4.3.1)
46
- oauth (>= 0.3.6)
47
- oauth2 (>= 0.5.0)
48
- kgio (2.7.2)
49
- log4r (1.1.10)
50
- mime-types (1.17.2)
51
- multi_json (1.1.0)
52
- multipart-post (1.1.5)
53
- nokogiri (1.5.2)
54
- oauth (0.4.5)
55
- oauth2 (0.5.2)
56
- faraday (~> 0.7)
57
- multi_json (~> 1.0)
58
- open4 (1.3.0)
59
- rack (1.4.1)
60
- rack-contrib (1.1.0)
61
- rack (>= 0.9.1)
62
- rack-protection (1.2.0)
63
- rack
64
- rack-test (0.6.1)
65
- rack (>= 1.0)
66
- raindrops (0.8.0)
67
- rdf (0.3.5)
68
- addressable (>= 2.2.6)
69
- rdf-raptor (0.4.1)
70
- ffi (>= 1.0)
71
- rdf (~> 0.3.0)
72
- rest-client (1.6.7)
73
- mime-types (>= 1.16)
74
- roo (1.10.1)
75
- choice (>= 0.1.4)
76
- google-spreadsheet-ruby (>= 0.1.5)
77
- nokogiri (>= 1.5.0)
78
- rubyzip (>= 0.9.4)
79
- spreadsheet (> 0.6.4)
80
- todonotes (>= 0.1.0)
81
- ruby-ole (1.2.11.3)
82
- rubyzip (0.9.6.1)
83
- sinatra (1.3.2)
84
- rack (~> 1.3, >= 1.3.6)
85
- rack-protection (~> 1.2)
86
- tilt (~> 1.3, >= 1.3.3)
87
- sinatra-contrib (1.3.1)
88
- backports (>= 2.0)
89
- eventmachine
90
- rack-protection
91
- rack-test
92
- sinatra (~> 1.3.0)
93
- tilt (~> 1.3)
94
- spreadsheet (0.6.8)
95
- ruby-ole (>= 1.0)
96
- tilt (1.3.3)
97
- todonotes (0.1.0)
98
- log4r
99
- unicorn (4.2.0)
100
- kgio (~> 2.6)
101
- rack
102
- raindrops (~> 0.7)
103
-
104
- PLATFORMS
105
- ruby
106
-
107
- DEPENDENCIES
108
- opentox-client!
109
- opentox-server!
110
- rack-test
111
- toxbank-investigation!