Class: ActiveCMIS::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/active_cmis/repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, connection, logger, initial_data, authentication_info) ⇒ Repository

Returns a new instance of Repository.



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

def initialize(server, connection, logger, initial_data, authentication_info) #:nodoc:
  @server = server
  @conn = connection
  @data = initial_data
  @logger = logger
  method, *params = authentication_info
  if method
    conn.authenticate(method, *params)
  end
end

Instance Attribute Details

#loggerLogger (readonly)

Returns A logger to which debug output and so on is sent.

Returns:

  • (Logger)

    A logger to which debug output and so on is sent



4
5
6
# File 'lib/active_cmis/repository.rb', line 4

def logger
  @logger
end

#serverActiveCMIS::Server (readonly)

Returns The server from which the repository was requested.

Returns:



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

def server
  @server
end

Instance Method Details

#acls_readable?Boolean

returns true if ACLs can at least be viewed

Returns:

  • (Boolean)


279
280
281
# File 'lib/active_cmis/repository.rb', line 279

def acls_readable?
  ["manage", "discover"].include? capabilities["ACL"]
end

#anonymous_userString

You should probably not use this directly, use :anonymous instead where a user name is required

Returns:

  • (String)


285
286
287
288
289
# File 'lib/active_cmis/repository.rb', line 285

def anonymous_user
  if acls_readable?
    data.xpath('cra:repositoryInfo/c:principalAnonymous', NS::COMBINED).text
  end
end

#authenticate(*authentication_info) ⇒ Repository

Use authentication to access the CMIS repository This returns a new Repository object, the existing repository will still use the previous authentication info. If the used authentication info (method, username, password) is the same as for the current Repository object, then self will be returned (unless the server repository cache is cleared first)

e.g.: authenticated = repo.authenticate(:basic, “username”, “password”)

Parameters:

  • method (:basic, :ntlm)
  • username (String)
  • password (String)

Returns:



34
35
36
# File 'lib/active_cmis/repository.rb', line 34

def authenticate(*authentication_info)
  server.repository(key, authentication_info)
end

#base_typesCollection<Class>

A collection containing the CMIS base types supported by this repository

Returns:



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/active_cmis/repository.rb', line 156

def base_types
  @base_types ||= begin
                    query = "app:collection[cra:collectionType[child::text() = 'types']]/@href"
                    href = data.xpath(query, NS::COMBINED)
                    if href.first
                      url = href.first.text
                      Collection.new(self, url) do |entry|
                        id = entry.xpath("cra:type/c:id", NS::COMBINED).text
                        type_by_id id
                      end
                    else
                      raise "Repository has no types collection, this is strange and wrong"
                    end
                  end
end

#capabilitiesHash{String => String,Boolean}

Describes the capabilities of the repository

Returns:

  • (Hash{String => String,Boolean})

    The hash keys have capability cut of their name



251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/active_cmis/repository.rb', line 251

def capabilities
  @capabilities ||= begin
                      capa = {}
                      data.xpath("cra:repositoryInfo/c:capabilities/*", NS::COMBINED).map do |node|
                        # FIXME: conversion should be based on knowledge about data model + transforming bool code should not be duplicated
                        capa[node.name.sub("capability", "")] = case t = node.text
                                          when "true", "1"; true
                                          when "false", "0"; false
                                          else t
                                          end
                      end
                      capa
                    end
end

#changes(options = {}) ⇒ Collection

Returns a collection with the changes since the given changeLogToken.

Completely uncached so use with care

Parameters:

  • options (defaults to: {})

    Keys can be Symbol or String, all options are optional

Options Hash (options):

  • filter (String)
  • changeLogToken (String)

    A token indicating which changes you already know about

  • maxItems (Integer)

    For paging

  • includeAcl (Boolean)
  • includePolicyIds (Boolean)
  • includeProperties (Boolean)

Returns:



192
193
194
195
196
197
198
199
# File 'lib/active_cmis/repository.rb', line 192

def changes(options = {})
  query = "at:link[@rel = '#{Rel[cmis_version][:changes]}']/@href"
  link = data.xpath(query, NS::COMBINED)
  if link = link.first
    link = Internal::Utils.append_parameters(link.to_s, options)
    Collection.new(self, link)
  end
