This project has retired. For details please refer to its
Attic page.
AbstractServiceImpl 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.PropertyIds;
22import org.apache.chemistry.opencmis.commons.data.Properties;
23import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
24import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer;
25import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
26import org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException;
27import org.apache.chemistry.opencmis.inmemory.storedobj.api.DocumentVersion;
28import org.apache.chemistry.opencmis.inmemory.storedobj.api.ObjectStore;
29import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoreManager;
30import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoredObject;
31import org.apache.chemistry.opencmis.inmemory.storedobj.api.VersionedDocument;
3233/**34 * Common functionality for all service implementations35 *36 * @author Jens37 *38 */39publicclassAbstractServiceImpl {
4041protectedfinalStoreManager fStoreManager;
4243protectedAbstractServiceImpl(StoreManager storeManager) {
44 fStoreManager = storeManager;
45 }
4647/**48 * check if repository is known and that object exists. To avoid later calls49 * to again retrieve the object from the id return the retrieved object for50 * later use.51 *52 * @param repositoryId53 * repository id54 * @param objectId55 * object id56 * @return object for objectId57 */58protectedStoredObject checkStandardParameters(String repositoryId, String objectId) {
5960ObjectStore objStore = fStoreManager.getObjectStore(repositoryId);
6162if (objStore == null) {
63thrownew CmisObjectNotFoundException("Unknown repository id: " + repositoryId);
64 }
6566StoredObject so = objStore.getObjectById(objectId);
6768if (so == null) {
69thrownew CmisObjectNotFoundException("Unknown object id: " + objectId);
70 }
7172return so;
73 }
7475protectedStoredObject checkExistingObjectId(ObjectStore objStore, String objectId) {
76StoredObject so = objStore.getObjectById(objectId);
7778if (so == null) {
79thrownew CmisObjectNotFoundException("Unknown object id: " + objectId);
80 }
8182return so;
83 }
8485protectedvoid checkRepositoryId(String repositoryId) {
86ObjectStore objStore = fStoreManager.getObjectStore(repositoryId);
8788if (objStore == null) {
89thrownew CmisObjectNotFoundException("Unknown repository id: " + repositoryId);
90 }
91 }
9293protected TypeDefinition getTypeDefinition(String repositoryId, Properties properties) {
94 String typeId = (String) properties.getProperties().get(PropertyIds.OBJECT_TYPE_ID).getFirstValue();
95 TypeDefinitionContainer typeDefC = fStoreManager.getTypeById(repositoryId, typeId);
96if (typeDefC == null) {
97thrownew RuntimeException("Cannot create object, a type with id " + typeId + " is unknown");
98 }
99100return typeDefC.getTypeDefinition();
101 }
102103protected TypeDefinition getTypeDefinition(String repositoryId, StoredObject obj) {
104105 TypeDefinitionContainer typeDefC = fStoreManager.getTypeById(repositoryId, obj.getTypeId());
106return typeDefC.getTypeDefinition();
107 }
108109/**110 * We allow checkin, cancel, checkout operations on a single version as well111 * as on a version series This method returns the versioned document112 * (version series) in each case113 *114 * @param value115 * version or version series id of a document116 * @return version series id117 */118protectedVersionedDocument getVersionedDocumentOfObjectId(StoredObject so) {
119VersionedDocument verDoc;
120if (so instanceof DocumentVersion) {
121// get document the version is contained in to c122 verDoc = ((DocumentVersion) so).getParentDocument();
123 } else {
124 verDoc = (VersionedDocument) so;
125 }
126127return verDoc;
128 }
129130protectedVersionedDocument testIsNotCheckedOutBySomeoneElse(StoredObject so, String user) {
131 checkIsVersionableObject(so);
132VersionedDocument verDoc = getVersionedDocumentOfObjectId(so);
133if (verDoc.isCheckedOut()) {
134 testCheckedOutByCurrentUser(user, verDoc);
135 }
136137return verDoc;
138 }
139140protectedVersionedDocument testHasProperCheckedOutStatus(StoredObject so, String user) {
141 checkIsVersionableObject(so);
142VersionedDocument verDoc = getVersionedDocumentOfObjectId(so);
143144 checkHasUser(user);
145146 testIsCheckedOut(verDoc);
147 testCheckedOutByCurrentUser(user, verDoc);
148149return verDoc;
150 }
151152protectedvoid checkIsVersionableObject(StoredObject so) {
153if (!(so instanceof VersionedDocument || so instanceof DocumentVersion)) {
154thrownew RuntimeException(
155"Object is of a versionable type but not instance of VersionedDocument or DocumentVersion.");
156 }
157 }
158159protectedvoid checkHasUser(String user) {
160if (null == user || user.length() == 0) {
161thrownew CmisUpdateConflictException("Object can't be checked-in, no user is given.");
162 }
163 }
164165protectedvoid testCheckedOutByCurrentUser(String user, VersionedDocument verDoc) {
166if (!user.equals(verDoc.getCheckedOutBy())) {
167thrownew CmisUpdateConflictException("Object can't be checked-in, user " + verDoc.getCheckedOutBy()
168 + " has checked out the document.");
169 }
170 }
171172protectedvoid testIsCheckedOut(VersionedDocument verDoc) {
173if (!verDoc.isCheckedOut()) {
174thrownew CmisUpdateConflictException("Canot check-in: Document " + verDoc.getId() + " is not checked out.");
175 }
176 }
177178 }