Class: CmisServer::ContentStreamService
- Inherits:
-
Object
- Object
- CmisServer::ContentStreamService
- Defined in:
- app/services/cmis_server/content_stream_service.rb
Defined Under Namespace
Classes: CapabilityError, NotSupportedError, ObjectNotFoundError
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
-
#append_content_stream(object_id, content_stream, is_last_chunk = true) ⇒ Boolean
Ajoute du contenu à un stream existant.
-
#initialize(context = {}) ⇒ ContentStreamService
constructor
A new instance of ContentStreamService.
- #repository ⇒ Object
Constructor Details
#initialize(context = {}) ⇒ ContentStreamService
Returns a new instance of ContentStreamService.
5 6 7 |
# File 'app/services/cmis_server/content_stream_service.rb', line 5 def initialize(context = {}) @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'app/services/cmis_server/content_stream_service.rb', line 3 def context @context end |
Instance Method Details
#append_content_stream(object_id, content_stream, is_last_chunk = true) ⇒ Boolean
Ajoute du contenu à un stream existant
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/services/cmis_server/content_stream_service.rb', line 18 def append_content_stream(object_id, content_stream, is_last_chunk = true) # Vérifier que le repository supporte l'ajout de contenu unless repository.capabilities[:append_content_stream] raise CapabilityError.new("Repository does not support appending content stream") end # Récupérer l'objet object = repository.object(object_id) if object.nil? raise ObjectNotFoundError.new("Object '#{object_id}' not found") end # Vérifier que l'objet est un document unless object.is_a?(DocumentObject) raise NotSupportedError.new("Object '#{object_id}' is not a document") end # Si l'objet n'a pas encore de contenu, c'est un ajout initial if object.content_stream.nil? object.content_stream = content_stream else # Combiner le contenu existant avec le nouveau contenu existing_content = object.content_stream.stream.read object.content_stream.stream.rewind # Important pour réinitialiser le curseur new_content = content_stream.stream.read combined_content = StringIO.new(existing_content + new_content) # Créer un nouveau content stream avec le contenu combiné combined_stream = ContentStream.new( id: object.content_stream.id, media_type: object.content_stream.media_type, # Conserver le type MIME original stream: combined_content, filename: object.content_stream.filename ) object.content_stream = combined_stream end # Mettre à jour les propriétés du document si nécessaire if is_last_chunk object.cmis_content_stream_length = object.content_stream.length if object.respond_to?(:cmis_content_stream_length=) object.cmis_content_stream_mime_type = object.content_stream.media_type if object.respond_to?(:cmis_content_stream_mime_type=) object.cmis_content_stream_file_name = object.content_stream.filename if object.respond_to?(:cmis_content_stream_file_name=) end # Enregistrer l'objet repository.update_object(object) true end |
#repository ⇒ Object
9 10 11 |
# File 'app/services/cmis_server/content_stream_service.rb', line 9 def repository context[:repository] end |