end

#cmis_versionString

The version of the CMIS standard supported by this repository

Returns:

  • (String)


51
52
53
54
55
56
57
# File 'lib/active_cmis/repository.rb', line 51

def cmis_version
  # NOTE: we might want to "version" our xml namespaces depending on the CMIS version
  # If we do that we need to make this method capable of not using the predefined namespaces
  #
  # On the other hand breaking the XML namespace is probably going to break other applications too so the might not change them even when the spec is updated
  @cmis_version ||= data.xpath("cra:repositoryInfo/c:cmisVersionSupported", NS::COMBINED).text
end

#connInternal::Connection

Returns an Internal::Connection object, normally you should not use this directly



245
246
247
# File 'lib/active_cmis/repository.rb', line 245

def conn
  @conn ||= Internal::Connection.new
end

#descriptionString

A description of the repository

Returns:

  • (String)


67
68
69
# File 'lib/active_cmis/repository.rb', line 67

def description
  @name ||= data.xpath("cra:repositoryInfo/c:repositoryDescription", NS::COMBINED).text
end

#inspectString

Returns:

  • (String)


45
46
47
# File 'lib/active_cmis/repository.rb', line 45

def inspect
  "<#ActiveCMIS::Repository #{key}>"
end

#keyString

The identifier of the repository

Returns:

  • (String)


40
41
42
# File 'lib/active_cmis/repository.rb', line 40

def key
  @key ||= data.xpath('cra:repositoryInfo/c:repositoryId', NS::COMBINED).text
end

#latest_changelog_tokenString

