infopark_cloud_connector 6.8.0.110.6570b45 → 6.8.0.210.ed204b0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,46 @@
1
+ module RailsConnector
2
+
3
+ module MarkerHelper # :nodoc:
4
+
5
+ def edit_marker(obj, attr, options = {}, &block)
6
+ if Configuration.editor_interface_enabled?
7
+ default_value = options.delete(:default_value)
8
+
9
+ if block_given?
10
+ content = block.call(obj, attr)
11
+ content = default_value || raw(" ") if content.blank?
12
+ end
13
+
14
+ tag_type = options.delete(:tag) || :span
15
+ content_tag(
16
+ tag_type,
17
+ content.to_s,
18
+ options
19
+ )
20
+ else
21
+ block_given? ? block.call(obj, attr) : nil
22
+ end
23
+ end
24
+
25
+ def marker_menu(left=0, top=0, &block)
26
+ end
27
+
28
+ def marker_menu_target(tag_name, options = {}, &block)
29
+ content_tag(
30
+ tag_name,
31
+ capture(&block),
32
+ options
33
+ )
34
+ end
35
+
36
+ def include_edit_marker_support
37
+ end
38
+
39
+ def render_marker_code
40
+ end
41
+
42
+ private
43
+
44
+ end
45
+
46
+ end
@@ -15,3 +15,5 @@ module RailsConnector
15
15
 
16
16
  autoload_all_sources
17
17
  end
18
+
19
+ require "rails_connector/cloud_engine" if defined?(Rails)
@@ -0,0 +1,5 @@
1
+ module ::RailsConnector
2
+ class CloudEngine < Rails::Engine #:nodoc:
3
+ end
4
+ end
5
+
@@ -1,5 +1,3 @@
1
- require 'restclient'
2
-
3
1
  module RailsConnector
4
2
 
5
3
  # This class provides a basic implementation for accessing the search using the cms api.
@@ -13,9 +11,6 @@ module RailsConnector
13
11
  #
14
12
  # <tt>:limit</tt>:: The maximum number of hits
15
13
  # <tt>:offset</tt>:: The search offset
16
- # <tt>:url</tt>:: The URL to the CMS API search
17
- # <tt>:login</tt>:: The login for the CMS API search
18
- # <tt>:api_key</tt>:: The api_key for the CMS API search
19
14
  def initialize(query_string, options = {})
20
15
  @query_string = query_string
21
16
  @options = Configuration.cms_api_options.merge(options)
@@ -23,25 +18,11 @@ module RailsConnector
23
18
 
24
19
  # Accesses Cms Api Search using #query and fetches search hits.
25
20
  def fetch_hits
26
- headers = {
27
- :content_type => :json,
28
- :accept => :json,
29
- }
30
- headers[:host] = @options[:http_host] if @options[:http_host].present?
31
- hits = MultiJson.decode(
32
- RestClient::Request.execute({
33
- :method => :get,
34
- :url => url,
35
- :user => @options[:login],
36
- :password => @options[:api_key],
37
- :headers => headers,
38
- :payload => MultiJson.encode({
39
- :query => query,
40
- :offset => @options[:offset],
41
- :size => @options[:limit],
42
- }),
43
- })
44
- )
21
+ hits = CmsRestApi.get(resource_path, {
22
+ :query => query,
23
+ :offset => @options[:offset],
24
+ :size => @options[:limit],
25
+ })
45
26
 
46
27
  result = SES::SearchResult.new(hits['total'])
47
28
  hits['results'].each do |hit|
@@ -53,8 +34,8 @@ module RailsConnector
53
34
 
54
35
  private
55
36
 
56
- def url
57
- "#{@options[:url]}/revisions/#{Workspace.current.revision_id}/objs/search"
37
+ def resource_path
38
+ "revisions/#{Workspace.current.revision_id}/objs/search"
58
39
  end
59
40
 
60
41
  def query
@@ -3,9 +3,9 @@ module RailsConnector
3
3
  class CmsBackend
4
4
 
5
5
  def self.current
6
- @current ||=
7
- DynamoCmsBackend.new
8
- # ServiceCmsBackend.new
6
+ @current ||= begin
7
+ RailsConnector::Configuration.content_service ? ServiceCmsBackend.new : DynamoCmsBackend.new
8
+ end
9
9
  end
10
10
 
11
11
  def self.begin_caching
@@ -16,14 +16,22 @@ module RailsConnector
16
16
  current.end_caching
17
17
  end
18
18
 
