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

Parameters:

  • endpoint (URI)

    The URL where the CMIS AtomPub REST endpoint can be found

  • logger (Logger)

    The logger that will be used to log debug/info messages

  • authentication_info (Array?) (defaults to: nil)

    Optional authentication info to be used when retrieving the data from the AtomPub endpoint



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)

Returns The location of the server.

Returns:

  • (URI)

    The location of the server



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

def endpoint
  @endpoint
end

#loggerLogger (readonly)

Returns A default logger for derived repositories.

Returns:

  • (Logger)

    A default logger for derived repositories



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

def logger
  @logger
end

#optionsHash (readonly)

Returns Options to be used by the HTTP objects.

Returns:

  • (Hash)

    Options to be used by the HTTP objects



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

def options
  @options
end

Class Method Details

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

Returns The cache of known Servers.

Returns:

  • ({(URI, Logger) => Server})

    The cache of known Servers



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

Returns Cached by endpoint and logger.

Returns:

  • (Server)

    Cached by endpoint and logger



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

Parameters:

  • method (Symbol)

    Currently only :basic is supported

  • params

    The parameters that need to be sent to the Net::HTTP authentication method used, username and password for basic authentication

See Also:



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

Returns:

  • (String)


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

Returns:

  • (<{:id, :name} => String>)


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.

Parameters:

  • repository_id (String)
  • authentication_info (Array) (defaults to: @authentication_info)

Returns:



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

Returns:

  • (String)


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