001/* 002 * Copyright (c) 2006-2013 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 * Benjamin JALON <bjalon@nuxeo.com> 011 */ 012package org.nuxeo.ecm.automation.core.operations.document; 013 014import org.nuxeo.ecm.automation.core.Constants; 015import org.nuxeo.ecm.automation.core.annotations.Context; 016import org.nuxeo.ecm.automation.core.annotations.Operation; 017import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 018import org.nuxeo.ecm.automation.core.annotations.Param; 019import org.nuxeo.ecm.automation.core.collectors.DocumentModelCollector; 020import org.nuxeo.ecm.core.api.CoreSession; 021import org.nuxeo.ecm.core.api.DocumentModel; 022import org.nuxeo.ecm.core.api.DocumentRef; 023import org.nuxeo.ecm.core.api.NuxeoException; 024import org.nuxeo.ecm.core.api.PathRef; 025 026/** 027 * @author <a href="mailto:bjalon@nuxeo.com">Benjamin JALON</a> 028 * @since 5.7 029 */ 030@Operation(id = CreateProxyLive.ID, category = Constants.CAT_DOCUMENT, label = "Create Proxy Live", description = "This operation will create a proxy that points the given document as input. This is like a symbolic link for File System. The proxy will be created into the destination specified as parameter. <p>The document returned is the proxy live.<p> Remark: <b>you will have a strange behavior if the input is a folderish.</b>", aliases = { "CreateProxyLive" }) 031public class CreateProxyLive { 032 033 public static final String ID = "Document.CreateLiveProxy"; 034 035 @Context 036 protected CoreSession session; 037 038 @Param(name = "Destination Path") 039 protected String path; 040 041 @OperationMethod(collector = DocumentModelCollector.class) 042 public DocumentModel run(DocumentModel input) { 043 DocumentRef docRef = new PathRef(path); 044 if (!session.exists(docRef)) { 045 throw new NuxeoException(String.format("Destination \"%s\" specified into operation not found", path)); 046 } 047 048 DocumentModel proxy = session.createProxy(input.getRef(), docRef); 049 050 return proxy; 051 } 052 053}