1   package org.wcb.model.service.impl;
2   
3   import org.wcb.model.service.IValidatorService;
4   import org.wcb.model.vo.hibernate.Logbook;
5   
6   /**
7    * <small>
8    * Copyright (c)  2006  wbogaardt.
9    * Permission is granted to copy, distribute and/or modify this document
10   * under the terms of the GNU Free Documentation License, Version 1.2
11   * or any later version published by the Free Software Foundation;
12   * with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
13   * Texts.  A copy of the license is included in the section entitled "GNU
14   * Free Documentation License".
15   * <p/>
16   * $File:  $ <br>
17   * $Change:  $ submitted by $Author: wbogaardt $ at $DateTime: Mar 29, 2006 8:21:52 AM $ <br>
18   * </small>
19   *
20   * @author wbogaardt
21   * @version 1
22   *          Date: Mar 29, 2006
23   *          Time: 8:21:52 AM
24   */
25  
26  public class LogbookValidationService implements IValidatorService {
27  
28      private Logbook logObject;
29  
30  
31      public Object getObject() {
32          return logObject;
33      }
34  
35      public void setObject(Object logObject) {
36          if (logObject instanceof Logbook) {
37              this.logObject = (Logbook) logObject;
38          }
39      }
40  
41      /**
42       * Validates the logbook object for time, all fields entered.
43       * @return  Return true for successful validation or false for failed validation
44       */
45      public boolean validate() {
46          return logObject != null && validateFlightTime() && validateEnteredFields();
47      }
48  
49      private boolean validateEnteredFields() {
50          return !(logObject.getRegistration() == null && logObject.getFaaFrom() == null && logObject.getFaaTo() == null);
51      }
52  
53      /**
54       * The rules are if you you have a total flight time none of the sub valued
55       * flight times can be greater than it. For example You cannot be pilot in
56       * command longer than the plane is flying or cross country flying longer
57       * than the total flight time. This basically checks all those sub values
58       * are less than the total flight time.
59       *
60       * @return true that everthing checks out false that one value is off.
61       */
62      private boolean validateFlightTime() {
63          //It's a pcatd (computer) so we don't check time
64          if (logObject.getRegistration().equalsIgnoreCase("PCADT")) {
65              return true;
66          }
67          Double dTotal = logObject.getFlightDuration();
68          Double dPIC = logObject.getPic();
69          Double dSIC = logObject.getSic();
70          Double dCrossCountry = logObject.getCrossCountry();
71          Double dInstructing = logObject.getFlightInstructing();
72          Double dSafety = logObject.getSafetyPilot();
73          Double dDual = logObject.getDualReceived();
74          Double dSolo = logObject.getSolo();
75          Double dNight = logObject.getConditionNight();
76          Double dActual = logObject.getConditionActualImc();
77          Double dSimulated = logObject.getConditionSimulatedImc();
78          Double dSimulator = logObject.getConditionFlightSim();
79          if (dPIC != null && dTotal < dPIC) {
80              return false;
81          }
82          if (dSIC!=null && dTotal < dSIC) {
83              return false;
84          }
85          if (dCrossCountry!=null && dTotal < dCrossCountry) {
86              return false;
87          }
88          if (dInstructing!=null && dTotal < dInstructing) {
89              return false;
90          }
91          if (dSafety!=null && dTotal < dSafety) {
92              return false;
93          }
94          if (dDual!=null && dTotal < dDual) {
95              return false;
96          }
97          if (dSolo!=null && dTotal < dSolo) {
98              return false;
99          }
100         if (dNight!=null && dTotal < dNight) {
101             return false;
102         }
103         if (dActual!=null && dTotal < dActual) {
104             return false;
105         }
106         if (dSimulated!=null && dTotal < dSimulated) {
107             return false;
108         }
109         return !(dSimulator != null && dTotal < dSimulator);
110     }
111 }