Coverage details for ui.command.IO.SaveNewSessionCommand

LineHitsSource
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  */
430public class SaveNewSessionCommand extends Command {
440 
450    private static final transient Logger logger = Logger
460            .getLogger(SaveNewSessionCommand.class.getName());
470 
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) {
700        super();
710        // TODO Auto-generated constructor stub
720        this.newSessionDialog = newSessionDialog;
730        this.sessionCreationPanel = sessionCreationPanel;
740    }
750 
76     /*
77      * (non-Javadoc)
78      *
79      * @see ui.command.Command#prologo()
80      */
81     @Override
82     protected void prologo() {
830        user = sessionCreationPanel.getUser();
840        workstation = sessionCreationPanel.getWorkstation();
850        description = newSessionDialog.getSessionDescription();
860        startTime = newSessionDialog.getSessionStartTime();
870        endTime = newSessionDialog.getSessionEndTime();
880        service = newSessionDialog.getSessionService();
890 
900        GregorianCalendar startTimeGC = new GregorianCalendar();
910        startTimeGC.setTime(startTime);
920        GregorianCalendar endTimeGC = new GregorianCalendar();
930        endTimeGC.setTime(endTime);
940        startTime = new Date(startTimeGC.getTimeInMillis());
950        endTime = new Date(new GregorianCalendar(
960                startTimeGC.get(Calendar.YEAR),
970                startTimeGC.get(Calendar.MONTH),
980                startTimeGC.get(Calendar.DATE),
990                endTimeGC.get(Calendar.HOUR) + 12, endTimeGC
1000                        .get(Calendar.MINUTE), endTimeGC.get(Calendar.SECOND))
1010                .getTimeInMillis());
1020 
1030        if (isValidSessionData(user, workstation, description, startTime,
1040                endTime, service))
1050            setStatus(EXECUTE_STATUS);
1060        else
1070            setStatus(ERROR_STATUS);
1080    }
1090 
110     private boolean isValidSessionData(User user, Workstation workstation,
111             String description, Date startTime, Date endTime, Service service) {
1120        if (user == null) {
1130            this.sessionCreationPanel.setUserError(true);
1140            return false;
1150        } else
1160            this.sessionCreationPanel.setUserError(false);
1170 
1180        if (workstation == null) {
1190            this.sessionCreationPanel.setWorkstationError(true);
1200            return false;
1210        } else
1220            this.sessionCreationPanel.setWorkstationError(false);
1230 
1240        if (!Control.isValidSessionDate(startTime, endTime)) {
1250            this.newSessionDialog.setSessionDateError(true);
1260            return false;
1270        } else
1280            this.newSessionDialog.setSessionDateError(false);
1290 
1300        return true;
1310    }
132  
133     /*
134      * (non-Javadoc)
135      *
136      * @see ui.command.Command#execution()
137      */
138     @Override
139     protected void execution() throws Exception {
1400        switch (getStatus()) {
1410        case ERROR_STATUS:
1420            break;
1430        case VETOED_STATUS:
1440            break;
1450        case EXECUTE_STATUS:
1460            logger.debug("NewSession : " + "start " + startTime + " end " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1470                    + endTime + " valid ? " //$NON-NLS-1$
1480                    + Control.isValidSessionDate(startTime, endTime));
1490            Session session = SessionFactory.newSession(user, workstation,
1500                    description, startTime, endTime, service);
1510            InternetCafeManager.getInstance().addSession(session);
1520            setStatus(SUCCESS_STATUS);
1530            break;
154         }
1550    }
1560}

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.