[ARVADOS] updated: 995dd33ec5bc9ebb7cc4ff075a1f5e1a4e7db20c

git at public.curoverse.com git at public.curoverse.com
Fri Apr 25 15:41:36 EDT 2014


Summary of changes:
 .../api/app/controllers/application_controller.rb  |    8 +-
 services/api/lib/eventbus.rb                       |    7 +--
 services/api/lib/load_param.rb                     |   39 ++++++++++
 services/api/lib/record_filters.rb                 |   81 +++++++++++--------
 services/api/test/integration/websocket_test.rb    |    6 +-
 5 files changed, 95 insertions(+), 46 deletions(-)

       via  995dd33ec5bc9ebb7cc4ff075a1f5e1a4e7db20c (commit)
      from  4eb42fd91dc5e50840e0d3db5d5201561602a508 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 995dd33ec5bc9ebb7cc4ff075a1f5e1a4e7db20c
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Fri Apr 25 15:40:54 2014 -0400

    Resolving application_controller.rb merge conflicts, tests pass.

diff --git a/services/api/app/controllers/application_controller.rb b/services/api/app/controllers/application_controller.rb
index 5dd5b52..1368eeb 100644
--- a/services/api/app/controllers/application_controller.rb
+++ b/services/api/app/controllers/application_controller.rb
@@ -30,8 +30,6 @@ class ApplicationController < ActionController::Base
 
   attr_accessor :resource_attrs
 
-  DEFAULT_LIMIT = 100
-
   def index
     @objects.uniq!(&:id)
     if params[:eager] and params[:eager] != '0' and params[:eager] != 0 and params[:eager] != ''
@@ -107,7 +105,7 @@ class ApplicationController < ActionController::Base
                   "    AND mng_links.head_uuid=#{klass.table_name}.uuid")
           cond_sql += " OR mng_links.uuid IS NOT NULL"
         end
-        @objects = @objects.where(cond_sql, *cond_params)
+        @objects = @objects.where(cond_sql, *cond_params).order(:uuid)
         @limit = limit_all - all_objects.count
         apply_where_limit_order_params
         items_available = @objects.
@@ -186,7 +184,9 @@ class ApplicationController < ActionController::Base
   end
 
   def apply_where_limit_order_params
-    ft = record_filters @filters
+    ar_table_name = @objects.table_name
+
+    ft = record_filters @filters, ar_table_name
     if ft[:cond_out].any?
       @objects = @objects.where(ft[:cond_out].join(' AND '), *ft[:param_out])
     end
diff --git a/services/api/lib/eventbus.rb b/services/api/lib/eventbus.rb
index ac023e5..b36378b 100644
--- a/services/api/lib/eventbus.rb
+++ b/services/api/lib/eventbus.rb
@@ -41,11 +41,6 @@ class EventBus
     Log
   end
 
-  # used in RecordFilters
-  def table_name
-    model_class.table_name
-  end
-
   def initialize
     @channel = EventMachine::Channel.new
     @mtx = Mutex.new
@@ -78,7 +73,7 @@ class EventBus
           cond_out = []
           param_out = []
           ws.filters.each do |filter|
-            ft = record_filters filter.filters
+            ft = record_filters filter.filters, Log.table_name
             cond_out += ft[:cond_out]
             param_out += ft[:param_out]
           end
diff --git a/services/api/lib/load_param.rb b/services/api/lib/load_param.rb
index f1c3198..dba0582 100644
--- a/services/api/lib/load_param.rb
+++ b/services/api/lib/load_param.rb
@@ -5,6 +5,8 @@
 
 module LoadParam
 
+  DEFAULT_LIMIT = 100
+
   def load_where_param
     if params[:where].nil? or params[:where] == ""
       @where = {}
@@ -36,4 +38,41 @@ module LoadParam
     end
   end
 
+  def load_limit_offset_order_params
+    if params[:limit]
+      unless params[:limit].to_s.match(/^\d+$/)
+        raise ArgumentError.new("Invalid value for limit parameter")
+      end
+      @limit = params[:limit].to_i
+    else
+      @limit = DEFAULT_LIMIT
+    end
+
+    if params[:offset]
+      unless params[:offset].to_s.match(/^\d+$/)
+        raise ArgumentError.new("Invalid value for offset parameter")
+      end
+      @offset = params[:offset].to_i
+    else
+      @offset = 0
+    end
+
+    @orders = []
+    if params[:order]
+      params[:order].split(',').each do |order|
+        attr, direction = order.strip.split " "
+        direction ||= 'asc'
+        if attr.match /^[a-z][_a-z0-9]+$/ and
+            model_class.columns.collect(&:name).index(attr) and
+            ['asc','desc'].index direction.downcase
+          @orders << "#{table_name}.#{attr} #{direction.downcase}"
+        end
+      end
+    end
+    if @orders.empty?
+      @orders << "#{table_name}.modified_at desc"
+    end
+  end
+
+
 end
