This project has retired. For details please refer to its
Attic page.
InMemoryMultiFilingServiceImpl xref
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19package org.apache.chemistry.opencmis.inmemory.server;
2021import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
22import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
23import org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException;
24import org.apache.chemistry.opencmis.commons.impl.server.ObjectInfoImpl;
25import org.apache.chemistry.opencmis.commons.server.CallContext;
26import org.apache.chemistry.opencmis.commons.server.ObjectInfoHandler;
27import org.apache.chemistry.opencmis.inmemory.storedobj.api.Folder;
28import org.apache.chemistry.opencmis.inmemory.storedobj.api.MultiFiling;
29import org.apache.chemistry.opencmis.inmemory.storedobj.api.ObjectStore;
30import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoreManager;
31import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoredObject;
32import org.apache.commons.logging.Log;
33import org.apache.commons.logging.LogFactory;
3435publicclassInMemoryMultiFilingServiceImplextendsInMemoryAbstractServiceImpl {
3637privatestaticfinal Log LOG = LogFactory.getLog(InMemoryMultiFilingServiceImpl.class.getName());
3839finalAtomLinkInfoProvider fAtomLinkProvider;
4041publicInMemoryMultiFilingServiceImpl(StoreManager storeMgr) {
42super(storeMgr);
43 fAtomLinkProvider = newAtomLinkInfoProvider(storeMgr);
44 }
4546publicvoid addObjectToFolder(CallContext context, String repositoryId, String objectId, String folderId,
47 Boolean allVersions, ExtensionsData extension, ObjectInfoHandler objectInfos) {
4849 LOG.debug("Begin addObjectToFolder()");
5051StoredObject[] sos = validator.addObjectToFolder(context, repositoryId, objectId, folderId, allVersions, extension);
5253if (allVersions != null && allVersions.booleanValue() == false) {
54thrownew CmisNotSupportedException(
55"Cannot add object to folder, version specific filing is not supported.");
56 }
57StoredObject so = sos[0];
58StoredObject folder = sos[1];
59 checkObjects(so, folder);
6061Folder newParent = (Folder) folder;
62MultiFiling obj = (MultiFiling) so;
63 obj.addParent(newParent);
6465if (context.isObjectInfoRequired()) {
66 ObjectInfoImpl objectInfo = new ObjectInfoImpl();
67 fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfo);
68 fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, folder, objectInfo);
69 objectInfos.addObjectInfo(objectInfo);
70 }
7172 LOG.debug("End addObjectToFolder()");
73 }
7475publicvoid removeObjectFromFolder(CallContext context, String repositoryId, String objectId,
76 String folderId, ExtensionsData extension, ObjectInfoHandler objectInfos) {
7778 LOG.debug("Begin removeObjectFromFolder()");
7980StoredObject[] sos = validator.removeObjectFromFolder(context, repositoryId, objectId, folderId, extension);
81StoredObject so = sos[0];
8283ObjectStore objectStore = fStoreManager.getObjectStore(repositoryId);
84StoredObject folder = sos[1];
8586 checkObjects(so, folder);
87Folder parent = (Folder) folder;
88MultiFiling obj = (MultiFiling) so;
89 obj.removeParent(parent);
9091// To be able to provide all Atom links in the response we need92// additional information:93if (context.isObjectInfoRequired()) {
94 ObjectInfoImpl objectInfo = new ObjectInfoImpl();
95 fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfo);
96 fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, folder, objectInfo);
97 objectInfos.addObjectInfo(objectInfo);
98 }
99100 LOG.debug("End removeObjectFromFolder()");
101 }
102103privatestaticvoid checkObjects(StoredObject so, StoredObject folder) {
104if (!(so instanceof MultiFiling)) {
105thrownew CmisConstraintException("Cannot add object to folder, object id " + so.getId()
106 + " is not a multi-filed object.");
107 }
108109if ((so instanceof Folder)) {
110thrownew CmisConstraintException("Cannot add object to folder, object id " + folder.getId()
111 + " is a folder and folders are not multi-filed.");
112 }
113114if (!(folder instanceof Folder)) {
115thrownew CmisConstraintException("Cannot add object to folder, folder id " + folder.getId()
116 + " does not refer to a folder.");
117 }
118 }
119120 }