001/* 002 * (C) Copyright 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 * Olivier Grisel <ogrisel@nuxeo.com> 016 */ 017package org.nuxeo.drive.operations; 018 019import java.io.IOException; 020 021import org.nuxeo.drive.adapter.FolderItem; 022import org.nuxeo.drive.service.FileSystemItemManager; 023import org.nuxeo.ecm.automation.OperationContext; 024import org.nuxeo.ecm.automation.core.Constants; 025import org.nuxeo.ecm.automation.core.annotations.Context; 026import org.nuxeo.ecm.automation.core.annotations.Operation; 027import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 028import org.nuxeo.ecm.core.api.Blob; 029import org.nuxeo.runtime.api.Framework; 030 031/** 032 * Gets the top level {@link FolderItem} for the currently authenticated user. 033 * 034 * @author Olivier Grisel 035 */ 036@Operation(id = NuxeoDriveGetTopLevelFolder.ID, category = Constants.CAT_SERVICES, label = "Nuxeo Drive: Get the top level folder") 037public class NuxeoDriveGetTopLevelFolder { 038 039 public static final String ID = "NuxeoDrive.GetTopLevelFolder"; 040 041 @Context 042 protected OperationContext ctx; 043 044 @OperationMethod 045 public Blob run() throws IOException { 046 047 FileSystemItemManager fileSystemItemManager = Framework.getLocalService(FileSystemItemManager.class); 048 FolderItem topLevelFolder = fileSystemItemManager.getTopLevelFolder(ctx.getPrincipal()); 049 return NuxeoDriveOperationHelper.asJSONBlob(topLevelFolder); 050 } 051 052}