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) ⇒ 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



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

def initialize(endpoint, logger, authentication_info = nil)
  @endpoint = endpoint
  @logger = logger


  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

Class Method Details

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

Returns The cache of known Servers.

Returns:

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

    The cache of known Servers



21
22
23
# File 'lib/active_cmis/server.rb', line 21

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

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

Returns Cached by endpoint and logger.

Returns:

  • (Server)

    Cached by endpoint and logger



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

def self.new(endpoint, logger = nil, authentication_info = nil)
  endpoint = case endpoint
             when URI; endpoint
             else URI(endpoint.to_s)
             end
  server = super(endpoint, logger || ActiveCMIS.default_logger, authentication_info)
  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:



57
58
59
# File 'lib/active_cmis/server.rb', line 57

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



91
92
93
# File 'lib/active_cmis/server.rb', line 91

def clear_repositories
  @cached_repositories = {}
end

#inspectString

Returns:

  • (String)


26
27
28
# File 'lib/active_cmis/server.rb', line 26

def inspect
  "Server #{@endpoint}"
end

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

Lists all the available repositories

Returns:

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


99
100
101
102
103
# File 'lib/active_cmis/server.rb', line 99

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:



72
73
74
75
# File 'lib/active_cmis/server.rb', line 72

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

#to_sString

Returns:

  • (String)


30
31
32
# File 'lib/active_cmis/server.rb', line 30

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