infopark_fiona_connector 7.0.1 → 7.0.1.5.2.3.rc8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +5 -5
  2. data/app/controllers/cms_controller.rb +1 -1
  3. data/app/controllers/rails_connector/default_cms_controller.rb +4 -6
  4. data/app/helpers/cms_helper.rb +1 -1
  5. data/app/helpers/cms_routing_helper.rb +1 -1
  6. data/app/helpers/rails_connector/cms_asset_helper.rb +4 -5
  7. data/app/helpers/rails_connector/cms_tag_helper.rb +0 -3
  8. data/app/helpers/rails_connector/default_cms_helper.rb +0 -2
  9. data/app/helpers/rails_connector/default_cms_routing_helper.rb +15 -16
  10. data/app/helpers/rails_connector/display_helper.rb +31 -33
  11. data/app/helpers/rails_connector/editing_helper.rb +2 -8
  12. data/app/helpers/rails_connector/layout_helper.rb +2 -5
  13. data/app/helpers/rails_connector/marker_helper.rb +63 -64
  14. data/app/helpers/rails_connector/table_of_contents_helper.rb +1 -3
  15. data/config/cms_routes.rb +15 -15
  16. data/lib/gem_dependencies.rb +8 -7
  17. data/lib/generators/rails_connector/install/install_generator.rb +6 -6
  18. data/lib/generators/rails_connector/install/templates/initializers/rails_connector.rb +1 -1
  19. data/lib/infopark_fiona_connector.rb +7 -6
  20. data/lib/meta_eager_loader.rb +1 -0
  21. data/lib/rails_connector/attr_dict.rb +54 -31
  22. data/lib/rails_connector/attribute.rb +93 -0
  23. data/lib/rails_connector/authenticable.rb +12 -5
  24. data/lib/rails_connector/basic_obj.rb +126 -132
  25. data/lib/rails_connector/blob.rb +4 -5
  26. data/lib/rails_connector/blob_mapping.rb +15 -0
  27. data/lib/rails_connector/blob_mysql.rb +3 -5
  28. data/lib/rails_connector/blob_oracle.rb +5 -7
  29. data/lib/rails_connector/channel.rb +18 -0
  30. data/lib/rails_connector/cms_accessible.rb +21 -24
  31. data/lib/rails_connector/cms_base_model.rb +12 -4
  32. data/lib/rails_connector/cms_dispatch_controller.rb +9 -12
  33. data/lib/rails_connector/cms_env.rb +4 -7
  34. data/lib/rails_connector/cms_test_request.rb +1 -16
  35. data/lib/rails_connector/configuration.rb +14 -16
  36. data/lib/rails_connector/content.rb +7 -0
  37. data/lib/rails_connector/core_extensions/time.rb +3 -4
  38. data/lib/rails_connector/date_attribute.rb +2 -4
  39. data/lib/rails_connector/default_search_request.rb +1 -1
  40. data/lib/rails_connector/engine.rb +18 -17
  41. data/lib/rails_connector/errors.rb +2 -5
  42. data/lib/rails_connector/fiona_datetime.rb +14 -0
  43. data/lib/rails_connector/fiona_engine.rb +3 -4
  44. data/lib/rails_connector/html_string.rb +0 -2
  45. data/lib/rails_connector/job.rb +10 -0
  46. data/lib/rails_connector/link.rb +7 -4
  47. data/lib/rails_connector/link_list.rb +1 -5
  48. data/lib/rails_connector/link_resolvable.rb +1 -5
  49. data/lib/rails_connector/lucene_search_request.rb +20 -24
  50. data/lib/rails_connector/markdown_string.rb +0 -2
  51. data/lib/rails_connector/meta.rb +143 -0
  52. data/lib/rails_connector/meta/eager_loader.rb +84 -0
  53. data/lib/rails_connector/named_link.rb +25 -14
  54. data/lib/rails_connector/news.rb +8 -4
  55. data/lib/rails_connector/obj_class.rb +138 -0
  56. data/lib/rails_connector/obj_class_attr.rb +5 -0
  57. data/lib/rails_connector/object_with_meta_data.rb +13 -0
  58. data/lib/rails_connector/permission.rb +2 -6
  59. data/lib/rails_connector/rack_middlewares.rb +1 -2
  60. data/lib/rails_connector/ses.rb +3 -8
  61. data/lib/rails_connector/ses/verity_accessor.rb +43 -46
  62. data/lib/rails_connector/string_tagging.rb +0 -3
  63. data/lib/rails_connector/verity_search_request.rb +6 -9
  64. data/lib/search_request.rb +1 -1
  65. data/lib/version.rb +1 -1
  66. metadata +31 -20
