This project has retired. For details please refer to its
Attic page.
StoredObjectImpl xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.inmemory.storedobj.impl;
20
21 import java.math.BigInteger;
22 import java.util.Date;
23 import java.util.GregorianCalendar;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.TimeZone;
28 import java.util.Map.Entry;
29
30 import org.apache.chemistry.opencmis.commons.PropertyIds;
31 import org.apache.chemistry.opencmis.commons.data.Acl;
32 import org.apache.chemistry.opencmis.commons.data.AllowableActions;
33 import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
34 import org.apache.chemistry.opencmis.commons.data.ObjectList;
35 import org.apache.chemistry.opencmis.commons.data.PropertyData;
36 import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
37 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
38 import org.apache.chemistry.opencmis.commons.enums.RelationshipDirection;
39 import org.apache.chemistry.opencmis.commons.spi.BindingsObjectFactory;
40 import org.apache.chemistry.opencmis.inmemory.DataObjectCreator;
41 import org.apache.chemistry.opencmis.inmemory.FilterParser;
42 import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoredObject;
43
44
45
46
47
48
49
50 public class StoredObjectImpl implements StoredObject {
51
52 protected String fId;
53 protected String fName;
54 protected String fTypeId;
55 protected String fCreatedBy;
56 protected String fModifiedBy;
57 protected GregorianCalendar fCreatedAt;
58 protected GregorianCalendar fModifiedAt;
59 protected String fRepositoryId;
60 protected Map<String, PropertyData<?>> fProperties;
61 protected final ObjectStoreImpl fObjStore;
62 protected int fAclId;
63
64 StoredObjectImpl(ObjectStoreImpl objStore) {
65 GregorianCalendar now = getNow();
66 now.setTime(new Date());
67 fCreatedAt = now;
68 fModifiedAt = now;
69 fObjStore = objStore;
70 }
71
72 public String getId() {
73 return fId;
74 }
75
76 public String getName() {
77 return fName;
78 }
79
80 public void setName(String name) {
81 fName = name;
82 }
83
84 public String getTypeId() {
85 return fTypeId;
86 }
87
88 public void setTypeId(String type) {
89 fTypeId = type;
90 }
91
92 public String getCreatedBy() {
93 return fCreatedBy;
94 }
95
96 public void setCreatedBy(String createdBy) {
97 this.fCreatedBy = createdBy;
98 }
99
100 public String getModifiedBy() {
101 return fModifiedBy;
102 }
103
104 public void setModifiedBy(String modifiedBy) {
105 this.fModifiedBy = modifiedBy;
106 }
107
108 public GregorianCalendar getCreatedAt() {
109 return fCreatedAt;
110 }
111
112 public void setCreatedAt(GregorianCalendar createdAt) {
113 this.fCreatedAt = createdAt;
114 }
115
116 public GregorianCalendar getModifiedAt() {
117 return fModifiedAt;
118 }
119
120 public void setModifiedAtNow() {
121 this.fModifiedAt = getNow();
122 }
123
124 public void setRepositoryId(String repositoryId) {
125 fRepositoryId = repositoryId;
126 }
127
128 public String getRepositoryId() {
129 return fRepositoryId;
130 }
131
132 public void setProperties(Map<String, PropertyData<?>> props) {
133 fProperties = props;
134 }
135
136 public Map<String, PropertyData<?>> getProperties() {
137 return fProperties;
138 }
139
140 public String getChangeToken() {
141 GregorianCalendar lastModified = getModifiedAt();
142 String token = Long.valueOf(lastModified.getTimeInMillis()).toString();
143 return token;
144 }
145
146 public void rename(String newName) {
147 setName(newName);
148 }
149
150 public void createSystemBasePropertiesWhenCreated(Map<String, PropertyData<?>> properties, String user) {
151 addSystemBaseProperties(properties, user, true);
152 }
153
154 public void updateSystemBasePropertiesWhenModified(Map<String, PropertyData<?>> properties, String user) {
155 addSystemBaseProperties(properties, user, false);
156 }
157
158 public void fillProperties(Map<String, PropertyData<?>> properties, BindingsObjectFactory objFactory,
159 List<String> requestedIds) {
160
161 if (FilterParser.isContainedInFilter(PropertyIds.NAME, requestedIds)) {
162 properties.put(PropertyIds.NAME, objFactory.createPropertyStringData(PropertyIds.NAME, getName()));
163 }
164 if (FilterParser.isContainedInFilter(PropertyIds.OBJECT_ID, requestedIds)) {
165 properties.put(PropertyIds.OBJECT_ID, objFactory.createPropertyIdData(PropertyIds.OBJECT_ID, getId()));
166 }
167 if (FilterParser.isContainedInFilter(PropertyIds.OBJECT_TYPE_ID, requestedIds)) {
168 properties.put(PropertyIds.OBJECT_TYPE_ID, objFactory.createPropertyIdData(PropertyIds.OBJECT_TYPE_ID,
169 getTypeId()));
170 }
171
172
173
174
175
176
177 if (FilterParser.isContainedInFilter(PropertyIds.CREATED_BY, requestedIds)) {
178 properties.put(PropertyIds.CREATED_BY, objFactory.createPropertyStringData(PropertyIds.CREATED_BY,
179 getCreatedBy()));
180 }
181 if (FilterParser.isContainedInFilter(PropertyIds.CREATION_DATE, requestedIds)) {
182 properties.put(PropertyIds.CREATION_DATE, objFactory.createPropertyDateTimeData(PropertyIds.CREATION_DATE,
183 getCreatedAt()));
184 }
185 if (FilterParser.isContainedInFilter(PropertyIds.LAST_MODIFIED_BY, requestedIds)) {
186 properties.put(PropertyIds.LAST_MODIFIED_BY, objFactory.createPropertyStringData(
187 PropertyIds.LAST_MODIFIED_BY, getModifiedBy()));
188 }
189 if (FilterParser.isContainedInFilter(PropertyIds.LAST_MODIFICATION_DATE, requestedIds)) {
190 properties.put(PropertyIds.LAST_MODIFICATION_DATE, objFactory.createPropertyDateTimeData(
191 PropertyIds.LAST_MODIFICATION_DATE, getModifiedAt()));
192 }
193 if (FilterParser.isContainedInFilter(PropertyIds.CHANGE_TOKEN, requestedIds)) {
194 String token = getChangeToken();
195 properties.put(PropertyIds.CHANGE_TOKEN, objFactory.createPropertyStringData(PropertyIds.CHANGE_TOKEN,
196 token));
197 }
198
199
200 if (null != fProperties) {
201 for (Entry<String, PropertyData<?>> prop : fProperties.entrySet()) {
202 if (FilterParser.isContainedInFilter(prop.getKey(), requestedIds)) {
203 properties.put(prop.getKey(), prop.getValue());
204 }
205 }
206 }
207
208 }
209
210
211
212
213 public void setCustomProperties(Map<String, PropertyData<?>> properties) {
214 properties = new HashMap<String, PropertyData<?>>(properties);
215
216
217 removeAllSystemProperties(properties);
218 setProperties(properties);
219 }
220
221 private static GregorianCalendar getNow() {
222 GregorianCalendar now = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
223 return now;
224 }
225
226
227
228
229
230
231 private void addSystemBaseProperties(Map<String, PropertyData<?>> properties, String user, boolean isCreated) {
232 if (user == null) {
233 user = "unknown";
234 }
235
236
237
238 setModifiedBy(user);
239 if (isCreated) {
240 setCreatedBy(user);
241 setName((String) properties.get(PropertyIds.NAME).getFirstValue());
242 setTypeId((String) properties.get(PropertyIds.OBJECT_TYPE_ID).getFirstValue());
243 } else {
244 setModifiedAtNow();
245 }
246 }
247
248
249
250
251
252
253 protected void setSystemBasePropertiesWhenCreatedDirect(String name, String typeId, String user) {
254
255
256 setModifiedBy(user);
257 setCreatedBy(user);
258 setName(name);
259 setTypeId(typeId);
260 }
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282 private static void removeAllSystemProperties(Map<String, PropertyData<?>> properties) {
283
284 if (properties.containsKey(PropertyIds.NAME)) {
285 properties.remove(PropertyIds.NAME);
286 }
287 if (properties.containsKey(PropertyIds.OBJECT_ID)) {
288 properties.remove(PropertyIds.OBJECT_ID);
289 }
290 if (properties.containsKey(PropertyIds.OBJECT_TYPE_ID)) {
291 properties.remove(PropertyIds.OBJECT_TYPE_ID);
292 }
293 if (properties.containsKey(PropertyIds.BASE_TYPE_ID)) {
294 properties.remove(PropertyIds.BASE_TYPE_ID);
295 }
296 if (properties.containsKey(PropertyIds.CREATED_BY)) {
297 properties.remove(PropertyIds.CREATED_BY);
298 }
299 if (properties.containsKey(PropertyIds.CREATION_DATE)) {
300 properties.remove(PropertyIds.CREATION_DATE);
301 }
302 if (properties.containsKey(PropertyIds.LAST_MODIFIED_BY)) {
303 properties.remove(PropertyIds.LAST_MODIFIED_BY);
304 }
305 if (properties.containsKey(PropertyIds.LAST_MODIFICATION_DATE)) {
306 properties.remove(PropertyIds.LAST_MODIFICATION_DATE);
307 }
308 if (properties.containsKey(PropertyIds.CHANGE_TOKEN)) {
309 properties.remove(PropertyIds.CHANGE_TOKEN);
310 }
311
312 if (properties.containsKey(PropertyIds.IS_IMMUTABLE)) {
313 properties.remove(PropertyIds.IS_IMMUTABLE);
314 }
315 if (properties.containsKey(PropertyIds.IS_LATEST_VERSION)) {
316 properties.remove(PropertyIds.IS_LATEST_VERSION);
317 }
318 if (properties.containsKey(PropertyIds.IS_MAJOR_VERSION)) {
319 properties.remove(PropertyIds.IS_MAJOR_VERSION);
320 }
321 if (properties.containsKey(PropertyIds.IS_LATEST_MAJOR_VERSION)) {
322 properties.remove(PropertyIds.IS_LATEST_MAJOR_VERSION);
323 }
324 if (properties.containsKey(PropertyIds.VERSION_LABEL)) {
325 properties.remove(PropertyIds.VERSION_LABEL);
326 }
327 if (properties.containsKey(PropertyIds.VERSION_SERIES_ID)) {
328 properties.remove(PropertyIds.VERSION_SERIES_ID);
329 }
330 if (properties.containsKey(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT)) {
331 properties.remove(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT);
332 }
333 if (properties.containsKey(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY)) {
334 properties.remove(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY);
335 }
336 if (properties.containsKey(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID)) {
337 properties.remove(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID);
338 }
339 if (properties.containsKey(PropertyIds.CHECKIN_COMMENT)) {
340 properties.remove(PropertyIds.CHECKIN_COMMENT);
341 }
342 if (properties.containsKey(PropertyIds.CONTENT_STREAM_LENGTH)) {
343 properties.remove(PropertyIds.CONTENT_STREAM_LENGTH);
344 }
345 if (properties.containsKey(PropertyIds.CONTENT_STREAM_MIME_TYPE)) {
346 properties.remove(PropertyIds.CONTENT_STREAM_MIME_TYPE);
347 }
348 if (properties.containsKey(PropertyIds.CONTENT_STREAM_FILE_NAME)) {
349 properties.remove(PropertyIds.CONTENT_STREAM_FILE_NAME);
350 }
351 if (properties.containsKey(PropertyIds.CONTENT_STREAM_ID)) {
352 properties.remove(PropertyIds.CONTENT_STREAM_ID);
353 }
354
355 if (properties.containsKey(PropertyIds.PARENT_ID)) {
356 properties.remove(PropertyIds.PARENT_ID);
357 }
358 if (properties.containsKey(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS)) {
359 properties.remove(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS);
360 }
361 if (properties.containsKey(PropertyIds.PATH)) {
362 properties.remove(PropertyIds.PATH);
363 }
364
365 if (properties.containsKey(PropertyIds.SOURCE_ID)) {
366 properties.remove(PropertyIds.SOURCE_ID);
367 }
368 if (properties.containsKey(PropertyIds.TARGET_ID)) {
369 properties.remove(PropertyIds.TARGET_ID);
370 }
371
372 if (properties.containsKey(PropertyIds.POLICY_TEXT)) {
373 properties.remove(PropertyIds.POLICY_TEXT);
374 }
375 }
376
377 public void persist() {
378
379
380 fId = fObjStore.storeObject(this);
381 }
382
383 public Acl getAcl() {
384 return fObjStore.getAcl(fAclId);
385 }
386
387 public int getAclId() {
388 return fAclId;
389 }
390
391 public void setAclId(int aclId) {
392 fAclId = aclId;
393 }
394
395 public ObjectList getObjectRelationships(
396 Boolean includeSubRelationshipTypes,
397 RelationshipDirection relationshipDirection, String typeId,
398 String filter, Boolean includeAllowableActions,
399 BigInteger maxItems, BigInteger skipCount,
400 ExtensionsData extension, String user) {
401
402 return null;
403 }
404
405 public AllowableActions getAllowableActions(String user) {
406 AllowableActions actions = DataObjectCreator.fillAllowableActions(this, user);
407 return actions;
408 }
409
410 }