001/* 002 * (C) Copyright 2015 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-2.1.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 * Thierry Delprat <tdelprat@nuxeo.com> 016 * Antoine Taillefer <ataillefer@nuxeo.com> 017 */ 018 019package org.nuxeo.ecm.automation.server.jaxrs.batch; 020 021import java.io.IOException; 022import java.io.InputStream; 023import java.util.List; 024import java.util.Map; 025 026import org.nuxeo.ecm.core.api.Blob; 027import org.nuxeo.ecm.core.api.CoreSession; 028import org.nuxeo.ecm.core.transientstore.api.TransientStore; 029 030/** 031 * Service interface to collect inputs (Blobs) for an operation or operation chain. 032 * 033 * @since 5.4.2 034 */ 035public interface BatchManager { 036 037 /** 038 * Returns the {@link TransientStore} backing the batches. 039 * 040 * @since 7.4 041 */ 042 TransientStore getTransientStore(); 043 044 /** 045 * Adds an inputStream as a blob to a batch. Will create a new {@link Batch} if needed. 046 * <p> 047 * Streams are persisted as temporary files. 048 */ 049 void addStream(String batchId, String index, InputStream is, String name, String mime) throws IOException; 050 051 /** 052 * Adds an inputStream as a chunk to a batch. Will create a new {@link Batch} if needed. 053 * <p> 054 * Streams are persisted as temporary files. 055 * 056 * @since 7.4 057 */ 058 void addStream(String batchId, String index, InputStream is, int chunkCount, int chunkIndex, String name, 059 String mime, long fileSize) throws IOException; 060 061 /** 062 * Returns true if there is a batch for the given {@code batchId}, false otherwise. 063 * 064 * @since 5.7.2 065 */ 066 boolean hasBatch(String batchId); 067 068 /** 069 * Gets Blobs associated to a given batch. Returns null if batch does not exist. 070 */ 071 List<Blob> getBlobs(String batchId); 072 073 /** 074 * Gets Blobs associated to a given batch. Returns null if batch does not exist. Waits for upload in progress if 075 * needed. 076 * 077 * @since 5.7 078 */ 079 List<Blob> getBlobs(String batchId, int timeoutS); 080 081 Blob getBlob(String batchId, String fileIndex); 082 083 Blob getBlob(String batchId, String fileIndex, int timeoutS); 084 085 /** 086 * @since 7.4 087 */ 088 List<BatchFileEntry> getFileEntries(String batchId); 089 090 /** 091 * @since 7.4 092 */ 093 BatchFileEntry getFileEntry(String batchId, String fileIndex); 094 095 /** 096 * Cleans up the temporary storage associated to the batch. 097 */ 098 void clean(String batchId); 099 100 /** 101 * Initializes a batch by with an automatically generated id. 102 * 103 * @return the batch id 104 * @since 7.4 105 */ 106 String initBatch(); 107 108 /** 109 * Initializes a batch with a given batchId and Context Name. If batchId is not provided, it will be automatically 110 * generated. 111 * 112 * @return the batchId 113 * @deprecated since 7.10, use {@link BatchManager#initBatch()} instead. 114 */ 115 @Deprecated 116 String initBatch(String batchId, String contextName); 117 118 /** 119 * Executes the chain or operation on the {@code Blobs} from the given {@code batchId}. 120 * <p> 121 * This method does not clean the temporary storage associated to the {@code batchId}. 122 * 123 * @since 5.7 124 */ 125 Object execute(String batchId, String chainOrOperationId, CoreSession session, Map<String, Object> contextParams, 126 Map<String, Object> operationParams); 127 128 /** 129 * Executes the chain or operation on the {@code Blob} from the given {@code batchId} and {@code fileIndex}. 130 * <p> 131 * This method does not clean the temporary storage associated to the {@code batchId}. 132 * 133 * @since 5.7.2 134 */ 135 Object execute(String batchId, String fileIndex, String chainOrOperationId, CoreSession session, 136 Map<String, Object> contextParams, Map<String, Object> operationParams); 137 138 /** 139 * Executes the chain or operation on the {@code Blobs} from the given {@code batchId}. 140 * <p> 141 * This method cleans the temporary storage associated to the {@code batchId} after the execution. 142 * 143 * @since 5.7 144 */ 145 Object executeAndClean(String batchId, String chainOrOperationId, CoreSession session, 146 Map<String, Object> contextParams, Map<String, Object> operationParams); 147 148}