This project has retired. For details please refer to its Attic page.
InMemoryMultiFilingServiceImpl 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 org.apache.chemistry.opencmis.commons.data.ExtensionsData;
22  import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
23  import org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException;
24  import org.apache.chemistry.opencmis.commons.impl.server.ObjectInfoImpl;
25  import org.apache.chemistry.opencmis.commons.server.CallContext;
26  import org.apache.chemistry.opencmis.commons.server.ObjectInfoHandler;
27  import org.apache.chemistry.opencmis.inmemory.storedobj.api.Folder;
28  import org.apache.chemistry.opencmis.inmemory.storedobj.api.MultiFiling;
29  import org.apache.chemistry.opencmis.inmemory.storedobj.api.ObjectStore;
30  import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoreManager;
31  import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoredObject;
32  import org.apache.commons.logging.Log;
33  import org.apache.commons.logging.LogFactory;
34  
35  public class InMemoryMultiFilingServiceImpl extends InMemoryAbstractServiceImpl {
36  
37      private static final Log LOG = LogFactory.getLog(InMemoryMultiFilingServiceImpl.class.getName());
38  
39      final AtomLinkInfoProvider fAtomLinkProvider;
40  
41      public InMemoryMultiFilingServiceImpl(StoreManager storeMgr) {
42          super(storeMgr);
43          fAtomLinkProvider = new AtomLinkInfoProvider(storeMgr);
44      }
45  
46      public void addObjectToFolder(CallContext context, String repositoryId, String objectId, String folderId,
47              Boolean allVersions, ExtensionsData extension, ObjectInfoHandler objectInfos) {
48  
49          LOG.debug("Begin addObjectToFolder()");
50  
51          StoredObject[] sos = validator.addObjectToFolder(context, repositoryId, objectId, folderId, allVersions, extension);
52  
53          if (allVersions != null && allVersions.booleanValue() == false) {
54              throw new CmisNotSupportedException(
55                      "Cannot add object to folder, version specific filing is not supported.");
56          }
57          StoredObject so = sos[0];
58          StoredObject folder = sos[1];
59          checkObjects(so, folder);
60  
61          Folder newParent = (Folder) folder;
62          MultiFiling obj = (MultiFiling) so;
63          obj.addParent(newParent);
64  
65          if (context.isObjectInfoRequired()) {
66              ObjectInfoImpl objectInfo = new ObjectInfoImpl();
67              fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfo);
68              fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, folder, objectInfo);
69              objectInfos.addObjectInfo(objectInfo);
70          }
71  
72          LOG.debug("End addObjectToFolder()");
73      }
74  
75      public void removeObjectFromFolder(CallContext context, String repositoryId, String objectId,
76              String folderId, ExtensionsData extension, ObjectInfoHandler objectInfos) {
77  
78          LOG.debug("Begin removeObjectFromFolder()");
79  
80          StoredObject[] sos = validator.removeObjectFromFolder(context, repositoryId, objectId, folderId, extension);
81          StoredObject so = sos[0];
82  
83          ObjectStore objectStore = fStoreManager.getObjectStore(repositoryId);
84          StoredObject folder = sos[1];
85  
86          checkObjects(so, folder);
87          Folder parent = (Folder) folder;
88          MultiFiling obj = (MultiFiling) so;
89          obj.removeParent(parent);
90  
91          // To be able to provide all Atom links in the response we need
92          // additional information:
93          if (context.isObjectInfoRequired()) {
94              ObjectInfoImpl objectInfo = new ObjectInfoImpl();
95              fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfo);
96              fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, folder, objectInfo);
97              objectInfos.addObjectInfo(objectInfo);
98          }
99  
100         LOG.debug("End removeObjectFromFolder()");
101     }
102 
103     private static void checkObjects(StoredObject so, StoredObject folder) {
104         if (!(so instanceof MultiFiling)) {
105             throw new CmisConstraintException("Cannot add object to folder, object id " + so.getId()
106                     + " is not a multi-filed object.");
107         }
108 
109         if ((so instanceof Folder)) {
110             throw new CmisConstraintException("Cannot add object to folder, object id " + folder.getId()
111                     + " is a folder and folders are not multi-filed.");
112         }
113 
114         if (!(folder instanceof Folder)) {
115             throw new CmisConstraintException("Cannot add object to folder, folder id " + folder.getId()
116                     + " does not refer to a folder.");
117         }
118     }
119 
120 }