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.openr66.protocol.localhandler.packet.json;
21  
22  import com.fasterxml.jackson.annotation.JsonAutoDetect;
23  import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
24  import com.fasterxml.jackson.annotation.JsonIgnore;
25  import org.waarp.openr66.database.data.DbTaskRunner;
26  import org.waarp.openr66.protocol.configuration.PartnerConfiguration;
27  import org.waarp.openr66.protocol.localhandler.packet.LocalPacketFactory;
28  
29  import java.util.Date;
30  
31  /**
32   * Transfer request JSON packet
33   */
34  @JsonAutoDetect(fieldVisibility = Visibility.NONE, getterVisibility = Visibility.ANY, setterVisibility = Visibility.ANY)
35  public class TransferRequestJsonPacket extends JsonPacket {
36  
37    protected static final byte REQVALIDATE = 0;
38  
39    protected static final byte REQANSWERVALIDATE = 1;
40  
41    protected String rulename;
42  
43    protected int mode;
44  
45    protected String filename;
46  
47    protected String requested;
48  
49    protected int blocksize;
50  
51    protected int rank;
52  
53    protected long specialId;
54  
55    protected byte validate;
56  
57    protected long originalSize;
58  
59    protected String fileInformation = "";
60  
61    protected String separator = PartnerConfiguration.BAR_JSON_FIELD;
62  
63    protected Date start;
64  
65    protected boolean isAdditionalDelay;
66  
67    protected long delay;
68  
69    /**
70     * @return the isAdditionalDelay
71     */
72    public final boolean isAdditionalDelay() {
73      return isAdditionalDelay;
74    }
75  
76    /**
77     * @param isAdditionalDelay the isAdditionalDelay to set
78     */
79    public final void setAdditionalDelay(final boolean isAdditionalDelay) {
80      this.isAdditionalDelay = isAdditionalDelay;
81    }
82  
83    /**
84     * @return the delay
85     */
86    public final long getDelay() {
87      return delay;
88    }
89  
90    /**
91     * @param delay the delay to set
92     */
93    public final void setDelay(final long delay) {
94      this.delay = delay;
95    }
96  
97    /**
98     * @return the start
99     */
100   public final Date getStart() {
101     return start;
102   }
103 
104   /**
105    * @param start the start to set
106    */
107   public final void setStart(final Date start) {
108     this.start = start;
109   }
110 
111   /**
112    * @return the requested
113    */
114   public final String getRequested() {
115     return requested;
116   }
117 
118   /**
119    * @param requested the requested to set
120    */
121   public final void setRequested(final String requested) {
122     this.requested = requested;
123   }
124 
125   /**
126    * @return the rulename
127    */
128   public final String getRulename() {
129     return rulename;
130   }
131 
132   /**
133    * @param rulename the rulename to set
134    */
135   public final void setRulename(final String rulename) {
136     this.rulename = rulename;
137   }
138 
139   /**
140    * @return the mode
141    */
142   public final int getMode() {
143     return mode;
144   }
145 
146   /**
147    * @param mode the mode to set
148    */
149   public final void setMode(final int mode) {
150     this.mode = mode;
151   }
152 
153   /**
154    * @return the filename
155    */
156   public final String getFilename() {
157     return filename;
158   }
159 
160   /**
161    * @param filename the filename to set
162    */
163   public final void setFilename(final String filename) {
164     this.filename = filename;
165   }
166 
167   /**
168    * @return the blocksize
169    */
170   public final int getBlocksize() {
171     return blocksize;
172   }
173 
174   /**
175    * @param blocksize the blocksize to set
176    */
177   public final void setBlocksize(final int blocksize) {
178     this.blocksize = blocksize;
179   }
180 
181   /**
182    * @return the rank
183    */
184   public final int getRank() {
185     return rank;
186   }
187 
188   /**
189    * @param rank the rank to set
190    */
191   public final void setRank(final int rank) {
192     this.rank = rank;
193   }
194 
195   /**
196    * @return the specialId
197    */
198   public final long getSpecialId() {
199     return specialId;
200   }
201 
202   /**
203    * @param specialId the specialId to set
204    */
205   public final void setSpecialId(final long specialId) {
206     this.specialId = specialId;
207   }
208 
209   /**
210    * @return the validate
211    */
212   public final byte getValidate() {
213     return validate;
214   }
215 
216   /**
217    * @return True if is to validate
218    */
219   public final boolean isToValidate() {
220     return validate == REQVALIDATE;
221   }
222 
223   /**
224    * @param validate the validate to set
225    */
226   public final void setValidate(final byte validate) {
227     this.validate = validate;
228   }
229 
230   /**
231    * Validate the request
232    */
233   public final void validate() {
234     validate = REQANSWERVALIDATE;
235   }
236 
237   /**
238    * @return the originalSize
239    */
240   public final long getOriginalSize() {
241     return originalSize;
242   }
243 
244   /**
245    * @param originalSize the originalSize to set
246    */
247   public final void setOriginalSize(final long originalSize) {
248     this.originalSize = originalSize;
249   }
250 
251   /**
252    * @return the fileInformation
253    */
254   public final String getFileInformation() {
255     return fileInformation;
256   }
257 
258   /**
259    * @param fileInformation the fileInformation to set
260    */
261   public final void setFileInformation(String fileInformation) {
262     if (fileInformation == null) {
263       fileInformation = "";
264     }
265     this.fileInformation = fileInformation;
266   }
267 
268   /**
269    * @return the separator
270    */
271   public final String getSeparator() {
272     return separator;
273   }
274 
275   /**
276    * @param separator the separator to set
277    */
278   public final void setSeparator(final String separator) {
279     this.separator = separator;
280   }
281 
282   /**
283    * Update the JsonPacket from runner (blocksize, rank, specialid)
284    *
285    * @param runner
286    */
287   @JsonIgnore
288   public final void setFromDbTaskRunner(final DbTaskRunner runner) {
289     blocksize = runner.getBlocksize();
290     rank = runner.getRank();
291     specialId = runner.getSpecialId();
292     originalSize = runner.getOriginalSize();
293   }
294 
295   @Override
296   public final void setRequestUserPacket() {
297     setRequestUserPacket(LocalPacketFactory.REQUESTPACKET);
298   }
299 }