001/*
002 * (C) Copyright 2012 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 java.io.IOException;
020import java.util.List;
021
022import org.nuxeo.drive.adapter.FileSystemItem;
023import org.nuxeo.drive.adapter.FolderItem;
024import org.nuxeo.drive.service.FileSystemItemManager;
025import org.nuxeo.ecm.automation.OperationContext;
026import org.nuxeo.ecm.automation.core.Constants;
027import org.nuxeo.ecm.automation.core.annotations.Context;
028import org.nuxeo.ecm.automation.core.annotations.Operation;
029import org.nuxeo.ecm.automation.core.annotations.OperationMethod;
030import org.nuxeo.ecm.core.api.Blob;
031import org.nuxeo.runtime.api.Framework;
032
033/**
034 * Gets the children of the top level {@link FolderItem} for the currently authenticated user.
035 *
036 * @deprecated use NuxeoDriveGetTopLevelFolder and the NuxeoDriveGetChildren operations instead
037 * @author Antoine Taillefer
038 */
039@Deprecated
040@Operation(id = NuxeoDriveGetTopLevelChildren.ID, category = Constants.CAT_SERVICES, label = "Nuxeo Drive: Get top level children")
041public class NuxeoDriveGetTopLevelChildren {
042
043    public static final String ID = "NuxeoDrive.GetTopLevelChildren";
044
045    @Context
046    protected OperationContext ctx;
047
048    @OperationMethod
049    public Blob run() throws IOException {
050
051        FileSystemItemManager fileSystemItemManager = Framework.getLocalService(FileSystemItemManager.class);
052        List<FileSystemItem> children = fileSystemItemManager.getTopLevelChildren(ctx.getPrincipal());
053        return NuxeoDriveOperationHelper.asJSONBlob(children);
054    }
055
056}