@@ -0,0 +1,84 @@
1
+ require "singleton"
2
+ require "set"
3
+
4
+ module RailsConnector
5
+ module Meta
6
+ class EagerLoader
7
+ include Singleton
8
+ attr_reader :obj_classes
9
+
10
+ def initialize
11
+ # Rails.logger.debug "EagerLoader: I am eager to start working"
12
+ @obj_classes = {}
13
+ RailsConnector::ObjClass.includes(:custom_attributes_raw).all.each do |obj_class|
14
+ @obj_classes[obj_class.name] = obj_class if obj_class
15
+ end
16
+ preload_attribute_blobs
17
+ end
18
+
19
+ def obj_class(name)
20
+ name = name.to_s
21
+ if !@obj_classes.fetch(name, nil).nil?
22
+ @obj_classes[name]
23
+ else
24
+ # TODO: preload_attribute_blobs for obj_class
25
+ @obj_classes[name] ||= RailsConnector::ObjClass.find_by_obj_class_name(name)
26
+ end
27
+ end
28
+
29
+ def forget_obj_class(name)
30
+ @obj_classes.delete(name.to_s)
31
+ end
32
+
33
+ protected
34
+
35
+ def preload_attribute_blobs
36
+ attribute_names = Set.new
37
+ @obj_classes.each do |_, obj_class|
38
+ obj_class.custom_attributes.each do |attribute_name, _|
39
+ attribute_names << attribute_name
40
+ end
41
+ end
42
+
43
+ blob_names = attribute_names.map { |attribute_name| "#{attribute_name}.jsonAttributeDict" }
44
+ # Fiona >= 6.8
45
+ if RailsConnector::BlobMapping.exists?
46
+ blob_names = attribute_names.map { |attribute_name| "#{attribute_name}.jsonAttributeDict" }
47
+ fingerprint_map = RailsConnector::BlobMapping.get_fingerprint_map(blob_names)
48
+ blob_fingerprints = fingerprint_map.values
49
+ # NOTE: this is correct!
50
+ blobs = RailsConnector::Blob.where(blob_name: blob_fingerprints).to_a
51
+ blob_map = Hash[blobs.map { |b| [b.blob_name, b] }]
52
+
53
+ @obj_classes.each do |_, obj_class|
54
+ obj_class.custom_attributes.each do |_, attribute|
55
+ blob_name = "#{attribute.name}.jsonAttributeDict"
56
+ fingerprint = fingerprint_map[blob_name]
57
+ blob = blob_map[fingerprint]
58
+
59
+ next unless blob&.blob_data?
60
+
61
+ attribute.instance_variable_set(:@blob_data, ::JSON.parse(blob.blob_data))
62
+ end
63
+ end
64
+ # Fiona = 6.7
65
+ else
66
+ blob_names = attribute_names.map { |attribute_name| "#{attribute_name}.jsonAttributeDict" }
67
+ blobs = RailsConnector::Blob.where(blob_name: blob_names).to_a
68
+ blob_map = Hash[blobs.map { |b| [b.blob_name, b] }]
69
+
70
+ @obj_classes.each do |_, obj_class|
71
+ obj_class.custom_attributes.each do |_, attribute|
72
+ blob_name = "#{attribute.name}.jsonAttributeDict"
73
+ blob = blob_map[blob_name]
74
+
75
+ next unless blob&.blob_data?
76
+
77
+ attribute.instance_variable_set(:@blob_data, ::JSON.parse(blob.blob_data))
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -1,9 +1,9 @@
1
1
  module RailsConnector
