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.context.filesystem.R66Dir;
28  import openr66.protocol.exception.OpenR66ProtocolSystemException;
29  
30  /**
31   * Move the file (without renaming it)
32   *
33   * @author Frederic Bregier
34   *
35   */
36  public class MoveTask extends AbstractTask {
37      /**
38       * Internal Logger
39       */
40      private static final GgInternalLogger logger = GgInternalLoggerFactory
41              .getLogger(MoveTask.class);
42  
43      /**
44       * @param argRule
45       * @param delay
46       * @param argTransfer
47       * @param session
48       */
49      public MoveTask(String argRule, int delay, String argTransfer,
50              R66Session session) {
51          super(TaskType.MOVE, delay, argRule, argTransfer, session);
52      }
53  
54      /*
55       * (non-Javadoc)
56       *
57       * @see openr66.context.task.AbstractTask#run()
58       */
59      @Override
60      public void run() {
61          logger.info("Move with " + argRule + ":" + argTransfer + " and {}",
62                  session);
63          boolean success = false;
64          String directory = argRule;
65          directory = getReplacedValue(directory, argTransfer.split(" "));
66          String finalname = directory.split(" ")[0] + R66Dir.SEPARATOR +
67              session.getFile().getBasename();
68          try {
69              success = session.getFile().renameTo(finalname, true);
70          } catch (CommandAbstractException e) {
71              logger.error("Move with " + argRule + ":" + argTransfer + " and " +
72                      session, e);
73              futureCompletion.setFailure(new OpenR66ProtocolSystemException(e));
74              return;
75          }
76          if (success) {
77              session.getRunner().setFileMoved(finalname, success);
78              futureCompletion.setSuccess();
79          } else {
80              logger.error("Cannot Move with " + argRule + ":" + argTransfer +
81                      " and " + session);
82              futureCompletion.setFailure(new OpenR66ProtocolSystemException(
83                      "Cannot move file"));
84          }
85      }
86  
87  }