infopark_fiona_connector 7.0.1.5.2.3.rc7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +5 -0
  3. data/app/assets/images/admin/minus.gif +0 -0
  4. data/app/assets/images/bg80.png +0 -0
  5. data/app/assets/images/edit.png +0 -0
  6. data/app/assets/images/icons/mm_generic.png +0 -0
  7. data/app/assets/images/icons/mm_menu.png +0 -0
  8. data/app/assets/javascripts/editmarker.js +240 -0
  9. data/app/assets/javascripts/infopark_rails_connector.js.erb +0 -0
  10. data/app/assets/stylesheets/editmarker.css +70 -0
  11. data/app/assets/stylesheets/infopark_rails_connector.css.erb +0 -0
  12. data/app/controllers/cms_controller.rb +7 -0
  13. data/app/controllers/rails_connector/default_cms_controller.rb +41 -0
  14. data/app/helpers/cms_helper.rb +7 -0
  15. data/app/helpers/cms_routing_helper.rb +7 -0
  16. data/app/helpers/rails_connector/cms_asset_helper.rb +54 -0
  17. data/app/helpers/rails_connector/cms_tag_helper.rb +4 -0
  18. data/app/helpers/rails_connector/default_cms_helper.rb +21 -0
  19. data/app/helpers/rails_connector/default_cms_routing_helper.rb +119 -0
  20. data/app/helpers/rails_connector/display_helper.rb +124 -0
  21. data/app/helpers/rails_connector/editing_helper.rb +7 -0
  22. data/app/helpers/rails_connector/layout_helper.rb +26 -0
  23. data/app/helpers/rails_connector/marker_helper.rb +371 -0
  24. data/app/helpers/rails_connector/table_of_contents_helper.rb +20 -0
  25. data/app/models/named_link.rb +2 -0
  26. data/app/views/cms/_index.html.erb +7 -0
  27. data/app/views/cms/index.html.erb +1 -0
  28. data/app/views/errors/403_forbidden.html.erb +3 -0
  29. data/app/views/errors/410_gone.html.erb +7 -0
  30. data/config/cms_routes.rb +17 -0
  31. data/config/locales/de.rails_connector.errors.yml +11 -0
  32. data/config/locales/de.rails_connector.lib.yml +6 -0
  33. data/config/locales/de.rails_connector.views.yml +9 -0
  34. data/config/locales/en.rails_connector.errors.yml +10 -0
  35. data/config/locales/en.rails_connector.lib.yml +6 -0
  36. data/config/locales/en.rails_connector.views.yml +9 -0
  37. data/lib/gem_dependencies.rb +68 -0
  38. data/lib/generators/rails_connector/install/install_generator.rb +37 -0
  39. data/lib/generators/rails_connector/install/templates/app/models/obj.rb.erb +5 -0
  40. data/lib/generators/rails_connector/install/templates/initializers/rails_connector.rb +2 -0
  41. data/lib/generators/rails_connector/install/templates/local/configuration.rb +2 -0
  42. data/lib/infopark_fiona_connector.rb +44 -0
  43. data/lib/meta_eager_loader.rb +1 -0
  44. data/lib/obj.rb +3 -0
  45. data/lib/rails_connector/attr_dict.rb +169 -0
  46. data/lib/rails_connector/attr_value_provider.bundle +0 -0
  47. data/lib/rails_connector/attr_value_provider.so +0 -0
  48. data/lib/rails_connector/attr_value_provider64.so +0 -0
  49. data/lib/rails_connector/attribute.rb +93 -0
  50. data/lib/rails_connector/authenticable.rb +37 -0
  51. data/lib/rails_connector/basic_obj.rb +571 -0
  52. data/lib/rails_connector/blob.rb +75 -0
  53. data/lib/rails_connector/blob_mapping.rb +15 -0
  54. data/lib/rails_connector/blob_mysql.rb +30 -0
  55. data/lib/rails_connector/blob_oracle.rb +37 -0
  56. data/lib/rails_connector/cache_middleware.rb +13 -0
  57. data/lib/rails_connector/channel.rb +18 -0
  58. data/lib/rails_connector/cms_accessible.rb +111 -0
  59. data/lib/rails_connector/cms_base_model.rb +62 -0
  60. data/lib/rails_connector/cms_dispatch_controller.rb +43 -0
  61. data/lib/rails_connector/cms_env.rb +65 -0
  62. data/lib/rails_connector/cms_test_request.rb +8 -0
  63. data/lib/rails_connector/configuration.rb +174 -0
  64. data/lib/rails_connector/content.rb +7 -0
  65. data/lib/rails_connector/core_extensions.rb +1 -0
  66. data/lib/rails_connector/core_extensions/time.rb +17 -0
  67. data/lib/rails_connector/date_attribute.rb +26 -0
  68. data/lib/rails_connector/default_search_request.rb +6 -0
  69. data/lib/rails_connector/engine.rb +65 -0
  70. data/lib/rails_connector/errors.rb +6 -0
  71. data/lib/rails_connector/fiona_datetime.rb +14 -0
  72. data/lib/rails_connector/fiona_engine.rb +8 -0
  73. data/lib/rails_connector/html_string.rb +17 -0
  74. data/lib/rails_connector/job.rb +10 -0
  75. data/lib/rails_connector/link.rb +148 -0
  76. data/lib/rails_connector/link_list.rb +28 -0
  77. data/lib/rails_connector/link_resolvable.rb +5 -0
  78. data/lib/rails_connector/lucene_search_request.rb +102 -0
  79. data/lib/rails_connector/markdown_string.rb +17 -0
  80. data/lib/rails_connector/meta.rb +143 -0
  81. data/lib/rails_connector/meta/eager_loader.rb +84 -0
  82. data/lib/rails_connector/named_link.rb +90 -0
  83. data/lib/rails_connector/news.rb +20 -0
  84. data/lib/rails_connector/obj_class.rb +138 -0
  85. data/lib/rails_connector/obj_class_attr.rb +5 -0
  86. data/lib/rails_connector/object_with_meta_data.rb +13 -0
  87. data/lib/rails_connector/permission.rb +37 -0
  88. data/lib/rails_connector/rack_middlewares.rb +5 -0
  89. data/lib/rails_connector/ses.rb +78 -0
  90. data/lib/rails_connector/ses/verity_accessor.rb +127 -0
  91. data/lib/rails_connector/string_tagging.rb +26 -0
  92. data/lib/rails_connector/verity_search_request.rb +86 -0
  93. data/lib/search_request.rb +2 -0
  94. data/lib/version.rb +7 -0
  95. metadata +277 -0
