001 /** =====================================================================
002 *
003 * File Name : $Id: FaultDBForm.java,v 1.11 2007/12/14 12:18:50 cb Exp $
004 *
005 * Description
006 * -----------
007 *
008 * See javadoc comment
009 *
010 * =====================================================================
011 *
012 * @Author : Craige Bevil
013 * Control Software Group
014 * Isaac Newton Group of Telescopes
015 *
016 * =====================================================================
017 *
018 * Modification Log
019 *
020 * Vers Date Author Reason
021 * ---- ---- ------ ------
022 * 1 C.Bevil First Release
023 *
024 * Commissioning Notes
025 * -------------------
026 *
027 * None
028 *
029 * =====================================================================
030 *
031 * @Version : $Id: FaultDBForm.java,v 1.11 2007/12/14 12:18:50 cb Exp $
032 *
033 * @Author : $Author: cb $
034 *
035 * Header : $Header: /opt/INGsrc/src/CVS/softproj/FaultDatabase/src/FaultDatabase/FaultDatabase/src/GWTApplication/client/FaultDBForm.java,v 1.11 2007/12/14 12:18:50 cb Exp $
036 *
037 * Log : $Log: FaultDBForm.java,v $
038 * Log : Revision 1.11 2007/12/14 12:18:50 cb
039 * Log : Modified the code which determines if a text field is empty to be more
040 * Log : strict.
041 * Log :
042 * Log : Revision 1.10 2007/12/12 15:26:16 cb
043 * Log : Added new javascript library which allows fancy message boxes to be
044 * Log : displayed.
045 * Log :
046 * Log : Revision 1.9 2007/10/18 08:43:50 cb
047 * Log : Support for decommissioned instruments has been added to the system
048 * Log :
049 * Log : Revision 1.8 2007/08/20 11:51:34 cb
050 * Log : Added method which will check if a date which has been entered by a
051 * Log : user is in the future.
052 * Log :
053 * Log : Revision 1.7 2007/08/17 14:25:11 cb
054 * Log : Change the checking of some of the dates to allow them to be a bit
055 * Log : more flexible
056 * Log :
057 * Log : Revision 1.6 2007/08/13 10:03:39 cb
058 * Log : Made some speed optimsations in order to try and speed the update form
059 * Log : up
060 * Log :
061 * Log : Revision 1.5 2007/08/02 12:22:55 cb
062 * Log : Modified to support the extra tabs in the quick view tab panel to
063 * Log : include the different groups of outstanding faults.
064 * Log :
065 * Log : Revision 1.4 2007/08/01 13:00:08 cb
066 * Log : First prototype after import
067 * Log :
068 * Log : Revision 1.3 2007/07/24 08:24:48 cb
069 * Log : Added the initialisation of the printer list
070 * Log :
071 * Log : Revision 1.2 2007/07/13 10:54:08 cb
072 * Log : Complete interface prototype
073 * Log :
074 * Log : Revision 1.1.1.1 2007/06/01 08:33:26 cb
075 * Log : Imported using TkCVS
076 * Log :
077 *
078 * =====================================================================*/
079
080 package GWTApplication.client;
081
082 import com.google.gwt.user.client.*;
083 import com.google.gwt.user.client.rpc.*;
084 import com.google.gwt.user.client.ui.*;
085 import com.google.gwt.core.client.GWT;
086 import com.google.gwt.user.client.ui.FlexTable.*;
087
088 import com.gwtext.client.core.EventObject;
089 import com.gwtext.client.util.Format;
090 import com.gwtext.client.widgets.MessageBox;
091 import com.gwtext.client.widgets.MessageBoxConfig;
092
093 import java.util.*;
094
095 /**
096 * This is a base class which supports the forms which are to be
097 * displayed by the application. Most of the forms in the application
098 * subclass this class.
099 * @author Craige Bevil
100 * @version $Id: FaultDBForm.java,v 1.11 2007/12/14 12:18:50 cb Exp $
101 */
102
103 class FaultDBForm extends Composite {
104
105 /**
106 * This is a panel which will be used to indicate to the user that
107 * we are busy at the moment doing something
108 */
109
110 protected BusyIndicator busyIndicator = new BusyIndicator();
111
112 /**
113 * Indicates that we should not check the length of the string
114 */
115
116 public final static int NOLENGTHCHECK = -1;
117
118 /**
119 * This is the list of fault states
120 */
121
122 private static ArrayList FaultStateList = null;
123
124 /**
125 * This is the list of faults
126 */
127
128 private static ArrayList FaultTypeList = null;
129
130 /**
131 * This is a list of all of the staff members
132 */
133
134 private static ArrayList StaffMemberList = null;
135
136 /**
137 * This is the list of severities
138 */
139
140 private static ArrayList SeverityList = null;
141
142 /**
143 * This is the list of systems which can be selected
144 */
145
146 private static ArrayList SystemList = null;
147
148 /**
149 * This is the list of all instruments which can be selected
150 */
151
152 private static ArrayList InstrumentList = null;
153
154 /**
155 * This is the list of current instruments which can be selected
156 */
157
158 private static ArrayList CurrentInstrumentList = null;
159
160 /**
161 * This is the list of sites which can be selected
162 */
163
164 private static ArrayList SiteList = null;
165
166 /**
167 * This is a list static list of the TOs. We cache the list of the
168 * TOs so we do not have to get the list from the servlet all of
169 * the time
170 */
171
172 private static ArrayList TOList = null;
173
174 /**
175 * This is a list static list of the SAs. We cache the list of the
176 * SAs so we do not have to get the list from the servlet all of
177 * the time
178 */
179
180 private static ArrayList SAList = null;
181
182 /**
183 * This is a list static list of the DEs. We cache the list of the
184 * DEs so we do not have to get the list from the servlet all of
185 * the time
186 */
187
188 private static ArrayList DEList = null;
189
190 /**
191 * This is a list static list of the TOs. We cache the list of the
192 * TOs so we do not have to get the list from the servlet all of
193 * the time. This includes everybody who has been part of this
194 * group whether they are in the organisation or not.
195 */
196
197 private static ArrayList FullTOList = null;
198
199 /**
200 * This is a list static list of the SAs. We cache the list of the
201 * SAs so we do not have to get the list from the servlet all of
202 * the time. This includes everybody who has been part of this
203 * group whether they are in the organisation or not.
204 */
205
206 private static ArrayList FullSAList = null;
207
208 /**
209 * This is a list static list of the DEs. We cache the list of the
210 * DEs so we do not have to get the list from the servlet all of
211 * the time. This includes everybody who has been part of this
212 * group whether they are in the organisation or not.
213 */
214
215 private static ArrayList FullDEList = null;
216
217 /**
218 * This is a list static list of the staff. We cache the list of the
219 * staff so we do not have to get the list from the servlet all of
220 * the time. This includes everybody who has been part of this
221 * group whether they are in the organisation or not.
222 */
223
224 private static ArrayList FullStaffMemberList = null;
225
226 /**
227 * This is the user authentication details which were provided by
228 * the user
229 */
230
231 protected AuthenticationDetails UserAuthentication;
232
233 /**
234 * This class will be used for internationalization so that we can
235 * flick between the locales of English and Spanish.
236 */
237
238 protected InternationalizationConstants internationalizationConstants = (InternationalizationConstants) GWT.create(InternationalizationConstants.class);
239
240 /**
241 * This is the service which will be used to access the servlet
242 * which is running in the tomcat container
243 */
244
245 protected FaultServiceAsync svc;
246
247 /**
248 * Holds a list of the printers that the servlet knows about. This
249 * variable is shared amongst the instances of this class to save
250 * continually having to refer to the servlet for the information.
251 */
252
253 protected static ArrayList PrinterList;
254
255 /**
256 * A static initialiser which will get the all of the lists from
257 * the servlet to make sure that we are not pulling them across
258 * from the servlet all of the time otherwise we end up with a
259 * load of syncronisation problems. It should be noted that this
260 * static initialiser is only called the first time that we
261 * instantiate an object which uses this class.
262 */
263
264 static {
265
266 final FaultServiceAsync svc = (FaultServiceAsync) GWT.create(FaultService.class);
267 final ServiceDefTarget endPoint = (ServiceDefTarget) svc;
268
269 endPoint.setServiceEntryPoint(GWT.getModuleBaseURL() + "/faultService");
270
271 // Get a list of all current staff members
272
273 svc.getStaffMembers (false,new AsyncCallback() {
274
275 public void onSuccess (final Object result) {
276 StaffMemberList = (ArrayList)result;
277 }
278
279 public void onFailure (Throwable ex)
280 {
281 MessageBox.alert("Information","Failed to get the list of staff members");
282 }
283 });
284
285 // Get the list of the current telescope operators back from the database
286
287 svc.getTelescopeOperators (false,new AsyncCallback() {
288
289 public void onSuccess (final Object result) {
290 TOList = (ArrayList)result;
291 }
292
293 public void onFailure (final Throwable ex)
294 {
295 MessageBox.alert("Information","Failed to get the list of telescope operators");
296 }
297 });
298
299
300 // Now get the current support astronomers
301
302 svc.getSupportAstronomers (false,new AsyncCallback() {
303
304 public void onSuccess (final Object result) {
305 SAList = (ArrayList)result;
306 }
307
308 public void onFailure (final Throwable ex)
309 {
310 MessageBox.alert("Information","Failed to get the list of support astronomers");
311 }
312 });
313
314 // Now get the list of current DEs from the servlet
315
316 svc.getDutyTechnicians (false,new AsyncCallback() {
317
318 public void onSuccess (final Object result) {
319 DEList = (ArrayList)result;
320 }
321
322 public void onFailure (final Throwable ex)
323 {
324 MessageBox.alert("Information","Failed to get the list of duty technicians");
325 }
326 });
327
328 // Now get the list of instruments of all instruments
329
330 svc.getInstruments (true, new AsyncCallback() {
331
332 public void onSuccess (final Object result) {
333 InstrumentList = (ArrayList)result;
334 }
335
336 public void onFailure (final Throwable ex)
337 {
338 MessageBox.alert("Information","Failed to get the list of instruments " + ex.getMessage());
339 }
340 });
341
342 // Get a list of only those instruments which are in use
343
344 svc.getInstruments (false, new AsyncCallback() {
345
346 public void onSuccess (final Object result) {
347 CurrentInstrumentList = (ArrayList)result;
348 }
349
350 public void onFailure (final Throwable ex)
351 {
352 MessageBox.alert("Information","Failed to get the list of instruments " + ex.getMessage());
353 }
354 });
355
356 // Get a list of all staff members whether here or not
357
358 svc.getStaffMembers (true,new AsyncCallback() {
359
360 public void onSuccess (final Object result) {
361 FullStaffMemberList = (ArrayList)result;
362 }
363
364 public void onFailure (final Throwable ex)
365 {
366 MessageBox.alert("Information","Failed to get the list of staff members");
367 }
368 });
369
370 // Get the list of the telescope operators back from the database whether here or not
371
372 svc.getTelescopeOperators (true,new AsyncCallback() {
373
374 public void onSuccess (final Object result) {
375 FullTOList = (ArrayList)result;
376 }
377
378 public void onFailure (final Throwable ex)
379 {
380 MessageBox.alert("Information","Failed to get the list of telescope operators");
381 }
382 });
383
384
385 // Now get the current support astronomers whether here or not
386
387 svc.getSupportAstronomers (true,new AsyncCallback() {
388
389 public void onSuccess (final Object result) {
390 FullSAList = (ArrayList)result;
391 }
392
393 public void onFailure (final Throwable ex)
394 {
395 MessageBox.alert("Information","Failed to get the list of support astronomers");
396 }
397 });
398
399 // Now get the list of current DEs from the servlet whether here or not
400
401 svc.getDutyTechnicians (true,new AsyncCallback() {
402
403 public void onSuccess (final Object result) {
404 FullDEList = (ArrayList)result;
405 }
406
407 public void onFailure (final Throwable ex)
408 {
409 MessageBox.alert("Information","Failed to get the list of duty technicians");
410 }
411 });
412
413
414 // Now get the list of sites
415
416 svc.getSites (new AsyncCallback() {
417
418 public void onSuccess (final Object result) {
419 SiteList = (ArrayList)result;
420 }
421
422 public void onFailure (final Throwable ex)
423 {
424 MessageBox.alert("Information","Failed to get the list of sites" + ex.getMessage());
425 }
426 });
427
428 // Now get the lsit of systems
429
430 svc.getSystems (new AsyncCallback() {
431
432 public void onSuccess (final Object result) {
433 SystemList = (ArrayList)result;
434 }
435
436 public void onFailure (final Throwable ex)
437 {
438 MessageBox.alert("Information","Failed to get the list of systems" + ex.getMessage());
439 }
440 });
441
442 // Get the list of severities from the servlet
443
444 svc.getSeverity (new AsyncCallback() {
445
446 public void onSuccess (final Object result) {
447 SeverityList = (ArrayList)result;
448 }
449
450 public void onFailure (final Throwable ex)
451 {
452 MessageBox.alert("Information","Failed to get the list of severity");
453 }
454 });
455
456
457 // Get a list of the fault types
458
459 svc.getFaultType (new AsyncCallback() {
460
461 public void onSuccess (final Object result) {
462 FaultTypeList = (ArrayList)result;
463 }
464
465 public void onFailure (final Throwable ex)
466 {
467 MessageBox.alert("Information","Failed to get the list of the fault types ");
468 }
469 });
470
471 // Get the fault states which are allowed
472
473 svc.getStates (new AsyncCallback() {
474
475 public void onSuccess (final Object result) {
476 FaultStateList = (ArrayList)result;
477 }
478
479 public void onFailure (final Throwable ex)
480 {
481 MessageBox.alert("Information","Failed to get the list of the fault states");
482 }
483 });
484
485 // Get the details of the printers from the servlet and store
486 // them for later use
487
488 svc.getPostscriptPrinters(new AsyncCallback() {
489
490 public void onSuccess (final Object result) {
491
492 PrinterList = new ArrayList();
493
494 final ArrayList temp = (ArrayList)result;
495
496 for (int i=0; i < temp.size() ;i++) {
497 PrinterList.add((String)temp.get(i));
498 }
499 }
500
501 public void onFailure (final Throwable ex){
502 MessageBox.alert("Information","Unable to get printer list" + ex.getMessage());
503 }
504
505 });
506 }
507
508 /**
509 * Gets a list of the telescope operators from the tomcat faultdb
510 * servlet and initialises the list of the telescope operators in
511 * the list box which was provided by the caller.
512 * @param listBox This is the listbox widget which is to have it's list populated
513 * @param defaultUser This is the default value in the list to be
514 * selected.
515 * @param IncludeStaffWhichHaveLeft Include all of the staff in
516 * this group which have left the organisation. =
517 */
518
519 void fillListBoxWithTelescopeOperators (final ListBox listBox,
520 final String defaultUser,
521 final boolean IncludeStaffWhichHaveLeft) {
522
523 // Now clear out the listbox of it's existing contents
524
525 listBox.clear();
526
527 ArrayList staffList;
528
529 if (IncludeStaffWhichHaveLeft) {
530 staffList = FullTOList;
531 } else {
532 staffList = TOList;
533 }
534
535 createDropDownList (staffList,defaultUser,listBox);
536
537 }
538
539
540 /**
541 * Gets a list of the support astronomer from the tomcat faultdb
542 * servlet and initialises the list box which was provided by the caller.
543 * @param listBox This is the listbox widget which is to have it's list populated
544 * @param defaultUser This is the default value in the list to be
545 * selected.
546 * @param IncludeStaffWhichHaveLeft Whether to include staff that
547 * have already left the ING in the list
548 */
549
550 protected void fillListBoxWithSupportAstronomers (final ListBox listBox,final String defaultUser,final boolean IncludeStaffWhichHaveLeft) {
551
552 // Now clear out the listbox of it's existing contents
553
554 listBox.clear();
555
556 ArrayList staffList;
557
558 if (IncludeStaffWhichHaveLeft) {
559 staffList = FullSAList;
560 } else {
561 staffList = SAList;
562 }
563
564 createDropDownList (staffList,defaultUser,listBox);
565 }
566
567 /**
568 * Adds the names of the people into the list provided. If the
569 * defaultUser cannot be found then if the option
570 * FaultDatabaseConstants.DEFAULTUSER can be found in the list
571 * then that is selected instead.
572 * @param staffList An array of type person which is to be
573 * included in the list.
574 * @param defaultUser This is the default value in the list to be
575 * @param listBox This is the listbox widget which is to have it's list populated
576 */
577
578 private void createDropDownList (final ArrayList staffList,
579 final String defaultUser,
580 final ListBox listBox) {
581
582 // The index in the list if unknown is specified.
583
584 final int NOTKNOWN = -1;
585
586 int unknownIndex = NOTKNOWN;
587
588 boolean optionSelected = false;
589
590 for (int i=0; i < staffList.size(); i++) {
591
592 final Person newPerson = (Person)staffList.get(i);
593
594 // Now add the name of the person to the list
595
596 listBox.addItem(newPerson.getName() + " " + newPerson.getSurname(),newPerson.getEmailAddress());
597
598 if (defaultUser != null) {
599
600 // Record where unknown is in the list if it is present,
601 // this is an alternative if we cannot find the default
602 // item in the list
603
604 if (optionSelected == false && newPerson.getEmailAddress().equalsIgnoreCase(FaultDatabaseConstants.DEFAULTUSER)) {
605 unknownIndex = i;
606 }
607
608 if (!optionSelected && defaultUser.equals(newPerson.getEmailAddress())) {
609 optionSelected = true;
610 listBox.setSelectedIndex(i);
611 }
612 }
613 }
614
615 // If we could not find the default user (if specified) in the
616 // list then we select unknown
617
618 if (unknownIndex != NOTKNOWN && !optionSelected) {
619 listBox.setSelectedIndex(unknownIndex);
620 }
621 }
622
623 /**
624 * Gets a list of the duty technician from the tomcat faultdb
625 * servlet and initialises the list box which was provided by the caller.
626 * @param listBox This is the listbox widget which is to have it's list populated
627 * @param defaultUser This is the default value in the list to be
628 * selected.
629 * @param IncludeStaffWhichHaveLeft Include all of the staff in
630 * this group which have left the organisation.
631 */
632
633 protected void fillListBoxWithDutyTechnicians (final ListBox listBox,
634 final String defaultUser,
635 final boolean IncludeStaffWhichHaveLeft) {
636
637 // Now clear out the listbox of it's existing contents
638
639 listBox.clear();
640
641 ArrayList staffList;
642
643 if (IncludeStaffWhichHaveLeft) {
644 staffList = FullDEList;
645 } else {
646 staffList = DEList;
647 }
648
649 createDropDownList (staffList,defaultUser,listBox);
650 }
651
652 /**
653 * Called to set the default option in a list box widget.
654 * @param KeyValue This is the option which is to be selected
655 * @param TargetList This is the list in which the option is to be
656 * selected
657 */
658
659 public void selectDefaultListOption (final String KeyValue, final ListBox TargetList) {
660
661 if (KeyValue == null) {
662 return;
663 }
664
665 for (int i=0; i < TargetList.getItemCount(); i++) {
666
667 final String value = TargetList.getValue(i);
668
669 if (value.equals(KeyValue)) {
670 TargetList.setSelectedIndex(i);
671 return;
672 }
673 }
674 }
675
676 /**
677 * Gets a list of the staff members from the tomcat faultdb
678 * servlet and initialises the list box which was provided by the
679 * caller.
680 * @param listBox This is the listbox widget which is to have it's
681 * list populated
682 * @param defaultUser This is the default value in the list to be
683 * selected.
684 * @param IncludeStaffWhichHaveLeft Include all of the staff in
685 * this group which have left the organisation.
686 */
687
688 protected void fillListBoxWithStaffMembers (final ListBox listBox,
689 final String defaultUser,
690 final boolean IncludeStaffWhichHaveLeft) {
691
692 // Now clear out the listbox of it's existing contents
693
694 listBox.clear();
695
696 ArrayList staffList;
697
698 if (IncludeStaffWhichHaveLeft) {
699 staffList = FullStaffMemberList;
700 } else {
701 staffList = StaffMemberList;
702 }
703
704 createDropDownList (staffList,defaultUser,listBox);
705 }
706
707
708 /**
709 * Gets a list of the all instruments from the tomcat faultdb
710 * servlet and initialises the list box which was provided by the
711 * caller.
712 * @param listBox This is the listbox widget which is to have it's list populated
713 */
714
715 protected void fillListBoxWithInstruments (final ListBox listBox, final String CurrentLocale) {
716
717 // Now clear out the listbox of it's existing contents
718
719 listBox.clear();
720
721 for (int i=0; i < InstrumentList.size(); i++) {
722
723 final Instrument newInstrument = (Instrument)InstrumentList.get(i);
724
725 // Now add the name of the instrument to the list
726
727 if (CurrentLocale.equalsIgnoreCase("en")) {
728 listBox.addItem(newInstrument.getEn_description(),newInstrument.getId());
729 } else {
730 listBox.addItem(newInstrument.getSp_description(),newInstrument.getId());
731 }
732 }
733 }
734
735 /**
736 * Gets a list of only the current instruments (not
737 * decommissioned) from the tomcat faultdb servlet and initialises
738 * the list box which was provided by the caller.
739 * @param listBox This is the listbox widget which is to have it's list populated
740 */
741
742 protected void fillListBoxWithCurrentInstruments (final ListBox listBox, final String CurrentLocale) {
743
744 // Now clear out the listbox of it's existing contents
745
746 listBox.clear();
747
748 for (int i=0; i < CurrentInstrumentList.size(); i++) {
749
750 final Instrument newInstrument = (Instrument)CurrentInstrumentList.get(i);
751
752 // Now add the name of the instrument to the list
753
754 if (CurrentLocale.equalsIgnoreCase("en")) {
755 listBox.addItem(newInstrument.getEn_description(),newInstrument.getId());
756 } else {
757 listBox.addItem(newInstrument.getSp_description(),newInstrument.getId());
758 }
759 }
760 }
761
762 /**
763 * Gets a list of the sites from the tomcat faultdb servlet and
764 * initialises the list box which was provided by the caller.
765 * @param listBox This is the listbox widget which is to have it's
766 * list populated
767 */
768
769 protected void fillListBoxWithSites (final ListBox listBox, final String CurrentLocale) {
770
771 // Now clear out the listbox of its existing contents
772
773 listBox.clear();
774
775 for (int i=0; i < SiteList.size(); i++) {
776
777 final Site newSite = (Site)SiteList.get(i);
778
779 // Now add the name of the site to the list
780
781 if (CurrentLocale.equalsIgnoreCase("en")) {
782 listBox.addItem(newSite.getEn_description(),newSite.getId());
783 } else {
784 listBox.addItem(newSite.getSp_description(),newSite.getId());
785 }
786 }
787 }
788
789 /**
790 * Gets a list of the systems from the tomcat faultdb servlet and
791 * initialises the list box which was provided by the caller.
792 * @param listBox This is the listbox widget which is to have it's
793 * list populated
794 */
795
796 protected void fillListBoxWithSystems (final ListBox listBox, final String CurrentLocale) {
797
798 // Now clear out the listbox of it's existing contents
799
800 listBox.clear();
801
802 for (int i=0; i < SystemList.size(); i++) {
803
804 final FDBSystem newSystem = (FDBSystem)SystemList.get(i);
805
806 // Now add the name of the system to the list
807
808 if (CurrentLocale.equalsIgnoreCase("en")) {
809 listBox.addItem(newSystem.getEn_description(),newSystem.getId());
810 } else {
811 listBox.addItem(newSystem.getSp_description(),newSystem.getId());
812 }
813 }
814 }
815
816 /**
817 * Gets a list of the severities from the tomcat faultdb servlet and
818 * initialises the list box which was provided by the caller.
819 * @param listBox This is the listbox widget which is to have it's
820 * list populated
821 */
822
823 protected void fillListBoxWithSeverity (final ListBox listBox, final String CurrentLocale) {
824
825 // Now clear out the listbox of it's existing contents
826
827 listBox.clear();
828
829 for (int i=0; i < SeverityList.size(); i++) {
830
831 final Severity newSeverity = (Severity)SeverityList.get(i);
832
833 // Now add the name of the severity to the list
834
835 if (CurrentLocale.equalsIgnoreCase("en")) {
836 listBox.addItem(newSeverity.getEn_description(),newSeverity.getId());
837 } else {
838 listBox.addItem(newSeverity.getSp_description(),newSeverity.getId());
839 }
840 }
841 }
842
843 /**
844 * Used to verify that a field which represents the time has been
845 * entered in the correct format of HH:MM in 24 hour clock
846 * @param TimeToVerify This is a string which contains the time
847 * which is to be verified
848 * @return boolean True if the time is in the correct format,
849 * false otherwise
850 */
851
852 protected boolean verifyTimeFormat (final String TimeToVerify) {
853
854 // If the field is empty reject the time
855
856 if (TimeToVerify == null) {
857 return false;
858 }
859
860 // Thank the lord for regex .....
861
862 return TimeToVerify.matches("(2[0-3]|[0-1]?[0-9]):[0-5][0-9]");
863 }
864
865 /**
866 * Verify that the date that has been specified is not after the
867 * current date
868 * @param DateToTest This is the date to test specified in the
869 * format DD/MM/YYYY
870 * @return boolean True if the date is valid and not after the
871 * current date
872 */
873
874 protected boolean verifyDateNotInFuture (final String DateToTest) {
875
876 final Date currentDate = new Date();
877
878 // Now split up the date string into it's components.
879
880 final String[] dateComponents = DateToTest.split("/");
881
882 try {
883
884 // Note that the order that we check to see if the year,
885 // month and date is in the future is important.
886
887 // Verify that the year the user has specified is not in the
888 // future.
889
890 int yearSpecified = Integer.parseInt(dateComponents[2]);
891
892 if (yearSpecified >= 1900) {
893 yearSpecified -= 1900;
894 } else {
895
896 // If the user specified a two digit year then we add
897 // 100 years to the date as the date that we get back
898 // from the Date object is year after 1900
899
900 if (dateComponents[2].length() == 2 ) {
901 yearSpecified += 100;
902 }
903 }
904
905 if (yearSpecified > currentDate.getYear()) {
906 return false;
907 } else if (yearSpecified < currentDate.getYear()) {
908
909 // If the year is from last year then we do not need
910 // to check the month and date fields
911
912 return true;
913 }
914
915 // Verify that the user has not specified a month in the
916 // future
917
918 int monthSpecified = Integer.parseInt(dateComponents[1]);
919
920 if (monthSpecified > (currentDate.getMonth() + 1)) {
921 return false;
922 } else if (monthSpecified < (currentDate.getMonth() + 1)) {
923
924 // If the month is from a previous month to the one
925 // that we are in at the moment then there is no point
926 // in checking the date
927
928 return true;
929 }
930
931 // Verify that the user has not specified a day of month
932 // in the future in the future
933
934 int daySpecified = Integer.parseInt(dateComponents[0]);
935
936 if (daySpecified > currentDate.getDate()) {
937 return false;
938 }
939
940 } catch (NumberFormatException e) {
941 return false;
942 }
943
944 return true;
945 }
946
947 /**
948 * Used to verify that a field which represents the date has been
949 * entered in the correct format of DD/MM/YYYY
950 * @param DateToVerify This is a string which contains the time
951 * which is to be verified
952 * @return boolean True if the time is in the correct format,
953 * false otherwise
954 */
955
956 protected boolean verifyDateFormat (final String DateToVerify) {
957
958 if (DateToVerify == null) {
959 return false;
960 }
961
962 if (DateToVerify.matches("(3[0-1]|[0-2]?[0-9])/(1[0-2]|0[1-9]|[1-9])/([0-9]{2})")) {
963 return true;
964 }
965
966 return DateToVerify.matches("(3[0-1]|[0-2]?[0-9])/(1[0-2]|0[1-9]|[1-9])/([0-9]{4})");
967 }
968
969 /**
970 * Get current date in the format DD/MM/YYYY and return it to the
971 * caller.
972 */
973
974 protected String getCurrentDate () {
975
976 final Date date = new Date();
977
978 String DOM = Integer.toString(date.getDate());
979
980 String MOY = Integer.toString(date.getMonth() + 1);
981
982 if (DOM.length() == 1) {
983 DOM = "0" + date.getDate();
984 }
985
986 if (MOY.length() == 1) {
987 MOY = "0" + (date.getMonth() + 1);
988 }
989
990 return DOM + "/" + MOY + "/" + (date.getYear() + 1900);
991
992 }
993
994 /**
995 * Get current time in the format HH:MM and return it to the
996 * caller
997 */
998
999 protected String getCurrentTime () {
1000
1001 final Date time = new Date();
1002
1003 String hours = Integer.toString(time.getHours());
1004
1005 String minutes = Integer.toString(time.getMinutes());
1006
1007 if (hours.length() == 1) {
1008 hours = "0" + time.getHours();
1009 }
1010
1011 if (minutes.length() == 1) {
1012 minutes = "0" + time.getMinutes();
1013 }
1014
1015 return hours + ":" + minutes;
1016 }
1017
1018 /**
1019 * Gets a list of the fault types from the tomcat faultdb servlet and
1020 * initialises the list box which was provided by the caller.
1021 * @param listBox This is the listbox widget which is to have it's
1022 * list populated
1023 */
1024
1025 protected void fillListBoxWithFaultType (final ListBox listBox, final String CurrentLocale) {
1026
1027 // Now clear out the listbox of it's existing contents
1028
1029 listBox.clear();
1030
1031 for (int i=0; i < FaultTypeList.size(); i++) {
1032
1033 final FaultType newFaultType = (FaultType)FaultTypeList.get(i);
1034
1035 // Now add the name of the FaultType to the list
1036
1037 if (CurrentLocale.equalsIgnoreCase("en")) {
1038 listBox.addItem(newFaultType.getEn_description(),newFaultType.getId());
1039 } else {
1040 listBox.addItem(newFaultType.getSp_description(),newFaultType.getId());
1041 }
1042 }
1043 }
1044
1045 /**
1046 * Gets a list of the fault states from the tomcat faultdb servlet and
1047 * initialises the list box which was provided by the caller.
1048 * @param listBox This is the listbox widget which is to have it's
1049 * list populated
1050 */
1051
1052 protected void fillListBoxWithStates (final ListBox listBox, final String CurrentLocale) {
1053
1054 // Now clear out the listbox of it's existing contents
1055
1056 listBox.clear();
1057
1058 for (int i=0; i < FaultStateList.size(); i++) {
1059
1060 final State newState = (State)FaultStateList.get(i);
1061
1062 // Now add the name of the state to the list
1063
1064 if (CurrentLocale.equalsIgnoreCase("en")) {
1065 listBox.addItem(newState.getEn_description(),newState.getId());
1066 } else {
1067 listBox.addItem(newState.getSp_description(),newState.getId());
1068 }
1069 }
1070 }
1071
1072 /**
1073 * This method will be used to set the selected value in the
1074 * listbox specified to the value which has been provided by the
1075 * caller.
1076 * @param list This is the list widget which contains the value which is to be selected.
1077 * @param value This is the value which is to be selected in the list.
1078 * @return boolean True if we managed to select the value in the
1079 * list which was specified by the value parameter.
1080 */
1081
1082 protected boolean setSelectedItemInListbox(final ListBox list, final String value) {
1083
1084 final int NOTKNOWN = -1;
1085
1086 int unknownIndex = NOTKNOWN;
1087
1088 boolean optionSelected = false;
1089
1090 if (value == null) {
1091 return false;
1092 }
1093
1094 for (int i=0; i < list.getItemCount() ;i++) {
1095
1096 String listValue = list.getValue(i);
1097
1098 // Record where unknown is in the list just in case we
1099 // cannot find the value that we are looking for
1100
1101 if (unknownIndex == NOTKNOWN && listValue.equalsIgnoreCase(FaultDatabaseConstants.DEFAULTUSER)) {
1102 unknownIndex = i;
1103 }
1104
1105 if (listValue.equalsIgnoreCase(value)) {
1106 list.setSelectedIndex(i);
1107 return true;
1108 }
1109 }
1110
1111 // If we found the unknown option in the list and we could not
1112 // find the default value which we were given then set the
1113 // default option to unknown
1114
1115 if (unknownIndex != NOTKNOWN) {
1116 list.setSelectedIndex(unknownIndex);
1117 }
1118
1119 return false;
1120 }
1121
1122 /**
1123 * Check to see if the string which has been specified is actually
1124 * empty after being stripped of HTML markup and symbols.
1125 * @param stringToCheck This is the string to be checked
1126 * @return boolean True if the string contains some text otherwise false.
1127 */
1128
1129 protected boolean stringContainsText (final String stringToCheck) {
1130
1131 String textToVerify = stringToCheck;
1132
1133 // Remove all HTML characters before checking the length of
1134 // the string
1135
1136 textToVerify = textToVerify.replaceAll("<.*?>","");
1137
1138 // Remove all symbols as well
1139
1140 textToVerify = textToVerify.replaceAll(" ","");
1141
1142 // Remove all space characters symbols as well
1143
1144 textToVerify = textToVerify.replaceAll(" ","");
1145
1146 textToVerify = textToVerify.trim();
1147
1148 if (textToVerify.length() == 0) {
1149 return false;
1150 }
1151
1152 return true;
1153 }
1154
1155 /**
1156 * This will verify that the text field is not empty or too full
1157 * to fit in the database.
1158 * @param FieldName This is the name of the field
1159 * @param MaxLength This is the maximum number of characters that
1160 * are allowed in the field. If this is set to {@link
1161 * #NOLENGTHCHECK NOLENGTHCHECK} then
1162 * we do not perform the check.
1163 * @param TextToVerify This is the text which is to be verified
1164 * @throws FieldInvalidException Throw if the field is not valid
1165 * @return True if the field is okay
1166 */
1167
1168 protected boolean verifyText (final String FieldName, final int MaxLength, final String TextToVerify) throws FieldInvalidException {
1169
1170 String textToVerify = TextToVerify;
1171
1172 // Check to see if the text contains any real characters.
1173
1174 if (!stringContainsText(TextToVerify)) {
1175 throw new FieldInvalidException(internationalizationConstants.textFieldEmpty(FieldName));
1176 }
1177
1178 // Verify that it does not contain more than allocated number
1179 // of characters
1180
1181 if (MaxLength != NOLENGTHCHECK && textToVerify.length() > MaxLength) {
1182 throw new FieldInvalidException(internationalizationConstants.textFieldFull(FieldName,MaxLength));
1183 }
1184
1185 return true;
1186 }
1187
1188 /**
1189 * Take an email address and return the full name of the
1190 * person. It does this by going through the <@link
1191 * #StaffMemberList> array.
1192 * @param emailAddress
1193 * @return String The full name of the person. It returns unknown
1194 * if the name is not known.
1195 */
1196
1197 protected String getFullUserNameFromEmailAddress (final String emailAddress) {
1198
1199 for (int i=0; i < StaffMemberList.size(); i++) {
1200
1201 final Person temp = (Person)StaffMemberList.get(i);
1202
1203 if (temp.getEmailAddress().equals(emailAddress)) {
1204 return temp.getName() + " " + temp.getSurname();
1205 }
1206 }
1207
1208 return "Unknown";
1209 }
1210
1211
1212 /**
1213 * This method will be used to return a HTML which can be clicked
1214 * on to create an email.
1215 * @param emailAddress Email address of recipient
1216 * @param faultId Defect number of fault which the email is
1217 * associated
1218 * @param faultTitle This is the title of the fault
1219 * @param linkText This is the text of the link
1220 * @return This is the link which can then be dropped into some
1221 * HTML
1222 */
1223
1224 public static String createEmailLink (final String emailAddress,
1225 final int faultId,
1226 final String faultTitle,
1227 final String linkText) {
1228
1229 // If the user is not guest or unknown then we allow a link so
1230 // he can be emailed.
1231
1232 if (!emailAddress.equalsIgnoreCase(FaultDatabaseConstants.GUEST) && !emailAddress.equalsIgnoreCase(FaultDatabaseConstants.DEFAULTUSER)) {
1233 return "<a href=\"mailto:" + emailAddress + "?Subject=DR " + faultId + " - " + faultTitle + "\">" + linkText + "</a>";
1234 } else {
1235 return linkText;
1236 }
1237 }
1238 }