This project has retired. For details please refer to its Attic page.
InMemoryDiscoveryServiceImpl 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.math.BigInteger;
22  import java.util.ArrayList;
23  import java.util.GregorianCalendar;
24  import java.util.List;
25  
26  import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
27  import org.apache.chemistry.opencmis.commons.data.ObjectData;
28  import org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer;
29  import org.apache.chemistry.opencmis.commons.data.ObjectList;
30  import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
31  import org.apache.chemistry.opencmis.commons.enums.ChangeType;
32  import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
33  import org.apache.chemistry.opencmis.commons.impl.dataobjects.ChangeEventInfoDataImpl;
34  import org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectDataImpl;
35  import org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectListImpl;
36  import org.apache.chemistry.opencmis.commons.server.CallContext;
37  import org.apache.chemistry.opencmis.commons.server.ObjectInfoHandler;
38  import org.apache.chemistry.opencmis.commons.spi.Holder;
39  import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoreManager;
40  import org.apache.commons.logging.Log;
41  import org.apache.commons.logging.LogFactory;
42  
43  public class InMemoryDiscoveryServiceImpl extends InMemoryAbstractServiceImpl{
44      
45      private static final Log LOG = LogFactory.getLog(InMemoryDiscoveryServiceImpl.class);
46  
47      final AtomLinkInfoProvider fAtomLinkProvider;
48      final InMemoryNavigationServiceImpl fNavigationService; // real implementation of
49      // the service
50      final InMemoryRepositoryServiceImpl fRepositoryService;
51  
52      public InMemoryDiscoveryServiceImpl(StoreManager storeManager, InMemoryRepositoryServiceImpl repSvc,
53              InMemoryNavigationServiceImpl navSvc) {
54          super(storeManager);
55          fAtomLinkProvider = new AtomLinkInfoProvider(fStoreManager);
56          fNavigationService = navSvc;
57          fRepositoryService = repSvc;
58      }
59  
60      public ObjectList getContentChanges(CallContext context, String repositoryId, Holder<String> changeLogToken,
61              Boolean includeProperties, String filter, Boolean includePolicyIds, Boolean includeAcl,
62              BigInteger maxItems, ExtensionsData extension, ObjectInfoHandler objectInfos) {
63          // dummy implementation using hard coded values
64  
65          RepositoryInfo rep = fRepositoryService.getRepositoryInfo(context, repositoryId, null);
66          String rootFolderId = rep.getRootFolderId();
67  
68          ObjectListImpl objList = new ObjectListImpl();
69          List<ObjectInFolderContainer> tempRes = fNavigationService.getDescendants(context, repositoryId, rootFolderId,
70                  BigInteger.valueOf(3), filter, false, IncludeRelationships.NONE, null, false, extension, null);
71  
72          // convert ObjectInFolderContainerList to objectList
73          List<ObjectData> lod = new ArrayList<ObjectData>();
74          for (ObjectInFolderContainer obj : tempRes) {
75              convertList(lod, obj);
76          }
77          objList.setObjects(lod);
78          objList.setNumItems(BigInteger.valueOf(lod.size()));
79  
80          // To be able to provide all Atom links in the response we need
81          // additional information:
82          fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, null, objectInfos, objList);
83          return objList;
84      }
85  
86      private void convertList(List<ObjectData> lod, ObjectInFolderContainer obj) {
87          lod.add(obj.getObject().getObject());
88          // add dummy event info
89          ObjectData oif = obj.getObject().getObject();
90          ObjectDataImpl oifImpl = (ObjectDataImpl) oif;
91          ChangeEventInfoDataImpl changeEventInfo = new ChangeEventInfoDataImpl();
92          changeEventInfo.setChangeType(ChangeType.UPDATED);
93          changeEventInfo.setChangeTime(new GregorianCalendar());
94          oifImpl.setChangeEventInfo(changeEventInfo);
95          if (null != obj.getChildren()) {
96              for (ObjectInFolderContainer oifc : obj.getChildren()) {
97                  convertList(lod, oifc);
98              }
99          }
100     }
101 
102      public ObjectList query(CallContext context, String repositoryId, String statement, Boolean searchAllVersions,
103             Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
104             BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
105 
106         LOG.debug("start query()");
107         validator.query(context, repositoryId, extension);
108         
109         String user = context.getUsername();
110         ObjectList res;
111         
112         res = fStoreManager.query(user, repositoryId, statement, searchAllVersions, includeAllowableActions,
113                 includeRelationships, renditionFilter, maxItems, skipCount);
114         LOG.debug("stop query()");
115         return res;
116     }
117 
118 }