1 /* 2 * This file is part of Waarp Project (named also Waarp or GG). 3 * 4 * Copyright (c) 2019, Waarp SAS, and individual contributors by the @author 5 * tags. See the COPYRIGHT.txt in the distribution for a full listing of 6 * individual contributors. 7 * 8 * All Waarp Project is free software: you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or (at your 11 * option) any later version. 12 * 13 * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY 14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 15 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License along with 18 * Waarp . If not, see <http://www.gnu.org/licenses/>. 19 */ 20 package org.waarp.openr66.context.task; 21 22 import org.waarp.openr66.context.R66Session; 23 import org.waarp.openr66.protocol.exception.OpenR66ProtocolNetworkException; 24 import org.waarp.openr66.s3.WaarpR66S3Client; 25 import org.waarp.openr66.s3.taskfactory.S3TaskFactory; 26 import org.waarp.openr66.s3.taskfactory.S3TaskFactory.S3TaskType; 27 28 /** 29 * S3 DELETE Task<br> 30 * <p> 31 * Result of arguments will be as S3 DELETE command.<br> 32 * Format is the following:<br> 33 * "-URL url of S3 service <br> 34 * -accessKey access Key for S3 service <br> 35 * -secretKey secret Key for S3 service <br> 36 * -bucketName bucket Name where to retrieve the object <br> 37 * -sourceName source Name from the bucket to delete the final Object <br> 38 * <br> 39 * <br> 40 * The order of actions will be:<br> 41 * 1) connection to S3 service using access Key and Secret Key<br> 42 * 2) Delete from the bucket the source Object<br> 43 * 3) the current File is unchanged<br> 44 */ 45 public class S3DeleteTask extends S3AbstractTask { 46 private static final S3TaskFactory.S3TaskType taskType = 47 S3TaskFactory.S3TaskType.S3DELETE; 48 49 /** 50 * Constructor 51 * 52 * @param argRule 53 * @param delay 54 * @param argTransfer 55 * @param session 56 */ 57 public S3DeleteTask(final String argRule, final int delay, 58 final String argTransfer, final R66Session session) { 59 super(TaskType.EXTENDED, delay, argRule, argTransfer, session); 60 } 61 62 /** 63 * The order of actions will be:<br> 64 * 1) connection to S3 service using access Key and Secret Key<br> 65 * 2) Delete from the bucket the source Object<br> 66 * 3) the current File is unchanged<br> 67 */ 68 @Override 69 public void run() { 70 if (!getParams()) { 71 return; 72 } 73 final WaarpR66S3Client s3Client = 74 new WaarpR66S3Client(taskUtil.getAccessKey(), taskUtil.getSecretKey(), 75 taskUtil.getUrl()); 76 try { 77 s3Client.deleteFile(taskUtil.getBucketName(), taskUtil.getSourceName()); 78 logger.debug("DELETED {}", taskUtil.getSourceName()); 79 futureCompletion.setSuccess(); 80 } catch (final OpenR66ProtocolNetworkException e) { 81 finalizeInError(e, "Error while S3 Action"); 82 } 83 } 84 85 @Override 86 public final S3TaskType getS3TaskType() { 87 return taskType; 88 } 89 }