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.andand.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)
22 raise ActiveRecord::RecordNotFound
27 params.keys.collect(&:to_sym).each do |param|
28 if @@exposed_actions[param]
29 return self.send(param)
35 expose_action :copy_selections_into_project do
39 expose_action :move_selections_into_project do
43 def move_or_copy action
44 uuids_to_add = params["selection"]
46 collect { |x| ArvadosBase::resource_class_for_uuid(x) }.
48 each do |resource_class|
49 resource_class.filter([['uuid','in',uuids_to_add]]).each do |src|
50 if resource_class == Collection
51 dst = Link.new(owner_uuid: @object.uuid,
52 tail_uuid: @object.uuid,
60 if dst.respond_to? :'name='
62 dst.name = "Copy of #{dst.name}"
64 dst.name = "Copy of unnamed #{dst.class_for_display.downcase}"
70 raise ArgumentError.new "Unsupported action #{action}"
72 dst.owner_uuid = @object.uuid
73 dst.tail_uuid = @object.uuid if dst.class == Link
78 dst.name += " (#{Time.now.localtime})" if dst.respond_to? :name=
86 def arv_normalize mt, *opts
88 IO.popen(['arv-normalize'] + opts, 'w+b') do |io|
91 while buf = io.read(2**16)
98 expose_action :combine_selected_files_into_collection do
101 params["selection"].each do |s|
102 a = ArvadosBase::resource_class_for_uuid s
106 m = CollectionsHelper.match(Link.find(s).head_uuid)
110 m = CollectionsHelper.match(s)
113 if m and m[1] and m[2]
114 lst.append(m[1] + m[2])
119 collections = Collection.where(uuid: lst)
122 collections.each do |c|
129 mt = chash[m[1]+m[2]].manifest_text
131 combined += arv_normalize mt, '--extract', m[4][1..-1]
133 combined += chash[m[1]+m[2]].manifest_text
137 normalized = arv_normalize combined
138 normalized_stripped = arv_normalize combined, '--strip'
142 d = Digest::MD5.new()
143 d << normalized_stripped
144 newuuid = "#{d.hexdigest}+#{normalized_stripped.length}"
148 'ARVADOS_API_HOST' =>
149 arvados_api_client.arvados_v1_base.
150 sub(/\/arvados\/v1/, '').
151 sub(/^https?:\/\//, ''),
152 'ARVADOS_API_TOKEN' => Thread.current[:arvados_api_token],
153 'ARVADOS_API_HOST_INSECURE' =>
154 Rails.configuration.arvados_insecure_https ? 'true' : 'false'
157 IO.popen([env, 'arv-put', '--raw'], 'w+b') do |io|
158 io.write normalized_stripped
160 while buf = io.read(2**16)
164 newc = Collection.new({:uuid => newuuid, :manifest_text => normalized})
171 link_class: "provenance",
177 redirect_to controller: 'collections', action: :show, id: newc.uuid