1b5bf78dbeb61821411e6cb754d6d977825bad58
[arvados.git] / services / api / app / controllers / arvados / v1 / links_controller.rb
1 class Arvados::V1::LinksController < ApplicationController
2
3   def create
4     resource_attrs.delete :head_kind
5     resource_attrs.delete :tail_kind
6     super
7   end
8
9   protected
10
11   # Overrides ApplicationController load_where_param
12   def load_where_param
13     super
14
15     # head_kind and tail_kind columns are now virtual,
16     # equivilent functionality is now provided by
17     # 'is_a', so fix up any old-style 'where' clauses.
18     if @where
19       @filters ||= []
20       if @where[:head_kind]
21         @filters << ['head_uuid', 'is_a', @where[:head_kind]]
22         @where.delete :head_kind
23       end
24       if @where[:tail_kind]
25         @filters << ['tail_uuid', 'is_a', @where[:tail_kind]]
26         @where.delete :tail_kind
27       end
28     end
29   end
30
31   # Overrides ApplicationController load_filters_param
32   def load_filters_param
33     super
34
35     # head_kind and tail_kind columns are now virtual,
36     # equivilent functionality is now provided by
37     # 'is_a', so fix up any old-style 'filter' clauses.
38     @filters = @filters.map do |k|
39       if k[0] == 'head_kind' and k[1] == '='
40         ['head_uuid', 'is_a', k[2]]
41       elsif k[0] == 'tail_kind' and k[1] == '='
42         ['tail_uuid', 'is_a', k[2]]
43       else
44         k
45       end
46     end
47   end
48
49 end