| 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.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 | */ | |
| 70 | 0 | public SaveUserCommand(UserPanel userPanel, User user, boolean createNewUser) { |
| 71 | 0 | this.userPanel = userPanel; |
| 72 | 0 | this.user = user; |
| 73 | 0 | this.createNewUser = createNewUser; |
| 74 | 0 | } |
| 75 | 0 | |
| 76 | /* | |
| 77 | * (non-Javadoc) | |
| 78 | * | |
| 79 | * @see ui.command.Command#prologo() | |
| 80 | */ | |
| 81 | @Override | |
| 82 | protected void prologo() { | |
| 83 | 0 | name = getUserPanel().getUserName(); |
| 84 | 0 | surname = getUserPanel().getUserSurname(); |
| 85 | 0 | gender = getUserPanel().getUserGender(); |
| 86 | 0 | birthday = getUserPanel().getUserBirthday(); |
| 87 | 0 | nickname = getUserPanel().getUserNickname(); |
| 88 | 0 | password = getUserPanel().getUserPassword(); |
| 89 | 0 | retypedPassword = getUserPanel().getRetypedPassword(); |
| 90 | 0 | credential = getUserPanel().getUserCredential(); |
| 91 | 0 | imagePath = getUserPanel().getUserImagePath(); |
| 92 | 0 | document = getUserPanel().getUserDocument(); |
| 93 | 0 | if (isValidUserData(name, surname, gender, birthday, nickname, |
| 94 | 0 | password, retypedPassword, credential, imagePath, document)) |
| 95 | 0 | setStatus(EXECUTE_STATUS); |
| 96 | 0 | else |
| 97 | 0 | setStatus(ERROR_STATUS); |
| 98 | 0 | } |
| 99 | 0 | |
| 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) { | |
| 104 | 0 | if (!Control.isValidUserName(name)) { |
| 105 | 0 | getUserPanel().setUserNameError(true); |
| 106 | 0 | return false; |
| 107 | 0 | } else |
| 108 | 0 | getUserPanel().setUserNameError(false); |
| 109 | 0 | |
| 110 | 0 | if (!Control.isValidUserSurname(surname)) { |
| 111 | 0 | getUserPanel().setUserSurnameError(true); |
| 112 | 0 | return false; |
| 113 | 0 | } else |
| 114 | 0 | getUserPanel().setUserSurnameError(false); |
| 115 | 0 | |
| 116 | 0 | if (!Control.isValidBirthdayDate(birthday)) { |
| 117 | 0 | getUserPanel().setUserBirthdayError(true); |
| 118 | 0 | return false; |
| 119 | 0 | } else |
| 120 | 0 | getUserPanel().setUserBirthdayError(false); |
| 121 | 0 | |
| 122 | 0 | if (!Control.isValidUserNickname(nickname)) { |
| 123 | 0 | getUserPanel().setUserNicknameError(true); |
| 124 | 0 | return false; |
| 125 | 0 | } else |
| 126 | 0 | getUserPanel().setUserNicknameError(false); |
| 127 | 0 | |
| 128 | 0 | if (!password.equals(retypedPassword)) { |
| 129 | 0 | getUserPanel().setUserPasswordError(true); |
| 130 | 0 | return false; |
| 131 | 0 | } else |
| 132 | 0 | getUserPanel().setUserPasswordError(false); |
| 133 | 0 | |
| 134 | 0 | if (!Control.isValidUserPassword(password)) { |
| 135 | 0 | getUserPanel().setUserPasswordError(true); |
| 136 | 0 | return false; |
| 137 | 0 | } else |
| 138 | 0 | getUserPanel().setUserPasswordError(false); |
| 139 | 0 | |
| 140 | 0 | if (!Control.isValidUserDocument(document)) { |
| 141 | 0 | getUserPanel().setUserDocumentError(true); |
| 142 | 0 | return false; |
| 143 | 0 | } else |
| 144 | 0 | getUserPanel().setUserDocumentError(false); |
| 145 | 0 | |
| 146 | 0 | return true; |
| 147 | 0 | } |
| 148 | ||
| 149 | /* | |
| 150 | * (non-Javadoc) | |
| 151 | * | |
| 152 | * @see ui.command.Command#execution() | |
| 153 | */ | |
| 154 | @Override | |
| 155 | protected void execution() throws Exception { | |
| 156 | 0 | switch (getStatus()) { |
| 157 | 0 | case ERROR_STATUS: |
| 158 | 0 | break; |
| 159 | 0 | case VETOED_STATUS: |
| 160 | 0 | break; |
| 161 | 0 | case EXECUTE_STATUS: |
| 162 | 0 | if (createNewUser) { |
| 163 | 0 | user = UserFactory.newUser(name, surname, gender, birthday, |
| 164 | 0 | nickname, password, credential, document, imagePath); |
| 165 | 0 | InternetCafeManager.getInstance().addUser(user); |
| 166 | 0 | setStatus(SUCCESS_STATUS); |
| 167 | 0 | } else { |
| 168 | 0 | user.setName(name); |
| 169 | 0 | user.setSurname(surname); |
| 170 | 0 | user.setGender(gender); |
| 171 | 0 | user.setBirthday(birthday); |
| 172 | 0 | user.setNickname(nickname); |
| 173 | 0 | user.setPassword(password); |
| 174 | 0 | user.setCredential(credential); |
| 175 | 0 | user.setImagePath(imagePath); |
| 176 | 0 | user.setDocument(document); |
| 177 | 0 | setStatus(SUCCESS_STATUS); |
| 178 | 0 | } |
| 179 | break; | |
| 180 | } | |
| 181 | 0 | } |
| 182 | 0 | |
| 183 | /** | |
| 184 | * @return Returns the userPanel. | |
| 185 | */ | |
| 186 | private UserPanel getUserPanel() { | |
| 187 | 0 | return userPanel; |
| 188 | } | |
| 189 | ||
| 190 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |