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.logging.GgInternalLogger;
24  import goldengate.common.logging.GgInternalLoggerFactory;
25  
26  import java.io.File;
27  
28  import openr66.context.R66Session;
29  import openr66.protocol.exception.OpenR66ProtocolSystemException;
30  import openr66.protocol.utils.FileUtils;
31  
32  /**
33   * Copy and Rename task
34   *
35   * @author Frederic Bregier
36   *
37   */
38  public class CopyRenameTask extends AbstractTask {
39      /**
40       * Internal Logger
41       */
42      private static final GgInternalLogger logger = GgInternalLoggerFactory
43              .getLogger(CopyRenameTask.class);
44  
45      /**
46       * @param argRule
47       * @param delay
48       * @param argTransfer
49       * @param session
50       */
51      public CopyRenameTask(String argRule, int delay, String argTransfer,
52              R66Session session) {
53          super(TaskType.COPYRENAME, delay, argRule, argTransfer, session);
54      }
55  
56      /*
57       * (non-Javadoc)
58       *
59       * @see openr66.context.task.AbstractTask#run()
60       */
61      @Override
62      public void run() {
63          String finalname = argRule;
64          finalname = getReplacedValue(finalname, argTransfer.split(" "));
65          logger.info("Copy and Rename to " + finalname + " with " + argRule +
66                  ":" + argTransfer + " and {}", session);
67          File from = session.getFile().getTrueFile();
68          File to = new File(finalname);
69          try {
70              FileUtils.copy(from, to, false, false);
71          } catch (OpenR66ProtocolSystemException e1) {
72              logger.error("Copy and Rename to " + finalname + " with " +
73                      argRule + ":" + argTransfer + " and " + session, e1);
74              futureCompletion.setFailure(new OpenR66ProtocolSystemException(e1));
75              return;
76          }
77          futureCompletion.setSuccess();
78      }
79  
80  }