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.context.filesystem.R66Dir;
30  import openr66.context.task.exception.OpenR66RunnerException;
31  
32  /**
33   * This task validate the File Path according to the follwing argument:<br>
34   * - the full path is get from the current file<br>
35   * - the arg path is transformed as usual (static and dynamic from information transfer)
36   * and should be the beginning of the correct valid path<br>
37   * - the full path should begin with one of the result of the transformation (blank separated)<br>
38   * <br>
39   * For instance "#OUTPATH# #INPATH# #WORKPATH# #ARHCPATH#" will test that the current file is in one of
40   * the standard path.
41   *
42   * @author Frederic Bregier
43   *
44   */
45  public class ValidFilePathTask extends AbstractTask {
46      /**
47       * Internal Logger
48       */
49      private static final GgInternalLogger logger = GgInternalLoggerFactory
50              .getLogger(ValidFilePathTask.class);
51  
52      /**
53       * @param argRule
54       * @param delay
55       * @param argTransfer
56       * @param session
57       */
58      public ValidFilePathTask(String argRule, int delay, String argTransfer,
59              R66Session session) {
60          super(TaskType.VALIDFILEPATH, delay, argRule, argTransfer, session);
61      }
62  
63      /*
64       * (non-Javadoc)
65       *
66       * @see openr66.context.task.AbstractTask#run()
67       */
68      @Override
69      public void run() {
70          String finalname = argRule;
71          finalname = R66Dir.normalizePath(
72                  getReplacedValue(finalname, argTransfer.split(" ")));
73          logger.info("Test Valid Path with " + finalname + " from {}", session);
74          File from = session.getFile().getTrueFile();
75          String curpath = R66Dir.normalizePath(from.getAbsolutePath());
76          String [] paths = finalname.split(" ");
77          for (String base: paths) {
78              if (curpath.startsWith(base)) {
79                  if (delay > 0) {
80                      logger.info("Validate File "+curpath+" from " + base + " and\n    " +
81                          session.toString());
82                  }
83                  futureCompletion.setSuccess();
84                  return;
85              }
86          }
87          if (delay > 0) {
88              logger.error("Unvalidate File: "+curpath+"\n    " +
89                  session.toString());
90          }
91          futureCompletion.setFailure(new OpenR66RunnerException("File not Validated"));
92      }
93  
94  }