Class: CmisServer::TypeRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/cmis_server/type_registry.rb

Class Method Summary collapse

Class Method Details

.create_type(type_definition) ⇒ Object

CMIS 1.1: Création dynamique de type



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cmis_server/type_registry.rb', line 17

def create_type(type_definition)
  # Validation du parent type
  parent_id = type_definition[:parent_id]
  parent_type = get_type(parent_id)
  
  unless parent_type
    raise CmisServer::InvalidTypeDefinition.new("Parent type '#{parent_id}' does not exist")
  end
  
  # Vérification que l'ID n'existe pas déjà
  type_id = type_definition[:id]
  if get_type(type_id)
    raise CmisServer::InvalidTypeDefinition.new("Type '#{type_id}' already exists")
  end
  
  # Création du type avec le parent approprié
  type_attributes = type_definition.merge(parent_type: parent_type)
  type = create_type_instance(type_attributes)
  
  # Enregistrement du type
  register_type(type_id, type)
  
  type
end

.delete_type(type_id) ⇒ Object

CMIS 1.1: Suppression d’un type



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/cmis_server/type_registry.rb', line 67

def delete_type(type_id)
  type = get_type(type_id)
  
  unless type
    raise CmisServer::InvalidTypeDefinition.new("Type '#{type_id}' does not exist")
  end
  
  # Vérifier si le type a des enfants
  has_children = types.values.any? { |t| t.parent_id == type_id }
  if has_children
    raise CmisServer::InvalidOperation.new("Cannot delete type with children")
  end
  
  # Vérifier si le type est utilisé par des objets
  if type_has_instances?(type_id)
    raise CmisServer::InvalidOperation.new("Cannot delete type with instances")
  end
  
  # Suppression du type
  types.delete(type_id)
  
  true
end

.get_type(id) ⇒ Object



8
9
10
# File 'lib/cmis_server/type_registry.rb', line 8

def get_type(id)
  types[id]
end

.register_type(id, type) ⇒ Object



4
5
6
# File 'lib/cmis_server/type_registry.rb', line 4

def register_type(id, type)
  types[id] = type
end

.typesObject



12
13
14
# File 'lib/cmis_server/type_registry.rb', line 12

def types
  @types ||= Hash.new
end

.update_type(type_definition) ⇒ Object

CMIS 1.1: Mise à jour d’un type existant



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cmis_server/type_registry.rb', line 43

def update_type(type_definition)
  type_id = type_definition[:id]
  existing_type = get_type(type_id)
  
  unless existing_type
    raise CmisServer::InvalidTypeDefinition.new("Type '#{type_id}' does not exist")
  end
  
  # Nous ne permettons pas de changer le parent d'un type
  if type_definition[:parent_id] && type_definition[:parent_id] != existing_type.parent_id
    raise CmisServer::InvalidTypeDefinition.new("Cannot change parent type")
  end
  
  # Créer un nouveau type avec les propriétés mises à jour
  updated_attributes = type_definition.merge(parent_type: existing_type.parent_type)
  updated_type = create_type_instance(updated_attributes)
  
  # Remplacer l'ancien type
  register_type(type_id, updated_type)
  
  updated_type
end