1   package org.wcb.model.service.impl;
2   
3   import org.wcb.model.manager.*;
4   import org.wcb.model.service.ILogbookService;
5   import org.wcb.model.vo.hibernate.*;
6   import org.wcb.model.vo.hibernate.FAA8710ApplicationBO;
7   import org.wcb.exception.ServiceException;
8   import org.wcb.exception.ManagerException;
9   
10  import java.util.List;
11  import java.util.Collection;
12  
13  /**
14   * <small>
15   * Copyright (c)  2006  wbogaardt.
16   * Permission is granted to copy, distribute and/or modify this document
17   * under the terms of the GNU Free Documentation License, Version 1.2
18   * or any later version published by the Free Software Foundation;
19   * with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
20   * Texts.  A copy of the license is included in the section entitled "GNU
21   * Free Documentation License".
22   * <p/>
23   * $File:  $ <br>
24   * $Change:  $ submitted by $Author: wbogaardt $ at $DateTime: Mar 24, 2006 12:19:51 PM $ <br>
25   * </small>
26   *
27   * @author wbogaardt
28   * @version 1
29   *          Date: Mar 24, 2006
30   *          Time: 12:19:51 PM
31   */
32  
33  public class LogbookService implements ILogbookService {
34  
35      private ILogbookManager logbookManager;
36      private IAircraftManager aircraftManager;
37      private IAircraftTypeManager aircraftTypeManager;
38      private IAirportManager airportManager;
39      private IApplicantManager applicantManager;
40  
41      public ILogbookManager getLogbookManager() {
42          return logbookManager;
43      }
44  
45      public void setLogbookManager(ILogbookManager logbookManager) {
46          this.logbookManager = logbookManager;
47      }
48  
49      public IAircraftManager getAircraftManager() {
50          return aircraftManager;
51      }
52  
53      public void setAircraftManager(IAircraftManager aircraftManager) {
54          this.aircraftManager = aircraftManager;
55      }
56  
57      public IAircraftTypeManager getAircraftTypeManager() {
58          return aircraftTypeManager;
59      }
60  
61      public void setAircraftTypeManager(IAircraftTypeManager aircraftTypeManager) {
62          this.aircraftTypeManager = aircraftTypeManager;
63      }
64  
65      public IAirportManager getAirportManager() {
66          return airportManager;
67      }
68  
69      public void setAirportManager(IAirportManager airportManager) {
70          this.airportManager = airportManager;
71      }
72  
73  
74      public IApplicantManager getApplicantManager() {
75          return applicantManager;
76      }
77  
78      public void setApplicantManager(IApplicantManager applicantManager) {
79          this.applicantManager = applicantManager;
80      }
81  
82      public Logbook findLogBookEntry(Integer pkId) throws ServiceException {
83          try
84          {
85              return logbookManager.findEntry(pkId);
86          } catch (ManagerException me) {
87              throw new ServiceException("Logbook entry was not found for id " + pkId);
88          }
89      }
90  
91      public void saveLogBookEntry(Logbook oEntry) throws ServiceException {
92          try
93          {
94              logbookManager.saveEntry(oEntry);
95          }
96          catch (ManagerException me)
97          {
98              throw new ServiceException("Logbook entry failed to be saved.");
99          }
100     }
101 
102     public void saveLogBookEntry(Collection<Logbook> oSaveEntries) throws ServiceException {
103         try
104         {
105             logbookManager.saveOrUpdateLogbook(oSaveEntries);
106         }
107         catch (ManagerException me)
108         {
109             throw new ServiceException("Failed to save logbook entries from importing # " + oSaveEntries.size(), me);
110         }
111     }
112 
113     public void deleteLogBookEntry(Logbook oEntry) throws ServiceException {
114         try
115         {
116             logbookManager.deleteEntry(oEntry);
117         }
118         catch (ManagerException me)
119         {
120             throw new ServiceException("Logbook entry failed to be deleted.");
121         }
122     }
123 
124     public List<Logbook> getAllLogbookEntries() throws ServiceException {
125         try
126         {
127             return logbookManager.findAll();
128         }
129         catch (ManagerException me)
130         {
131             throw new ServiceException("Manager Exception", me);
132         }
133     }
134 
135     public List<Logbook> findByRegistration(String reg) throws ServiceException {
136         try
137         {
138             return logbookManager.findByRegistration(reg);
139         }
140         catch (ManagerException me)
141         {
142             throw new ServiceException("Failed to find any log entries");
143         }
144     }
145 
146     public AircraftBO getAircraftByRegistration(String regid) throws ServiceException {
147         try
148         {
149             return aircraftManager.findByRegistry(regid);
150         }
151         catch (ManagerException me)
152         {
153             throw new ServiceException("Failed to find the aircraft with registration " + regid, me);
154         }
155     }
156 
157     public void saveAircraft(AircraftBO craft) throws ServiceException {
158         try
159         {
160             aircraftManager.saveOrUpdateAircraft(craft);
161         }
162         catch (ManagerException me)
163         {
164             throw new ServiceException("Unable to save aircraft");
165         }
166     }
167 
168     public AircraftTypeBO getAircraftTypeById(Integer id) throws ServiceException {
169         try
170         {
171             return aircraftTypeManager.getAircraftTypeById(id);
172         }
173         catch (ManagerException me)
174         {
175             throw new ServiceException("Failed to find aircraft type by id " + id, me);
176         }
177     }
178 
179     public List<AircraftTypeBO> findAllAircraftType() throws ServiceException {
180         try
181         {
182             return aircraftTypeManager.getAllAircraftTypes();
183         }
184         catch (ManagerException me)
185         {
186             throw new ServiceException("Failed to find any aircraft types", me);
187         }
188     }
189 
190     public void saveAircraftType(AircraftTypeBO type) throws ServiceException {
191         try
192         {
193             aircraftTypeManager.saveAircraftType(type);
194         }
195         catch (ManagerException me)
196         {
197             throw new ServiceException("Failed to save aircraft types", me);
198         }
199 
200     }
201 
202     public void deleteAircraft(AircraftBO craft) throws ServiceException {
203         try
204         {
205             aircraftManager.deleteAircraftEntry(craft);
206         }
207         catch (ManagerException me)
208         {
209             throw new ServiceException("Failed to delete aircraft" + craft.getRegistrationNumber(), me);
210         }
211     }
212 
213     public List<AircraftBO> findAllAircraft() throws ServiceException {
214         try
215         {
216             return aircraftManager.findAll();
217         }
218         catch (ManagerException me)
219         {
220             throw new ServiceException("Failed to find any aircraft ", me);
221         }
222     }
223 
224     public List<AirportBO> findAllAirport() throws ServiceException {
225         try
226         {
227             return airportManager.findAll();
228         }
229         catch (ManagerException me)
230         {
231             throw new ServiceException("Failed to find any airport ", me);
232         }
233     }
234 
235     public AirportBO findByAirportFaa(String faaCode) throws ServiceException {
236         try
237         {
238             return airportManager.findByAirportFaa(faaCode);
239         }
240         catch (ManagerException me)
241         {
242             throw new ServiceException("Failed to find airport as " + faaCode, me);
243         }
244     }
245 
246     public void saveAirport(AirportBO oSave) throws ServiceException {
247         try
248         {
249             airportManager.saveOrUpdateAirport(oSave);
250         }
251         catch (ManagerException me)
252         {
253             throw new ServiceException("Failed to save Airport" + oSave.getFaa(), me);
254         }
255     }
256 
257     public void saveAirports(Collection<AirportBO> oSave) throws ServiceException {
258         try
259         {
260             airportManager.saveOrUpdateAirports(oSave);
261         }
262         catch (ManagerException me)
263         {
264             throw new ServiceException("Failed to save Airports # " + oSave.size(), me);
265         }
266     }
267 
268     public void deleteAirport(AirportBO oAirport) throws ServiceException {
269         try
270         {
271             airportManager.deleteAirportEntry(oAirport);
272         }
273         catch (ManagerException me)
274         {
275             throw new ServiceException("Failed to delete airport " + oAirport.getFaa(), me);
276         }
277     }
278 
279     /**
280      * Logbook user information.
281      * @param oSave
282      * @throws ServiceException
283      */
284      public void saveApplicant(FAA8710ApplicationBO oSave) throws ServiceException {
285         try
286         {
287             applicantManager.saveApplicant(oSave);
288         }
289         catch (ManagerException me)
290         {
291             throw new ServiceException("Failed to save Applicant " + oSave.getName(), me);
292         }
293     }
294 
295     public FAA8710ApplicationBO getApplicant() throws ServiceException {
296         try
297         {
298             return applicantManager.findEntry(1);
299         }
300         catch (ManagerException me)
301         {
302             throw new ServiceException("Failed to find applicant as " + 1, me);
303         }
304     }
305 }