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.ftp.core.data;
21  
22  import org.waarp.common.command.exception.CommandAbstractException;
23  import org.waarp.common.logging.WaarpLogger;
24  import org.waarp.common.logging.WaarpLoggerFactory;
25  import org.waarp.ftp.core.command.FtpCommandCode;
26  import org.waarp.ftp.core.exception.FtpNoFileException;
27  import org.waarp.ftp.core.file.FtpFile;
28  
29  import java.util.List;
30  
31  /**
32   * Class that owns one transfer to be run
33   */
34  public class FtpTransfer {
35    private static final WaarpLogger logger =
36        WaarpLoggerFactory.getLogger(FtpTransfer.class);
37  
38    /**
39     * The command to execute
40     */
41    private final FtpCommandCode command;
42  
43    /**
44     * The information (list) on which the command was executed
45     */
46    private final List<String> info;
47  
48    /**
49     * The original path on which the command was executed
50     */
51    private String path;
52  
53    /**
54     * Current Ftp FileInterface
55     */
56    private final FtpFile currentFile;
57  
58    /**
59     * The status
60     */
61    private boolean status;
62  
63    /**
64     * @param command
65     * @param fileOrInfo
66     * @param path
67     */
68    public FtpTransfer(final FtpCommandCode command,
69                       final List<String> fileOrInfo, final String path) {
70      this.command = command;
71      info = fileOrInfo;
72      this.path = path;
73      currentFile = null;
74    }
75  
76    /**
77     * @param command
78     * @param file
79     */
80    public FtpTransfer(final FtpCommandCode command, final FtpFile file) {
81      this.command = command;
82      currentFile = file;
83      try {
84        path = file.getFile();
85      } catch (final CommandAbstractException ignored) {
86        // nothing
87      }
88      info = null;
89    }
90  
91    /**
92     * @return the command
93     */
94    public final FtpCommandCode getCommand() {
95      return command;
96    }
97  
98    /**
99     * @return the file
100    *
101    * @throws FtpNoFileException
102    */
103   public final FtpFile getFtpFile() throws FtpNoFileException {
104     if (currentFile == null) {
105       throw new FtpNoFileException("No file associated with the transfer");
106     }
107     return currentFile;
108   }
109 
110   /**
111    * @return the Info
112    */
113   public final List<String> getInfo() {
114     return info;
115   }
116 
117   /**
118    * @return the path
119    */
120   public final String getPath() {
121     return path;
122   }
123 
124   /**
125    * @return the status
126    */
127   public final boolean getStatus() {
128     return status;
129   }
130 
131   /**
132    * @param status
133    */
134   public final void setStatus(final boolean status) {
135     if (!status && logger.isDebugEnabled()) {
136       logger.debug("Status false", new Exception("Trace only"));
137     }
138     this.status = status;
139   }
140 
141   /**
142    *
143    */
144   @Override
145   public String toString() {
146     return command.name() + ' ' + path;
147   }
148 }