001/* 002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thierry Delprat <tdelprat@nuxeo.com> 018 * Antoine Taillefer <ataillefer@nuxeo.com> 019 */ 020 021package org.nuxeo.ecm.automation.server.jaxrs.batch; 022 023import java.io.IOException; 024import java.io.InputStream; 025import java.util.List; 026import java.util.Map; 027 028import org.nuxeo.ecm.core.api.Blob; 029import org.nuxeo.ecm.core.api.CoreSession; 030import org.nuxeo.ecm.core.transientstore.api.TransientStore; 031 032/** 033 * Service interface to collect inputs (Blobs) for an operation or operation chain. 034 * 035 * @since 5.4.2 036 */ 037public interface BatchManager { 038 039 /** 040 * Returns the {@link TransientStore} backing the batches. 041 * 042 * @since 7.4 043 */ 044 TransientStore getTransientStore(); 045 046 /** 047 * Adds an inputStream as a blob to a batch. Will create a new {@link Batch} if needed. 048 * <p> 049 * Streams are persisted as temporary files. 050 */ 051 void addStream(String batchId, String index, InputStream is, String name, String mime) throws IOException; 052 053 /** 054 * Adds an inputStream as a chunk to a batch. Will create a new {@link Batch} if needed. 055 * <p> 056 * Streams are persisted as temporary files. 057 * 058 * @since 7.4 059 */ 060 void addStream(String batchId, String index, InputStream is, int chunkCount, int chunkIndex, String name, 061 String mime, long fileSize) throws IOException; 062 063 /** 064 * Returns true if there is a batch for the given {@code batchId}, false otherwise. 065 * 066 * @since 5.7.2 067 */ 068 boolean hasBatch(String batchId); 069 070 /** 071 * Gets Blobs associated to a given batch. Returns null if batch does not exist. 072 */ 073 List<Blob> getBlobs(String batchId); 074 075 /** 076 * Gets Blobs associated to a given batch. Returns null if batch does not exist. Waits for upload in progress if 077 * needed. 078 * 079 * @since 5.7 080 */ 081 List<Blob> getBlobs(String batchId, int timeoutS); 082 083 Blob getBlob(String batchId, String fileIndex); 084 085 Blob getBlob(String batchId, String fileIndex, int timeoutS); 086 087 /** 088 * @since 7.4 089 */ 090 List<BatchFileEntry> getFileEntries(String batchId); 091 092 /** 093 * @since 7.4 094 */ 095 BatchFileEntry getFileEntry(String batchId, String fileIndex); 096 097 /** 098 * Cleans up the temporary storage associated to the batch. 099 */ 100 void clean(String batchId); 101 102 /** 103 * Initializes a batch by with an automatically generated id. 104 * 105 * @return the batch id 106 * @since 7.4 107 */ 108 String initBatch(); 109 110 /** 111 * Initializes a batch with a given batchId and Context Name. If batchId is not provided, it will be automatically 112 * generated. 113 * 114 * @return the batchId 115 * @deprecated since 7.10, use {@link BatchManager#initBatch()} instead. 116 */ 117 @Deprecated 118 String initBatch(String batchId, String contextName); 119 120 /** 121 * Executes the chain or operation on the {@code Blobs} from the given {@code batchId}. 122 * <p> 123 * This method does not clean the temporary storage associated to the {@code batchId}. 124 * 125 * @since 5.7 126 */ 127 Object execute(String batchId, String chainOrOperationId, CoreSession session, Map<String, Object> contextParams, 128 Map<String, Object> operationParams); 129 130 /** 131 * Executes the chain or operation on the {@code Blob} from the given {@code batchId} and {@code fileIndex}. 132 * <p> 133 * This method does not clean the temporary storage associated to the {@code batchId}. 134 * 135 * @since 5.7.2 136 */ 137 Object execute(String batchId, String fileIndex, String chainOrOperationId, CoreSession session, 138 Map<String, Object> contextParams, Map<String, Object> operationParams); 139 140 /** 141 * Executes the chain or operation on the {@code Blobs} from the given {@code batchId}. 142 * <p> 143 * This method cleans the temporary storage associated to the {@code batchId} after the execution. 144 * 145 * @since 5.7 146 */ 147 Object executeAndClean(String batchId, String chainOrOperationId, CoreSession session, 148 Map<String, Object> contextParams, Map<String, Object> operationParams); 149 150 /** 151 * Removes a file from a batch. 152 * 153 * @since 8.4 154 */ 155 boolean removeFileEntry(String batchId, String filedIdx); 156 157}