Coverage details for ui.command.IO.SaveUserCommand

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.Date;
23  
24 import ui.command.Command;
25 import ui.panel.UserPanel;
26 import base.Control;
27 import base.InternetCafeManager;
28 import base.user.Document;
29 import base.user.User;
30 import base.user.UserFactory;
31  
32 public class SaveUserCommand extends Command {
33  
34     private UserPanel userPanel;
35  
36     private User user;
37  
38     private boolean createNewUser;
39  
40     private String name;
41  
42     private String surname;
43  
44     private String gender;
45  
46     private Date birthday;
47  
48     private String nickname;
49  
50     private String password;
51  
52     private String retypedPassword;
53  
54     private String credential;
55  
56     private String imagePath;
57  
58     private Document document;
59  
60     /**
61      * @param userPanel
62      * The UserPanel instance from wich must retrieve the User's
63      * data.
64      * @param user
65      * The instance of user that will be the result of this command.
66      * @param createNewUser
67      * States if that Command must create a new user or modify the
68      * User's data of an existing User instance.
69      */
700    public SaveUserCommand(UserPanel userPanel, User user, boolean createNewUser) {
710        this.userPanel = userPanel;
720        this.user = user;
730        this.createNewUser = createNewUser;
740    }
750 
76     /*
77      * (non-Javadoc)
78      *
79      * @see ui.command.Command#prologo()
80      */
81     @Override
82     protected void prologo() {
830        name = getUserPanel().getUserName();
840        surname = getUserPanel().getUserSurname();
850        gender = getUserPanel().getUserGender();
860        birthday = getUserPanel().getUserBirthday();
870        nickname = getUserPanel().getUserNickname();
880        password = getUserPanel().getUserPassword();
890        retypedPassword = getUserPanel().getRetypedPassword();
900        credential = getUserPanel().getUserCredential();
910        imagePath = getUserPanel().getUserImagePath();
920        document = getUserPanel().getUserDocument();
930        if (isValidUserData(name, surname, gender, birthday, nickname,
940                password, retypedPassword, credential, imagePath, document))
950            setStatus(EXECUTE_STATUS);
960        else
970            setStatus(ERROR_STATUS);
980    }
990 
100     private boolean isValidUserData(String name, String surname, String gender,
101             Date birthday, String nickname, String password,
102             String retypedPassword, String credential, String imagePath,
103             Document document) {
1040        if (!Control.isValidUserName(name)) {
1050            getUserPanel().setUserNameError(true);
1060            return false;
1070        } else
1080            getUserPanel().setUserNameError(false);
1090 
1100        if (!Control.isValidUserSurname(surname)) {
1110            getUserPanel().setUserSurnameError(true);
1120            return false;
1130        } else
1140            getUserPanel().setUserSurnameError(false);
1150 
1160        if (!Control.isValidBirthdayDate(birthday)) {
1170            getUserPanel().setUserBirthdayError(true);
1180            return false;
1190        } else
1200            getUserPanel().setUserBirthdayError(false);
1210 
1220        if (!Control.isValidUserNickname(nickname)) {
1230            getUserPanel().setUserNicknameError(true);
1240            return false;
1250        } else
1260            getUserPanel().setUserNicknameError(false);
1270 
1280        if (!password.equals(retypedPassword)) {
1290            getUserPanel().setUserPasswordError(true);
1300            return false;
1310        } else
1320            getUserPanel().setUserPasswordError(false);
1330 
1340        if (!Control.isValidUserPassword(password)) {
1350            getUserPanel().setUserPasswordError(true);
1360            return false;
1370        } else
1380            getUserPanel().setUserPasswordError(false);
1390 
1400        if (!Control.isValidUserDocument(document)) {
1410            getUserPanel().setUserDocumentError(true);
1420            return false;
1430        } else
1440            getUserPanel().setUserDocumentError(false);
1450 
1460        return true;
1470    }
148  
149     /*
150      * (non-Javadoc)
151      *
152      * @see ui.command.Command#execution()
153      */
154     @Override
155     protected void execution() throws Exception {
1560        switch (getStatus()) {
1570        case ERROR_STATUS:
1580            break;
1590        case VETOED_STATUS:
1600            break;
1610        case EXECUTE_STATUS:
1620            if (createNewUser) {
1630                user = UserFactory.newUser(name, surname, gender, birthday,
1640                        nickname, password, credential, document, imagePath);
1650                InternetCafeManager.getInstance().addUser(user);
1660                setStatus(SUCCESS_STATUS);
1670            } else {
1680                user.setName(name);
1690                user.setSurname(surname);
1700                user.setGender(gender);
1710                user.setBirthday(birthday);
1720                user.setNickname(nickname);
1730                user.setPassword(password);
1740                user.setCredential(credential);
1750                user.setImagePath(imagePath);
1760                user.setDocument(document);
1770                setStatus(SUCCESS_STATUS);
1780            }
179             break;
180         }
1810    }
1820 
183     /**
184      * @return Returns the userPanel.
185      */
186     private UserPanel getUserPanel() {
1870        return userPanel;
188     }
189  
190 }

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.