001/* 002 * Copyright (c) 2006-2011 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 * bstefanescu 011 */ 012package org.nuxeo.ecm.automation.core.operations; 013 014import org.nuxeo.ecm.automation.OperationContext; 015import org.nuxeo.ecm.automation.OperationException; 016import org.nuxeo.ecm.automation.core.Constants; 017import org.nuxeo.ecm.automation.core.annotations.Context; 018import org.nuxeo.ecm.automation.core.annotations.Operation; 019import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 020import org.nuxeo.ecm.automation.core.annotations.Param; 021import org.nuxeo.ecm.automation.core.util.BlobList; 022import org.nuxeo.ecm.core.api.Blob; 023 024/** 025 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 026 */ 027@Operation(id = RestoreBlobsInput.ID, category = Constants.CAT_EXECUTION, label = "Restore Files Input", description = "Restore the file list input from a context variable given its name. Return the files.") 028public class RestoreBlobsInput { 029 030 public static final String ID = "Context.RestoreBlobsInput"; 031 032 @Context 033 protected OperationContext ctx; 034 035 @Param(name = "name") 036 protected String name; 037 038 @OperationMethod 039 public BlobList run() throws OperationException { 040 Object obj = ctx.get(name); 041 if (obj instanceof BlobList) { 042 return (BlobList) obj; 043 } else if (obj instanceof Blob) { 044 return new BlobList((Blob) obj); 045 } 046 throw new OperationException( 047 "Illegal state error for restore files operation. The context map doesn't contains a file list variable with name " 048 + name); 049 } 050 051}