2
-
3
2
  # This class provides methods used to retrieve objects from CMS based an entry
4
3
  # in CMS of the obj_class <tt>NamedLink</tt>.
5
4
  # @api public
6
5
  class NamedLink
6
+ LINKLIST_NAME = "related_links".freeze
7
7
 
8
8
  # @api public
9
9
  class NotFound < StandardError
@@ -18,21 +18,33 @@ module RailsConnector
18
18
  def self.generate_named_links_cache
19
19
  return if @@named_links_cache
20
20
 
21
- found_objects = BasicObj.where(obj_class: 'NamedLink')
21
+ # add method for get related_links attiribute for simply Obj-instance
22
+ attributes = RailsConnector::Attribute.where(attribute_name: LINKLIST_NAME)
23
+ if attributes.length != 0
24
+ Obj.send(:define_attribute, LINKLIST_NAME, ActiveRecord::Type::String.new)
25
+ Obj.send(:delegate, LINKLIST_NAME.to_sym, to: :attr_dict)
26
+ else
27
+ Rails.logger.warn "Check if you NamedLink class is defined properly. Attibute related_links does not exist."
28
+ # there is not attribute named 'related_links' defined
29
+ @@named_links_cache = []
30
+ @@updated_at = Time.now
31
+ return nil
32
+ end
33
+
34
+ found_objects = BasicObj.where(obj_class: "NamedLink")
22
35
  Rails.logger.warn "Couldn't find NamedLink CMS Object!" if found_objects.empty?
23
36
  Rails.logger.warn "More than one NamedLink CMS Object found!" if found_objects.size > 1
24
37
 
25
- @@named_links_cache = found_objects.
26
- sort_by(&:valid_from).
27
- reverse.
28
- map(&:related_links).
29
- flatten(1).
30
- each_with_object({}) do |link_obj, temp|
31
- temp[link_obj.title] = link_obj.destination_object
32
- end
38
+ @@named_links_cache = found_objects
39
+ .sort_by(&:valid_from)
40
+ .reverse
41
+ .flat_map(&:related_links)
42
+ .each_with_object({}) do |link_obj, temp|
43
+ temp[link_obj.title] = link_obj.destination_object
44
+ end
33
45
 
34
46
  @@updated_at = Time.now
35
- return nil
47
+ nil
36
48
  end
37
49
 
38
50
  # Sets the time in minutes after which the cache will be expired.
@@ -56,7 +68,8 @@ module RailsConnector
56
68
  # @api public
57
69
  def self.get_object(title, options = {})
58
70
  object = named_links[title.to_s]
59
- raise NotFound, "The NamedLink '#{title.to_s}' does not exist" if object.nil?
71
+ raise NotFound, "The NamedLink '#{title}' does not exist" if object.nil?
72
+
60
73
  options[:cache] == false ? object.reload : object
61
74
  end
62
75
 
@@ -73,7 +86,5 @@ module RailsConnector
73
86
  def self.named_links_cache
74
87
  @@named_links_cache
75
88
  end
76
-
77
89
  end
78
-
79
90
  end
@@ -1,16 +1,20 @@
1
1
  module RailsConnector
2
-
3
2
  # The CMS news object
4
3
  #
5
4
  # This class models the join table between channels and objects.
6
5
  # Instances of this class also hold information about validity range.
7
6
  # @api public
8
7
  class News < CmsBaseModel
9
-
10
8
  self.primary_key = "news_id"
11
9
 
12
- belongs_to :object, :class_name => 'Obj', :foreign_key => 'object_id'
10
+ belongs_to :object, class_name: "Obj", foreign_key: "object_id"
13
11
 
14
- end
12
+ def self.table_name
13
+ "#{table_name_prefix}" "news"
14
+ end
15
15
 
16
+ scope :active, -> { where("? BETWEEN valid_from AND valid_until", Time.now.to_s(:number)) }
17
+
18
+ scope :for_channel, ->(channel_name) { where(channel_name: channel_name) }
19
+ end
16
20
  end
