infopark_cloud_connector 6.8.0.356.19698103 → 6.8.0.406.131718077

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,8 +15,8 @@ class Cache
15
15
  value
16
16
  end
17
17
 
18
- def write(key, value)
19
- @fallback_backend.write(cache_key_for_fallback_backend(key), value) if @fallback_backend
18
+ def write(key, value, options={})
19
+ @fallback_backend.write(cache_key_for_fallback_backend(key), value, options) if @fallback_backend
20
20
  @cache[key] = value
21
21
  end
22
22
 
@@ -15,7 +15,7 @@ module RailsConnector
15
15
  # @api public
16
16
  def initialize(query_string, options = {})
17
17
  @query_string = query_string
18
- @options = Configuration.cms_api_options.merge(options)
18
+ @options = options
19
19
  end
20
20
 
21
21
  # Accesses Cms Api Search using #query and fetches search hits.
@@ -32,6 +32,10 @@ module RailsConnector
32
32
  current.query_counter
33
33
  end
34
34
 
35
+ def self.find_blob_data_by_id(id)
36
+ current.find_blob_data_by_id(id)
37
+ end
38
+
35
39
  end
36
40
 
37
41
  end
@@ -1,4 +1,5 @@
1
1
  require 'restclient'
2
+ require 'active_support/all'
2
3
 
3
4
  module RailsConnector
4
5
 
@@ -20,6 +21,8 @@ module RailsConnector
20
21
  # RailsConnector::CmsRestApi.delete('revisions/001384beff9e5845/objs/f4123622ff07b70b')
21
22
  class CmsRestApi
22
23
 
24
+ cattr_accessor :credentials
25
+
23
26
  def self.get(resource_path, payload = nil)
24
27
  request_cms_api(:get, resource_path, payload)
25
28
  end
@@ -32,8 +35,14 @@ module RailsConnector
32
35
  request_cms_api(:post, resource_path, payload)
33
36
  end
34
37
 
35
- def self.delete(resource_path)
36
- request_cms_api(:delete, resource_path, nil)
38
+ def self.delete(resource_path, payload = nil)
39
+ request_cms_api(:delete, resource_path, payload)
40
+ end
41
+
42
+ # @param [Hash] value
43
+ # @return [void]
44
+ def self.credentials=(value)
45
+ @@credentials = value.symbolize_keys
37
46
  end
38
47
 
39
48
  private
@@ -47,10 +56,6 @@ module RailsConnector
47
56
  MultiJson.decode(RestClient::Request.execute(request_params))
48
57
  end
49
58
 
50
- def self.credentials
51
- RailsConnector::Configuration.cms_api_options
52
- end
53
-
54
59
  def self.basic_request_params
55
60
  headers = {
56
61
  :content_type => :json,
@@ -7,8 +7,7 @@ class ContentService
7
7
  retry_once_on_socket_error do
8
8
  ConnectionManager.ensure_started(uri)
9
9
  request = build_request(path, payload)
10
- response = ConnectionManager.connection.request(request)
11
- MultiJson.load(response.body)
10
+ handle_response(ConnectionManager.connection.request(request))
12
11
  end
13
12
  end
14
13
 
@@ -34,6 +33,14 @@ class ContentService
34
33
  request
35
34
  end
36
35
 
36
+ def handle_response(response)
37
+ if response.code.first == '2'
38
+ MultiJson.load(response.body)
39
+ else
40
+ raise "Server responded with status code #{response.code}"
41
+ end
42
+ end
43
+
37
44
  def uri
38
45
  url = config['url']
39
46
  url = "#{DEFAULT_PROTOCOL}://#{url}" unless url.match /^http/
@@ -78,7 +85,8 @@ class ContentService
78
85
  conn = Net::HTTP.new(uri.host, uri.port)
79
86
  if uri.scheme == 'https'
80
87
  conn.use_ssl = true
81
- conn.verify_mode = OpenSSL::SSL::VERIFY_PEER
88
+ # TODO: Change to OpenSSL::SSL::VERIFY_PEER
89
+ conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
82
90
  end
83
91
  retry_twice_on_socket_error { conn.start }
84
92
  @connection = conn
@@ -18,6 +18,7 @@ module RailsConnector
18
18
 
19
19
  def find_workspace_data_by_id(id)
20
20
  WorkspaceDataFromDatabase.find(id)
21
+ rescue Kvom::NotFound
21
22
  end
22
23
 
23
24
  def find_obj_data_by(workspace_data, index, keys)
@@ -37,7 +37,7 @@ class ServiceBlob
37
37
  private
38
38
 
39
39
  def raw_data
40
- @raw_data ||= ContentService.query("blobs/query", :blob_ids => [id])["blobs"][id]
40
+ @raw_data ||= CmsBackend.find_blob_data_by_id(id)
41
41
  end
42
42
 
43
43
  def meta_data
@@ -5,6 +5,7 @@ module RailsConnector
5
5
  # connects the cloud connector to the connector service
6
6
  class ServiceCmsBackend < CmsBackend
7
7
  CACHE_PREFIX = 'v1'
8
+ BLOB_DATA_CACHE_PREFIX = 'blob_data'.freeze
8
9
 
9
10
  def initialize
10
11
  @query_counter = 0
@@ -13,14 +14,15 @@ module RailsConnector
13
14
  def begin_caching
14
15
  @editable_cache = Configuration.cache_editable_workspaces ? persistent_cache : Cache.new
15
16
  @read_only_cache = persistent_cache
17
+ @blob_data_cache = persistent_cache
16
18
  end
17
19
 
18
20
  def end_caching
19
- @editable_cache = @read_only_cache = nil
21
+ @editable_cache = @read_only_cache = @blob_data_cache = nil
20
22
  end
21
23
 
22
24
  def caching?
23
- @read_only_cache && @editable_cache
25
+ @read_only_cache && @editable_cache && @blob_data_cache
24
26
  end
25
27
 
26
28
  def query_counter
@@ -32,8 +34,9 @@ module RailsConnector
32
34
  "workspaces/query",
33
35
  :workspace_id => id
34
36
  )
