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.client.api.SecondaryType; 023import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException; 024import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException; 025import org.apache.chemistry.opencmis.commons.spi.Holder; 026import org.nuxeo.ecm.core.api.CoreSession; 027import org.nuxeo.ecm.core.api.DocumentModel; 028import org.nuxeo.ecm.core.api.IdRef; 029import org.nuxeo.ecm.core.opencmis.impl.server.NuxeoObjectData; 030 031/** 032 * Base abstract fileable live local CMIS Object. 033 */ 034public abstract class NuxeoFileableObject extends NuxeoObject implements FileableCmisObject { 035 036 public NuxeoFileableObject(NuxeoSession session, NuxeoObjectData data, ObjectType type, 037 List<SecondaryType> secondaryTypes) { 038 super(session, data, type, secondaryTypes); 039 } 040 041 @Override 042 public List<Folder> getParents(OperationContext context) { 043 // context ignored 044 CoreSession coreSession = data.doc.getCoreSession(); 045 DocumentModel parent = coreSession.getParentDocument(new IdRef(getId())); 046 if (parent == null || nuxeoCmisService.isFilteredOut(parent)) { 047 return Collections.emptyList(); 048 } 049 Folder folder = (Folder) session.getObject(parent, session.getDefaultContext()); 050 return Collections.singletonList(folder); 051 } 052 053 @Override 054 public List<Folder> getParents() { 055 return getParents(null); 056 } 057 058 @Override 059 public List<String> getPaths() { 060 return Collections.singletonList(data.doc.getPathAsString()); 061 } 062 063 @Override 064 public void addToFolder(ObjectId folderId, boolean allVersions) { 065 throw new UnsupportedOperationException("Multi-filing not supported"); 066 } 067 068 @Override 069 public void removeFromFolder(ObjectId folderId) { 070 service.removeObjectFromFolder(getRepositoryId(), getId(), folderId == null ? null : folderId.getId(), null); 071 } 072 073 @Override 074 public NuxeoFileableObject move(ObjectId sourceFolder, ObjectId targetFolder, OperationContext context) { 075 // context ignored 076 Holder<String> objectIdHolder = new Holder<String>(getId()); 077 if (sourceFolder == null) { 078 throw new CmisInvalidArgumentException("Missing source folder"); 079 } 080 if (targetFolder == null) { 081 throw new CmisInvalidArgumentException("Missing target folder"); 082 } 083 service.moveObject(getRepositoryId(), objectIdHolder, targetFolder.getId(), sourceFolder.getId(), null); 084 return this; 085 } 086 087 @Override 088 public NuxeoFileableObject move(ObjectId sourceFolder, ObjectId targetFolder) { 089 return move(sourceFolder, targetFolder, null); 090 } 091 092}