Class: CmisServer::BulkUpdateService
- Inherits:
-
Object
- Object
- CmisServer::BulkUpdateService
- Defined in:
- app/services/cmis_server/bulk_update_service.rb
Defined Under Namespace
Classes: CapabilityError
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
-
#bulk_update(object_ids, properties) ⇒ Hash
Met à jour en masse les propriétés de plusieurs objets.
-
#initialize(context = {}) ⇒ BulkUpdateService
constructor
A new instance of BulkUpdateService.
- #repository ⇒ Object
Constructor Details
#initialize(context = {}) ⇒ BulkUpdateService
Returns a new instance of BulkUpdateService.
5 6 7 |
# File 'app/services/cmis_server/bulk_update_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/bulk_update_service.rb', line 3 def context @context end |
Instance Method Details
#bulk_update(object_ids, properties) ⇒ Hash
Met à jour en masse les propriétés de plusieurs objets
17 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 |
# File 'app/services/cmis_server/bulk_update_service.rb', line 17 def bulk_update(object_ids, properties) # Vérifier que le repository supporte la mise à jour en masse unless repository.capabilities[:bulk_update] raise CapabilityError.new("Repository does not support bulk update") end result = { succeeded: [], failed: [] } # Traiter chaque objet individuellement mais dans une seule opération atomique repository.transaction do object_ids.each do |object_id| begin # Récupérer l'objet object = repository.object(object_id) if object.nil? result[:failed] << { id: object_id, message: "Object not found" } next end # Appliquer les nouvelles propriétés properties.each do |property_id, value| if object.properties.has_key?(property_id) object.properties[property_id].value = value else # Si la propriété n'existe pas, c'est peut-être une propriété d'un type secondaire qui n'est pas encore appliqué result[:failed] << { id: object_id, message: "Property '#{property_id}' not found" } next end end # Valider et enregistrer l'objet if object.valid? repository.update_object(object) result[:succeeded] << object_id else result[:failed] << { id: object_id, message: "Validation failed: #{object.errors..join(', ')}" } end rescue StandardError => e # En cas d'erreur, ajouter l'objet à la liste des échecs result[:failed] << { id: object_id, message: e. } end end end result end |
#repository ⇒ Object
9 10 11 |
# File 'app/services/cmis_server/bulk_update_service.rb', line 9 def repository context[:repository] end |