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,28 @@
1
+ module RailsConnector
2
+ # @api public
3
+ class LinkList < Array
4
+ def initialize(link_definitions)
5
+ if link_definitions.blank?
6
+ super([])
7
+ else
8
+ super(build_links(link_definitions.map(&:symbolize_keys)))
9
+ end
10
+ end
11
+
12
+ # @api public
13
+ def destination_objects
14
+ map { |link| link.destination_object }.compact
15
+ end
16
+
17
+ private
18
+
19
+ def build_links(link_definitions)
20
+ object_ids = link_definitions.map { |link_data| link_data[:destination] }.compact.uniq
21
+ objects = object_ids.empty? ? [] : Obj.find(object_ids)
22
+ link_definitions.each_with_object([]) do |link_data, links|
23
+ link = Link.new(link_data, objects.detect { |o| o && o.id == link_data[:destination] })
24
+ links << link if link.active?
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ module RailsConnector
2
+ module LinkResolvable
3
+ attr_accessor :source
4
+ end
5
+ end
@@ -0,0 +1,102 @@
1
+ require "rsolr"
2
+
3
+ module RailsConnector
4
+ # This class provides a basic implementation for accessing a Solr search server.
5
+ # It can be activated by making it the superclass of SearchRequest
6
+ # (instead of DefaultSearchRequest).
7
+ # It should be customized by subclassing.
8
+ class LuceneSearchRequest
9
+ attr_reader :query_string
10
+
11
+ # Sanitizes the given +query_string+ and takes +options+ for accessing Solr.
12
+ #
13
+ # +options+ is a hash and may include:
14
+ #
15
+ # <tt>:limit</tt>:: The maximum number of hits
16
+ # <tt>:offset</tt>:: The search offset
17
+ # <tt>:solr_url</tt>:: A non-default Solr server URL
18
+ # <tt>:filter_query</tt>:: See #filter_query_conditions
19
+ # <tt>:solr_parameters</tt>:: A hash of additional query parameters (e. g. +timeAllowed+, +sort+)
20
+ # <tt>:lazy_load</tt>:: when set to false (the default), the hits will load their associated Objs immediatley. Otherwise they will be loaded lazyly (when accessed through Hit#obj). Note that loading lazyly may expose hits that do not have an Obj, i.e. they return nil when Hit#obj is invoked. When loading immediately, those hits are filtered.
21
+ def initialize(query_string, options = nil)
22
+ @query_string = self.class.sanitize(query_string)
23
+ @options = Configuration.search_options.merge(options || {})
24
+ end
25
+
26
+ # Accesses Solr and fetches search hits.
27
+ #
28
+ # Uses the #filter_query and +options+ given in #new.
29
+ def fetch_hits
30
+ solr = RSolr.connect(url: @options[:solr_url])
31
+ solr_result = solr.get("select", params: solr_query_parameters)
32
+ solr_response = solr_result["response"]
33
+ build_search_result(solr_response["numFound"], solr_response["docs"], solr_response["maxScore"])
34
+ end
35
+
36
+ # Removes unwanted characters from +text+.
37
+ def self.sanitize(text)
38
+ text.gsub(/[^\w*]/, " ").gsub(/\s+/, " ").strip
39
+ end
40
+
41
+ def solr_query_for_query_string
42
+ @query_string.downcase.split(/\s+/).map do |word|
43
+ word unless %w(and or not).include?(word)
44
+ end.compact.join(" AND ")
45
+ end
46
+
47
+ # Combines filter query conditions (see #filter_query_conditions).
48
+ #
49
+ # A filter query is used to reduce the number of documents before executing the actual query.
50
+ # By default, all filter query conditions must be met, each is passed on as a separate filter query.
51
+ def filter_query
52
+ filter_query_conditions.values.compact
53
+ end
54
+
55
+ # A hash of conditions, combined to a filter query by #filter_query.
56
+ # Note that all values of the hash must be valid Solr syntax.
57
+ # The keys have no meaning and exist only so single conditions can be replaced
58
+ # in a subclass:
59
+ #
60
+ # class SearchRequest < LuceneSearchRequest
61
+ # def filter_query_conditions
62
+ # super.merge(:subset => 'path:/de/*')
63
+ # end
64
+ # end
65
+ def filter_query_conditions
66
+ conditions = {}
67
+ conditions[:object_type] = "NOT object_type:image"
68
+ conditions[:suppress_export] = "NOT suppress_export:1"
69
+ now = Time.now
70
+ conditions[:valid_from] = "NOT valid_from:[#{(now + 1.second).to_iso} TO *]"
71
+ conditions[:valid_until] = "NOT valid_until:[* TO #{now.to_iso}]"
72
+ conditions.merge(@options[:filter_query] || {})
73
+ end
74
+
75
+ private
76
+
77
+ def solr_query_parameters
78
+ {
79
+ q: solr_query_for_query_string,
80
+ fq: filter_query,
81
+ fl: "id,score",
82
+ start: @options[:offset],
83
+ rows: @options[:limit]
84
+ }.merge(@options[:solr_parameters] || {})
85
+ end
86
+
87
+ def build_search_result(total_hits, docs, max_score)
88
+ result = SES::SearchResult.new(total_hits)
89
+ docs.each do |doc|
90
+ id = doc["id"]
91
+ score = doc["score"] / max_score
92
+ hit = SES::Hit.new(id, score, doc)
93
+ if @options[:lazy_load].blank? && hit.obj.blank?
94
+ Rails.logger.warn("OBJ with ID ##{doc["id"]} not found: This search result will not be shown")
95
+ else
96
+ result << hit
97
+ end
98
+ end
99
+ result
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,17 @@
1
+ module RailsConnector
2
+ # Include this module in order to tag the string as one with Markdown content
3
+ module MarkdownString
4
+ include LinkResolvable
5
+ # Returns whether the String contains Markdown (default to true, overrides String.markdown?).
6
+ def markdown?
7
+ true
8
+ end
9
+ end
10
+ end
11
+
12
+ class String
13
+ # Returns whether the String contains Markdown (default to false).
14
+ def markdown?
15
+ false
16
+ end
17
+ end
@@ -0,0 +1,143 @@
1
+ module RailsConnector
2
+ module Meta
3
+ # This method is an equivalent of Rails.logger.silence, which has been deprecated
4
+ def self.hello_im_rails_and_im_retarted_so_please_be_patient
5
+ old_logger_level = Rails.logger.level
6
+ Rails.logger.level = Logger::ERROR
7
+ yield self
8
+ ensure
9
+ Rails.logger.level = old_logger_level
10
+ end
11
+
12
+ def self.included(base) #:nodoc:
13
+ # Class enhancements
14
+ base.extend(ClassMethods)
15
+ end
16
+
17
+ # The RailsConnector::ObjClass object for this file format.
18
+ # This will always return a proper object, even if no custom
19
+ # Ruby class exists.
20
+ def obj_class_definition
21
+ @obj_class_definition ||= RailsConnector::Meta::EagerLoader.instance.obj_class(obj_class)
22
+ end
23
+ alias_method :obj_class_def, :obj_class_definition
24
+
25
+ # Returns true, if there is a custom Ruby class defined for the object
26
+ # or false, if it is represented by RailsConnector::Obj
27
+ def has_custom_ruby_class?
28
+ self.class.is_custom_ruby_class?
29
+ end
30
+
31
+ # Returns the custom attributes in the form of a Hash.
32
+ def custom_attributes
33
+ obj_class_definition.custom_attributes
34
+ end
35
+
36
+ # Returns true, if the file format has an attribute of the given name.
37
+ def custom_attribute?(attr)
38
+ obj_class_definition.custom_attribute?(attr)
39
+ end
40
+
41
+ # Returns an Array of String of all mandatory attributes, no mather if it's
42
+ # custom or built-in. Built-in attributes are underscored (valid_from,
43
+ # not validFrom).
44
+ # Possible +options+ are:
45
+ # <tt>:only_custom_attributes</tt>:: Return only custom attributes, omit
46
+ # built-in attributes like content_type or valid_from.
47
+ def mandatory_attribute_names(options = {})
48
+ obj_class_definition.mandatory_attribute_names(options)
49
+ end
50
+
51
+ # Returns true, if the file format has an mandatory attribute of the given name.
52
+ def mandatory_attribute?(attr)
53
+ obj_class_definition.mandatory_attribute?(attr)
54
+ end
55
+
56
+ # Returns the version of this object. This number is increased every time
57
+ # this object is released.
58
+ def version
59
+ load_meta_details
60
+ @object_with_meta_data.version.presence.to_i || 0
61
+ end
62
+
63
+ # Returns the time of the reminder, if it is set.
64
+ def reminder_from
65
+ load_meta_details
66
+ @object_with_meta_data.reminder_from.presence &&
67
+ ::ActiveModel::Type::DateTime.new.deserialize(@object_with_meta_data.reminder_from)
68
+ end
69
+
70
+ # Returns the reminder comment, if a reminder is set.
71
+ def reminder_comment
72
+ load_meta_details
73
+ @object_with_meta_data.reminder_comment
74
+ end
75
+
76
+ # Return the name of the workflow, that is assigned to this object.
77
+ def workflow_name
78
+ load_meta_details
79
+ @object_with_meta_data.workflow_name
80
+ end
81
+
82
+ # Return the current editor as a String. If there is no edited content,
83
+ # which is always the case in live mode, an empty String is returned.
84
+ # The 'contents' table is queried for this information.
85
+ def editor
86
+ return @editor if @editor
87
+
88
+ load_meta_details
89
+
90
+ content_id =
91
+ if edited?
92
+ @object_with_meta_data.edited_content_id
93
+ else
94
+ @object_with_meta_data.released_cont_id
95
+ end
96
+
97
+ if content_id
98
+ content = RailsConnector::Content.find(content_id)
99
+ @editor = content.editor
100
+ else
101
+ @editor = ""
102
+ end
103
+ end
104
+
105
+ def committed?
106
+ load_meta_details
107
+ !@object_with_meta_data.committed_cont_id.nil?
108
+ end
109
+
110
+ private
111
+
112
+ # Load the objects details from the `objects' tables.
113
+ def load_meta_details #:nodoc:
114
+ return if @object_with_meta_data
115
+
116
+ @object_with_meta_data = RailsConnector::ObjectWithMetaData.find(id)
117
+
118
+ # reset depending instance variables
119
+ @editor = nil
120
+ end
121
+
122
+ # the methods in this module will become class methods
123
+ module ClassMethods
124
+ # The RailsConnector::ObjClass object for this file format.
125
+ # This will only return a proper object if a custom Ruby class exists
126
+ # and will throw a RuntimeError otherwise.
127
+ def obj_class_definition
128
+ unless is_custom_ruby_class?
129
+ raise "Obtaining the obj_class_definition of an Obj without custom Ruby class " \
130
+ "is logically impossible."
131
+ end
132
+ @obj_class_definition ||= RailsConnector::Meta::EagerLoader.instance.obj_class(name)
133
+ end
134
+ alias_method :obj_class_def, :obj_class_definition
135
+
136
+ # RailsConnector::AbstractObj returns false, everything else true.
137
+ # TODO: RailsConnector::AbstractObj does not exist here
138
+ def is_custom_ruby_class?
139
+ self != RailsConnector::BasicObj
140
+ end
141
+ end
142
+ end
143
+ end
@@ -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
@@ -0,0 +1,90 @@
1
+ module RailsConnector
2
+ # This class provides methods used to retrieve objects from CMS based an entry
3
+ # in CMS of the obj_class <tt>NamedLink</tt>.
4
+ # @api public
5
+ class NamedLink
6
+ LINKLIST_NAME = "related_links".freeze
7
+
8
+ # @api public
9
+ class NotFound < StandardError
10
+ end
11
+
12
+ @@named_links_cache = nil
13
+ @@updated_at = nil
14
+ @@cache_expiry_time = nil
15
+
16
+ # Generates a cache of named links based on the CMS objects related link list.
17
+ # Raises exceptions if zero or more than one objects have this obj_class
18
+ def self.generate_named_links_cache
19
+ return if @@named_links_cache
20
+
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")
35
+ Rails.logger.warn "Couldn't find NamedLink CMS Object!" if found_objects.empty?
36
+ Rails.logger.warn "More than one NamedLink CMS Object found!" if found_objects.size > 1
37
+
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
45
+
46
+ @@updated_at = Time.now
47
+ nil
48
+ end
49
+
50
+ # Sets the time in minutes after which the cache will be expired.
51
+ # The default expiry time is set to 1 minute
52
+ # @api public
53
+ def self.cache_expiry_time=(value)
54
+ @@cache_expiry_time = value
55
+ end
56
+
57
+ def self.cache_expiry_time
58
+ @@cache_expiry_time || 1
59
+ end
60
+
61
+ def self.cache_expired?
62
+ @@updated_at.nil? || @@updated_at <= cache_expiry_time.minute.ago
63
+ end
64
+
65
+ # Returns the CMS object mapped to the given title or nil.
66
+ # The title can be a string of symbol.
67
+ # If :cache => false is provided, the object will not be fetched from the cache.
68
+ # @api public
69
+ def self.get_object(title, options = {})
70
+ object = named_links[title.to_s]
71
+ raise NotFound, "The NamedLink '#{title}' does not exist" if object.nil?
72
+
73
+ options[:cache] == false ? object.reload : object
74
+ end
75
+
76
+ def self.reset_cache
77
+ @@named_links_cache = nil
78
+ end
79
+
80
+ def self.named_links
81
+ reset_cache if cache_expired?
82
+ generate_named_links_cache unless named_links_cache
83
+ named_links_cache
84
+ end
85
+
86
+ def self.named_links_cache
87
+ @@named_links_cache
88
+ end
89
+ end
90
+ end