Class: ActiveCMIS::Server

Inherits:
Object
  • Object
show all
Includes:
Internal::Caching
Defined in:
lib/active_cmis/server.rb

Overview

This class is used to manage different CMIS servers.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Internal::Caching

included

Constructor Details

#initialize(endpoint, logger, authentication_info = nil, options = nil) ⇒ Server

A connection needs the URL to a CMIS REST endpoint.

It's used to manage all communication with the CMIS Server


42
43
44
45
46
47
48
49
50
51
52
# File 'lib/active_cmis/server.rb', line 42

def initialize(endpoint, logger, authentication_info = nil, options = nil)
  @endpoint = endpoint
  @logger = logger
  @options = options || {}

  method, *params = authentication_info
  @authentication_info = authentication_info
  if method
    conn.authenticate(method, *params)
  end
end

Instance Attribute Details

#endpointURI (readonly)


6
7
8
# File 'lib/active_cmis/server.rb', line 6

def endpoint
  @endpoint
end

#loggerLogger (readonly)


8
9
10
# File 'lib/active_cmis/server.rb', line 8

def logger
  @logger
end

#optionsHash (readonly)


10
11
12
# File 'lib/active_cmis/server.rb', line 10

def options
  @options
end

Class Method Details

.endpoints{(URI, Logger) => Server}


23
24
25
# File 'lib/active_cmis/server.rb', line 23

def self.endpoints
  @endpoints ||= Hash.new {|h, k| h[k] = Hash.new {|h2, k2| h2[k2] = {}}}
end

.new(endpoint, logger = nil, authentication_info = nil, options = nil) ⇒ Server


13
14
15
16
17
18
19
20
# File 'lib/active_cmis/server.rb', line 13

def self.new(endpoint, logger = nil, authentication_info = nil, options = nil)
  endpoint = case endpoint
             when URI; endpoint
             else URI(endpoint.to_s)
             end
  server = super(endpoint, logger || ActiveCMIS.default_logger, authentication_info, options)
  endpoints[endpoint.to_s][authentication_info][logger] ||= server
end

Instance Method Details

#authenticate(*authentication_info) ⇒ void

This method returns an undefined value.

This returns a new Server object using the specified authentication info


59
60
61
# File 'lib/active_cmis/server.rb', line 59

def authenticate(*authentication_info)
  self.class.new(endpoint, logger, authentication_info)
end

#clear_repositoriesvoid

This method returns an undefined value.

Reset cache of Repository objects


93
94
95
# File 'lib/active_cmis/server.rb', line 93

def clear_repositories
  @cached_repositories = {}
end

#inspectString


28
29
30
# File 'lib/active_cmis/server.rb', line 28

def inspect
  "Server #{@endpoint}"
end

#repositories<{:id, :name} => String>

Lists all the available repositories


101
102
103
104
105
# File 'lib/active_cmis/server.rb', line 101

def repositories
  repositories = repository_info.xpath("/app:service/app:workspace/cra:repositoryInfo", NS::COMBINED)
  repositories.map {|ri| next {:id => ri.xpath("ns:repositoryId", "ns" => NS::CMIS_CORE).text,
    :name => ri.xpath("ns:repositoryName", "ns" => NS::CMIS_CORE).text }}
end

#repository(repository_id, authentication_info = @authentication_info) ⇒ Repository

Returns the _Repository identified by the ID Authentication will take place with the optional second paramater, if it is absent and there is server authentcation then the server authentication will be used

Cached by the repository_id and, authentcation info. The cache can be reset by calling clear_repositories.


74
75
76
77
# File 'lib/active_cmis/server.rb', line 74

def repository(repository_id, authentication_info = @authentication_info)
  key = [repository_id, authentication_info]
  cached_repositories[key] ||= uncached_repository(*key)
end

#to_sString


32
33
34
# File 'lib/active_cmis/server.rb', line 32

def to_s
  "Server " + @endpoint.to_s + " : " + repositories.map {|h| h[:name] + "(#{h[:id]})"}.join(", ")
end