View Javadoc

1   /**
2      This file is part of GoldenGate Project (named also GoldenGate or GG).
3   
4      Copyright 2009, Frederic Bregier, 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 GoldenGate Project is free software: you can redistribute it and/or 
9      modify it under the terms of the GNU General Public License as published 
10     by the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12  
13     GoldenGate is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17  
18     You should have received a copy of the GNU General Public License
19     along with GoldenGate .  If not, see <http://www.gnu.org/licenses/>.
20   */
21  package openr66.context.task;
22  
23  import goldengate.common.command.exception.CommandAbstractException;
24  import goldengate.common.logging.GgInternalLogger;
25  import goldengate.common.logging.GgInternalLoggerFactory;
26  import openr66.context.R66Session;
27  import openr66.protocol.exception.OpenR66ProtocolSystemException;
28  
29  /**
30   * Move and Rename the current file
31   *
32   * @author Frederic Bregier
33   *
34   */
35  public class MoveRenameTask extends AbstractTask {
36      /**
37       * Internal Logger
38       */
39      private static final GgInternalLogger logger = GgInternalLoggerFactory
40              .getLogger(MoveRenameTask.class);
41  
42      /**
43       * @param argRule
44       * @param delay
45       * @param argTransfer
46       * @param session
47       */
48      public MoveRenameTask(String argRule, int delay, String argTransfer,
49              R66Session session) {
50          super(TaskType.MOVERENAME, delay, argRule, argTransfer, session);
51      }
52  
53      /*
54       * (non-Javadoc)
55       *
56       * @see openr66.context.task.AbstractTask#run()
57       */
58      @Override
59      public void run() {
60          boolean success = false;
61          String finalname = argRule;
62          finalname = getReplacedValue(finalname, argTransfer.split(" ")).split(" ")[0];
63          logger.debug("Move and Rename to " + finalname + " with " + argRule +
64                  ":" + argTransfer + " and {}", session);
65          try {
66              success = session.getFile().renameTo(finalname, true);
67          } catch (CommandAbstractException e) {
68              logger.error("Move and Rename to " + finalname + " with " +
69                      argRule + ":" + argTransfer + " and " + session, e);
70              futureCompletion.setFailure(new OpenR66ProtocolSystemException(e));
71              return;
72          }
73          if (success) {
74              session.getRunner().setFileMoved(finalname, success);
75              futureCompletion.setSuccess();
76          } else {
77              logger.error("Cannot Move and Rename to " + finalname + " with " +
78                      argRule + ":" + argTransfer + " and " + session);
79              futureCompletion.setFailure(new OpenR66ProtocolSystemException(
80                      "Cannot move file"));
81          }
82      }
83  
84  }