@@ -0,0 +1,138 @@
1
+ module RailsConnector
2
+ # This class is used to read out the custom attributes,
3
+ # mandatory attributes and titles of an Obj.
4
+ # Warning: Dependent on the setup of your DB replication, most tables
5
+ # with meta information will not be available on your live system!
6
+ class ObjClass < CmsBaseModel
7
+ self.primary_key = :obj_class_id
8
+
9
+ has_many :custom_attributes_jt, class_name: "::RailsConnector::ObjClassAttr", foreign_key: "obj_class_id", primary_key: "obj_class_id"
10
+ has_many :custom_attributes_raw, through: :custom_attributes_jt, source: :custom_attributes_raw
11
+
12
+ alias_attribute :name, :obj_class_name
13
+ alias_attribute :type, :obj_type
14
+
15
+ attribute :is_enabled, :boolean
16
+ alias_attribute :enabled, :is_enabled
17
+
18
+ %w(attributeGroupNames attributeGroups canCreateNewsItems completionCheck
19
+ contentTypes createPermission workflowModification validSubObjClasses
20
+ validSubObjClassCheck
21
+ validContentTypes titles recordSetCallback presetFromParentAttributes
22
+ presetAttributes).each do |key|
23
+ define_method(key.underscore) do
24
+ load_blob_data
25
+ @blob_data[key]
26
+ end
27
+ end
28
+
29
+ # Returns the title of the file format or nil, if it was not set.
30
+ def title(language)
31
+ titles[language.to_s].presence
32
+ end
33
+
34
+ # returns channel feature is_activate?
35
+ def can_create_news_items?
36
+ can_create_news_items.to_i != 0
37
+ end
38
+
39
+ def ruby_class
40
+ @r_klass ||= RailsConnector::BasicObj.compute_type(name)
41
+ end
42
+
43
+ # Returns true, if a custom Ruby class exists.
44
+ def has_custom_ruby_class?
45
+ ruby_class != Obj
46
+ end
47
+
48
+ # Returns the custom attributes in the form of a Hash.
49
+ def custom_attributes
50
+ # create a Hash (with indifferent access) out of an Array of ActiveRecord objects
51
+ @custom_attributes ||= custom_attributes_raw.map do |attr|
52
+ { attr.attribute_name => attr }
53
+ end.reduce(HashWithIndifferentAccess.new, &:merge)
54
+ end
55
+
56
+ # Returns true, if the Obj Class has an attribute of the given name.
57
+ def custom_attribute?(attr)
58
+ custom_attributes.key?(attr.to_s)
59
+ end
60
+
61
+ # Returns an Array of String of all mandatory attributes found for this ObjClass,
62
+ # no matter if it is a custom or built-in attribute. Built-in attributes
63
+ # are underscored (valid_from, not validFrom).
64
+ # Possible +options+ are:
65
+ # <tt>:only_custom_attributes</tt>:: Return only custom attributes, omit
66
+ # built-in attributes like content_type or valid_from.
67
+ def mandatory_attribute_names(options = {})
68
+ only_custom_attributes ||= options[:only_custom_attributes] || false
69
+ build_mandatory_attribute_arrays
70
+ return @mandatory_custom_attributes if only_custom_attributes
71
+
72
+ @mandatory_attributes
73
+ end
74
+
75
+ # Returns true, if the file format has an mandatory attribute of the given name.
76
+ def mandatory_attribute?(attr)
77
+ mandatory_attribute_names.include?(attr.to_s)
78
+ end
79
+
80
+ # Convenience method for find_by_obj_class_name
81
+ def self.find_by_name(*args)
82
+ find_by_obj_class_name(*args)
83
+ end
84
+
85
+ # Reads a whole bunch of data, where only some of it is useful
86
+ # in a Rails application:
87
+ # attributeGroups, availableBlobEditors, bodyTemplateName,
88
+ # canCreateNewsItems, completionCheck, mandatoryAttributes,
89
+ # presetAttributes, recordSetCallback, titles, validSubObjClassCheck,
90
+ # workflowModification
91
+ def self.read_blob_data(name) #:nodoc:
92
+ blob = RailsConnector::Meta.hello_im_rails_and_im_retarted_so_please_be_patient do # these queries really pollute our logs!
93
+ blob_name =
94
+ if RailsConnector::BlobMapping.exists?
95
+ RailsConnector::BlobMapping.get_fingerprint("#{name}.jsonObjClassDict")
96
+ else
97
+ "#{name}.jsonObjClassDict"
98
+ end
99
+
100
+ RailsConnector::Blob.find_without_excluded_blob_data(blob_name)
101
+ end
102
+
103
+ return {} unless blob&.blob_data?
104
+
105
+ JSON.parse(blob.blob_data)
106
+ end
107
+
108
+ private
109
+
110
+ def load_blob_data #:nodoc:
111
+ return if @blob_data
112
+
113
+ @blob_data = self.class.read_blob_data(name)
114
+
115
+ # reset depending instance variables
116
+ @mandatory_custom_attributes = @mandatory_attributes = nil
117
+ end
118
+
119
+ def build_mandatory_attribute_arrays #:nodoc:
120
+ return if @mandatory_attributes
121
+
122
+ load_blob_data
123
+
124
+ @mandatory_custom_attributes = []
125
+ @mandatory_attributes = []
126
+ (@blob_data["mandatoryAttributes"] || []).each do |attr|
127
+ attr_name = attr.to_s
128
+ if custom_attribute?(attr_name)
129
+ @mandatory_custom_attributes << attr_name
130
+ else
131
+ # only modify built-in attributes; i.e. `validFrom` will become `valid_from`
132
+ attr_name = attr_name.underscore
133
+ end
134
+ @mandatory_attributes << attr_name
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,5 @@
1
+ module RailsConnector
2
+ class ObjClassAttr < CmsBaseModel
3
+ has_many :custom_attributes_raw, class_name: "::RailsConnector::Attribute", foreign_key: "attribute_id", primary_key: "attribute_id"
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ module RailsConnector
2
+ # This class allows us to read out the version and
3
+ # the reminder information of an Obj
4
+ class ObjectWithMetaData < CmsBaseModel #:nodoc:
5
+ # If we name the class Object, conflicts with the plain Ruby
6
+ # objects inside the RailsConnector will occur.
7
+ def self.table_name
8
+ "#{table_name_prefix}" "objects"
9
+ end
10
+
11
+ self.primary_key = :object_id
12
+ end
13
+ end
@@ -1,8 +1,7 @@
1
1
  module RailsConnector
