View Javadoc
1   /*
2    * Copyright (c) 2002-2022, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.genericattributes.business;
35  
36  import fr.paris.lutece.portal.business.file.File;
37  import fr.paris.lutece.portal.business.physicalfile.PhysicalFile;
38  
39  import java.io.Serializable;
40  
41  import org.apache.commons.lang3.math.NumberUtils;
42  
43  /**
44   * class Response
45   */
46  public class Response implements Serializable
47  {
48      /**
49       * Active status value
50       */
51      public static final int CONSTANT_STATUS_ACTIVE = 1;
52  
53      /**
54       * Anonymized status value
55       */
56      public static final int CONSTANT_STATUS_ANONYMIZED = 10;
57  
58      /**
59       * Default iteration number of a Response
60       */
61      private static final int DEFAULT_ITERATION_NUMBER = NumberUtils.INTEGER_MINUS_ONE;
62  
63      /**
64       * The resource type of responses
65       */
66      public static final String RESOURCE_TYPE = "GENERICATTRIBUTES_RESPONSE";
67      private static final long serialVersionUID = -4566081273426609947L;
68      private int _nIdResponse;
69      private String _strToStringValueResponse;
70      private Entry _entry;
71      private int _nIterationNumber = DEFAULT_ITERATION_NUMBER;
72      private Field _field;
73      private String _strResponseValue;
74      private int _nStatus;
75      private File _file;
76      private boolean _bIsImage;
77      private int _nSortOrder;
78  
79      /**
80       * Default constructor
81       */
82      public Response( )
83      {
84          // Do nothing
85      }
86  
87      /**
88       * Creates a response that is a copy of another response
89       * 
90       * @param response
91       *            The response to copy
92       */
93      public Response href="../../../../../../fr/paris/lutece/plugins/genericattributes/business/Response.html#Response">Response( Response response )
94      {
95          this._nIdResponse = response.getIdResponse( );
96          this._strToStringValueResponse = response.getToStringValueResponse( );
97          this._entry = response.getEntry( );
98          this._field = response.getField( );
99          this._strResponseValue = response.getResponseValue( );
100         this._nStatus = response.getStatus( );
101         this._nSortOrder = response.getSortOrder( );
102 
103         File file = response.getFile( );
104 
105         if ( file != null )
106         {
107             _file = new File( );
108             _file.setExtension( file.getExtension( ) );
109             _file.setIdFile( file.getIdFile( ) );
110             _file.setMimeType( file.getMimeType( ) );
111             _file.setSize( file.getSize( ) );
112             _file.setTitle( file.getTitle( ) );
113 
114             PhysicalFile physicalFile = file.getPhysicalFile( );
115 
116             if ( physicalFile != null )
117             {
118                 PhysicalFile pfDuplicated = new PhysicalFile( );
119                 pfDuplicated.setIdPhysicalFile( pfDuplicated.getIdPhysicalFile( ) );
120                 pfDuplicated.setValue( pfDuplicated.getValue( ) );
121                 _file.setPhysicalFile( pfDuplicated );
122             }
123         }
124     }
125 
126     /**
127      *
128      * @return the question associate to the response
129      */
130     public Entry getEntry( )
131     {
132         return _entry;
133     }
134 
135     /**
136      * set the question associate to the response
137      * 
138      * @param entry
139      *            the question associate to the response
140      */
141     public void setEntry( Entry entry )
142     {
143         _entry = entry;
144     }
145 
146     /**
147      * Return the iteration number of the response
148      * 
149      * @return the nIterationNumber
150      */
151     public int getIterationNumber( )
152     {
153         return _nIterationNumber;
154     }
155 
156     /**
157      * Set the iteration number of the response
158      * 
159      * @param nIterationNumber
160      *            the nIterationNumber to set
161      */
162     public void setIterationNumber( int nIterationNumber )
163     {
164         this._nIterationNumber = nIterationNumber;
165     }
166 
167     /**
168      *
169      * @return the id of the response
170      */
171     public int getIdResponse( )
172     {
173         return _nIdResponse;
174     }
175 
176     /**
177      * set the id of the response
178      * 
179      * @param idResponse
180      *            the id of the response
181      */
182     public void setIdResponse( int idResponse )
183     {
184         _nIdResponse = idResponse;
185     }
186 
187     /**
188      * get the field associate to the response
189      * 
190      * @return the field associate to the response
191      */
192     public Field getField( )
193     {
194         return _field;
195     }
196 
197     /**
198      * set the field associate to the response
199      * 
200      * @param field
201      *            field
202      */
203     public void setField( Field field )
204     {
205         _field = field;
206     }
207 
208     /**
209      * return the string value response
210      * 
211      * @return the string value of the response
212      */
213     public String getToStringValueResponse( )
214     {
215         if ( _strToStringValueResponse != null )
216         {
217             return _strToStringValueResponse;
218         }
219 
220         return _strResponseValue;
221     }
222 
223     /**
224      * set the string value response
225      * 
226      * @param strValueResponse
227      *            the string value of the response
228      */
229     public void setToStringValueResponse( String strValueResponse )
230     {
231         _strToStringValueResponse = strValueResponse;
232     }
233 
234     /**
235      * Set the response value
236      * 
237      * @param strResponseValue
238      *            the response value
239      */
240     public void setResponseValue( String strResponseValue )
241     {
242         _strResponseValue = strResponseValue;
243     }
244 
245     /**
246      * Get the response value
247      * 
248      * @return the response value
249      */
250     public String getResponseValue( )
251     {
252         return _strResponseValue;
253     }
254 
255     /**
256      * Get the status of this response
257      * 
258      * @return The status of this response
259      */
260     public int getStatus( )
261     {
262         return _nStatus;
263     }
264 
265     /**
266      * Set the status of this response
267      * 
268      * @param nStatus
269      *            The status of this response
270      */
271     public void setStatus( int nStatus )
272     {
273         this._nStatus = nStatus;
274     }
275 
276     /**
277      * Get the file associated with this response
278      * 
279      * @return the file The file associated with this response
280      */
281     public File getFile( )
282     {
283         return _file;
284     }
285 
286     /**
287      * Set the file associated with this response
288      * 
289      * @param file
290      *            The file associated with this response
291      */
292     public void setFile( File file )
293     {
294         this._file = file;
295     }
296 
297     /**
298      * Get the isImage of this response
299      * 
300      * @return The bIsImage of this response
301      */
302     public boolean getIsImage( )
303     {
304         return _bIsImage;
305     }
306 
307     /**
308      * Set the isImage of this response
309      * 
310      * @param bIsImage
311      *            of this response
312      */
313     public void setIsImage( boolean bIsImage )
314     {
315         this._bIsImage = bIsImage;
316     }
317 
318     /**
319      * @return the nSortOrder
320      */
321     public int getSortOrder( )
322     {
323         return _nSortOrder;
324     }
325 
326     /**
327      * @param nSortOrder the nSortOrder to set
328      */
329     public void setSortOrder( int nSortOrder )
330     {
331         _nSortOrder = nSortOrder;
332     }
333 }