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

A connection needs the URL to a CMIS REST endpoint.

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



36
37
38
39
# File 'lib/active_cmis/server.rb', line 36

def initialize(endpoint, logger)
  @endpoint = endpoint
  @logger = logger
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



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

def self.endpoints
  @endpoints ||= {}
end

.new(endpoint, logger = nil) ⇒ Server

Returns Cached by endpoint and logger.

Returns:

  • (Server)

    Cached by endpoint and logger



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

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

Instance Method Details

#authenticate(method, *params) ⇒ void

This method returns an undefined value.

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:



44
45
46
# File 'lib/active_cmis/server.rb', line 44

def authenticate(method, *params)
  conn.authenticate(method, *params)
end

#inspectString

Returns:

  • (String)


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

def inspect
  "Server #{@endpoint}"
end

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

Lists all the available repositories

Returns:

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


68
69
70
71
72
# File 'lib/active_cmis/server.rb', line 68

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

Returns the _Repository identified by the ID

Cached by the repository_id, no way to reset cache yet

Parameters:

  • repository_id (String)

Returns:



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/active_cmis/server.rb', line 53

def repository(repository_id)
  cached_repositories[repository_id] ||= begin
                                           repository_data = repository_info.
                                             xpath("/app:service/app:workspace[cra:repositoryInfo/c:repositoryId[child::text() = '#{repository_id}']]", NS::COMBINED)
                                           if repository_data.empty?
                                             raise Error::ObjectNotFound.new("The repository #{repository_id} doesn't exist")
                                           else
                                             Repository.new(conn.dup, logger.dup, repository_data)
                                           end
                                         end
end

#to_sString

Returns:

  • (String)


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

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