diff --git a/services/api/lib/record_filters.rb b/services/api/lib/record_filters.rb
index 6750797..3f0a845 100644
--- a/services/api/lib/record_filters.rb
+++ b/services/api/lib/record_filters.rb
@@ -6,47 +6,60 @@
 #   @objects
 module RecordFilters
 
-  def record_filters filters
+  def record_filters filters, ar_table_name
     cond_out = []
     param_out = []
-    if filters.is_a? Array and filters.any?
-      filters.each do |attr, operator, operand|
-        if !model_class.searchable_columns(operator).index attr.to_s
-          raise ArgumentError.new("Invalid attribute '#{attr}' in condition")
-        end
-        case operator.downcase
-        when '=', '<', '<=', '>', '>=', 'like'
-          if operand.is_a? String
-            cond_out << "#{table_name}.#{attr} #{operator} ?"
-            if (# any operator that operates on value rather than
-                # representation:
-                operator.match(/[<=>]/) and
-                model_class.attribute_column(attr).type == :datetime)
-              operand = Time.parse operand
-            end
-            param_out << operand
-          end
-        when 'in'
-          if operand.is_a? Array
-            cond_out << "#{table_name}.#{attr} IN (?)"
-            param_out << operand
+
+    filters.each do |filter|
+      attr, operator, operand = filter
+      if !filter.is_a? Array
+        raise ArgumentError.new("Invalid element in filters array: #{filter.inspect} is not an array")
+      elsif !operator.is_a? String
+        raise ArgumentError.new("Invalid operator '#{operator}' (#{operator.class}) in filter")
+      elsif !model_class.searchable_columns(operator).index attr.to_s
+        raise ArgumentError.new("Invalid attribute '#{attr}' in filter")
+      end
+      case operator.downcase
+      when '=', '<', '<=', '>', '>=', 'like'
+        if operand.is_a? String
+          cond_out << "#{ar_table_name}.#{attr} #{operator} ?"
+          if (# any operator that operates on value rather than
+              # representation:
+              operator.match(/[<=>]/) and
+              model_class.attribute_column(attr).type == :datetime)
+            operand = Time.parse operand
           end
-        when 'is_a'
-          operand = [operand] unless operand.is_a? Array
-          cond = []
-          operand.each do |op|
-              cl = ArvadosModel::kind_class op
-              if cl
-                cond << "#{table_name}.#{attr} like ?"
-                param_out << cl.uuid_like_pattern
-              else
-                cond << "1=0"
-              end
+          param_out << operand
+        elsif operand.nil? and operator == '='
+          cond_out << "#{ar_table_name}.#{attr} is null"
+        else
+          raise ArgumentError.new("Invalid operand type '#{operand.class}' "\
+                                  "for '#{operator}' operator in filters")
+        end
+      when 'in'
+        if operand.is_a? Array
+          cond_out << "#{ar_table_name}.#{attr} IN (?)"
+          param_out << operand
+        else
+          raise ArgumentError.new("Invalid operand type '#{operand.class}' "\
+                                  "for '#{operator}' operator in filters")
+        end
+      when 'is_a'
+        operand = [operand] unless operand.is_a? Array
+        cond = []
+        operand.each do |op|
+          cl = ArvadosModel::kind_class op
+          if cl
+            cond << "#{ar_table_name}.#{attr} like ?"
+            param_out << cl.uuid_like_pattern
+          else
+            cond << "1=0"
           end
-          cond_out << cond.join(' OR ')
         end
+        cond_out << cond.join(' OR ')
       end
     end
+
     {:cond_out => cond_out, :param_out => param_out}
   end
 
diff --git a/services/api/test/integration/websocket_test.rb b/services/api/test/integration/websocket_test.rb
index 666175d..3bba0ef 100644
--- a/services/api/test/integration/websocket_test.rb
+++ b/services/api/test/integration/websocket_test.rb
@@ -254,17 +254,19 @@ class WebsocketTest < ActionDispatch::IntegrationTest
           state = 2
         when 2
           l1 = d["object_uuid"]
+          assert_not_nil l1, "Unexpected message: #{d}"
           state = 3
         when 3
           l2 = d["object_uuid"]
+          assert_not_nil l2, "Unexpected message: #{d}"
           ws.close
         end
       end
 
     end
 
-    assert_equal l1, logs(:log4).object_uuid
-    assert_equal l2, logs(:log5).object_uuid
+    assert_equal logs(:log4).object_uuid, l1
+    assert_equal logs(:log5).object_uuid, l2
   end
 
   test "connect, subscribe, get event, unsubscribe" do

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list