Class: LucidWorks::Collection

Inherits:
Base
  • Object
show all
Defined in:
lib/lucid_works/collection.rb,
lib/lucid_works/collection/info.rb,
lib/lucid_works/collection/click.rb,
lib/lucid_works/collection/index.rb,
lib/lucid_works/collection/settings.rb

Defined Under Namespace

Classes: Click, Index, Info, Settings

Constant Summary collapse

LOGS_COLLECTION_NAME =
'LucidWorksLogs'
AD_FILTERING =
'adfiltering'
ROLE_FILTERING =
'filterbyrole'
STATIC_ACL_CONFIG =
{
  "filterer.class" => "com.lucid.security.WindowsACLQueryFilterer",
  "provider.class" => "com.lucid.security.ad.ADACLTagProvider",
}
MAGIC_ACL_ONLY_FILTER_SETTING =
{'should_clause' => '*:* -data_source_type:smb'}

Constants included from Utils::BoolConverter

Utils::BoolConverter::FALSE_VALUES, Utils::BoolConverter::TRUE_VALUES

Instance Attribute Summary

Attributes inherited from Base

#attributes, #id, #parent, #persisted, #raw_response, #response_data

Instance Method Summary collapse

Methods inherited from Base

all, #collection_url, collection_url, create, #destroy, extract_parent_from_options, find, first, human_attribute_value, #human_attribute_value, #initialize, #inspect, last, #member_url, #persisted?, #read_attribute_for_validation, #save, schema, singleton_name, to_select, #update_attributes

Methods included from SimpleNaming

#model_name

Methods included from Utils::BoolConverter

#to_bool

Constructor Details

This class inherits a constructor from LucidWorks::Base

Instance Method Details

#acl_only?Boolean

Returns:

  • (Boolean)


145
146
147
148
149
# File 'lib/lucid_works/collection.rb', line 145

def acl_only?
  filterer_config = self.filtering_settings['filterer.config']
  return false if filterer_config.nil?
  return self.filtering_settings['filterer.config'] != MAGIC_ACL_ONLY_FILTER_SETTING #rescue false
end

#admin_urlObject

URL of Solr’s build-in admin page



117
118
119
# File 'lib/lucid_works/collection.rb', line 117

def admin_url
  "#{server.host}/solr/#{name}/admin/"
end

#assert_components_include_ad_xor_roleObject



151
152
153
154
155
# File 'lib/lucid_works/collection.rb', line 151

def assert_components_include_ad_xor_role
  # require 'ruby-debug'; debugger
  raise "conflicting filtering components" if self.components.include?(AD_FILTERING) && self.components.include?(ROLE_FILTERING)
  raise "missing filtering components" if ! self.components.include?(AD_FILTERING) && ! self.components.include?(ROLE_FILTERING)
end

#build_synonym(attributes = {}) ⇒ Object



84
85
86
# File 'lib/lucid_works/collection.rb', line 84

def build_synonym(attributes = {})
  Synonym.new(attributes.merge(:collection => self))
end

#componentsObject



135
136
137
# File 'lib/lucid_works/collection.rb', line 135

def components
  JSON.parse(RestClient.get(uri + "/components/all.json?handlerName=%2Flucid"))
end

#compute_component_set(acl_filtering_enabled) ⇒ Object



161
162
163
164
165
166
# File 'lib/lucid_works/collection.rb', line 161

def compute_component_set(acl_filtering_enabled)
  new_component_set = self.components.clone
  new_component_set.delete(ROLE_FILTERING)
  new_component_set.delete(AD_FILTERING)
  new_component_set.unshift acl_filtering_enabled == 'true' ? AD_FILTERING : ROLE_FILTERING
end

#configure_filtering(opts) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/lucid_works/collection.rb', line 168

