View Javadoc
1   /*
2    * Copyright (c) 2002-2021, 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.importexport.business.importdata;
35  
36  /**
37   * Describe a message of imported elements
38   */
39  public class ImportMessage
40  {
41      /**
42       * Status that indicates that the item was skipped
43       */
44      public static final int STATUS_SKIPPED = 0;
45      /**
46       * Status that indicates that an error occurred during the importation of the item
47       */
48      public static final int STATUS_ERROR = 1;
49      /**
50       * Status that indicates that the item was successfully imported
51       */
52      public static final int STATUS_OK = 10;
53  
54      private String _strMessage;
55      private int _nStatus;
56      private int _nItemNumber;
57  
58      /**
59       * Creates a new import message
60       * 
61       * @param strMessage
62       *            The message
63       * @param nStatus
64       *            The {@link #setStatus(int) status} of the message
65       * @param nItemNumber
66       *            The number of the imported item
67       */
68      public ImportMessage( String strMessage, int nStatus, int nItemNumber )
69      {
70          this._strMessage = strMessage;
71          this._nStatus = nStatus;
72          this._nItemNumber = nItemNumber;
73      }
74  
75      /**
76       * Get the message
77       * 
78       * @return the message
79       */
80      public String getMessage( )
81      {
82          return _strMessage;
83      }
84  
85      /**
86       * Set the message
87       * 
88       * @param strMessage
89       *            the message
90       */
91      public void setMessage( String strMessage )
92      {
93          this._strMessage = strMessage;
94      }
95  
96      /**
97       * Get the status of the importation of the item described by this {@link ImportMessage}. Status are :
98       * <ul>
99       * <li>{@link #STATUS_SKIPPED} if the item was skipped</li>
100      * <li>{@link #STATUS_ERROR} if an error occurred during the importation of the item</li>
101      * <li>{@link #STATUS_OK} if the item was successfully imported</li>
102      * </ul>
103      * 
104      * @return The status
105      */
106     public int getStatus( )
107     {
108         return _nStatus;
109     }
110 
111     /**
112      * Set the status of importation of the item described by this {@link ImportMessage}.
113      * 
114      * @param nStatus
115      *            <ul>
116      *            <li>{@link #STATUS_SKIPPED} if the item was skipped</li>
117      *            <li>{@link #STATUS_ERROR} if an error occurred during the importation of the item</li>
118      *            <li>{@link #STATUS_OK} if the item was successfully imported</li>
119      *            </ul>
120      */
121     public void setStatus( int nStatus )
122     {
123         this._nStatus = nStatus;
124     }
125 
126     /**
127      * Get the number of the imported item in the data source
128      * 
129      * @return the number of the imported item in the data source
130      */
131     public int getItemNumber( )
132     {
133         return _nItemNumber;
134     }
135 
136     /**
137      * Set the number of the imported item in the data source. This number should be unique for every row of a data source
138      * 
139      * @param nItemNumber
140      *            The imported item number
141      */
142     public void setItemNumber( int nItemNumber )
143     {
144         this._nItemNumber = nItemNumber;
145     }
146 
147     /**
148      * {@inheritDoc}
149      */
150     @Override
151     public String toString( )
152     {
153         StringBuilder sbMessage = new StringBuilder( );
154         if ( _nStatus == STATUS_ERROR )
155         {
156             sbMessage.append( "Error : " );
157         }
158         else
159             if ( _nStatus == STATUS_SKIPPED )
160             {
161                 sbMessage.append( "Skipped : " );
162             }
163             else
164                 if ( _nStatus == STATUS_OK )
165                 {
166                     sbMessage.append( "Ok : " );
167                 }
168         sbMessage.append( _nItemNumber );
169         sbMessage.append( ", " );
170         sbMessage.append( _strMessage );
171 
172         return sbMessage.toString( );
173     }
174 }