Class: CmisServer::TypeManagementService
- Inherits:
-
Object
- Object
- CmisServer::TypeManagementService
- Defined in:
- app/services/cmis_server/type_management_service.rb
Defined Under Namespace
Classes: CapabilityError, DeleteTypeError, DuplicateTypeError, TypeNotFoundError, ValidationError
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
-
#create_type(type) ⇒ Type
Crée un nouveau type dans le repository.
-
#delete_type(type_id) ⇒ Boolean
Supprime un type du repository.
-
#initialize(context = {}) ⇒ TypeManagementService
constructor
A new instance of TypeManagementService.
- #repository ⇒ Object
-
#update_type(type) ⇒ Type
Met à jour un type existant dans le repository.
Constructor Details
#initialize(context = {}) ⇒ TypeManagementService
Returns a new instance of TypeManagementService.
7 8 9 |
# File 'app/services/cmis_server/type_management_service.rb', line 7 def initialize(context = {}) @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
5 6 7 |
# File 'app/services/cmis_server/type_management_service.rb', line 5 def context @context end |
Instance Method Details
#create_type(type) ⇒ Type
Crée un nouveau type dans le repository
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 |
# File 'app/services/cmis_server/type_management_service.rb', line 18 def create_type(type) # Vérifier que le repository supporte la création de types unless repository.capabilities[:create_type] raise CapabilityError.new("Repository does not support type creation") end # Vérifier que le type parent existe parent_type = repository.type(type.parent_id) if parent_type.nil? raise TypeNotFoundError.new("Parent type '#{type.parent_id}' not found") end # Vérifier que le type n'existe pas déjà if repository.type(type.id) raise DuplicateTypeError.new("Type '#{type.id}' already exists") end # Valider le type unless type.valid? raise ValidationError.new("Type validation failed: #{type.errors..join(', ')}") end # Créer le type repository.add_type(type) # Retourner le type créé repository.type(type.id) end |
#delete_type(type_id) ⇒ Boolean
Supprime un type du repository
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/services/cmis_server/type_management_service.rb', line 77 def delete_type(type_id) # Vérifier que le repository supporte la suppression de types unless repository.capabilities[:delete_type] raise CapabilityError.new("Repository does not support type deletion") end # Vérifier que le type existe type = repository.type(type_id) if type.nil? raise TypeNotFoundError.new("Type '#{type_id}' not found") end # Vérifier qu'aucun objet n'utilise ce type if has_instances?(type_id) raise DeleteTypeError.new("Cannot delete type '#{type_id}' because it has instances") end # Supprimer le type repository.delete_type(type_id) true end |
#repository ⇒ Object
11 12 13 |
# File 'app/services/cmis_server/type_management_service.rb', line 11 def repository context[:repository] end |
#update_type(type) ⇒ Type
Met à jour un type existant dans le repository
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/services/cmis_server/type_management_service.rb', line 50 def update_type(type) # Vérifier que le repository supporte la mise à jour de types unless repository.capabilities[:update_type] raise CapabilityError.new("Repository does not support type update") end # Vérifier que le type existe existing_type = repository.type(type.id) if existing_type.nil? raise TypeNotFoundError.new("Type '#{type.id}' not found") end # Valider les modifications unless type.valid? raise ValidationError.new("Type validation failed: #{type.errors..join(', ')}") end # Mettre à jour le type repository.update_type(type) # Retourner le type mis à jour repository.type(type.id) end |