def configure_filtering(opts)
  if ! opts[:config]['java.naming.provider.url'].blank? && opts[:config]['java.naming.provider.url'] !~ %r(://)
    opts[:config]['java.naming.provider.url'] = "ldap://#{opts[:config]['java.naming.provider.url']}" 
  end
  filtering_settings = STATIC_ACL_CONFIG.merge('provider.config' => opts[:config])
  filtering_settings["filterer.config"] = opts[:acl_only] ? {} : MAGIC_ACL_ONLY_FILTER_SETTING
  
  errors = {}
  method = RestClient.send(:get, uri+'/filtering')['adfiltering'] ? :put : :post
  begin
    response = RestClient.send(method, uri+'/filtering/adfiltering', filtering_settings.to_json, :content_type => :json)
  rescue => exception
    JSON.parse(exception.response)['errors'].each {|e| errors[e['code']] = e['message']}
  end
  
  new_component_set = compute_component_set(opts[:enabled])
  if new_component_set.sort != self.components.sort
    begin
      response = RestClient.send(:put, uri+'/components/components?handlerName=/lucid', new_component_set.to_json, :content_type => :json)
    rescue => exception
      JSON.parse(exception.response)['errors'].each {|e| errors[e['code']] = e['message']}
    end
  end
  raise LucidWorks::AclConfigInvalid.new(errors) unless errors.empty?
end

#destroyable?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/lucid_works/collection.rb', line 27

def destroyable?
  true
end

#empty!Object



36
37
38
# File 'lib/lucid_works/collection.rb', line 36

def empty!
  build_index.destroy(:params => {:key => 'iaccepttherisk'})
end

#filtering_enabled?Boolean

Returns:

  • (Boolean)


139
140
141
142
143
# File 'lib/lucid_works/collection.rb', line 139

def filtering_enabled?
  # current core implementation requires exactly one of filterbyrole or adfiltering
  assert_components_include_ad_xor_role
  return self.components.include?(AD_FILTERING)
end

#filtering_settingsObject



157
158
159
# File 'lib/lucid_works/collection.rb', line 157

def filtering_settings
  JSON.parse(RestClient.get(uri + "/filtering"))['adfiltering'] || {}
end

#jdbcdriver_classesObject



131
132
133
# File 'lib/lucid_works/collection.rb', line 131

def jdbcdriver_classes
  JSON.parse RestClient.get(uri + "/jdbcdrivers/classes")
end

#jdbcdriversObject

We have to handle the jdbcdrivers model in a custom way, as a GET on …/jdbcdrivers returns a list of strings, but then you can actually do a DELETE on …/jdbcdrivers/name. For the DELETE reason we do use a LucidWorks::Base model, but we have to create them by hand.



124
125
126
127
128
129
# File 'lib/lucid_works/collection.rb', line 124

def jdbcdrivers
  driverlist = JSON.parse RestClient.get(self.uri + '/jdbcdrivers')
  driverlist.map do |drivername|
    Jdbcdriver.new(:name => drivername, :collection => self)
  end
end

#prime_activitiesObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/lucid_works/collection.rb', line 88

def prime_activities
  self.activities!.sort!{|a,b|a.id <=> b.id}
  num_created = 0
  activities_to_return = ::LucidWorks::Activity::TYPES.map do |type|
    if act = self.activities.detect{|act| act.type == type}
      act
    else
      num_created += 1
      start_time = Time.now.change(:min => 0) + num_created.hours
      self.create_activity(:type => type, :active => false, :start_time => start_time, :period => 1.days.seconds.to_i)
    end
  end
  self.activities! if num_created > 0
  activities_to_return
end

#rsolrObject

Sometimes we want to use the raw Rsolr class, instead of Rsolr::Ext



41
42
43
44
45
46
47
48
# File 'lib/lucid_works/collection.rb', line 41

def rsolr
  unless @rsolr
    server_uri = self.server.host
    @path_prefix = URI.parse(server_uri).path # The API key
    @rsolr = RSolr.connect :url => server_uri.dup
  end
  @rsolr
end

#rsolr_extObject



50
51
52
53
54
55
56
57
# File 'lib/lucid_works/collection.rb', line 50

def rsolr_ext
  unless @rsolr_ext
    server_uri = self.server.host
    @path_prefix = URI.parse(server_uri).path # The API key
    @rsolr_ext = RSolr::Ext.connect :url => server_uri.dup
  end
  @rsolr_ext
end

#rsolr_get(path_suffix, search_params) ⇒ Object

Lower level access to rsolr, for things like autocomplete queries



60
61
62
# File 'lib/lucid_works/collection.rb', line 60

def rsolr_get(path_suffix, search_params)
  rsolr.get "#{@path_prefix}/solr/#{name}/#{path_suffix}", :params => search_params
end

#search(search_params = {}) ⇒ Object

Perform a Solr search using RSolr



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/lucid_works/collection.rb', line 65

def search(search_params={})
  search_params[:page] ||= 1
  search_params[:per_page] ||= 10
  resp = rsolr_ext.find "#{@path_prefix}/solr/#{name}/select", search_params
  if search_params[:wt] == :xml
    data = Nokogiri.XML(resp)
    raise "search received bad XML" unless data.root
  else
    data = resp
  end
  data
end

#synonymsObject



78
79
80
81
82
# File 'lib/lucid_works/collection.rb', line 78

def synonyms
  settings.synonym_list.each_with_index.map do |mapping, index|
    Synonym.new(:id => index, :collection => self, :mapping => mapping, :persisted => true)
  end
end

#system?Boolean

is this a ‘system’ collection

Returns:

  • (Boolean)


32
33
34
# File 'lib/lucid_works/collection.rb', line 32

def system?
  name == LOGS_COLLECTION_NAME
end