This project has retired. For details please refer to its Attic page.
AtomLinkInfoProvider xref

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.inmemory.server;
20  
21  import java.util.List;
22  
23  import org.apache.chemistry.opencmis.commons.data.ObjectData;
24  import org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer;
25  import org.apache.chemistry.opencmis.commons.data.ObjectInFolderData;
26  import org.apache.chemistry.opencmis.commons.data.ObjectInFolderList;
27  import org.apache.chemistry.opencmis.commons.data.ObjectList;
28  import org.apache.chemistry.opencmis.commons.data.ObjectParentData;
29  import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
30  import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
31  import org.apache.chemistry.opencmis.commons.impl.server.ObjectInfoImpl;
32  import org.apache.chemistry.opencmis.commons.server.ObjectInfoHandler;
33  import org.apache.chemistry.opencmis.inmemory.storedobj.api.Content;
34  import org.apache.chemistry.opencmis.inmemory.storedobj.api.DocumentVersion;
35  import org.apache.chemistry.opencmis.inmemory.storedobj.api.Filing;
36  import org.apache.chemistry.opencmis.inmemory.storedobj.api.ObjectStore;
37  import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoreManager;
38  import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoredObject;
39  import org.apache.chemistry.opencmis.inmemory.storedobj.api.VersionedDocument;
40  import org.apache.chemistry.opencmis.inmemory.types.PropertyCreationHelper;
41  
42  /**
43   * For the Atom binding more information might be required than the result of a
44   * service call provides (mainly to fill all the links). This class fills the
45   * objectInfoHolder that was introduced for this purpose
46   *
47   * @author Jens
48   *
49   */
50  public class AtomLinkInfoProvider {
51  
52      private final StoreManager fStoreManager;
53  
54      public AtomLinkInfoProvider(StoreManager storeManager) {
55          fStoreManager = storeManager;
56      }
57  
58      /**
59       * FillObjectInfoHolder object with required information needed for Atom
60       * binding for a single object
61       *
62       * @param repositoryId
63       *            id of repository
64       * @param objectId
65       *            object to retrieve information for
66       * @param objectInfos
67       *            Holder to fill with information
68       */
69      public void fillInformationForAtomLinks(String repositoryId, StoredObject so, ObjectData od, ObjectInfoImpl objInfo) {
70          if (null == objInfo || null == so) {
71              return;
72          }
73          TypeDefinition typeDef = fStoreManager.getTypeById(repositoryId, so.getTypeId()).getTypeDefinition();
74  
75          // Fill all setters:
76          objInfo.setId(so.getId());
77          objInfo.setName(so.getName());
78          objInfo.setCreatedBy(so.getCreatedBy()); // !
79          objInfo.setCreationDate(so.getCreatedAt()); // !
80          objInfo.setLastModificationDate(so.getModifiedAt());
81          objInfo.setTypeId(so.getTypeId());
82          objInfo.setBaseType(typeDef.getBaseTypeId());
83          objInfo.setObject(od);
84  
85          // versioning information:
86          if (so instanceof DocumentVersion) {
87              DocumentVersion ver = (DocumentVersion) so;
88              DocumentVersion pwc = ver.getParentDocument().getPwc();
89              objInfo.setIsCurrentVersion(ver == ver.getParentDocument().getLatestVersion(false));
90              objInfo.setVersionSeriesId(ver.getParentDocument().getId());
91              objInfo.setWorkingCopyId(pwc == null ? null : pwc.getId());
92              objInfo.setWorkingCopyOriginalId(pwc == ver ? ver.getParentDocument().getLatestVersion(false).getId()
93                      : null);
94          } else if (so instanceof VersionedDocument) {
95              VersionedDocument doc = (VersionedDocument) so;
96              DocumentVersion pwc = doc.getPwc();
97              objInfo.setIsCurrentVersion(false);
98              objInfo.setVersionSeriesId(doc.getId());
99              objInfo.setWorkingCopyId(pwc == null ? null : pwc.getId());
100             objInfo.setWorkingCopyOriginalId(null);
101         } else { // unversioned document
102             objInfo.setIsCurrentVersion(true);
103             objInfo.setVersionSeriesId(null);
104             objInfo.setWorkingCopyId(null);
105             objInfo.setWorkingCopyOriginalId(null);
106         }
107 
108         if (so instanceof Content) {
109             Content cont = ((Content) so);
110             objInfo.setHasContent(cont.getContent(0, -1) != null);
111             objInfo.setContentType(cont.getContent(0, -1) != null ? cont.getContent(0, -1).getMimeType() : null);
112             objInfo.setFileName(cont.getContent(0, -1) != null ? cont.getContent(0, -1).getFileName() : null);
113         } else {
114             objInfo.setHasContent(false);
115             objInfo.setContentType(null);
116             objInfo.setFileName(null);
117         }
118 
119         // Filing
120         if (so instanceof Filing) {
121             Filing sop = ((Filing) so);
122             objInfo.setHasParent(sop.hasParent());
123         } else {
124             objInfo.setHasParent(false);
125         }
126 
127         // Renditions, currently not supported by in-memory provider
128         objInfo.setRenditionInfos(null);
129 
130         // Relationships, currently not supported by in-memory provider
131         objInfo.setSupportsRelationships(false);
132         objInfo.setRelationshipSourceIds(null);
133         objInfo.setRelationshipTargetIds(null);
134 
135         // Policies, currently not supported by in-memory provider
136         objInfo.setSupportsPolicies(false);
137 
138         // ACLs, currently not supported by in-memory provider
139         objInfo.setHasAcl(true);
140 
141         objInfo.setSupportsDescendants(true);
142         objInfo.setSupportsFolderTree(true);
143 
144     }
145 
146     public void fillInformationForAtomLinks(String repositoryId, StoredObject so, ObjectInfoImpl objectInfo) {
147         TypeDefinition td = fStoreManager.getTypeById(repositoryId, so.getTypeId()).getTypeDefinition();
148         ObjectData od = PropertyCreationHelper.getObjectData(td, so, null, null, false,
149                 IncludeRelationships.NONE, null, false, false, null);
150         fillInformationForAtomLinks(repositoryId, so, od, objectInfo);
151     }
152 
153     /**
154      * FillObjectInfoHolder object with required information needed for Atom
155      * binding for a single object
156      *
157      * @param repositoryId
158      *            id of repository
159      * @param objectId
160      *            object to retrieve information for
161      * @param objectInfos
162      *            Holder to fill with information
163      */
164    public void fillInformationForAtomLinks(String repositoryId, String objectId, ObjectInfoImpl objectInfo) {
165         if (null == objectInfo || null == objectId) {
166             return;
167         }
168 
169         ObjectStore objectStore = fStoreManager.getObjectStore(repositoryId);
170         StoredObject so = objectStore.getObjectById(objectId);
171         fillInformationForAtomLinks(repositoryId, so, objectInfo);
172     }
173 
174 
175     /**
176      * FillObjectInfoHolder object with required information needed for Atom
177      * binding after a getChildren() call in navigation service
178      *
179      * @param repositoryId
180      *            id of repository
181      * @param objectId
182      *            object to retrieve information for
183      * @param objectInfos
184      *            Holder to fill with information
185      * @param objList
186      *            result of getChildren call
187      */
188     public void fillInformationForAtomLinks(String repositoryId, String objectId, ObjectInfoHandler objectInfos,
189             ObjectInFolderList objList) {
190 
191         if (null == objectInfos || null == objList || null == objectId) {
192             return;
193         }
194 
195 
196         // Fill object information for requested object
197         ObjectInfoImpl objectInfo = new ObjectInfoImpl();
198         fillInformationForAtomLinks(repositoryId, objectId, objectInfo);
199         objectInfos.addObjectInfo(objectInfo);
200 
201         // Fill object information for all children in result list
202         for (ObjectInFolderData object : objList.getObjects()) {
203             objectInfo = new ObjectInfoImpl();
204             fillInformationForAtomLinks(repositoryId, object.getObject().getId(), objectInfo);
205             objectInfos.addObjectInfo(objectInfo);
206         }
207     }
208 
209     /**
210      * FillObjectInfoHolder object with required information needed for Atom
211      * binding for an object list
212      *
213      * @param repositoryId
214      *            id of repository
215      * @param objectId
216      *            object to retrieve information for
217      * @param objectInfos
218      *            Holder to fill with information
219      * @param objList
220      *            result of getChildren call
221      */
222     public void fillInformationForAtomLinks(String repositoryId, String objectId, ObjectInfoHandler objectInfos,
223             ObjectList objList) {
224 
225         ObjectInfoImpl objectInfo = new ObjectInfoImpl();
226         if (null != objectId) {
227             // Fill object information for requested object
228             fillInformationForAtomLinks(repositoryId, objectId, objectInfo);
229             objectInfos.addObjectInfo(objectInfo);
230         }
231 
232         if (null != objList && null != objList.getObjects()) {
233             // Fill object information for all children in result list
234             List<ObjectData> listObjects = objList.getObjects();
235             if (null != listObjects) {
236                 for (ObjectData object : listObjects) {
237                     objectInfo = new ObjectInfoImpl();
238                     fillInformationForAtomLinks(repositoryId, object.getId(), objectInfo);
239                     objectInfos.addObjectInfo(objectInfo);
240                 }
241             }
242         }
243 
244     }
245 
246     /**
247      * FillObjectInfoHolder object with required information needed for Atom
248      * binding for an ObjectInFolderContainer
249      *
250      * @param repositoryId
251      *            id of repository
252      * @param objectId
253      *            object to retrieve information for
254      * @param objectInfos
255      *            Holder to fill with information
256      * @param objList
257      *            result of getChildren call
258      */
259     private void fillInformationForAtomLinks(String repositoryId, ObjectInfoHandler objectInfos,
260             ObjectInFolderContainer oifc) {
261 
262         if (null == objectInfos || null == oifc) {
263             return;
264         }
265 
266         // Fill object information for all elements in result list
267         fillInformationForAtomLinks(repositoryId, objectInfos, oifc.getObject());
268 
269         if (null != oifc.getChildren()) {
270             for (ObjectInFolderContainer object : oifc.getChildren()) {
271                 // call recursively
272                 ObjectInfoImpl objectInfo = new ObjectInfoImpl();
273                 fillInformationForAtomLinks(repositoryId, objectInfos, object);
274                 objectInfos.addObjectInfo(objectInfo);
275             }
276         }
277     }
278 
279     /**
280      * FillObjectInfoHolder object with required information needed for Atom
281      * binding for a list with ObjectInFolderContainers
282      *
283      * @param repositoryId
284      *            id of repository
285      * @param objectId
286      *            object to retrieve information for
287      * @param objectInfos
288      *            Holder to fill with information
289      * @param oifcList
290      *            result of getDescendants call
291      */
292     public void fillInformationForAtomLinks(String repositoryId, String objectId, ObjectInfoHandler objectInfos,
293             List<ObjectInFolderContainer> oifcList) {
294 
295         if (null == objectInfos || null == oifcList || null == objectId) {
296             return;
297         }
298 
299         ObjectInfoImpl objectInfo = new ObjectInfoImpl();
300         // Fill object information for requested object
301         fillInformationForAtomLinks(repositoryId, objectId, objectInfo);
302         objectInfos.addObjectInfo(objectInfo);
303 
304         for (ObjectInFolderContainer object : oifcList) {
305             fillInformationForAtomLinks(repositoryId, objectInfos, object);
306         }
307     }
308 
309     private void fillInformationForAtomLinks(String repositoryId, ObjectInfoHandler objectInfos,
310             ObjectInFolderData object) {
311 
312         ObjectInfoImpl objectInfo = new ObjectInfoImpl();
313         fillInformationForAtomLinks(repositoryId, object.getObject().getId(), objectInfo);
314         objectInfos.addObjectInfo(objectInfo);
315     }
316 
317     /**
318      * FillObjectInfoHolder object with required information needed for Atom
319      * binding for a list with ObjectParentData objects
320      *
321      * @param repositoryId
322      *            id of repository
323      * @param objectId
324      *            object to retrieve information for
325      * @param objectInfos
326      *            Holder to fill with information
327      * @param objParents
328      *            result of getObjectParents call
329      */
330     public void fillInformationForAtomLinksGetParents(String repositoryId, String objectId,
331             ObjectInfoHandler objectInfos, List<ObjectParentData> objParents) {
332 
333         if (null == objectInfos || null == objParents || null == objectId) {
334             return;
335         }
336 
337         // Fill object information for requested object
338         ObjectInfoImpl objectInfo = new ObjectInfoImpl();
339         fillInformationForAtomLinks(repositoryId, objectId, objectInfo);
340 
341         for (ObjectParentData object : objParents) {
342             objectInfo = new ObjectInfoImpl();
343             fillInformationForAtomLinks(repositoryId, object.getObject().getId(), objectInfo);
344             objectInfos.addObjectInfo(objectInfo);
345         }
346     }
347 
348 }