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(connection, logger, initial_data) ⇒ Repository

Returns a new instance of Repository.



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

def initialize(connection, logger, initial_data) #:nodoc:
  @conn = connection
  @data = initial_data
  @logger = logger
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

Instance Method Details

#acls_readable?Boolean

returns true if ACLs can at least be viewed

Returns:

  • (Boolean)


210
211
212
# File 'lib/active_cmis/repository.rb', line 210

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)


216
217
218
219
220
# File 'lib/active_cmis/repository.rb', line 216

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

#authenticate(method, *params) ⇒ void

This method returns an undefined value.

Use authentication to access the CMIS repository

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



17
18
19
20
# File 'lib/active_cmis/repository.rb', line 17

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

#base_typesCollection<Class>

A collection containing the CMIS base types supported by this repository

Returns:



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/active_cmis/repository.rb', line 93

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



182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/active_cmis/repository.rb', line 182

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:



129
130
131
132
133
134
135
136
# File 'lib/active_cmis/repository.rb', line 129

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)


35
36
37
38
39
40
41
# File 'lib/active_cmis/repository.rb', line 35

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



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

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

#inspectString

Returns:

  • (String)


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

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

#keyString

The identifier of the repository

Returns:

  • (String)


24
25
26
# File 'lib/active_cmis/repository.rb', line 24

def key
  @key ||= data.xpath('cra:repositoryInfo/c:repositoryId', 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:



48
49
50
# File 'lib/active_cmis/repository.rb', line 48

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



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

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

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


199
200
201
# File 'lib/active_cmis/repository.rb', line 199

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:



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/active_cmis/repository.rb', line 149

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

#root_folderFolder

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

Returns:



170
171
172
# File 'lib/active_cmis/repository.rb', line 170

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

#type_by_id(id) ⇒ Class

Finds the type with a given ID in the repository

Returns:

  • (Class)


61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/active_cmis/repository.rb', line 61

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


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

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

#version_specific_filing?Boolean

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

Returns:

  • (Boolean)


205
206
207
# File 'lib/active_cmis/repository.rb', line 205

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)


224
225
226
227
228
# File 'lib/active_cmis/repository.rb', line 224

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