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;
025
026/**
027 * Batch Handler encapsulates functionality to handle Batch Upload behaviours.
028 *
029 * @since 10.1
030 */
031public interface BatchHandler {
032
033    /**
034     * Initializes this batch handler with the given name and configuration properties.
035     *
036     * @param name the batch handler's name
037     * @param properties the configuration properties
038     */
039    void initialize(String name, Map<String, String> properties);
040
041    /**
042     * Gets the batch handler's name.
043     *
044     * @return the batch handler's name
045     */
046    String getName();
047
048    /**
049     * Initiates a new batch with an optional externally provided id.
050     *
051     * @param batchId the id to use for the batch, or {@code null} to generate it
052     * @return a newly created batch
053     */
054    Batch newBatch(String batchId);
055
056    /**
057     * Attempts to fetch a batch with the given id.
058     *
059     * @param batchId the batch id to fetch
060     * @return the batch with the given id, or {@code null} if not found
061     */
062    Batch getBatch(String batchId);
063
064    /**
065     * Callback for the batch handler to execute post-upload actions. This is only typically used in third-party batch
066     * handlers.
067     *
068     * @param batchId the batch id
069     * @param fileIdx the file index within the batch
070     * @param fileInfo file information regarting the uploaded file
071     * @return {@code true} if the action was success
072     */
073    default boolean completeUpload(String batchId, String fileIdx, BatchFileInfo fileInfo) {
074        return true;
075    }
076
077}