This project has retired. For details please refer to its
Attic page.
InMemoryAbstractServiceImpl 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.CmisInvalidArgumentException;
26import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException;
27import org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException;
28import org.apache.chemistry.opencmis.inmemory.storedobj.api.CmisServiceValidator;
29import org.apache.chemistry.opencmis.inmemory.storedobj.api.DocumentVersion;
30import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoreManager;
31import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoredObject;
32import org.apache.chemistry.opencmis.inmemory.storedobj.api.VersionedDocument;
3334/**35 * Common functionality for all service implementations36 *37 * @author Jens38 *39 */40publicclassInMemoryAbstractServiceImpl {
4142protectedfinalStoreManager fStoreManager;
43protectedfinalCmisServiceValidator validator;
4445protectedInMemoryAbstractServiceImpl(StoreManager storeManager, CmisServiceValidator validator) {
46this.fStoreManager = storeManager;
47this.validator = validator;
48 }
4950protectedInMemoryAbstractServiceImpl(StoreManager storeManager) {
51this.fStoreManager = storeManager;
52this.validator = storeManager.getServiceValidator();
53 }
5455protected TypeDefinition getTypeDefinition(String repositoryId, Properties properties) {
56if (null == properties)
57returnnull;
5859 String typeId = (String) properties.getProperties().get(PropertyIds.OBJECT_TYPE_ID).getFirstValue();
60 TypeDefinitionContainer typeDefC = fStoreManager.getTypeById(repositoryId, typeId);
61if (typeDefC == null) {
62thrownew CmisInvalidArgumentException("Cannot create object, a type with id " + typeId + " is unknown");
63 }
6465return typeDefC.getTypeDefinition();
66 }
6768protected TypeDefinition getTypeDefinition(String repositoryId, StoredObject obj) {
6970 TypeDefinitionContainer typeDefC = fStoreManager.getTypeById(repositoryId, obj.getTypeId());
71return typeDefC.getTypeDefinition();
72 }
7374/**75 * We allow checkin, cancel, checkout operations on a single version as well76 * as on a version series This method returns the versioned document77 * (version series) in each case78 *79 * @param value80 * version or version series id of a document81 * @return version series id82 */83protectedVersionedDocument getVersionedDocumentOfObjectId(StoredObject so) {
8485VersionedDocument verDoc;
86if (so instanceof DocumentVersion) {
87// get document the version is contained in to c88 verDoc = ((DocumentVersion) so).getParentDocument();
89 } else {
90 verDoc = (VersionedDocument) so;
91 }
9293return verDoc;
94 }
9596protectedVersionedDocument testIsNotCheckedOutBySomeoneElse(StoredObject so, String user) {
97 checkIsVersionableObject(so);
98VersionedDocument verDoc = getVersionedDocumentOfObjectId(so);
99if (verDoc.isCheckedOut()) {
100 testCheckedOutByCurrentUser(user, verDoc);
101 }
102103return verDoc;
104 }
105106protectedVersionedDocument testHasProperCheckedOutStatus(StoredObject so, String user) {
107108 checkIsVersionableObject(so);
109VersionedDocument verDoc = getVersionedDocumentOfObjectId(so);
110111 checkHasUser(user);
112113 testIsCheckedOut(verDoc);
114 testCheckedOutByCurrentUser(user, verDoc);
115116return verDoc;
117 }
118119protectedvoid checkIsVersionableObject(StoredObject so) {
120if (!(so instanceof VersionedDocument || so instanceof DocumentVersion)) {
121thrownew CmisInvalidArgumentException(
122"Object is of a versionable type but not instance of VersionedDocument or DocumentVersion.");
123 }
124 }
125126protectedvoid checkHasUser(String user) {
127if (null == user || user.length() == 0) {
128thrownew CmisPermissionDeniedException("Object can't be checked-in, no user is given.");
129 }
130 }
131132protectedvoid testCheckedOutByCurrentUser(String user, VersionedDocument verDoc) {
133if (!user.equals(verDoc.getCheckedOutBy())) {
134thrownew CmisUpdateConflictException("User " + verDoc.getCheckedOutBy()
135 + " has checked out the document.");
136 }
137 }
138139protectedvoid testIsCheckedOut(VersionedDocument verDoc) {
140if (!verDoc.isCheckedOut()) {
141thrownew CmisUpdateConflictException("Document " + verDoc.getId() + " is not checked out.");
142 }
143 }
144145protectedboolean isCheckedOut(StoredObject so, String user) {
146if (so instanceof VersionedDocument || so instanceof DocumentVersion) {
147VersionedDocument verDoc = getVersionedDocumentOfObjectId(so);
148return verDoc.isCheckedOut() && user.equals(verDoc.getCheckedOutBy());
149 } else150return false;
151152153 }
154155 }