@@ -0,0 +1,20 @@
1
+ module RailsConnector
2
+ # The CMS news object
3
+ #
4
+ # This class models the join table between channels and objects.
5
+ # Instances of this class also hold information about validity range.
6
+ # @api public
7
+ class News < CmsBaseModel
8
+ self.primary_key = "news_id"
9
+
10
+ belongs_to :object, class_name: "Obj", foreign_key: "object_id"
11
+
12
+ def self.table_name
13
+ "#{table_name_prefix}" "news"
14
+ end
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
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
@@ -0,0 +1,37 @@
1
+ module RailsConnector
2
+ # The permissions assigned to an Obj.
3
+ class Permission < CmsBaseModel
4
+ belongs_to :object, class_name: "Obj", foreign_key: "object_id"
5
+
6
+ # Returns the Array of the names of the user groups to which read permission has been granted.
7
+ def self.read
8
+ user_groups_for_permission_type(1)
9
+ end
10
+
11
+ # Returns the Array of the names of the user groups to which write permission has been granted
12
+ def self.write
13
+ user_groups_for_permission_type(2)
14
+ end
15
+
16
+ # Returns the Array of the names of the user groups to which root permission has been granted
17
+ def self.root
18
+ user_groups_for_permission_type(3)
19
+ end
20
+
21
+ # Returns the Array of the names of the user groups to which the children creation permission has been granted.
22
+ def self.create_children
23
+ user_groups_for_permission_type(4)
24
+ end
25
+
26
+ # Returns the Array of the names of the user groups to which live read permission has been granted.
27
+ def self.live
28
+ user_groups_for_permission_type(5)
29
+ end
30
+
31
+ def self.user_groups_for_permission_type(permission_type)
32
+ # Field name "user_login" is a legacy from CM tables.
33
+ # Actually the field contains the user group.
34
+ select(:user_login).where(permission_type: permission_type).map(&:user_login)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ module RailsConnector
2
+ def self.rack_middlewares
3
+ [RailsConnector::CacheMiddleware]
4
+ end
5
+ end
@@ -0,0 +1,78 @@
1
+ require "search_request"
2
+
3
+ module RailsConnector
4
+ # This module accesses the Infopark Search Engine Server.
5
+ # @api public
6
+ module SES
7
+ autoload :VerityAccessor, "rails_connector/ses/verity_accessor"
8
+
9
+ # This method enables Obj to perform searches using the SES Search Engine Server.
10
+ def self.enable
11
+ ::Obj.extend Obj::ClassMethods
12
+ end
13
+
14
+ module Obj
15
+ # Extends the model class Obj with the class method find_with_ses.
16
+ module ClassMethods
17
+ # Queries the search engine and returns a SearchResult. The parameters
18
+ # are passed on to a SearchRequest (a kind of DefaultSearchRequest by default).
19
+ #
20
+ # Exceptions:
21
+ # * SearchError - The search engine reported an error.
22
+ #
23
+ def find_with_ses(query_string, options = {})
24
+ SearchRequest.new(query_string, options).fetch_hits
25
+ end
26
+ end
27
+ end
28
+
29
+ class SearchError < StandardError
30
+ end
31
+
32
+ # SearchResult is the list of hits in response to a search query. Since the
33
+ # maximum number of hits to return has been specified, there might be more
34
+ # hits available in the search engine.
35
+ # @api public
36
+ class SearchResult < Array
37
+ # The total number of hits.
38
+ # @api public
39
+ attr_reader :total_hits
40
+
41
+ def initialize(total_hits)
42
+ super()
43
+ @total_hits = total_hits
44
+ end
45
+ end
46
+
47
+ # A hit represents a found document for a particular search query.
48
+ # @api public
49
+ class Hit
50
+ # The ID of the found Obj.
51
+ # @api public
52
+ attr_reader :id, :score, :doc
53
+
54
+ # The score of the hit.
55
+ # @api public
56
+
57
+ # The raw result hash returned by the search engine, for a low-level access.
58
+ # Don't use this unless you know what you're doing.
59
+ # Be aware that this is not migration safe.
60
+ # @api public
61
+
62
+ def initialize(id, score, doc = {}, obj = nil)
63
+ @id = id
64
+ @score = score
65
+ @doc = doc
66
+ @obj = obj
67
+ end
68
+
69
+ # Returns the hit's corresponding Obj (or nil if none found in the database).
70
+ # @api public
71
+ def obj
72
+ @obj ||= ::Obj.find(@id)
73
+ rescue RailsConnector::ResourceNotFound
74
+ nil
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,127 @@
1
+ require "builder"
2
+
3
+ module RailsConnector
4
+ module SES
5
+ class VerityAccessor
6
+ require "net/http"
7
+ require "uri"
8
+ require "rexml/document"
9
+
10
+ #--
11
+ # Options: see VeritySearchRequest
12
+ #++
13
+ def initialize(query, options = {})
14
+ @query = query
15
+ @options = {
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
26
+ }.merge(options)
27
+ @options[:collections] = Array(options[:collection]).flatten if options.has_key?(:collection)
28
+ end
29
+
30
+ # Queries the SES and returns a SearchResult.
31
+ #
32
+ # Exceptions:
33
+ # * SearchError - SES reported an error.
34
+ #
35
+ def search
36
+ parse_response_payload(send_to_ses(build_request_payload))
37
+ end
38
+
39
+ private
40
+
41
+ def build_request_payload
42
+ x = Builder::XmlMarkup.new
43
+ x.instruct!
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
56
+ x.start @options[:offset].to_i + 1
57
+ x.length @options[:limit]
58
+ end
59
+ x.minRelevance @options[:min_relevance]
60
+ x.maxDocs @options[:max_docs]
61
+
62
+ unless @options[:sort_order].blank?
63
+ x.sortOrder do
64
+ @options[:sort_order].each do |attribute, direction|
65
+ x.sortField attribute, direction: direction
66
+ end
67
+ end
68
+ end
69
+
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
77
+ end
78
+
79
+ def send_to_ses(payload)
80
+ res = Net::HTTP.new(@options[:host], @options[:port].to_i).start do |http|
81
+ req = Net::HTTP::Post.new("/xml")
82
+ req.body = payload
83
+ http.request(req)
84
+ end
85
+ res.body
86
+ end
87
+
88
+ def parse_response_payload(response)
89
+ xml = REXML::Document.new(response)
90
+ if xml.elements["/ses-payload/ses-response/ses-code"].attributes["numeric"] == "200"
91
+ build_successful_result(xml)
92
+ else
93
+ handle_error(xml)
94
+ end
95
+ end
96
+
97
+ def build_successful_result(response)
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)
101
+ if hit.obj.present?
102
+ result << hit
103
+ else
104
+ Rails.logger.warn("OBJ with ID ##{record.elements["objId"].text.to_i} not found: This search result will not be shown")
105
+ end
106
+ end
107
+ result
108
+ end
109
+
110
+ # SES raises these errors:
111
+ # 100171: ERROR_SYSTEM_SES_INTERNALVERITYERROR_DS
112
+ # 100230: ERROR_SYSTEM_SES_VERITYERROR_DS
113
+ # 100099: ERROR_SYSTEM_SES_DUPLICATECOLLETION_S
114
+ # 100173: ERROR_SYSTEM_SES_OPENCOLLECTIONFAILED
115
+ # 100103: ERROR_SYSTEM_SEARCHENGINE_SESSIONNEWFAILED
116
+ # 100177: ERROR_SYSTEM_SEARCHENGINE_BULKSUBMITFAILED
117
+ def handle_error(response)
118
+ msg = ""
119
+ response.elements.each("/ses-payload/ses-response/ses-code/errorStack/error") do |error|
120
+ msg << error.elements["phrase"].text
121
+ msg << "\n"
122
+ end
123
+ raise SearchError, msg
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,26 @@
1
+ module RailsConnector
2
+ # adds flavour to strings
3
+ module StringTagging
4
+ # html flavour
5
+ def self.tag_as_html(string, source)
6
+ unless string.blank?
7
+ class << string
8
+ include RailsConnector::HtmlString
9
+ end
10
+ string.source = source
11
+ end
12
+ string
13
+ end
14
+
15
+ # markdown flavour
16
+ def self.tag_as_markdown(string, source)
17
+ unless string.blank?
18
+ class << string
19
+ include RailsConnector::MarkdownString
20
+ end
21
+ string.source = source
22
+ end
23
+ string
24
+ end
25
+ end
26
+ end