Changelog token representing the most recent change to this repository (will represent the most recent change at the time that this ActiveCMIS::Repository was created

Returns:

  • (String)


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

def latest_changelog_token
  @changelog_token ||= data.xpath("cra:repositoryInfo/c:latestChangeLogToken", NS::COMBINED).text
end

#nameString

The name of the repository, meant for display purposes

Returns:

  • (String)


61
62
63
# File 'lib/active_cmis/repository.rb', line 61

def name
  @name ||= data.xpath("cra:repositoryInfo/c:repositoryName", NS::COMBINED).text
end

#object_by_id(id, parameters = {"renditionFilter" => "*", "includeAllowableActions" => "true", "includeACL" => true}) ⇒ Object

Finds the object with a given ID in the repository

Parameters:

  • id (String)
  • parameters (defaults to: {"renditionFilter" => "*", "includeAllowableActions" => "true", "includeACL" => true})

    A list of parameters used to get (defaults are what you should use)

Returns:



111
112
113
# File 'lib/active_cmis/repository.rb', line 111

def object_by_id(id, parameters = {"renditionFilter" => "*", "includeAllowableActions" => "true", "includeACL" => true})
  ActiveCMIS::Object.from_parameters(self, parameters.merge("id" => id))
end

#object_by_id_url(parameters) ⇒ Object



116
117
118
119
120
# File 'lib/active_cmis/repository.rb', line 116

def object_by_id_url(parameters)
  template = pick_template("objectbyid")
  raise "Repository does not define required URI-template 'objectbyid'" unless template
  url = fill_in_template(template, parameters)
end

#product_nameString

The name of the product behind this Repository

Returns:

  • (String)


79
80
81
# File 'lib/active_cmis/repository.rb', line 79

def product_name
  @product_name ||= data.xpath("cra:repositoryInfo/c:productName", NS::COMBINED).text
end

#product_versionString

The version of the product behind this Repository

Returns:

  • (String)


85
86
87
# File 'lib/active_cmis/repository.rb', line 85

def product_version
  @product_version ||= data.xpath("cra:repositoryInfo/c:productVersion", NS::COMBINED).text
end

#pwc_updatable?Boolean

Responds with true if Private Working Copies are updateable, false otherwise (if false the PWC object can only be updated during the checkin)

Returns:

  • (Boolean)


268
269
270
# File 'lib/active_cmis/repository.rb', line 268

def pwc_updatable?
  capabilities["PWCUpdatable"]
end

#query(query_string, options = {}) ⇒ Collection

Returns a collection with the results of a query (if supported by the repository)

Parameters:

  • query_string (#to_s)

    A query in the CMIS SQL format (unescaped in any way)

  • options ({Symbol => ::Object}) (defaults to: {})

    Optional configuration for the query

Options Hash (options):

  • :searchAllVersions (Boolean) — default: false
  • :includeAllowableActions (Boolean) — default: false
  • :includeRelationships ("none", "source", "target", "both")
  • :renditionFilter (String) — default: 'cmis:none'

    Possible values: ‘cmis:none’, ‘*’ (all), comma-separated list of rendition kinds or mimetypes

  • :maxItems (Integer)

    used for paging

  • :skipCount (Integer) — default: 0

    used for paging

Returns:

  • (Collection)

    A collection with each return value wrapped in a QueryResult



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/active_cmis/repository.rb', line 212

def query(query_string, options = {})
  raise "This repository does not support queries" if capabilities["Query"] == "none"
  # For the moment we make no difference between metadataonly,fulltextonly,bothseparate and bothcombined
  # Nor do we look at capabilities["Join"] (none, inneronly, innerandouter)

  # For searchAllVersions need to check capabilities["AllVersionsSearchable"]
  # includeRelationships, includeAllowableActions and renditionFilter only work if SELECT only contains attributes from 1 object
  valid_params = ["searchAllVersions", "includeAllowableActions", "includeRelationships", "renditionFilter", "maxItems", "skipCount"]
  invalid_params = options.keys - valid_params
  unless invalid_params.empty?
    raise "Invalid parameters for query: #{invalid_params.join ', '}"
  end

  # FIXME: options are not respected yet by pick_template
  url = pick_template("query", :mimetype => "application/atom+xml", :type => "feed")
  url = fill_in_template(url, options.merge("q" => query_string))
  Collection.new(self, url) do |entry|
    QueryResult.new(entry)
  end
end

#root_folder(reload = false) ⇒ Folder

The root folder of the repository (as defined in the CMIS standard)

Returns:



235
236
237
238
239
240
241
# File 'lib/active_cmis/repository.rb', line 235

def root_folder(reload = false)
  if reload
    @root_folder = object_by_id(data.xpath("cra:repositoryInfo/c:rootFolderId", NS::COMBINED).text)
  else
    @root_folder ||= object_by_id(data.xpath("cra:repositoryInfo/c:rootFolderId", NS::COMBINED).text)
  end
end

#thin_client_uriURI?

A URI that points to a web service for this repository. May not be present

Returns:

  • (URI, nil)


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

def thin_client_uri
  @thin_client_uri ||= begin
                         string = data.xpath("cra:repositoryInfo/c:thinClientURI", NS::COMBINED).text
                         URI.parse(string) if string && string != ""
                       end
end

#type_by_id(id) ⇒ Class

Finds the type with a given ID in the repository

Returns:

  • (Class)


124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/active_cmis/repository.rb', line 124

def type_by_id(id)
  @type_by_id ||= {}
  if result = @type_by_id[id]
    result
  else
    template = pick_template("typebyid")
    raise "Repository does not define required URI-template 'typebyid'" unless template
    url = fill_in_template(template, "id" => id)

    @type_by_id[id] = Type.create(conn, self, conn.get_atom_entry(url))
  end
end

#types<Class>

An array containing all the types used by this repository

Returns:

  • (<Class>)


174
175
176
177
178
# File 'lib/active_cmis/repository.rb', line 174

def types
  @types ||= base_types.map do |t|
    t.all_subtypes
  end.flatten
end

#vendorString

The name of the vendor of this Repository

Returns:

  • (String)


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

def vendor
  @vendor ||= data.xpath("cra:repositoryInfo/c:vendorName", NS::COMBINED).text
end

#version_specific_filing?Boolean

Responds with true if different versions of the same document can be filed in different folders

Returns:

  • (Boolean)


274
275
276
# File 'lib/active_cmis/repository.rb', line 274

def version_specific_filing?
  capabilities["VersionSpecificFiling"]
end

#world_userString

You should probably not use this directly, use :world instead where a user name is required

Returns:

  • (String)


293
294
295
296
297
# File 'lib/active_cmis/repository.rb', line 293

def world_user
  if acls_readable?
    data.xpath('cra:repositoryInfo/c:principalAnyone', NS::COMBINED).text
  end
end