001/* 002 * (C) Copyright 2012-2013 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Antoine Taillefer <ataillefer@nuxeo.com> 016 */ 017package org.nuxeo.drive.operations; 018 019import org.nuxeo.drive.adapter.FileSystemItem; 020import org.nuxeo.drive.service.FileSystemItemManager; 021import org.nuxeo.ecm.automation.InvalidOperationException; 022import org.nuxeo.ecm.automation.OperationContext; 023import org.nuxeo.ecm.automation.core.Constants; 024import org.nuxeo.ecm.automation.core.annotations.Context; 025import org.nuxeo.ecm.automation.core.annotations.Operation; 026import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 027import org.nuxeo.ecm.automation.core.annotations.Param; 028import org.nuxeo.runtime.api.Framework; 029 030/** 031 * Deletes the {@link FileSystemItem} with the given id for the currently authenticated user. 032 * 033 * @author Antoine Taillefer 034 */ 035@Operation(id = NuxeoDriveDelete.ID, category = Constants.CAT_SERVICES, label = "Nuxeo Drive: Delete") 036public class NuxeoDriveDelete { 037 038 public static final String ID = "NuxeoDrive.Delete"; 039 040 @Context 041 protected OperationContext ctx; 042 043 @Param(name = "id") 044 protected String id; 045 046 /** 047 * @since 6.0 048 */ 049 @Param(name = "parentId", required = false) 050 protected String parentId; 051 052 @OperationMethod 053 public void run() throws InvalidOperationException { 054 055 FileSystemItemManager fileSystemItemManager = Framework.getLocalService(FileSystemItemManager.class); 056 try { 057 if (parentId == null) { 058 fileSystemItemManager.delete(id, ctx.getPrincipal()); 059 } else { 060 fileSystemItemManager.delete(id, parentId, ctx.getPrincipal()); 061 } 062 063 } catch (UnsupportedOperationException e) { 064 throw new InvalidOperationException(e); 065 } 066 } 067 068}