Class: CmisServer::CmisObject

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

Direct Known Subclasses

DocumentObject, FolderObject, ItemObject

Defined Under Namespace

Classes: InvalidType

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, properties: {}, secondary_types: []) ⇒ CmisObject

Returns a new instance of CmisObject.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cmis_server/cmis_object.rb', line 11

def initialize(type:, properties: {}, secondary_types: [])
  self.type = type
  @secondary_types = []
  initialize_properties
  
  # Ajouter les types secondaires s'ils sont fournis
  secondary_types.each do |secondary_type|
    add_secondary_type(secondary_type)
  end

  # Stocker les propriétés directement sans utiliser de setters dynamiques
  properties.to_h.each do |property_id, property_value|
    @properties[property_id] = property_value
  end
end

Instance Attribute Details

#propertiesObject (readonly)

Returns the value of attribute properties.



6
7
8
# File 'lib/cmis_server/cmis_object.rb', line 6

def properties
  @properties
end

#secondary_typesObject (readonly)

Returns the value of attribute secondary_types.



7
8
9
# File 'lib/cmis_server/cmis_object.rb', line 7

def secondary_types
  @secondary_types
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/cmis_server/cmis_object.rb', line 5

def type
  @type
end

Instance Method Details

#add_secondary_type(secondary_type) ⇒ Object

CMIS 1.1: Méthodes pour gérer les types secondaires



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

def add_secondary_type(secondary_type)
  # Vérifier que le type est bien un type secondaire
  unless secondary_type.base_id == 'cmis:secondary'
    raise InvalidType.new("#{secondary_type.id} is not a secondary type")
  end
  
  # Vérifier que le type n'est pas déjà ajouté
  if has_secondary_type?(secondary_type.id)
    raise InvalidType.new("#{secondary_type.id} is already added")
  end
  
  # Ajouter le type secondaire
  @secondary_types << secondary_type
  
  # Ajouter les propriétés du type secondaire
  add_secondary_type_properties(secondary_type)
  
  # Mettre à jour la propriété cmis:secondaryObjectTypeIds
  update_secondary_type_ids
  
  secondary_type
end

#all_property_definitionsObject



136
137
138
139
140
141
142
143
144
145
# File 'lib/cmis_server/cmis_object.rb', line 136

def all_property_definitions
  # Combine les définitions de propriétés du type principal et des types secondaires
  all_defs = type.property_definitions.to_a
  
  @secondary_types.each do |secondary_type|
    all_defs.concat(secondary_type.property_definitions.to_a)
  end
  
  all_defs
end

#cmis_created_byObject



56
57
58
# File 'lib/cmis_server/cmis_object.rb', line 56

def cmis_created_by
  @properties['cmis:createdBy']&.value || 'Unknown'
end

#cmis_creation_dateObject



48
49
50
# File 'lib/cmis_server/cmis_object.rb', line 48

def cmis_creation_date
  @properties['cmis:creationDate']&.value || Time.now
end

#cmis_descriptionObject



44
45
46
# File 'lib/cmis_server/cmis_object.rb', line 44

def cmis_description
  @properties['cmis:description']&.value
end

#cmis_last_modification_dateObject



52
53
54
# File 'lib/cmis_server/cmis_object.rb', line 52

def cmis_last_modification_date
  @properties['cmis:lastModificationDate']&.value || Time.now
end

#cmis_nameObject



40
41
42
# File 'lib/cmis_server/cmis_object.rb', line 40

def cmis_name
  @properties['cmis:name']&.value
end

#cmis_object_idObject

Méthodes d’accès aux propriétés communes CMIS



32
33
34
# File 'lib/cmis_server/cmis_object.rb', line 32

def cmis_object_id
  @cmis_object_id || @properties['cmis:objectId']&.value
end

#cmis_object_id=(value) ⇒ Object



36
37
38
# File 'lib/cmis_server/cmis_object.rb', line 36

def cmis_object_id=(value)
  @cmis_object_id = value
end

#copy_properties_values_of(object) ⇒ Object



60
61
62
# File 'lib/cmis_server/cmis_object.rb', line 60

def copy_properties_values_of object
  self.properties.each{|_k,property| property.value=object.send(property.property_definition.getter_method_name)}
end

#has_secondary_type?(type_id) ⇒ Boolean

Returns:



107
108
109
# File 'lib/cmis_server/cmis_object.rb', line 107

def has_secondary_type?(type_id)
  @secondary_types.any? { |st| st.id == type_id }
end

#remove_secondary_type(type_id) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/cmis_server/cmis_object.rb', line 88

def remove_secondary_type(type_id)
  # Trouver le type secondaire
  secondary_type = @secondary_types.find { |st| st.id == type_id }
  unless secondary_type
    raise InvalidType.new("#{type_id} is not a secondary type of this object")
  end
  
  # Supprimer le type secondaire
  @secondary_types.delete(secondary_type)
  
  # Supprimer les propriétés associées à ce type secondaire
  remove_secondary_type_properties(secondary_type)
  
  # Mettre à jour la propriété cmis:secondaryObjectTypeIds
  update_secondary_type_ids
  
  true
end

#saveObject



130
131
132
133
134
# File 'lib/cmis_server/cmis_object.rb', line 130

def save
  # À implémenter selon votre système de stockage
  # Cette méthode devrait sauvegarder l'objet avec toutes ses propriétés
  true
end

#to_renderable_objectObject



27
28
29
# File 'lib/cmis_server/cmis_object.rb', line 27

def to_renderable_object
  CmisServer::RenderableObject.new(base_object: self)
end

#update_properties(properties_hash) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/cmis_server/cmis_object.rb', line 111

def update_properties(properties_hash)
  properties_hash.each do |prop_id, value|
    if @properties.key?(prop_id)
      @properties[prop_id].value = value
    else
      # Vérifier si cette propriété appartient à un type secondaire que nous n'avons pas encore
      property_def = find_property_definition(prop_id)
      if property_def && property_def.owning_type && property_def.owning_type.base_id == 'cmis:secondary'
        # Ajouter automatiquement le type secondaire
        add_secondary_type(property_def.owning_type)
        # Puis définir la valeur
        @properties[prop_id].value = value
      else
        raise ArgumentError, "Property #{prop_id} does not exist for this object"
      end
    end
  end
end