001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Florent Guillaume 018 */ 019package org.nuxeo.ecm.core.opencmis.impl.client; 020 021import java.util.Collections; 022import java.util.List; 023 024import org.apache.chemistry.opencmis.client.api.FileableCmisObject; 025import org.apache.chemistry.opencmis.client.api.Folder; 026import org.apache.chemistry.opencmis.client.api.ObjectId; 027import org.apache.chemistry.opencmis.client.api.ObjectType; 028import org.apache.chemistry.opencmis.client.api.OperationContext; 029import org.apache.chemistry.opencmis.client.api.SecondaryType; 030import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException; 031import org.apache.chemistry.opencmis.commons.spi.Holder; 032import org.nuxeo.ecm.core.api.CoreSession; 033import org.nuxeo.ecm.core.api.DocumentModel; 034import org.nuxeo.ecm.core.api.IdRef; 035import org.nuxeo.ecm.core.opencmis.impl.server.NuxeoObjectData; 036 037/** 038 * Base abstract fileable live local CMIS Object. 039 */ 040public abstract class NuxeoFileableObject extends NuxeoObject implements FileableCmisObject { 041 042 public NuxeoFileableObject(NuxeoSession session, NuxeoObjectData data, ObjectType type, 043 List<SecondaryType> secondaryTypes) { 044 super(session, data, type, secondaryTypes); 045 } 046 047 @Override 048 public List<Folder> getParents(OperationContext context) { 049 // context ignored 050 CoreSession coreSession = data.doc.getCoreSession(); 051 DocumentModel parent = coreSession.getParentDocument(new IdRef(getId())); 052 if (parent == null || nuxeoCmisService.isFilteredOut(parent)) { 053 return Collections.emptyList(); 054 } 055 Folder folder = (Folder) session.getObject(parent, session.getDefaultContext()); 056 return Collections.singletonList(folder); 057 } 058 059 @Override 060 public List<Folder> getParents() { 061 return getParents(null); 062 } 063 064 @Override 065 public List<String> getPaths() { 066 return Collections.singletonList(data.doc.getPathAsString()); 067 } 068 069 @Override 070 public void addToFolder(ObjectId folderId, boolean allVersions) { 071 throw new UnsupportedOperationException("Multi-filing not supported"); 072 } 073 074 @Override 075 public void removeFromFolder(ObjectId folderId) { 076 service.removeObjectFromFolder(getRepositoryId(), getId(), folderId == null ? null : folderId.getId(), null); 077 } 078 079 @Override 080 public NuxeoFileableObject move(ObjectId sourceFolder, ObjectId targetFolder, OperationContext context) { 081 // context ignored 082 Holder<String> objectIdHolder = new Holder<>(getId()); 083 if (sourceFolder == null) { 084 throw new CmisInvalidArgumentException("Missing source folder"); 085 } 086 if (targetFolder == null) { 087 throw new CmisInvalidArgumentException("Missing target folder"); 088 } 089 service.moveObject(getRepositoryId(), objectIdHolder, targetFolder.getId(), sourceFolder.getId(), null); 090 return this; 091 } 092 093 @Override 094 public NuxeoFileableObject move(ObjectId sourceFolder, ObjectId targetFolder) { 095 return move(sourceFolder, targetFolder, null); 096 } 097 098}