/*
 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * Contributors:
 *     Antoine Taillefer <ataillefer@nuxeo.com>
 */
package org.nuxeo.drive.operations;

import java.io.StringWriter;

import org.codehaus.jackson.map.ObjectMapper;
import org.nuxeo.drive.adapter.FileSystemItem;
import org.nuxeo.drive.service.FileSystemItemManager;
import org.nuxeo.ecm.automation.OperationContext;
import org.nuxeo.ecm.automation.core.Constants;
import org.nuxeo.ecm.automation.core.annotations.Context;
import org.nuxeo.ecm.automation.core.annotations.Operation;
import org.nuxeo.ecm.automation.core.annotations.OperationMethod;
import org.nuxeo.ecm.automation.core.annotations.Param;
import org.nuxeo.ecm.core.api.Blob;
import org.nuxeo.ecm.core.api.impl.blob.StreamingBlob;
import org.nuxeo.runtime.api.Framework;

/**
 * Check if the {@link FileSystemItem} with the given id exists for the
 * currently authenticated user.
 *
 * @author Antoine Taillefer
 */
@Operation(id = NuxeoDriveFileSystemItemExists.ID, category = Constants.CAT_SERVICES, label = "Nuxeo Drive: File system item exists")
public class NuxeoDriveFileSystemItemExists {

    public static final String ID = "NuxeoDrive.FileSystemItemExists";

    @Context
    protected OperationContext ctx;

    @Param(name = "id")
    protected String id;

    @OperationMethod
    public Blob run() throws Exception {

        FileSystemItemManager fileSystemItemManager = Framework.getLocalService(FileSystemItemManager.class);
        String exists = String.valueOf(fileSystemItemManager.exists(id,
                ctx.getPrincipal()));
        ObjectMapper mapper = new ObjectMapper();
        StringWriter writer = new StringWriter();
        mapper.writeValue(writer, exists);
        return StreamingBlob.createFromString(writer.toString(),
                "application/json");
    }

}

@@ -703,84 +703,8 @@
 s;%0A%0A
-import java.io.StringWriter;%0A%0Aimport org.codehaus.jackson.map.ObjectMapper;%0A
 impo
@@ -1949,22 +1949,23 @@
         
-String
+boolean
  exists 
@@ -1970,23 +1970,8 @@
 s = 
-String.valueOf(
 file
@@ -1998,32 +1998,16 @@
 ists(id,
-%0A               
  ctx.get
@@ -2022,152 +2022,8 @@
 l())
-);%0A        ObjectMapper mapper = new ObjectMapper();%0A        StringWriter writer = new StringWriter();%0A        mapper.writeValue(writer, exists)
 ;%0A  
@@ -2070,24 +2070,29 @@
 ing(
-writer.toString(
+String.valueOf(exists
 ),%0A 

Fix NuxeoDriveFileSystemItemExists operation boolean result