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.handler.impl; 021 022import java.io.Serializable; 023import java.util.Map; 024import java.util.Objects; 025 026import org.nuxeo.ecm.automation.server.jaxrs.batch.Batch; 027import org.nuxeo.ecm.automation.server.jaxrs.batch.BatchFileEntry; 028import org.nuxeo.ecm.automation.server.jaxrs.batch.handler.AbstractBatchHandler; 029import org.nuxeo.ecm.automation.server.jaxrs.batch.handler.BatchFileInfo; 030 031/** 032 * Default batch handler, 033 * 034 * @since 10.1 035 */ 036public class DefaultBatchHandler extends AbstractBatchHandler { 037 038 @Override 039 public Batch getBatch(String batchId) { 040 Map<String, Serializable> parameters = getBatchParameters(batchId); 041 if (parameters == null) { 042 return null; 043 } 044 045 // create the batch 046 return new Batch(batchId, parameters, getName()); 047 } 048 049 @Override 050 public boolean completeUpload(String batchId, String fileIndex, BatchFileInfo fileInfo) { 051 Batch batch = getBatch(batchId); 052 BatchFileEntry fileEntry = batch.getFileEntry(fileIndex, true); 053 return fileEntry.getFileSize() == fileInfo.getLength() 054 && Objects.equals(fileEntry.getMimeType(), fileInfo.getMimeType()) 055 && Objects.equals(fileEntry.getBlob().getDigest(), fileInfo.getMd5()); 056 } 057 058}