View Javadoc
1   /*
2    * Copyright (c) 2002-2018, Mairie de 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.appointment.modules.resource.web;
35  
36  import java.sql.Date;
37  import java.time.LocalTime;
38  import java.util.ArrayList;
39  import java.util.Calendar;
40  import java.util.Collections;
41  import java.util.Comparator;
42  import java.util.GregorianCalendar;
43  import java.util.HashMap;
44  import java.util.List;
45  import java.util.Locale;
46  import java.util.Map;
47  import java.util.Map.Entry;
48  import java.util.Optional;
49  
50  import javax.servlet.http.HttpServletRequest;
51  
52  import org.apache.commons.lang.StringUtils;
53  
54  import fr.paris.lutece.plugins.appointment.business.rule.ReservationRule;
55  import fr.paris.lutece.plugins.appointment.modules.resource.business.AppointmentResourceHome;
56  import fr.paris.lutece.plugins.appointment.modules.resource.business.calendar.CalendarAppointmentResourceDTO;
57  import fr.paris.lutece.plugins.appointment.modules.resource.business.calendar.CalendarDayDTO;
58  import fr.paris.lutece.plugins.appointment.modules.resource.business.form.FormResourceCalendar;
59  import fr.paris.lutece.plugins.appointment.service.AppointmentService;
60  import fr.paris.lutece.plugins.appointment.service.FormService;
61  import fr.paris.lutece.plugins.appointment.service.ReservationRuleService;
62  import fr.paris.lutece.plugins.appointment.service.WeekDefinitionService;
63  import fr.paris.lutece.plugins.appointment.web.AppointmentFormJspBean;
64  import fr.paris.lutece.plugins.appointment.web.dto.AppointmentDTO;
65  import fr.paris.lutece.plugins.appointment.web.dto.AppointmentFormDTO;
66  import fr.paris.lutece.plugins.resource.business.IResource;
67  import fr.paris.lutece.plugins.resource.service.ResourceService;
68  import fr.paris.lutece.plugins.resource.service.provider.IResourceProvider;
69  import fr.paris.lutece.portal.business.user.AdminUser;
70  import fr.paris.lutece.portal.service.template.AppTemplateService;
71  import fr.paris.lutece.portal.util.mvc.admin.MVCAdminJspBean;
72  import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
73  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
74  import fr.paris.lutece.portal.util.mvc.utils.MVCUtils;
75  import fr.paris.lutece.util.html.HtmlTemplate;
76  import fr.paris.lutece.util.url.UrlItem;
77  
78  /**
79   * Appointment resource JSP Bean
80   */
81  @Controller( controllerJsp = AppointmentResourceJspBean.CONTROLLER_JSP, controllerPath = AppointmentResourceJspBean.CONTROLLER_PATH, right = AppointmentFormJspBean.RIGHT_MANAGEAPPOINTMENTFORM )
82  public class AppointmentResourceJspBean extends MVCAdminJspBean
83  {
84      /**
85       * The path of the JSP of the controller
86       */
87      public static final String CONTROLLER_PATH = "jsp/admin/plugins/appointment/modules/resource";
88  
89      /**
90       * The name of the JSP of the controller
91       */
92      public static final String CONTROLLER_JSP = "ManageAppointmentResources.jsp";
93      private static final long serialVersionUID = 3684357156472596848L;
94  
95      // Views
96      private static final String VIEW_USER_CALENDAR = "VIEW_USER_CALENDAR";
97      private static final String VIEW_RESOURCE_CALENDAR = "viewResourceCalendar";
98  
99      // Templates
100     private static final String TEMPLATE_RESOURCE_CALENDAR = "admin/plugins/appointment/modules/resource/resource_calendar.html";
101     private static final String TEMPLATE_VIEW_RESOURCE_CALENDAR = "admin/plugins/appointment/modules/resource/view_resource_calendar.html";
102     private static final String TEMPLATE_VIEW_USER_CALENDAR = "admin/plugins/appointment/modules/resource/view_user_calendar.html";
103     private static final String TEMPLATE_APPOINTMENT_DESCRIPTION = "admin/plugins/appointment/modules/resource/appointment_description.html";
104 
105     // URL
106     private static final String CONTROLLER_JSP_URL = CONTROLLER_PATH + "/" + CONTROLLER_JSP;
107 
108     // Marks
109     private static final String MARK_RESOURCE = "resource";
110     private static final String MARK_LIST_DAYS = "listDays";
111     private static final String MARK_LIST_DAYS_OF_WEEK = "list_days_of_week";
112     private static final String MARK_STARTING_TIME = "startingTime";
113     private static final String MARK_ENDING_TIME = "endingTime";
114     private static final String MARK_STARTING_HOUR = "startingHour";
115     private static final String MARK_STARTING_MINUTE = "startingMinute";
116     private static final String MARK_ENDING_HOUR = "endingHour";
117     private static final String MARK_ENDING_MINUTE = "endingMinute";
118     private static final String MARK_DURATION = "duration";
119     private static final String MARK_CALENDAR = "calendar";
120     private static final String MARK_APPOINTMENT = "appointment";
121 
122     // Parameters
123     private static final String PARAMETER_ID_RESOURCE = "id_resource";
124     private static final String PARAMETER_RESOURCE_TYPE = "resource_type";
125     private static final String PARAMETER_REFERER = "referer";
126     private static final String PARAMETER_FROM_URL = "fromUrl";
127     private static final String PARAMETER_OFFSET_WEEK = "offsetWeek";
128 
129     // Messages
130     private static final String MESSAGE_RESOURCE_CALENDAR_PAGE_TITLE = "module.appointment.resource.resource_calendar.pageTitle";
131     private static final String MESSAGE_USER_CALENDAR_PAGE_TITLE = "module.appointment.resource.user_calendar.pageTitle";
132 
133     // Default values for calendar time stamps
134     private static final int DEFAULT_APPOINTMENT_DURATION = 30;
135 
136     /**
137      * List of i18n keys of days of week
138      */
139     private static final String [ ] MESSAGE_LIST_DAYS_OF_WEEK = {
140             "module.appointment.resource.manageCalendarSlots.labelMonday", "module.appointment.resource.manageCalendarSlots.labelTuesday",
141             "module.appointment.resource.manageCalendarSlots.labelWednesday", "module.appointment.resource.manageCalendarSlots.labelThursday",
142             "module.appointment.resource.manageCalendarSlots.labelFriday", "module.appointment.resource.manageCalendarSlots.labelSaturday",
143             "module.appointment.resource.manageCalendarSlots.labelSunday",
144     };
145 
146     /**
147      * Get the page to view the calendar of a user
148      * 
149      * @param request
150      *            the request
151      * @return The HTML code to display
152      */
153     @View( value = VIEW_USER_CALENDAR, defaultView = true )
154     public String getViewUserCalendar( HttpServletRequest request )
155     {
156         String strFromUrl = request.getParameter( PARAMETER_FROM_URL );
157 
158         if ( StringUtils.isEmpty( strFromUrl ) )
159         {
160             strFromUrl = request.getHeader( PARAMETER_REFERER );
161 
162             if ( StringUtils.isEmpty( strFromUrl ) )
163             {
164                 strFromUrl = AppointmentFormJspBean.getURLManageAppointmentForms( request );
165             }
166         }
167 
168         String strOffsetWeek = request.getParameter( PARAMETER_OFFSET_WEEK );
169 
170         int nOffsetWeek = 0;
171 
172         if ( StringUtils.isNotEmpty( strOffsetWeek ) )
173         {
174             nOffsetWeek = parseInt( strOffsetWeek );
175         }
176 
177         AdminUser adminUser = getUser( );
178 
179         IResource resource = ResourceService.getInstance( ).getResource( Integer.toString( adminUser.getUserId( ) ), AdminUser.RESOURCE_TYPE );
180 
181         Map<String, Object> model = getModel( );
182         model.put( MARK_CALENDAR, getWeekResourceCalendar( resource, nOffsetWeek, getLocale( ) ) );
183         model.put( MARK_RESOURCE, resource );
184         model.put( PARAMETER_OFFSET_WEEK, nOffsetWeek );
185         model.put( PARAMETER_FROM_URL, strFromUrl );
186 
187         return getPage( MESSAGE_USER_CALENDAR_PAGE_TITLE, TEMPLATE_VIEW_USER_CALENDAR, model );
188     }
189 
190     /**
191      * Get the calendar of a resource
192      * 
193      * @param request
194      *            The request
195      * @return The HTML content to display
196      */
197     @View( VIEW_RESOURCE_CALENDAR )
198     public String getResourceCalendar( HttpServletRequest request )
199     {
200         String strIdResource = request.getParameter( PARAMETER_ID_RESOURCE );
201         String strResourceType = request.getParameter( PARAMETER_RESOURCE_TYPE );
202 
203         if ( StringUtils.isEmpty( strIdResource ) || StringUtils.isEmpty( strResourceType ) )
204         {
205             return redirect( request, AppointmentFormJspBean.getURLManageAppointmentForms( request ) );
206         }
207 
208         String strFromUrl = request.getParameter( PARAMETER_FROM_URL );
209 
210         if ( StringUtils.isEmpty( strFromUrl ) )
211         {
212             strFromUrl = request.getHeader( PARAMETER_REFERER );
213 
214             if ( StringUtils.isEmpty( strFromUrl ) )
215             {
216                 strFromUrl = AppointmentFormJspBean.getURLManageAppointmentForms( request );
217             }
218         }
219 
220         String strOffsetWeek = request.getParameter( PARAMETER_OFFSET_WEEK );
221 
222         int nOffsetWeek = 0;
223 
224         if ( StringUtils.isNotEmpty( strOffsetWeek ) )
225         {
226             nOffsetWeek = parseInt( strOffsetWeek );
227         }
228 
229         IResourceProvider provider = ResourceService.getInstance( ).getResourceProvider( strResourceType );
230 
231         if ( provider != null )
232         {
233             IResource resource = provider.getResource( strIdResource, strResourceType );
234 
235             if ( resource != null )
236             {
237                 Map<String, Object> model = getModel( );
238                 model.put( MARK_CALENDAR, getWeekResourceCalendar( resource, nOffsetWeek, getLocale( ) ) );
239                 model.put( MARK_RESOURCE, resource );
240                 model.put( PARAMETER_OFFSET_WEEK, nOffsetWeek );
241                 model.put( PARAMETER_FROM_URL, strFromUrl );
242 
243                 return getPage( MESSAGE_RESOURCE_CALENDAR_PAGE_TITLE, TEMPLATE_VIEW_RESOURCE_CALENDAR, model );
244             }
245         }
246 
247         if ( StringUtils.isNotEmpty( strFromUrl ) )
248         {
249             return redirect( request, strFromUrl );
250         }
251 
252         return redirect( request, AppointmentFormJspBean.getURLManageAppointmentForms( request ) );
253     }
254 
255     /**
256      * Get the resource calendar for a week
257      * 
258      * @param resource
259      *            The resource to display in the calendar
260      * @param nOffsetWeek
261      *            The week to display in the calendar ( -1 == previous, 0 == current, 1 == next, etc. )
262      * @param locale
263      *            Locale for localization
264      * @return an HTML template to display the calendar
265      */
266     public static String getWeekResourceCalendar( IResource resource, int nOffsetWeek, Locale locale )
267     {
268 
269         Map<String, Object> model = new HashMap<>( );
270 
271         model.put( MARK_RESOURCE, resource );
272 
273         // Set the standard week type (nb of days, first day of the week, etc.)
274         Date dateMonday = getDateMonday( nOffsetWeek );
275         Calendar calendar = new GregorianCalendar( );
276         calendar.setTime( dateMonday );
277 
278         calendar.add( Calendar.DAY_OF_WEEK, 7 );
279 
280         Date dateMax = new Date( calendar.getTimeInMillis( ) );
281 
282         // Retrieve the IDs of the appointments tied to a resource, for a specific period
283         List<Integer> listIdAppointments = AppointmentResourceHome.findIdAppointmentsByResourceAndDate( resource.getIdResource( ), resource.getResourceType( ),
284                 dateMonday, dateMax );
285 
286         List<AppointmentDTO> listAppointment = new ArrayList<>( listIdAppointments.size( ) );
287 
288         Map<Integer, List<CalendarAppointmentResourceDTO>> mapCalendarAppointmentResourceByDayOfWeek = new HashMap<>( );
289 
290         int nStartingHour = 0;
291         int nStartingMinute = 0;
292         int nEndingHour = 0;
293         int nEndingMinute = 0;
294         int nMinGlobalStartingTime = 9999;
295         int nMaxGlobalEndingTime = 0;
296         int nMinDuration = -1;
297 
298         for ( int i = 1; i < 8; i++ )
299         {
300             mapCalendarAppointmentResourceByDayOfWeek.put( i, new ArrayList<>( ) );
301         }
302 
303         /*
304          * Get the minimum starting time, maximum ending time, and minimum duration of all possible Resources
305          */
306         for ( int nIdAppointment : listIdAppointments )
307         {
308             AppointmentDTO appointment = AppointmentService.buildAppointmentDTOFromIdAppointment( nIdAppointment );
309             listAppointment.add( appointment );
310 
311             CalendarAppointmentResourceDTO/calendar/CalendarAppointmentResourceDTO.html#CalendarAppointmentResourceDTO">CalendarAppointmentResourceDTO calendarAppointmentResource = new CalendarAppointmentResourceDTO( appointment.getIdAppointment( ),
312                     appointment.getStartingDateTime( ).getHour( ), appointment.getStartingDateTime( ).getMinute( ), appointment.getEndingDateTime( ).getHour( ),
313                     appointment.getEndingDateTime( ).getMinute( ), getAppointmentRecap( appointment, locale ), appointment.getIdForm( ) );
314             long startThen = appointment.getStartingDateTime( ).getHour( ) * 60 + appointment.getStartingDateTime( ).getMinute( );
315             long endThen = appointment.getEndingDateTime( ).getHour( ) * 60 + appointment.getEndingDateTime( ).getMinute( );
316 
317             int nStartingTimeSlot = (int) startThen;
318 
319             if ( nStartingTimeSlot < nMinGlobalStartingTime )
320             {
321                 nMinGlobalStartingTime = nStartingTimeSlot;
322                 nStartingHour = appointment.getStartingDateTime( ).getHour( );
323                 nStartingMinute = appointment.getStartingDateTime( ).getMinute( );
324             }
325 
326             int nEndingTimeSlot = (int) endThen;
327 
328             if ( nEndingTimeSlot > nMaxGlobalEndingTime )
329             {
330                 nMaxGlobalEndingTime = nEndingTimeSlot;
331                 nEndingHour = appointment.getEndingDateTime( ).getHour( );
332                 nEndingMinute = appointment.getEndingDateTime( ).getMinute( );
333             }
334 
335             if ( ( calendarAppointmentResource.getDuration( ) < nMinDuration ) || ( nMinDuration == -1 ) )
336             {
337                 nMinDuration = calendarAppointmentResource.getDuration( );
338             }
339 
340             int nDayOfWeek = appointment.getStartingDateTime( ).getDayOfWeek( ).getValue( );
341             List<CalendarAppointmentResourceDTO> listCalendar = mapCalendarAppointmentResourceByDayOfWeek.get( nDayOfWeek );
342             listCalendar.add( calendarAppointmentResource );
343         }
344 
345         List<CalendarDayDTO> listDays = new ArrayList<>( 7 );
346 
347         for ( Entry<Integer, List<CalendarAppointmentResourceDTO>> entry : mapCalendarAppointmentResourceByDayOfWeek.entrySet( ) )
348         {
349             CalendarDayDTOns/appointment/modules/resource/business/calendar/CalendarDayDTO.html#CalendarDayDTO">CalendarDayDTO day = new CalendarDayDTO( );
350             Calendar calendarDay = new GregorianCalendar( );
351             calendarDay.setTime( dateMonday );
352             calendarDay.add( Calendar.DAY_OF_WEEK, entry.getKey( ) - 1 );
353             day.setDate( calendarDay.getTime( ) );
354 
355             List<CalendarAppointmentResourceDTO> listCalendarApp = entry.getValue( );
356             Collections.sort( listCalendarApp );
357             day.setListAppointmentResourceDTO( listCalendarApp );
358             listDays.add( day );
359         }
360 
361         Collections.sort( listDays );
362 
363         List<AppointmentFormDTO> listForm = FormService.buildAllActiveAppointmentForm( );
364 
365         /*
366          * Set the calendar of the resource, and make sure the range of the time / date periods contains all the possible Forms
367          */
368         for ( AppointmentFormDTO form : listForm )
369         {
370             FormResourceCalendar resourceTimeRange = getResourceCalendarTimeRange( form.getIdForm( ) );
371 
372             int nOpeningTime = ( resourceTimeRange.getStartingTime( ).getHour( ) * 60 ) + resourceTimeRange.getStartingTime( ).getMinute( );
373 
374             if ( nOpeningTime < nMinGlobalStartingTime )
375             {
376                 nMinGlobalStartingTime = nOpeningTime;
377                 nStartingHour = resourceTimeRange.getStartingTime( ).getHour( );
378                 nStartingMinute = resourceTimeRange.getStartingTime( ).getMinute( );
379             }
380 
381             int nClosingTime = ( resourceTimeRange.getEndingTime( ).getHour( ) * 60 ) + resourceTimeRange.getEndingTime( ).getMinute( );
382 
383             if ( nClosingTime > nMaxGlobalEndingTime )
384             {
385                 nMaxGlobalEndingTime = nClosingTime;
386                 nEndingHour = resourceTimeRange.getEndingTime( ).getHour( );
387                 nEndingMinute = resourceTimeRange.getEndingTime( ).getMinute( );
388             }
389 
390             // Set the minimum duration for an appointment
391             if ( ( resourceTimeRange.getDuration( ) < nMinDuration ) || ( nMinDuration < 0 ) )
392             {
393                 nMinDuration = resourceTimeRange.getDuration( );
394             }
395         }
396 
397         model.put( MARK_LIST_DAYS, listDays );
398         model.put( PARAMETER_OFFSET_WEEK, nOffsetWeek );
399         model.put( MARK_LIST_DAYS_OF_WEEK, MESSAGE_LIST_DAYS_OF_WEEK );
400         model.put( MARK_STARTING_TIME, nMinGlobalStartingTime );
401         model.put( MARK_ENDING_TIME, nMaxGlobalEndingTime );
402         model.put( MARK_DURATION, nMinDuration );
403         model.put( MARK_STARTING_HOUR, nStartingHour );
404         model.put( MARK_STARTING_MINUTE, nStartingMinute );
405         model.put( MARK_ENDING_HOUR, nEndingHour );
406         model.put( MARK_ENDING_MINUTE, nEndingMinute );
407 
408         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_RESOURCE_CALENDAR, locale, model );
409 
410         return template.getHtml( );
411     }
412 
413     /**
414      * Get the time range and duration during which a resource is used / can be used for an appointment
415      * 
416      * @param idForm
417      *            ID of the form used to retrieve the specific time range, appointment duration, etc.
418      * @return a FormResourceCalendar object which contains the time range and duration for a used resource
419      */
420     private static FormResourceCalendar getResourceCalendarTimeRange( int idForm )
421     {
422         List<ReservationRule> listReservationRules = ReservationRuleService.findListReservationRule( idForm );
423 
424         LocalTime maxEndingTime = WeekDefinitionService.getMaxEndingTimeOfAListOfWeekDefinition( listReservationRules );
425         LocalTime minStartingTime = WeekDefinitionService.getMinStartingTimeOfAListOfWeekDefinition( listReservationRules );
426 
427         int maxAppointmentDuration = DEFAULT_APPOINTMENT_DURATION;
428 
429         Optional<ReservationRule> reservationRuleWithMaxDuration = listReservationRules.stream( )
430                 .max( Comparator.comparingInt( ReservationRule::getDurationAppointments ) );
431 
432         if ( reservationRuleWithMaxDuration.isPresent( ) )
433         {
434             maxAppointmentDuration = reservationRuleWithMaxDuration.get( ).getDurationAppointments( );
435         }
436         return new FormResourceCalendar( idForm, minStartingTime, maxEndingTime, maxAppointmentDuration );
437     }
438 
439     /**
440      * Get the description of an appointment
441      * 
442      * @param appointment
443      *            The appointment
444      * @param locale
445      *            The locale
446      * @return The HTML code of the description of the appointment
447      */
448     private static String getAppointmentRecap( AppointmentDTO appointment, Locale locale )
449     {
450         Map<String, Object> model = new HashMap<>( );
451         model.put( MARK_APPOINTMENT, appointment );
452 
453         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_APPOINTMENT_DESCRIPTION, locale, model );
454 
455         return template.getHtml( );
456     }
457 
458     /**
459      * Get the URL of the calendar of a resource
460      * 
461      * @param strIdResource
462      *            The id of the resource
463      * @param strResourceType
464      *            the resource type
465      * @return The URL of the calendar of the resource. Note that the base URL is not prefixed to the URL.
466      */
467     public static String getUrlResourceCalendar( String strIdResource, String strResourceType )
468     {
469         UrlItem urlItem = new UrlItem( CONTROLLER_JSP_URL );
470         urlItem.addParameter( MVCUtils.PARAMETER_VIEW, VIEW_RESOURCE_CALENDAR );
471         urlItem.addParameter( PARAMETER_ID_RESOURCE, strIdResource );
472         urlItem.addParameter( PARAMETER_RESOURCE_TYPE, strResourceType );
473 
474         return urlItem.getUrl( );
475     }
476 
477     /**
478      * Get the date of a Monday.
479      * 
480      * @param nOffsetWeek
481      *            The offset of the week (0 for the current week, 1 for the next one, ...)
482      * @return The date of the Monday of the requested week
483      */
484     private static Date getDateMonday( int nOffsetWeek )
485     {
486         Date date = new Date( System.currentTimeMillis( ) );
487         Calendar calendar = Calendar.getInstance( Locale.FRANCE );
488         calendar.setTime( date );
489         // We set the week to the requested one
490         calendar.add( Calendar.DAY_OF_MONTH, 7 * nOffsetWeek );
491 
492         // We get the current day of the week
493         int nCurrentDayOfWeek = calendar.get( Calendar.DAY_OF_WEEK );
494         // We add the day of the week to Monday on the calendar
495         calendar.add( Calendar.DAY_OF_WEEK, Calendar.MONDAY - nCurrentDayOfWeek );
496 
497         return new Date( calendar.getTimeInMillis( ) );
498     }
499 
500     /**
501      * Parse a string representing a positive or negative integer
502      * 
503      * @param strNumber
504      *            The string to parse
505      * @return The integer value of the number represented by the string, or 0 if the string could not be parsed
506      */
507     private int parseInt( String strNumber )
508     {
509         int nNumber = 0;
510 
511         if ( StringUtils.isEmpty( strNumber ) )
512         {
513             return nNumber;
514         }
515 
516         if ( strNumber.startsWith( "-" ) )
517         {
518             String strParseableNumber = strNumber.substring( 1 );
519 
520             if ( StringUtils.isNumeric( strParseableNumber ) )
521             {
522                 nNumber = Integer.parseInt( strParseableNumber ) * -1;
523             }
524         }
525         else
526             if ( StringUtils.isNumeric( strNumber ) )
527             {
528                 nNumber = Integer.parseInt( strNumber );
529             }
530 
531         return nNumber;
532     }
533 }