001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Florent Guillaume 011 */ 012package org.nuxeo.ecm.core.opencmis.impl.client; 013 014import java.util.Collections; 015import java.util.List; 016 017import org.apache.chemistry.opencmis.client.api.FileableCmisObject; 018import org.apache.chemistry.opencmis.client.api.Folder; 019import org.apache.chemistry.opencmis.client.api.ObjectId; 020import org.apache.chemistry.opencmis.client.api.ObjectType; 021import org.apache.chemistry.opencmis.client.api.OperationContext; 022import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException; 023import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException; 024import org.apache.chemistry.opencmis.commons.spi.Holder; 025import org.nuxeo.ecm.core.api.CoreSession; 026import org.nuxeo.ecm.core.api.DocumentModel; 027import org.nuxeo.ecm.core.api.IdRef; 028import org.nuxeo.ecm.core.opencmis.impl.server.NuxeoObjectData; 029 030/** 031 * Base abstract fileable live local CMIS Object. 032 */ 033public abstract class NuxeoFileableObject extends NuxeoObject implements FileableCmisObject { 034 035 public NuxeoFileableObject(NuxeoSession session, NuxeoObjectData data, ObjectType type) { 036 super(session, data, type); 037 } 038 039 @Override 040 public List<Folder> getParents(OperationContext context) { 041 // context ignored 042 CoreSession coreSession = data.doc.getCoreSession(); 043 DocumentModel parent = coreSession.getParentDocument(new IdRef(getId())); 044 if (parent == null || nuxeoCmisService.isFilteredOut(parent)) { 045 return Collections.emptyList(); 046 } 047 Folder folder = (Folder) session.getObject(parent, session.getDefaultContext()); 048 return Collections.singletonList(folder); 049 } 050 051 @Override 052 public List<Folder> getParents() { 053 return getParents(null); 054 } 055 056 @Override 057 public List<String> getPaths() { 058 return Collections.singletonList(data.doc.getPathAsString()); 059 } 060 061 @Override 062 public void addToFolder(ObjectId folderId, boolean allVersions) { 063 throw new UnsupportedOperationException("Multi-filing not supported"); 064 } 065 066 @Override 067 public void removeFromFolder(ObjectId folderId) { 068 service.removeObjectFromFolder(getRepositoryId(), getId(), folderId == null ? null : folderId.getId(), null); 069 } 070 071 @Override 072 public NuxeoFileableObject move(ObjectId sourceFolder, ObjectId targetFolder, OperationContext context) { 073 // context ignored 074 Holder<String> objectIdHolder = new Holder<String>(getId()); 075 if (sourceFolder == null) { 076 throw new CmisInvalidArgumentException("Missing source folder"); 077 } 078 if (targetFolder == null) { 079 throw new CmisInvalidArgumentException("Missing target folder"); 080 } 081 service.moveObject(getRepositoryId(), objectIdHolder, targetFolder.getId(), sourceFolder.getId(), null); 082 return this; 083 } 084 085 @Override 086 public NuxeoFileableObject move(ObjectId sourceFolder, ObjectId targetFolder) { 087 return move(sourceFolder, targetFolder, null); 088 } 089 090}