2
-
3
2
  # The permissions assigned to an Obj.
4
3
  class Permission < CmsBaseModel
5
- belongs_to :object, :class_name => 'Obj', :foreign_key => 'object_id'
4
+ belongs_to :object, class_name: "Obj", foreign_key: "object_id"
6
5
 
7
6
  # Returns the Array of the names of the user groups to which read permission has been granted.
8
7
  def self.read
@@ -29,13 +28,10 @@ module RailsConnector
29
28
  user_groups_for_permission_type(5)
30
29
  end
31
30
 
32
- private
33
-
34
31
  def self.user_groups_for_permission_type(permission_type)
35
32
  # Field name "user_login" is a legacy from CM tables.
36
33
  # Actually the field contains the user group.
37
- select(:user_login).where(:permission_type => permission_type).map(&:user_login)
34
+ select(:user_login).where(permission_type: permission_type).map(&:user_login)
38
35
  end
39
36
  end
40
-
41
37
  end
@@ -1,6 +1,5 @@
1
1
  module RailsConnector
2
2
  def self.rack_middlewares
3
- ["RailsConnector::CacheMiddleware"]
3
+ [RailsConnector::CacheMiddleware]
4
4
  end
5
5
  end
6
-
@@ -1,11 +1,9 @@
1
- require 'search_request'
1
+ require "search_request"
2
2
 
3
3
  module RailsConnector
