Class: UU::OS::REST::ResultList

Inherits:
Array
  • Object
show all
Defined in:
uu_os_framework-0.29.16/lib/uu/os/rest/result_list.rb

Overview

This data structure should be used for paging large result sets. It is typically used as return value for uuAPI services. The corresponding DTO structure with criteria should be used as parameter for the service.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (ResultList) initialize(criteria_cls, entry_cls, data = nil)

Creates new instance of result list.

Parameters:

  • criteria_cls (Class)

    Criteria DTO class

  • entry_cls (Class)

    Entry DTO class

  • data (String, Hash) (defaults to: nil)

    JSON or Hash containing result list data



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/result_list.rb', line 27

def initialize(criteria_cls, entry_cls, data=nil)
  super(0)
  if (criteria_cls.nil?) || (entry_cls.nil?)
    raise ArgumentError.new('Criteria and Entry classes must be given')
  end
  if data.nil?
    return
  elsif data.kind_of?String
    data = JSON.parse(data, :symbolize_names => true)
  end
  if !data.kind_of?Hash
    raise ArgumentError.new("Parameter data must be JSON String or Hash, but was #{data.class}.")
  end
  if data[:total_size]
    @total_size = data[:total_size]
  else
    @total_size = data[:totalSize]
  end
  @criteria = criteria_cls.new(data[:criteria])
  if data[:page_entries]
    data[:page_entries].each do |item|
      self << entry_cls.new(item)
    end
  elsif data[:pageEntries]
    data[:pageEntries].each do |item|
      self << entry_cls.new(item)
    end
  end
end

Instance Attribute Details

- (UU::OS::REST::PagingCriteria) criteria

Criteria used to get list.



20
21
22
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/result_list.rb', line 20

def criteria
  @criteria
end

- (Numeric) total_size

Total size of the list (sum of all pages).

Parameters:

  • (Numeric)

Returns:

  • (Numeric)


15
16
17
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/result_list.rb', line 15

def total_size
  @total_size
end