Class: CmisServer::CmisObject
- Inherits:
-
Object
- Object
- CmisServer::CmisObject
show all
- Defined in:
- lib/cmis_server/cmis_object.rb
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
secondary_types.each do |secondary_type|
add_secondary_type(secondary_type)
end
properties.to_h.each do |property_id, property_value|
@properties[property_id] = property_value
end
end
|
Instance Attribute Details
#properties ⇒ Object
Returns the value of attribute properties.
6
7
8
|
# File 'lib/cmis_server/cmis_object.rb', line 6
def properties
@properties
end
|
#secondary_types ⇒ Object
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
|
#type ⇒ Object
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)
unless secondary_type.base_id == 'cmis:secondary'
raise InvalidType.new("#{secondary_type.id} is not a secondary type")
end
if has_secondary_type?(secondary_type.id)
raise InvalidType.new("#{secondary_type.id} is already added")
end
@secondary_types << secondary_type
add_secondary_type_properties(secondary_type)
update_secondary_type_ids
secondary_type
end
|
#all_property_definitions ⇒ Object
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/cmis_server/cmis_object.rb', line 136
def all_property_definitions
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_by ⇒ Object
56
57
58
|
# File 'lib/cmis_server/cmis_object.rb', line 56
def cmis_created_by
@properties['cmis:createdBy']&.value || 'Unknown'
end
|
#cmis_creation_date ⇒ Object
48
49
50
|
# File 'lib/cmis_server/cmis_object.rb', line 48
def cmis_creation_date
@properties['cmis:creationDate']&.value || Time.now
end
|
#cmis_description ⇒ Object
44
45
46
|
# File 'lib/cmis_server/cmis_object.rb', line 44
def cmis_description
@properties['cmis:description']&.value
end
|
#cmis_last_modification_date ⇒ Object
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_name ⇒ Object
40
41
42
|
# File 'lib/cmis_server/cmis_object.rb', line 40
def cmis_name
@properties['cmis:name']&.value
end
|
#cmis_object_id ⇒ Object
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
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)
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
@secondary_types.delete(secondary_type)
remove_secondary_type_properties(secondary_type)
update_secondary_type_ids
true
end
|
#save ⇒ Object
130
131
132
133
134
|
# File 'lib/cmis_server/cmis_object.rb', line 130
def save
true
end
|
#to_renderable_object ⇒ Object
#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
property_def = find_property_definition(prop_id)
if property_def && property_def.owning_type && property_def.owning_type.base_id == 'cmis:secondary'
add_secondary_type(property_def.owning_type)
@properties[prop_id].value = value
else
raise ArgumentError, "Property #{prop_id} does not exist for this object"
end
end
end
end
|