001/* 002 * (C) Copyright 2018 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 * Luís Duarte 018 * Florent Guillaume 019 */ 020package org.nuxeo.ecm.automation.server.jaxrs.batch; 021 022import java.util.Map; 023 024import org.nuxeo.ecm.automation.server.jaxrs.batch.handler.BatchFileInfo; 025import org.nuxeo.ecm.core.transientstore.api.TransientStore; 026 027/** 028 * Batch Handler encapsulates functionality to handle Batch Upload behaviours. 029 * 030 * @since 10.1 031 */ 032public interface BatchHandler { 033 034 /** 035 * Initializes this batch handler with the given name and configuration properties. 036 * 037 * @param name the batch handler's name 038 * @param properties the configuration properties 039 */ 040 void initialize(String name, Map<String, String> properties); 041 042 /** 043 * Gets the batch handler's name. 044 * 045 * @return the batch handler's name 046 */ 047 String getName(); 048 049 /** 050 * Initiates a new batch with an optional externally provided id. 051 * 052 * @param batchId the id to use for the batch, or {@code null} to generate it 053 * @return a newly created batch 054 */ 055 Batch newBatch(String batchId); 056 057 /** 058 * Attempts to fetch a batch with the given id. 059 * 060 * @param batchId the batch id to fetch 061 * @return the batch with the given id, or {@code null} if not found 062 */ 063 Batch getBatch(String batchId); 064 065 /** 066 * Callback for the batch handler to execute post-upload actions. This is only typically used in third-party batch 067 * handlers. 068 * 069 * @param batchId the batch id 070 * @param fileIdx the file index within the batch 071 * @param fileInfo file information regarting the uploaded file 072 * @return {@code true} if the action was success 073 */ 074 default boolean completeUpload(String batchId, String fileIdx, BatchFileInfo fileInfo) { 075 return true; 076 } 077 078 /** 079 * Gets the transient store used by this batch handler. 080 * 081 * @since 10.10 082 */ 083 TransientStore getTransientStore(); 084 085}