Class: CmisServer::SecondaryTypeService
- Inherits:
-
Object
- Object
- CmisServer::SecondaryTypeService
- Defined in:
- app/services/cmis_server/secondary_type_service.rb
Defined Under Namespace
Classes: NotSupportedError, ObjectNotFoundError, TypeNotFoundError
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
-
#add_secondary_type(object_id, type_id) ⇒ Boolean
Ajoute un type secondaire à un objet.
-
#initialize(context = {}) ⇒ SecondaryTypeService
constructor
A new instance of SecondaryTypeService.
-
#remove_secondary_type(object_id, type_id) ⇒ Boolean
Supprime un type secondaire d’un objet.
- #repository ⇒ Object
Constructor Details
#initialize(context = {}) ⇒ SecondaryTypeService
Returns a new instance of SecondaryTypeService.
5 6 7 |
# File 'app/services/cmis_server/secondary_type_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/secondary_type_service.rb', line 3 def context @context end |
Instance Method Details
#add_secondary_type(object_id, type_id) ⇒ Boolean
Ajoute un type secondaire à un objet
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 |
# File 'app/services/cmis_server/secondary_type_service.rb', line 17 def add_secondary_type(object_id, type_id) # Récupérer l'objet object = repository.object(object_id) if object.nil? raise ObjectNotFoundError.new("Object '#{object_id}' not found") end # Récupérer le type secondaire secondary_type = repository.type(type_id) if secondary_type.nil? raise TypeNotFoundError.new("Type '#{type_id}' not found") end # Vérifier que c'est bien un type secondaire unless secondary_type.base_id == 'cmis:secondary' raise NotSupportedError.new("Type '#{type_id}' is not a secondary type") end # Vérifier que l'objet n'a pas déjà ce type secondaire if object.secondary_type_ids.include?(type_id) return true # Déjà ajouté, considéré comme un succès end # Ajouter le type secondaire à l'objet object.secondary_type_ids << type_id # Ajouter les propriétés du type secondaire à l'objet add_secondary_type_properties(object, secondary_type) # Enregistrer l'objet repository.update_object(object) true end |
#remove_secondary_type(object_id, type_id) ⇒ Boolean
Supprime un type secondaire d’un objet
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/services/cmis_server/secondary_type_service.rb', line 56 def remove_secondary_type(object_id, type_id) # 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 a ce type secondaire unless object.secondary_type_ids.include?(type_id) return true # Déjà supprimé, considéré comme un succès end # Récupérer le type secondaire secondary_type = repository.type(type_id) if secondary_type.nil? raise TypeNotFoundError.new("Type '#{type_id}' not found") end # Supprimer le type secondaire de l'objet object.secondary_type_ids.delete(type_id) # Supprimer les propriétés du type secondaire de l'objet remove_secondary_type_properties(object, secondary_type) # Enregistrer l'objet repository.update_object(object) true end |
#repository ⇒ Object
9 10 11 |
# File 'app/services/cmis_server/secondary_type_service.rb', line 9 def repository context[:repository] end |