1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.document.modules.cmis.service;
35
36 import org.apache.chemistry.opencmis.commons.data.PermissionMapping;
37 import org.apache.chemistry.opencmis.commons.definitions.PermissionDefinition;
38 import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
39 import org.apache.chemistry.opencmis.commons.impl.dataobjects.*;
40
41 import java.math.BigDecimal;
42 import java.math.BigInteger;
43
44 import java.util.*;
45
46
47
48
49
50 public abstract class BaseRepository
51 {
52
53
54
55
56
57
58 protected static PermissionDefinition createPermission( String permission, String description )
59 {
60 PermissionDefinitionDataImpl pd = new PermissionDefinitionDataImpl( );
61 pd.setPermission( permission );
62 pd.setDescription( description );
63
64 return pd;
65 }
66
67
68
69
70
71
72
73 protected static PermissionMapping createMapping( String key, String permission )
74 {
75 PermissionMappingDataImpl pm = new PermissionMappingDataImpl( );
76 pm.setKey( key );
77 pm.setPermissions( Collections.singletonList( permission ) );
78
79 return pm;
80 }
81
82
83
84
85
86
87
88
89
90 protected void addPropertyId( PropertiesImpl props, String typeId, Set<String> filter, String id, String value )
91 {
92 if ( !checkAddProperty( props, typeId, filter, id ) )
93 {
94 return;
95 }
96
97 props.addProperty( new PropertyIdImpl( id, value ) );
98 }
99
100
101
102
103
104
105
106
107
108 protected void addPropertyIdList( PropertiesImpl props, String typeId, Set<String> filter, String id,
109 List<String> value )
110 {
111 if ( !checkAddProperty( props, typeId, filter, id ) )
112 {
113 return;
114 }
115
116 props.addProperty( new PropertyIdImpl( id, value ) );
117 }
118
119
120
121
122
123
124
125
126
127 protected void addPropertyString( PropertiesImpl props, String typeId, Set<String> filter, String id, String value )
128 {
129 if ( !checkAddProperty( props, typeId, filter, id ) )
130 {
131 return;
132 }
133
134 props.addProperty( new PropertyStringImpl( id, value ) );
135 }
136
137
138
139
140
141
142
143
144
145 protected void addPropertyInteger( PropertiesImpl props, String typeId, Set<String> filter, String id, long value )
146 {
147 addPropertyBigInteger( props, typeId, filter, id, BigInteger.valueOf( value ) );
148 }
149
150
151
152
153
154
155
156
157
158 protected void addPropertyBigInteger( PropertiesImpl props, String typeId, Set<String> filter, String id,
159 BigInteger value )
160 {
161 if ( !checkAddProperty( props, typeId, filter, id ) )
162 {
163 return;
164 }
165
166 props.addProperty( new PropertyIntegerImpl( id, value ) );
167 }
168
169
170
171
172
173
174
175
176
177 protected void addPropertyBoolean( PropertiesImpl props, String typeId, Set<String> filter, String id, boolean value )
178 {
179 if ( !checkAddProperty( props, typeId, filter, id ) )
180 {
181 return;
182 }
183
184 props.addProperty( new PropertyBooleanImpl( id, value ) );
185 }
186
187
188
189
190
191
192
193
194
195 protected void addPropertyDateTime( PropertiesImpl props, String typeId, Set<String> filter, String id,
196 GregorianCalendar value )
197 {
198 if ( !checkAddProperty( props, typeId, filter, id ) )
199 {
200 return;
201 }
202
203 props.addProperty( new PropertyDateTimeImpl( id, value ) );
204 }
205
206
207
208
209
210
211
212
213
214 protected boolean checkAddProperty( org.apache.chemistry.opencmis.commons.data.Properties properties,
215 String typeId, Set<String> filter, String id )
216 {
217 if ( ( properties == null ) || ( properties.getProperties( ) == null ) )
218 {
219 throw new IllegalArgumentException( "Properties must not be null!" );
220 }
221
222 if ( id == null )
223 {
224 throw new IllegalArgumentException( "Id must not be null!" );
225 }
226
227 return true;
228 }
229
230
231
232
233
234
235
236 protected static boolean addPropertyDefault( PropertiesImpl props, PropertyDefinition<?> propDef )
237 {
238 if ( ( props == null ) || ( props.getProperties( ) == null ) )
239 {
240 throw new IllegalArgumentException( "Props must not be null!" );
241 }
242
243 if ( propDef == null )
244 {
245 return false;
246 }
247
248 List<?> defaultValue = propDef.getDefaultValue( );
249
250 if ( ( defaultValue != null ) && ( !defaultValue.isEmpty( ) ) )
251 {
252 switch ( propDef.getPropertyType( ) )
253 {
254 case BOOLEAN:
255 props.addProperty( new PropertyBooleanImpl( propDef.getId( ), (List<Boolean>) defaultValue ) );
256
257 break;
258
259 case DATETIME:
260 props.addProperty( new PropertyDateTimeImpl( propDef.getId( ),
261 (List<GregorianCalendar>) defaultValue ) );
262
263 break;
264
265 case DECIMAL:
266 props.addProperty( new PropertyDecimalImpl( propDef.getId( ), (List<BigDecimal>) defaultValue ) );
267
268 break;
269
270 case HTML:
271 props.addProperty( new PropertyHtmlImpl( propDef.getId( ), (List<String>) defaultValue ) );
272
273 break;
274
275 case ID:
276 props.addProperty( new PropertyIdImpl( propDef.getId( ), (List<String>) defaultValue ) );
277
278 break;
279
280 case INTEGER:
281 props.addProperty( new PropertyIntegerImpl( propDef.getId( ), (List<BigInteger>) defaultValue ) );
282
283 break;
284
285 case STRING:
286 props.addProperty( new PropertyStringImpl( propDef.getId( ), (List<String>) defaultValue ) );
287
288 break;
289
290 case URI:
291 props.addProperty( new PropertyUriImpl( propDef.getId( ), (List<String>) defaultValue ) );
292
293 break;
294
295 default:
296 throw new RuntimeException( "Unknown datatype! Spec change?" );
297 }
298
299 return true;
300 }
301
302 return false;
303 }
304
305
306
307
308
309
310 protected static GregorianCalendar millisToCalendar( long millis )
311 {
312 GregorianCalendar result = new GregorianCalendar( );
313 result.setTimeZone( TimeZone.getTimeZone( "GMT" ) );
314 result.setTimeInMillis( (long) ( Math.ceil( millis / 1000 ) * 1000 ) );
315
316 return result;
317 }
318 }