Class: GoodData::MandatoryUserFilter

Inherits:
UserFilter show all
Defined in:
lib/gooddata/models/user_filters/mandatory_user_filter.rb

Constant Summary

Constants inherited from MdObject

GoodData::MdObject::IDENTIFIERS_CFG, GoodData::MdObject::MD_OBJ_CTG

Constants included from GoodData::Mixin::MdIdToUri

GoodData::Mixin::MdIdToUri::IDENTIFIERS_CFG

Constants included from GoodData::Mixin::MdObjectIndexer

GoodData::Mixin::MdObjectIndexer::MD_OBJ_CTG

Constants included from GoodData::Mixin::MdObjectQuery

GoodData::Mixin::MdObjectQuery::ERROR_MESSAGE_NO_PROJECT

Instance Attribute Summary

Attributes inherited from Rest::Object

#client, #json, #project

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from UserFilter

#==, #delete, #expression, #expression=, #hash, #initialize, #level, #pretty_expression, #related_uri, #uri, #uri=, #variable

Methods inherited from MdObject

#==, #add_tag, #browser_uri, #delete, #deprecated, #deprecated=, find_replaceable_values, #get_flag?, #initialize, #listed?, #production, #production=, #project, #reload!, #remove_tag, replace, #replace, #replace!, replace_bracketed, replace_quoted, #restricted, #restricted=, #save_as, #set_flag, #tag_set, #unlisted, #unlisted=, #validate

Methods included from GoodData::Mixin::MdIdToUri

#identifier_to_uri

Methods included from GoodData::Mixin::MdObjectIndexer

#[]

Methods included from GoodData::Mixin::MdObjectQuery

#all, #dependency, #dependency?, #query, #usedby, #usedby?, #using, #using?

Methods included from GoodData::Mixin::MdFinders

#find_by_identifier, #find_by_tag, #find_by_title, #find_first_by_identifier, #find_first_by_title

Methods included from GoodData::Mixin::MdObjId

#uri_obj_id

Methods included from GoodData::Mixin::MdGrantees

#change_permission, #grant, #grantees, #revoke

Methods included from GoodData::Mixin::MdRelations

#dependency, #dependency?, #usedby, #usedby?, #using, #using?

Methods included from GoodData::Mixin::ObjId

#obj_id

Methods included from GoodData::Mixin::Links

#links

Methods inherited from Rest::Resource

#initialize

Methods inherited from Rest::Object

client, default_client, #initialize, #saved?

Methods included from GoodData::Mixin::DataPropertyReader

#data_property_reader

Methods included from GoodData::Mixin::DataPropertyWriter

#data_property_writer

Methods included from GoodData::Mixin::MetaPropertyReader

#metadata_property_reader

Methods included from GoodData::Mixin::MetaPropertyWriter

#metadata_property_writer

Methods included from GoodData::Mixin::MetaGetter

#meta

Methods included from GoodData::Mixin::DataGetter

#data

Methods included from GoodData::Mixin::RootKeyGetter

#root_key

Methods included from GoodData::Mixin::ContentGetter

#content

Constructor Details

This class inherits a constructor from GoodData::UserFilter

Class Method Details

.[](id, options = { client: GoodData.connection, project: GoodData.project }) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/gooddata/models/user_filters/mandatory_user_filter.rb', line 12

def [](id, options = { client: GoodData.connection, project: GoodData.project })
  if id == :all
    all(options)
  else
    super
  end
end

.all(options = { client: GoodData.connection, project: GoodData.project }) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/gooddata/models/user_filters/mandatory_user_filter.rb', line 20

def all(options = { client: GoodData.connection, project: GoodData.project })
  c = client(options)
  project = options[:project]
  filters = query('userFilter', nil, options)
  count = 1_000
  offset = 0
  user_lookup = {}
  loop do
    result = c.get("/gdc/md/#{project.pid}/userfilters?count=#{count}&offset=#{offset}")
    result['userFilters']['items'].each do |item|
      item['userFilters'].each do |f|
        user_lookup[f] = user_lookup[f] ? Array(user_lookup[f]).concat([item['user']]) : item['user']
      end
    end
    break if result['userFilters']['length'] < offset
    offset += count
  end
  mufs = filters.map do |filter_data|
    payload = {
      'expression' => filter_data['userFilter']['content']['expression'],
      'related' => user_lookup[filter_data['userFilter']['meta']['uri']],
      'level' => :user,
      'type'  => :filter,
      'uri'   => filter_data['userFilter']['meta']['uri']
    }
    c.create(GoodData::MandatoryUserFilter, payload, project: project)
  end
  mufs.enum_for
end

.count(options = { client: GoodData.connection, project: GoodData.project }) ⇒ Object



50
51
52
53
54
# File 'lib/gooddata/models/user_filters/mandatory_user_filter.rb', line 50

def count(options = { client: GoodData.connection, project: GoodData.project })
  c = client(options)
  project = options[:project]
  c.get(project.md['query'] + '/userfilters/')['query']['entries'].count
end

Instance Method Details



76
77
78
79
80
81
82
# File 'lib/gooddata/models/user_filters/mandatory_user_filter.rb', line 76

def related
  if related_uri.is_a? Array
    related_uri.map { |u| super u }
  else
    super
  end
end

#saveGoodData::MandatoryUserFilter

Creates or updates the mandatory user filter on the server



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/gooddata/models/user_filters/mandatory_user_filter.rb', line 60

def save
  data = {
    'userFilter' => {
      'content' => {
        'expression' => expression
      },
      'meta' => {
        'category' => 'userFilter',
        'title' => related_uri
      }
    }
  }
  res = client.post(project.md['obj'], data)
  @json[:uri] = res['uri']
end