4
-
5
4
  # This module accesses the Infopark Search Engine Server.
6
5
  # @api public
7
6
  module SES
8
-
9
7
  autoload :VerityAccessor, "rails_connector/ses/verity_accessor"
10
8
 
11
9
  # This method enables Obj to perform searches using the SES Search Engine Server.
@@ -51,19 +49,17 @@ module RailsConnector
51
49
  class Hit
52
50
  # The ID of the found Obj.
53
51
  # @api public
54
- attr_reader :id
52
+ attr_reader :id, :score, :doc
55
53
 
56
54
  # The score of the hit.
57
55
  # @api public
58
- attr_reader :score
59
56
 
60
57
  # The raw result hash returned by the search engine, for a low-level access.
61
58
  # Don't use this unless you know what you're doing.
62
59
  # Be aware that this is not migration safe.
63
60
  # @api public
64
- attr_reader :doc
65
61
 
66
- def initialize(id, score, doc={}, obj=nil)
62
+ def initialize(id, score, doc = {}, obj = nil)
67
63
  @id = id
68
64
  @score = score
69
65
  @doc = doc
@@ -79,5 +75,4 @@ module RailsConnector
79
75
  end
80
76
  end
81
77
  end
82
-
83
78
  end
@@ -1,12 +1,10 @@
1
1
  require "builder"
2
2
 
3
3
  module RailsConnector
4
-
5
4
  module SES
6
-
7
5
  class VerityAccessor
8
- require 'net/http'
9
- require 'uri'
6
+ require "net/http"
7
+ require "uri"
10
8
  require "rexml/document"
11
9
 
12
10
  #--
@@ -15,16 +13,16 @@ module RailsConnector
15
13
  def initialize(query, options = {})
16
14
  @query = query
17
15
  @options = {
18
- :host => 'localhost',
19
- :port => 3011,
20
- :offset => 0,
21
- :limit => 10,
22
- :min_relevance => 50,
23
- :max_docs => 'unlimited',
24
- :parser => 'simple',
25
- :sort_order => [["score", "desc"], ["name", "asc"]],
26
- :collections => ['cm-contents'],
27
- :base_query => nil
16
+ host: "localhost",
17
+ port: 3011,
18
+ offset: 0,
19
+ limit: 10,
20
+ min_relevance: 50,
21
+ max_docs: "unlimited",
22
+ parser: "simple",
23
+ sort_order: [%w(score desc), %w(name asc)],
24
+ collections: ["cm-contents"],
25
+ base_query: nil
28
26
  }.merge(options)
29
27
  @options[:collections] = Array(options[:collection]).flatten if options.has_key?(:collection)
30
28
  end
@@ -43,44 +41,44 @@ module RailsConnector
43
41
  def build_request_payload
44
42
  x = Builder::XmlMarkup.new
45
43
  x.instruct!