19
- def self.find_obj_data_by(workspace, index, keys)
20
- current.find_obj_data_by(workspace, index, keys)
19
+ def self.find_obj_data_by(workspace_data, index, keys)
20
+ current.find_obj_data_by(workspace_data, index, keys)
21
+ end
22
+
23
+ def self.find_workspace_data_by_id(id)
24
+ current.find_workspace_data_by_id(id)
21
25
  end
22
26
 
23
27
  def self.caching?
24
28
  current.caching?
25
29
  end
26
30
 
31
+ def self.query_counter
32
+ current.query_counter
33
+ end
34
+
27
35
  end
28
36
 
29
37
  end
@@ -0,0 +1,75 @@
1
+ require 'restclient'
2
+
3
+ module RailsConnector
4
+
5
+ # Provides a simple wrapper for the CMS Rest API
6
+ # using the credentials from {RailsConnector::Configuration.cms_api_options}.
7
+ #
8
+ # @example Request the published workspace:
9
+ # RailsConnector::CmsRestApi.get('workspaces/published')
10
+ #
11
+ # @example Create a new Obj:
12
+ # RailsConnector::CmsRestApi.post('revisions/001384beff9e5845/objs',
13
+ # {'obj' => {'_path' => '/new_obj', '_obj_class' => 'Publication'}})
14
+ #
15
+ # @example Update an Obj:
16
+ # RailsConnector::CmsRestApi.put('revisions/001384beff9e5845/objs/9e432077f0412a63',
17
+ # {'obj' => {'title' => 'new title'}})
18
+ #
19
+ # @example Delete an Obj:
20
+ # RailsConnector::CmsRestApi.delete('revisions/001384beff9e5845/objs/f4123622ff07b70b')
21
+ #
22
+ # @api private
23
+ class CmsRestApi
24
+
25
+ def self.get(resource_path, payload = nil)
26
+ request_cms_api(:get, resource_path, payload)
27
+ end
28
+
29
+ def self.put(resource_path, payload)
30
+ request_cms_api(:put, resource_path, payload)
31
+ end
32
+
33
+ def self.post(resource_path, payload)
34
+ request_cms_api(:post, resource_path, payload)
35
+ end
36
+
37
+ def self.delete(resource_path)
38
+ request_cms_api(:delete, resource_path, nil)
39
+ end
40
+
41
+ private
42
+
43
+ def self.request_cms_api(action, resource_path, payload)
44
+ request_params = basic_request_params
45
+ request_params[:method] = action
46
+ request_params[:url] = url(resource_path)
47
+ request_params[:payload] = MultiJson.encode(payload) if payload.present?
48
+
49
+ MultiJson.decode(RestClient::Request.execute(request_params))
50
+ end
51
+
52
+ def self.credentials
53
+ RailsConnector::Configuration.cms_api_options
54
+ end
55
+
56
+ def self.basic_request_params
57
+ headers = {
58
+ :content_type => :json,
59
+ :accept => :json,
60
+ }
61
+ headers[:host] = credentials[:http_host] if credentials[:http_host].present?
62
+
63
+ {
64
+ :user => credentials[:login],
65
+ :password => credentials[:api_key],
66
+ :headers => headers,
67
+ }
68
+ end
69
+
70
+ def self.url(resource_path)
71
+ "#{credentials[:url]}/#{resource_path}"
72
+ end
73
+ end
74
+
75
+ end
@@ -1,10 +1,8 @@
1
- class ConnectorService
2
-
1
+ class ContentService
3
2
  def self.query(path, payload)
