View Javadoc
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.taskfactory.S3TaskFactory;
25  import org.waarp.openr66.s3.taskfactory.S3TaskFactory.S3TaskType;
26  
27  /**
28   * S3 PUT and DELETE Task<br>
29   * <p>
30   * Result of arguments will be as a S3 PUT and R66 DELETE command.<br>
31   * Format is the following:<br>
32   * "-URL url of S3 service <br>
33   * -accessKey access Key for S3 service <br>
34   * -secretKey secret Key for S3 service <br>
35   * -bucketName bucket Name where to retrieve the object <br>
36   * -targetName source Name from the bucket to select the final Object <br>
37   * [-setTags 'name:value,...' without space]" <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) Store to the bucket the current File as the target Object<br>
43   * 3) if setTags is set, the informations are added as tags to the final S3 Object<br>
44   * 4) the current File is deleted<br>
45   */
46  public class S3PutAndR66DeleteTask extends S3PutTask {
47    private static final S3TaskFactory.S3TaskType taskType =
48        S3TaskFactory.S3TaskType.S3PUTR66DELETE;
49  
50    /**
51     * Constructor
52     *
53     * @param argRule
54     * @param delay
55     * @param argTransfer
56     * @param session
57     */
58    public S3PutAndR66DeleteTask(final String argRule, final int delay,
59                                 final String argTransfer,
60                                 final R66Session session) {
61      super(argRule, delay, argTransfer, session);
62    }
63  
64    /**
65     * The order of actions will be:<br>
66     * 1) connection to S3 service using access Key and Secret Key<br>
67     * 2) Store to the bucket the current File as the target Object<br>
68     * 3) if setTags is set, the informations are added as tags to the final S3 Object<br>
69     * 4) the current File is deleted<br>
70     */
71    @Override
72    public void run() {
73      try {
74        internalRun();
75      } catch (final OpenR66ProtocolNetworkException e) {
76        finalizeInError(e, "Error while S3 Action");
77        return;
78      }
79      final DeleteTask deleteTask = new DeleteTask("", 0, "", session);
80      deleteTask.run();
81      if (deleteTask.futureCompletion.isSuccess()) {
82        logger.debug("R66 Deleted");
83        futureCompletion.setSuccess();
84      } else {
85        logger.error("PUT file OK but local file deletion in error");
86        futureCompletion.setResult(deleteTask.futureCompletion.getResult());
87        futureCompletion.setFailure(deleteTask.futureCompletion.getCause());
88      }
89    }
90  
91    @Override
92    public S3TaskType getS3TaskType() {
93      return taskType;
94    }
95  }