35
- raw_workspace_data = raw_data["workspace"] or raise "Workspace Data missing"
36
- WorkspaceDataFromService.new(raw_workspace_data)
37
+ if raw_workspace_data = raw_data['workspace']
38
+ WorkspaceDataFromService.new raw_workspace_data
39
+ end
37
40
  end
38
41
 
39
42
  def find_obj_data_by(workspace_data, index, keys)
@@ -51,6 +54,14 @@ module RailsConnector
51
54
  end
52
55
  end
53
56
 
57
+ def find_blob_data_by_id(id)
58
+ if caching?
59
+ find_blob_data_from_cache_or_database_by_id(id)
60
+ else
61
+ find_blob_data_from_database_by(id)
62
+ end
63
+ end
64
+
54
65
  private
55
66
 
56
67
  def persistent_cache
@@ -136,6 +147,24 @@ module RailsConnector
136
147
  workspace_data.cachable? ? @read_only_cache : @editable_cache
137
148
  end
138
149
 
150
+ def find_blob_data_from_cache_or_database_by_id(id)
151
+ cache_key = "#{BLOB_DATA_CACHE_PREFIX}/#{id}"
152
+ if data_from_cache = @blob_data_cache.read(cache_key)
153
+ data_from_cache
154
+ else
155
+ data_from_database = find_blob_data_from_database_by(id)
156
+ if maxage = data_from_database['maxage']
157
+ @blob_data_cache.write(cache_key, data_from_database, :expires_in => maxage)
158
+ end
159
+ data_from_database
160
+ end
161
+ end
162
+
163
+ def find_blob_data_from_database_by(id)
164
+ @query_counter += 1
165
+ ContentService.query('blobs/query', :blob_ids => [id])['blobs'][id]
166
+ end
167
+
139
168
  end
140
169
 
141
170
  end
@@ -21,7 +21,11 @@ class Workspace
21
21
  end
22
22
 
23
23
  def self.find(id)
24
- Workspace.new(CmsBackend.find_workspace_data_by_id(id))
24
+ if workspace_data = CmsBackend.find_workspace_data_by_id(id)
25
+ Workspace.new workspace_data
26
+ else
27
+ raise ResourceNotFound, "Could not find #{self} with id #{id}"
28
+ end
25
29
  end
26
30
 
27
31
  def initialize(workspace_data)
@@ -15,7 +15,7 @@ class WorkspaceSelectionMiddleware
15
15
  if workspace_id
16
16
  begin
17
17
  Workspace.find(workspace_id)
18
- rescue Kvom::NotFound
18
+ rescue RailsConnector::ResourceNotFound
19
19
  Workspace.default
20
20
  end
21
21
  else
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infopark_cloud_connector
3
3
  version: !ruby/object:Gem::Version
4
- hash: 39396865
4
+ hash: 263434717
5
5
  prerelease:
6
6
  segments:
7
7
  - 6
8
8
  - 8
9
9
  - 0
10
- - 356
11
- - 19698103
12
- version: 6.8.0.356.19698103
10
+ - 406
11
+ - 131718077
12
+ version: 6.8.0.406.131718077
13
13
  platform: ruby
14
14
  authors:
15
15
  - Infopark AG
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2012-11-27 00:00:00 +01:00
20
+ date: 2012-12-04 00:00:00 +01:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -57,14 +57,14 @@ dependencies:
57
57
  requirements:
58
58
  - - "="
59
59
  - !ruby/object:Gem::Version
60
- hash: 39396865
60
+ hash: 263434717
61
61
  segments:
62
62
  - 6
63
63
  - 8
64
64
  - 0
65
- - 356
66
- - 19698103
67
- version: 6.8.0.356.19698103
65
+ - 406
66
+ - 131718077
67
+ version: 6.8.0.406.131718077
68
68
  version_requirements: *id003
69
69
  name: kvom
70
70
  prerelease: false