active_cmis 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.1.7
@@ -207,34 +207,19 @@ module ActiveCMIS
207
207
  private
208
208
  attr_reader :updated_contents
209
209
 
210
- # Optional parameters:
211
- # - properties: a hash key/definition pairs of properties to be rendered (defaults to all attributes)
212
- # - attributes: a hash key/value pairs used to determine the values rendered (defaults to self.attributes)
213
210
  def render_atom_entry(properties = self.class.attributes, attributes = self.attributes, options = {})
214
- builder = Nokogiri::XML::Builder.new do |xml|
215
- xml.entry(NS::COMBINED) do
216
- xml.parent.namespace = xml.parent.namespace_definitions.detect {|ns| ns.prefix == "at"}
217
- xml["at"].author do
218
- xml["at"].name conn.user # FIXME: find reliable way to set author?
219
- end
220
- if updated_contents && (options[:create] || options[:checkin])
221
- xml["cra"].content do
222
- xml["cra"].mediatype(updated_contents[:mime_type] || "application/binary")
223
- data = updated_contents[:data] || File.read(updated_contents[:file])
224
- xml["cra"].base64 [data].pack("m")
225
- end
226
- end
227
- xml["cra"].object do
228
- xml["c"].properties do
229
- properties.each do |key, definition|
230
- definition.render_property(xml, attributes[key])
231
- end
232
- end
211
+ super(properties, attributes, options) do |entry|
212
+ if updated_contents && (options[:create] || options[:checkin])
213
+ entry["cra"].content do
214
+ entry["cra"].mediatype(updated_contents[:mime_type] || "application/binary")
215
+ data = updated_contents[:data] || File.read(updated_contents[:file])
216
+ entry["cra"].base64 [data].pack("m")
233
217
  end
234
218
  end
219
+ if block_given?
220
+ yield(entry)
221
+ end
235
222
  end
236
- conn.logger.debug builder.to_xml
237
- builder.to_xml
238
223
  end
239
224
 
240
225
 
@@ -9,12 +9,27 @@ module ActiveCMIS
9
9
  end
10
10
  cache :items
11
11
 
12
+ def allowed_object_types
13
+ if attributes["cmis:allowedChildObjectTypeIds"].empty?
14
+ repository.types.select { |type| type.fileable }
15
+ else
16
+ # TODO: it is repository specific if subtypes of the allowed types MAY be filed (line 976)
17
+ #
18
+ # There is as far as I can see no other mention of this possibility in the spec, no way to
19
+ # check if this is so for any specific repository. In addition there is in a few places a
20
+ # requirement that an error is thrown if the cmis:objectTypeId is not in the list of allowed
21
+ # values. So for now this is not supported at all.
22
+ attributes["cmis:allowedChildObjectTypeIds"].map { |type_id| repository.type_by_id(type_id) }
23
+ end
24
+ end
25
+ cache :allowed_object_types
26
+
12
27
  private
13
28
  def create_url
14
29
  if f = parent_folders.first
15
30
  f.items.url
16
31
  else
17
- raise "Not possible"
32
+ raise "Not possible to create folder without parent folder"
18
33
  end
19
34
  end
20
35
  end
@@ -332,6 +332,8 @@ module ActiveCMIS
332
332
  # @param properties a hash key/definition pairs of properties to be rendered (defaults to all attributes)
333
333
  # @param attributes a hash key/value pairs used to determine the values rendered (defaults to self.attributes)
334
334
  # @param options
335
+ # @yield [entry] Optional block to customize the rendered atom entry
336
+ # @yieldparam [Nokogiri::XML::Builder] entry The entry XML builder element on which you can add additional tags (uses the NS::COMBINED namespaces)
335
337
  def render_atom_entry(properties = self.class.attributes, attributes = self.attributes, options = {})
336
338
  builder = Nokogiri::XML::Builder.new do |xml|
337
339
  xml.entry(NS::COMBINED) do
@@ -339,6 +341,12 @@ module ActiveCMIS
339
341
  xml["at"].author do
340
342
  xml["at"].name conn.user # FIXME: find reliable way to set author?
341
343
  end
344
+ xml["at"].title attributes["cmis:name"]
345
+ if attributes["cmis:objectId"]
346
+ xml["at"].id attributes["cmis:objectId"]
347
+ else
348
+ xml["at"].id "random-garbage"
349
+ end
342
350
  xml["cra"].object do
343
351
  xml["c"].properties do
344
352
  properties.each do |key, definition|
@@ -346,8 +354,10 @@ module ActiveCMIS
346
354
  end
347
355
  end
348
356
  end
357
+ yield(xml) if block_given?
349
358
  end
350
359
  end
360
+ conn.logger.debug builder.to_xml
351
361
  builder.to_xml
352
362
  end
353
363
 
@@ -391,7 +401,8 @@ module ActiveCMIS
391
401
  end
392
402
 
393
403
  properties = self.class.attributes.reject do |key, definition|
394
- !updated_attributes.include?(key) && !definition.required
404
+ # !updated_attributes.include?(key) && !definition.required
405
+ attributes[key].nil? or definition.updatability == "readonly"
395
406
  end
396
407
  body = render_atom_entry(properties, attributes, :create => true)
397
408
 
@@ -51,10 +51,14 @@ module ActiveCMIS
51
51
  end
52
52
  end
53
53
 
54
- if required && updatability == "readonly"
54
+ if required and updatability == "readonly"
55
55
  logger.warn "The server behaved strange: attribute #{self.inspect} required but readonly, will set required to false"
56
56
  @required = false
57
57
  end
58
+ if id == "cmis:objectTypeId" and updatability != "oncreate"
59
+ logger.warn "The server behaved strange: cmis:objectTypeId should be updatable on create but #{updatability}"
60
+ @updatability = "oncreate"
61
+ end
58
62
 
59
63
  @property_type = case property_type.downcase
60
64
  when "string"
@@ -186,6 +186,13 @@ module ActiveCMIS
186
186
  @attributes[attr.id] = attr
187
187
  end
188
188
  end
189
+ if %w(cmis:folder cmis:document).include? @baseId and not @fileable
190
+ logger.warn "The server behaved strange: #{@id}, with basetype #{@baseId} MUST be fileable"
191
+ @fileable = true
192
+ elsif @baseId == "cmis:relationship" and @fileable
193
+ logger.warn "The server behaved strange: #{@id}, with basetype #{@baseId} MUST NOT be fileable"
194
+ @fileable = false
195
+ end
189
196
  @attributes.freeze
190
197
  end
191
198
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_cmis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-03-01 00:00:00.000000000 +01:00
12
+ date: 2011-03-08 00:00:00.000000000 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
17
- requirement: &67303860 !ruby/object:Gem::Requirement
17
+ requirement: &69488280 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: 1.4.1
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *67303860
25
+ version_requirements: *69488280
26
26
  description: A CMIS library implementing both reading and updating capabilities through
27
27
  the AtomPub/REST binding to CMIS.
28
28
  email: joeri@xaop.com