Line | Hits | Source |
---|---|---|
1 | /******************************************************************************* | |
2 | * InternetCafe is a software solution that helps the management of Cybercafes | |
3 | * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005. | |
4 | * Copyright (C) 2006 Guido Angelo Ingenito | |
5 | ||
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version 2 | |
9 | * of the License, or (at your option) any later version. | |
10 | ||
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 | *******************************************************************************/ | |
20 | package ui.command.IO; | |
21 | ||
22 | import java.util.Calendar; | |
23 | import java.util.Date; | |
24 | import java.util.GregorianCalendar; | |
25 | ||
26 | import org.apache.log4j.Logger; | |
27 | ||
28 | import ui.command.Command; | |
29 | import ui.dialog.NewSessionDialog; | |
30 | import ui.panel.SessionCreationPanel; | |
31 | import base.Control; | |
32 | import base.InternetCafeManager; | |
33 | import base.network.Workstation; | |
34 | import base.service.Service; | |
35 | import base.session.Session; | |
36 | import base.session.SessionFactory; | |
37 | import base.user.User; | |
38 | ||
39 | /** | |
40 | * @author skunk | |
41 | * | |
42 | */ | |
43 | 0 | public class SaveNewSessionCommand extends Command { |
44 | 0 | |
45 | 0 | private static final transient Logger logger = Logger |
46 | 0 | .getLogger(SaveNewSessionCommand.class.getName()); |
47 | 0 | |
48 | private NewSessionDialog newSessionDialog; | |
49 | ||
50 | private SessionCreationPanel sessionCreationPanel; | |
51 | ||
52 | private User user; | |
53 | ||
54 | private Workstation workstation; | |
55 | ||
56 | private String description; | |
57 | ||
58 | private Date startTime; | |
59 | ||
60 | private Date endTime; | |
61 | ||
62 | private Service service; | |
63 | ||
64 | /** | |
65 | * @param newSessionDialog | |
66 | * @param sessionCreationPanel | |
67 | */ | |
68 | public SaveNewSessionCommand(NewSessionDialog newSessionDialog, | |
69 | SessionCreationPanel sessionCreationPanel) { | |
70 | 0 | super(); |
71 | 0 | // TODO Auto-generated constructor stub |
72 | 0 | this.newSessionDialog = newSessionDialog; |
73 | 0 | this.sessionCreationPanel = sessionCreationPanel; |
74 | 0 | } |
75 | 0 | |
76 | /* | |
77 | * (non-Javadoc) | |
78 | * | |
79 | * @see ui.command.Command#prologo() | |
80 | */ | |
81 | @Override | |
82 | protected void prologo() { | |
83 | 0 | user = sessionCreationPanel.getUser(); |
84 | 0 | workstation = sessionCreationPanel.getWorkstation(); |
85 | 0 | description = newSessionDialog.getSessionDescription(); |
86 | 0 | startTime = newSessionDialog.getSessionStartTime(); |
87 | 0 | endTime = newSessionDialog.getSessionEndTime(); |
88 | 0 | service = newSessionDialog.getSessionService(); |
89 | 0 | |
90 | 0 | GregorianCalendar startTimeGC = new GregorianCalendar(); |
91 | 0 | startTimeGC.setTime(startTime); |
92 | 0 | GregorianCalendar endTimeGC = new GregorianCalendar(); |
93 | 0 | endTimeGC.setTime(endTime); |
94 | 0 | startTime = new Date(startTimeGC.getTimeInMillis()); |
95 | 0 | endTime = new Date(new GregorianCalendar( |
96 | 0 | startTimeGC.get(Calendar.YEAR), |
97 | 0 | startTimeGC.get(Calendar.MONTH), |
98 | 0 | startTimeGC.get(Calendar.DATE), |
99 | 0 | endTimeGC.get(Calendar.HOUR) + 12, endTimeGC |
100 | 0 | .get(Calendar.MINUTE), endTimeGC.get(Calendar.SECOND)) |
101 | 0 | .getTimeInMillis()); |
102 | 0 | |
103 | 0 | if (isValidSessionData(user, workstation, description, startTime, |
104 | 0 | endTime, service)) |
105 | 0 | setStatus(EXECUTE_STATUS); |
106 | 0 | else |
107 | 0 | setStatus(ERROR_STATUS); |
108 | 0 | } |
109 | 0 | |
110 | private boolean isValidSessionData(User user, Workstation workstation, | |
111 | String description, Date startTime, Date endTime, Service service) { | |
112 | 0 | if (user == null) { |
113 | 0 | this.sessionCreationPanel.setUserError(true); |
114 | 0 | return false; |
115 | 0 | } else |
116 | 0 | this.sessionCreationPanel.setUserError(false); |
117 | 0 | |
118 | 0 | if (workstation == null) { |
119 | 0 | this.sessionCreationPanel.setWorkstationError(true); |
120 | 0 | return false; |
121 | 0 | } else |
122 | 0 | this.sessionCreationPanel.setWorkstationError(false); |
123 | 0 | |
124 | 0 | if (!Control.isValidSessionDate(startTime, endTime)) { |
125 | 0 | this.newSessionDialog.setSessionDateError(true); |
126 | 0 | return false; |
127 | 0 | } else |
128 | 0 | this.newSessionDialog.setSessionDateError(false); |
129 | 0 | |
130 | 0 | return true; |
131 | 0 | } |
132 | ||
133 | /* | |
134 | * (non-Javadoc) | |
135 | * | |
136 | * @see ui.command.Command#execution() | |
137 | */ | |
138 | @Override | |
139 | protected void execution() throws Exception { | |
140 | 0 | switch (getStatus()) { |
141 | 0 | case ERROR_STATUS: |
142 | 0 | break; |
143 | 0 | case VETOED_STATUS: |
144 | 0 | break; |
145 | 0 | case EXECUTE_STATUS: |
146 | 0 | logger.debug("NewSession : " + "start " + startTime + " end " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
147 | 0 | + endTime + " valid ? " //$NON-NLS-1$ |
148 | 0 | + Control.isValidSessionDate(startTime, endTime)); |
149 | 0 | Session session = SessionFactory.newSession(user, workstation, |
150 | 0 | description, startTime, endTime, service); |
151 | 0 | InternetCafeManager.getInstance().addSession(session); |
152 | 0 | setStatus(SUCCESS_STATUS); |
153 | 0 | break; |
154 | } | |
155 | 0 | } |
156 | 0 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |