1 class ActionsController < ApplicationController
4 def self.expose_action method, &block
5 @@exposed_actions[method] = true
6 define_method method, block
10 ArvadosBase::resource_class_for_uuid(params[:uuid])
14 @object = model_class.find(params[:uuid])
15 if @object.is_a? Link and
16 @object.link_class == 'name' and
17 ArvadosBase::resource_class_for_uuid(@object.head_uuid) == Collection
18 redirect_to collection_path(id: @object.uuid)
25 params.keys.collect(&:to_sym).each do |param|
26 if @@exposed_actions[param]
27 return self.send(param)
33 expose_action :copy_selections_into_project do
37 expose_action :move_selections_into_project do
41 def move_or_copy action
42 uuids_to_add = params["selection"]
44 collect { |x| ArvadosBase::resource_class_for_uuid(x) }.
46 each do |resource_class|
47 resource_class.filter([['uuid','in',uuids_to_add]]).each do |src|
48 if resource_class == Collection
49 dst = Link.new(owner_uuid: @object.uuid,
50 tail_uuid: @object.uuid,
58 if dst.respond_to? :'name='
60 dst.name = "Copy of #{dst.name}"
62 dst.name = "Copy of unnamed #{dst.class_for_display.downcase}"
68 raise ArgumentError.new "Unsupported action #{action}"
70 dst.owner_uuid = @object.uuid
71 dst.tail_uuid = @object.uuid if dst.class == Link
76 dst.name += " (#{Time.now.localtime})" if dst.respond_to? :name=
84 def arv_normalize mt, *opts
86 IO.popen(['arv-normalize'] + opts, 'w+b') do |io|
89 while buf = io.read(2**16)
96 expose_action :combine_selected_files_into_collection do
99 params["selection"].each do |s|
100 a = ArvadosBase::resource_class_for_uuid s
104 m = CollectionsHelper.match(Link.find(s).head_uuid)
108 m = CollectionsHelper.match(s)
111 if m and m[1] and m[2]
112 lst.append(m[1] + m[2])
117 collections = Collection.where(uuid: lst)
120 collections.each do |c|
127 mt = chash[m[1]+m[2]].manifest_text
129 combined += arv_normalize mt, '--extract', m[4][1..-1]
131 combined += chash[m[1]+m[2]].manifest_text
135 normalized = arv_normalize combined
136 normalized_stripped = arv_normalize combined, '--strip'
140 d = Digest::MD5.new()
141 d << normalized_stripped
142 newuuid = "#{d.hexdigest}+#{normalized_stripped.length}"
146 'ARVADOS_API_HOST' =>
147 arvados_api_client.arvados_v1_base.
148 sub(/\/arvados\/v1/, '').
149 sub(/^https?:\/\//, ''),
150 'ARVADOS_API_TOKEN' => Thread.current[:arvados_api_token],
151 'ARVADOS_API_HOST_INSECURE' =>
152 Rails.configuration.arvados_insecure_https ? 'true' : 'false'
155 IO.popen([env, 'arv-put', '--raw'], 'w+b') do |io|
156 io.write normalized_stripped
158 while buf = io.read(2**16)
162 newc = Collection.new({:uuid => newuuid, :manifest_text => normalized})
169 link_class: "provenance",
175 redirect_to controller: 'collections', action: :show, id: newc.uuid