4
3
  MultiJson.load(RestClient::Request.execute(
5
4
  :method => :post,
6
- # FIXME
7
- :url => "localhost:3001/#{path}",
5
+ :url => "#{url}/#{path}",
8
6
  :headers => {
9
7
  :content_type => :json,
10
8
  :accept => :json,
@@ -13,4 +11,12 @@ class ConnectorService
13
11
  ))
14
12
  end
15
13
 
14
+ private
15
+
16
+ def self.url
17
+ @url ||= begin
18
+ config = RailsConnector::Configuration.content_service
19
+ "#{config['login']}:#{config['api_key']}@#{config['url']}"
20
+ end
21
+ end
16
22
  end
@@ -3,6 +3,10 @@ module RailsConnector
3
3
  class DynamoCmsBackend
4
4
  CACHE_PREFIX = 'revision'
5
5
 
6
+ def initialize
7
+ @query_counter = 0
8
+ end
9
+
6
10
  def begin_caching
7
11
  @editable_cache = Configuration.cache_editable_workspaces ? persistent_cache : Cache.new
8
12
  @read_only_cache = persistent_cache
@@ -12,8 +16,12 @@ module RailsConnector
12
16
  @editable_cache = @read_only_cache = nil
13
17
  end
14
18
 
15
- def find_obj_data_by(workspace, index, keys)
16
- revision = workspace.revision
19
+ def find_workspace_data_by_id(id)
20
+ WorkspaceDataFromDatabase.find(id)
21
+ end
22
+
23
+ def find_obj_data_by(workspace_data, index, keys)
24
+ revision = workspace_data.revision
17
25
  raw_data =
18
26
  if caching?
19
27
  find_obj_data_from_cache_or_database_by(revision, index, keys)
@@ -32,6 +40,10 @@ module RailsConnector
32
40
  @read_only_cache && @editable_cache
33
41
  end
34
42
 
43
+ def query_counter
44
+ @query_counter
45
+ end
46
+
35
47
  private
36
48
 
37
49
  def persistent_cache
@@ -40,6 +52,7 @@ module RailsConnector
40
52
 
41
53
  def find_obj_data_from_database_by(revision, index, keys)
42
54
  return [] if keys.blank?
55
+ @query_counter += 1
43
56
  instrumenter = ActiveSupport::Notifications.instrumenter
44
57
  instrumenter.instrument(
45
58
  "cms_load.rails_connector", :name => "Obj Load", :index => index, :keys => keys
@@ -99,7 +99,7 @@ module RailsConnector
99
99
  # accepts the name of an "obj_by" - view and a list of keys.
100
100
  # returns a list of lists of Objs: a list of Objs for each given keys.
101
101
  def self.find_objs_by(view, keys) # :nodoc:
102
- CmsBackend.find_obj_data_by(Workspace.current, view, keys).map do |list|
102
+ CmsBackend.find_obj_data_by(Workspace.current.data, view, keys).map do |list|
103
103
  list.map { |obj_data| Obj.instantiate(obj_data) }
104
104
  end
105
105
  end
@@ -434,7 +434,7 @@ module RailsConnector
434
434
  # Notice that the ruby class of this Obj instance will NOT change,
435
435
  # even if the obj_class in the database has changed.
436
436
  def reload
437
- obj_data = CmsBackend.find_obj_data_by(Workspace.current, :id, [id.to_s]).first.first
437
+ obj_data = CmsBackend.find_obj_data_by(Workspace.current.data, :id, [id.to_s]).first.first
438
438
  update_data(obj_data)
439
439
  end
440
440
 
@@ -4,27 +4,91 @@ module RailsConnector
4
4
 
5
5
  # connects the cloud connector to the connector service
6
6
  class ServiceCmsBackend < CmsBackend
7
+ CACHE_PREFIX = 'v1'
8
+
9
+ def initialize
10
+ @query_counter = 0
11
+ end
7
12
 
8
13
  def begin_caching
9
- # TODO
14
+ @editable_cache = Configuration.cache_editable_workspaces ? persistent_cache : Cache.new
15
+ @read_only_cache = persistent_cache
10
16
  end
11
17
 
12
18
  def end_caching
13
- # TODO
19
+ @editable_cache = @read_only_cache = nil
14
20
  end
15
21
 
16
22
  def caching?
17
- # TODO
23
+ @read_only_cache && @editable_cache
24
+ end
25
+
26
+ def query_counter
27
+ @query_counter
28
+ end
29
+
30
+ def find_workspace_data_by_id(id)
31
+ raw_data = ContentService.query(
32
+ "workspaces/query",
33
+ :workspace_id => id
34
+ )
35
+ raw_workspace_data = raw_data["workspace"] or raise "Workspace Data missing"
36
+ WorkspaceDataFromService.new(raw_workspace_data)
37
+ end
38
+
39
+ def find_obj_data_by(workspace_data, index, keys)
40
+ raw_data =
41
+ if caching?
42
+ find_raw_data_from_cache_or_database_by(workspace_data, index, keys)
43
+ else
44
+ find_raw_data_from_database_by(workspace_data, index, keys)
45
+ end
46
+
47
+ raw_data.map do |raw_list|
48
+ raw_list.map do |raw_obj_data|
49
+ ObjDataFromService.new(raw_obj_data)
50
+ end
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def persistent_cache
57
+ Cache.new(:fallback_backend => Rails.cache, :cache_prefix => CACHE_PREFIX)
58
+ end
59
+
60
+ def find_raw_data_from_cache_or_database_by(workspace_data, index, keys)
61
+ keys_from_database = []
62
+ # load results from cache
63
+ results_from_cache = keys.map do |key|
64
+ cache_for(workspace_data).read(cache_key_for(workspace_data, index, key)).tap do |objs|
65
+ keys_from_database << key unless objs
66
+ end
67
+ end
68
+
69
+ # load cache misses from database and store them in cache
70
+ results_from_database =
71
+ find_raw_data_from_database_by(workspace_data, index, keys_from_database)
72
+ keys_from_database.each_with_index do |key, key_number|
73
+ store_raw_data_list_in_cache(workspace_data, index, key, results_from_database[key_number])
74
+ end
75
+
76
+ # combine the results
77
+ results_from_cache.map do |objs_from_cache|
78
+ objs_from_cache || results_from_database.shift
79
+ end
18
80
  end
19
81
 
20
- def find_obj_data_by(workspace, index, keys)
21
- raw_data = ConnectorService.query(
82
+ def find_raw_data_from_database_by(workspace_data, index, keys)
83
+ return [] if keys.blank?
84
+ @query_counter += 1
85
+ raw_data = ContentService.query(
22
86
  "objs/query",
23
87
  :queries => keys.map do |key|
24
88
  { :type => index, :param => key }
25
89
  end,
26
- :workspace => workspace.id,
27
- :revision => workspace.revision.id
90
+ :workspace_id => workspace_data.id,
91
+ :revision_id => workspace_data.revision_id
28
92
  )
29
93
 
30
94
  objs = {}
@@ -37,12 +101,36 @@ module RailsConnector
37
101
  id = obj_ref["id"]
38
102
 
39
103
  # TODO fetch missing ObjData from Service
40
- raw_obj_data = objs[id] or raise "Data for Obj with id #{id} missing!"
41
- ObjDataFromService.new(raw_obj_data)
104
+ objs[id] or raise "Data for Obj with id #{id} missing!"
42
105
  end
43
106
  end
44
107
  end
45
108
 
109
+ UNIQUE_INDICES = [:id, :path, :permalink].freeze
110
+
111
+ def store_raw_data_list_in_cache(workspace_data, index, key, raw_data_list)
112
+ raw_data_list.each do |values|
113
+ UNIQUE_INDICES.each do |unique_index|
114
+ store_item_in_cache(workspace_data, unique_index, values["_#{unique_index}"], [values])
115
+ end
116
+ end
117
+ unless UNIQUE_INDICES.include?(index)
118
+ store_item_in_cache(workspace_data, index, key, raw_data_list)
119
+ end
120
+ end
121
+
122
+ def store_item_in_cache(workspace_data, index, key, item)
123
+ cache_for(workspace_data).write(cache_key_for(workspace_data, index, key), item) if caching?
124
+ end
125
+
126
+ def cache_key_for(workspace_data, index, key)
127
+ "rev/#{workspace_data.revision_id}/obj/#{index}/#{key}"
128
+ end
129
+
130
+ def cache_for(workspace_data)
131
+ workspace_data.cachable? ? @read_only_cache : @editable_cache
132
+ end
133
+
46
134
  end
47
135
 
48
136
  end
@@ -1,10 +1,9 @@
1
1
  #:enddoc:
2
2
  module RailsConnector
3
3
 
4
- class Workspace < CmsBaseModel
5
- self.key_prefix = "ws"
6
-
7
- property :revision_id
4
+ class Workspace
5
+ extend ActiveModel::Naming
6
+ include Kvom::ModelIdentity
8
7
 
9
8
  def self.current=(workspace_or_proc)
10
9
  @current = workspace_or_proc
@@ -22,12 +21,34 @@ class Workspace < CmsBaseModel
22
21
  find("published")
23
22
  end
24
23
 
24
+ def self.find(id)
25
+ Workspace.new(CmsBackend.find_workspace_data_by_id(id))
26
+ end
27
+
28
+ def initialize(workspace_data)
29
+ @workspace_data = workspace_data
30
+ end
31
+
32
+ def id
33
+ @workspace_data.id
34
+ end
35
+
36
+ def revision_id
37
+ @workspace_data.revision_id
38
+ end
39
+
40
+ def data
41
+ @workspace_data
42
+ end
43
+
44
+ # only available with direct access to dynamo
25
45
  def revision
26
- @revision ||= Revision.find(revision_id)
46
+ @workspace_data.revision
27
47
  end
28
48
 
29
- def content_cache_id=(cc)
30
- revision.content_cache_id = cc
49
+ # only available with direct access to dynamo
50
+ def content_cache_id=(id)
51
+ @workspace_data.content_cache_id = id
31
52
  end
32
53
 
33
54
  end
@@ -0,0 +1,20 @@
1
+ #:enddoc:
2
+ module RailsConnector
3
+
4
+ class WorkspaceDataFromDatabase < CmsBaseModel
5
+
6
+ self.key_prefix = "ws"
7
+
8
+ property :revision_id
9
+
10
+ def revision
11
+ @revision ||= Revision.find(revision_id)
12
+ end
13
+
14
+ def content_cache_id=(id)
15
+ revision.content_cache_id = id
16
+ end
17
+
18
+ end
19
+
20
+ end # module RailsConnector
@@ -0,0 +1,27 @@
1
+ #:enddoc:
2
+ module RailsConnector
3
+
4
+ class WorkspaceDataFromService
5
+ def initialize(data)
6
+ @data = data
7
+ end
8
+
9
+ def revision_id
10
+ @data["revision_id"]
11
+ end
12
+
13
+ def id
14
+ @data["id"]
15
+ end
16
+
17
+ def cachable?
18
+ @data["is_cachable"]
19
+ end
20
+
21
+ # remove this method after DynamoCmsBackend has been removed from the Cloud Connector
22
+ def content_cache_id=(id)
23
+ # ignore, since not using content caches
24
+ end
25
+ end
26
+
27
+ end # module RailsConnector
metadata CHANGED
@@ -1,17 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infopark_cloud_connector
3
3
  version: !ruby/object:Gem::Version
4
- hash: 910834687
5
- prerelease: 14
4
+ hash: -847135200
5
+ prerelease: 10
6
6
  segments:
7
7
  - 6
8
8
  - 8
9
9
  - 0
10
- - 110
11
- - 6570
10
+ - 210
11
+ - ed
12
+ - 204
12
13
  - b
13
- - 45
14
- version: 6.8.0.110.6570b45
14
+ - 0
15
+ version: 6.8.0.210.ed204b0
15
16
  platform: ruby
16
17
  authors:
17
18
  - Infopark AG
@@ -19,7 +20,7 @@ autorequire:
19
20
  bindir: bin
20
21
  cert_chain: []
21
22
 
22
- date: 2012-10-26 00:00:00 +02:00
23
+ date: 2012-11-06 00:00:00 +01:00
23
24
  default_executable:
24
25
  dependencies:
25
26
  - !ruby/object:Gem::Dependency
@@ -59,16 +60,17 @@ dependencies:
59
60
  requirements:
60
61
  - - "="
61
62
  - !ruby/object:Gem::Version
62
- hash: 910834687
63
+ hash: -847135200
63
64
  segments:
64
65
  - 6
65
66
  - 8
66
67
  - 0
67
- - 110
68
- - 6570
68
+ - 210
69
+ - ed
70
+ - 204
69
71
  - b
70
- - 45
71
- version: 6.8.0.110.6570b45
72
+ - 0
73
+ version: 6.8.0.210.ed204b0
72
74
  version_requirements: *id003
73
75
  name: kvom
74
76
  prerelease: false
@@ -79,19 +81,22 @@ executables: []
79
81
 
80
82
  extensions: []
81
83
 
82
- extra_rdoc_files: []
83
-
84
+ extra_rdoc_files:
85
+ - app/helpers/rails_connector/marker_helper.rb
84
86
  files:
87
+ - app/helpers/rails_connector/marker_helper.rb
85
88
  - lib/infopark_cloud_connector.rb
86
89
  - lib/rails_connector/blob.rb
87
90
  - lib/rails_connector/cache.rb
88
91
  - lib/rails_connector/cache_middleware.rb
89
92
  - lib/rails_connector/chain.rb
93
+ - lib/rails_connector/cloud_engine.rb
90
94
  - lib/rails_connector/cms_api_search_request.rb
91
95
  - lib/rails_connector/cms_backend.rb
92
96
  - lib/rails_connector/cms_base_model.rb
93
- - lib/rails_connector/connector_service.rb
97
+ - lib/rails_connector/cms_rest_api.rb
94
98
  - lib/rails_connector/content_cache.rb
99
+ - lib/rails_connector/content_service.rb
95
100
  - lib/rails_connector/controller_runtime.rb
96
101
  - lib/rails_connector/date_attribute.rb
97
102
  - lib/rails_connector/default_search_request.rb
@@ -116,6 +121,8 @@ files:
116
121
  - lib/rails_connector/service_cms_backend.rb
117
122
  - lib/rails_connector/version.rb
118
123
  - lib/rails_connector/workspace.rb
124
+ - lib/rails_connector/workspace_data_from_database.rb
125
+ - lib/rails_connector/workspace_data_from_service.rb
119
126
  - lib/rails_connector/workspace_selection_middleware.rb
120
127
  has_rdoc: true
121
128
  homepage: http://www.infopark.de