46
- x.tag!('ses-payload', 'payload-id' => 'd-1f6a64dec16aa328-00000020-i', 'timestamp' => Time.now.to_iso, 'version' => '6') {
47
- x.tag!('ses-header') {
48
- x.tag!('ses-sender', 'sender-id' => '42', 'name' => 'infopark-rails-connector')
49
- }
50
- x.tag!('ses-request', 'request-id' => 'd-1f6a64dec16aa328-00000021-j-1', 'preclusive' => 'false') {
51
- x.tag!('ses-search') {
52
- x.query @query, :parser => @options[:parser]
53
- x.resultRecord {
54
- x.resultField 'objId'
55
- x.resultField 'score'
56
- }
57
- x.offset {
44
+ x.tag!("ses-payload", "payload-id" => "d-1f6a64dec16aa328-00000020-i", "timestamp" => Time.now.to_iso, "version" => "6") do
45
+ x.tag!("ses-header") do
46
+ x.tag!("ses-sender", "sender-id" => "42", "name" => "infopark-rails-connector")
47
+ end
48
+ x.tag!("ses-request", "request-id" => "d-1f6a64dec16aa328-00000021-j-1", "preclusive" => "false") do
49
+ x.tag!("ses-search") do
50
+ x.query @query, parser: @options[:parser]
51
+ x.resultRecord do
52
+ x.resultField "objId"
53
+ x.resultField "score"
54
+ end
55
+ x.offset do
58
56
  x.start @options[:offset].to_i + 1
59
57
  x.length @options[:limit]
60
- }
58
+ end
61
59
  x.minRelevance @options[:min_relevance]
62
60
  x.maxDocs @options[:max_docs]
63
61
 
64
62
  unless @options[:sort_order].blank?
65
- x.sortOrder {
63
+ x.sortOrder do
66
64
  @options[:sort_order].each do |attribute, direction|
67
- x.sortField attribute, :direction => direction
65
+ x.sortField attribute, direction: direction
68
66
  end
69
- }
67
+ end
70
68
  end
71
69
 
72
- x.searchBase {
73
- @options[:collections].each {|item| x.collection item }
74
- x.query @options[:base_query], :parser => @options[:parser] if @options[:base_query]
75
- }
76
- }
77
- }
78
- }
70
+ x.searchBase do
71
+ @options[:collections].each { |item| x.collection item }
72
+ x.query @options[:base_query], parser: @options[:parser] if @options[:base_query]
73
+ end
74
+ end
75
+ end
76
+ end
79
77
  end
80
78
 
81
79
  def send_to_ses(payload)
82
80
  res = Net::HTTP.new(@options[:host], @options[:port].to_i).start do |http|
83
- req = Net::HTTP::Post.new('/xml')
81
+ req = Net::HTTP::Post.new("/xml")
84
82
  req.body = payload
85
83
  http.request(req)
86
84
  end
@@ -89,7 +87,7 @@ module RailsConnector
89
87
 
90
88
  def parse_response_payload(response)
91
89
  xml = REXML::Document.new(response)
92
- if xml.elements['/ses-payload/ses-response/ses-code'].attributes['numeric'] == "200"
90
+ if xml.elements["/ses-payload/ses-response/ses-code"].attributes["numeric"] == "200"
93
91
  build_successful_result(xml)
94
92
  else
95
93
  handle_error(xml)
@@ -97,13 +95,13 @@ module RailsConnector
97
95
  end
98
96
 
99
97
  def build_successful_result(response)
100
- result = SearchResult.new(response.elements['/ses-payload/ses-response/ses-code/searchResults'].attributes['hits'].to_i)
101
- response.elements.to_a('/ses-payload/ses-response/ses-code/searchResults/record').each do |record|
102
- hit = Hit.new(record.elements['objId'].text.to_i, record.elements['score'].text.to_f)
98
+ result = SearchResult.new(response.elements["/ses-payload/ses-response/ses-code/searchResults"].attributes["hits"].to_i)
99
+ response.elements.to_a("/ses-payload/ses-response/ses-code/searchResults/record").each do |record|
100
+ hit = Hit.new(record.elements["objId"].text.to_i, record.elements["score"].text.to_f)
103
101
  if hit.obj.present?
104
102
  result << hit
105
103
  else
106
- Rails.logger.warn("OBJ with ID ##{record.elements['objId'].text.to_i} not found: This search result will not be shown")
104
+ Rails.logger.warn("OBJ with ID ##{record.elements["objId"].text.to_i} not found: This search result will not be shown")
107
105
  end
108
106
  end
109
107
  result
@@ -118,13 +116,12 @@ module RailsConnector
118
116
  # 100177: ERROR_SYSTEM_SEARCHENGINE_BULKSUBMITFAILED
119
117
  def handle_error(response)
120
118
  msg = ""
121
- response.elements.each('/ses-payload/ses-response/ses-code/errorStack/error') do |error|
122
- msg << error.elements['phrase'].text
119
+ response.elements.each("/ses-payload/ses-response/ses-code/errorStack/error") do |error|
120
+ msg << error.elements["phrase"].text
123
121
  msg << "\n"
124
122
  end
125
123
  raise SearchError, msg
126
124
  end
127
125
  end
128
126
  end
129
-
130
127
  end