| 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 ui.command.Command; | |
| 23 | import ui.panel.ServicePanel; | |
| 24 | import base.Control; | |
| 25 | import base.InternetCafeManager; | |
| 26 | import base.service.Service; | |
| 27 | import base.service.ServiceFactory; | |
| 28 | ||
| 29 | public class SaveServiceCommand extends Command { | |
| 30 | ||
| 31 | private ServicePanel servicePanel; | |
| 32 | ||
| 33 | private Service service; | |
| 34 | ||
| 35 | private boolean createService; | |
| 36 | ||
| 37 | private String name; | |
| 38 | ||
| 39 | private String description; | |
| 40 | ||
| 41 | private String rateType; | |
| 42 | ||
| 43 | private double baseRate; | |
| 44 | ||
| 45 | private int minDurationInMinute; | |
| 46 | ||
| 47 | private boolean careAboutMinDuration; | |
| 48 | ||
| 49 | private int maxDurationInMinute; | |
| 50 | ||
| 51 | private boolean careAboutMaxDuration; | |
| 52 | ||
| 53 | /** | |
| 54 | * @param servicePanel | |
| 55 | * @param createService | |
| 56 | */ | |
| 57 | public SaveServiceCommand(ServicePanel servicePanel, Service service, | |
| 58 | boolean createService) { | |
| 59 | 0 | super(); |
| 60 | 0 | // TODO Auto-generated constructor stub |
| 61 | 0 | this.servicePanel = servicePanel; |
| 62 | 0 | this.service = service; |
| 63 | 0 | this.createService = createService; |
| 64 | 0 | } |
| 65 | 0 | |
| 66 | /* | |
| 67 | * (non-Javadoc) | |
| 68 | * | |
| 69 | * @see ui.command.Command#prologo() | |
| 70 | */ | |
| 71 | @Override | |
| 72 | protected void prologo() { | |
| 73 | 0 | name = getServicePanel().getServiceName(); |
| 74 | 0 | description = getServicePanel().getServiceDescription(); |
| 75 | 0 | rateType = getServicePanel().getServiceRateType(); |
| 76 | 0 | baseRate = getServicePanel().getServiceBaseRate(); |
| 77 | 0 | minDurationInMinute = getServicePanel().getServiceMinDurationInMinute(); |
| 78 | 0 | careAboutMinDuration = getServicePanel() |
| 79 | 0 | .getServiceCareAboutMinDuration(); |
| 80 | 0 | maxDurationInMinute = getServicePanel().getServiceMaxDurationInMinute(); |
| 81 | 0 | careAboutMaxDuration = getServicePanel() |
| 82 | 0 | .getServiceCareAboutMaxDuration(); |
| 83 | 0 | if (isValidServiceData(name, description, rateType, baseRate, |
| 84 | 0 | minDurationInMinute, careAboutMinDuration, maxDurationInMinute, |
| 85 | 0 | careAboutMaxDuration)) |
| 86 | 0 | setStatus(EXECUTE_STATUS); |
| 87 | 0 | else |
| 88 | 0 | setStatus(ERROR_STATUS); |
| 89 | 0 | } |
| 90 | 0 | |
| 91 | private boolean isValidServiceData(String name, String description, | |
| 92 | String rateType, double baseRate, int minDurationInMinute, | |
| 93 | boolean careAboutMinDuration, int maxDurationInMinute, | |
| 94 | boolean careAboutMaxDuration) { | |
| 95 | 0 | if (name == null || name.length() == 0) { |
| 96 | 0 | this.getServicePanel().setNameError(true); |
| 97 | 0 | return false; |
| 98 | 0 | } else |
| 99 | 0 | this.getServicePanel().setNameError(false); |
| 100 | 0 | |
| 101 | 0 | if (baseRate < 0) { |
| 102 | 0 | this.getServicePanel().setBaseRateError(true); |
| 103 | 0 | return false; |
| 104 | 0 | } else |
| 105 | 0 | this.getServicePanel().setBaseRateError(false); |
| 106 | 0 | |
| 107 | 0 | if (!Control |
| 108 | 0 | .isValidServiceMinMaxDuration(minDurationInMinute, |
| 109 | 0 | careAboutMinDuration, maxDurationInMinute, |
| 110 | 0 | careAboutMaxDuration)) { |
| 111 | 0 | this.getServicePanel().setMinMaxDurationError(true); |
| 112 | 0 | return false; |
| 113 | 0 | } else |
| 114 | 0 | this.getServicePanel().setMinMaxDurationError(false); |
| 115 | 0 | |
| 116 | 0 | return true; |
| 117 | 0 | } |
| 118 | ||
| 119 | /* | |
| 120 | * (non-Javadoc) | |
| 121 | * | |
| 122 | * @see ui.command.Command#execution() | |
| 123 | */ | |
| 124 | @Override | |
| 125 | protected void execution() throws Exception { | |
| 126 | 0 | switch (getStatus()) { |
| 127 | 0 | case ERROR_STATUS: |
| 128 | 0 | break; |
| 129 | 0 | case VETOED_STATUS: |
| 130 | 0 | break; |
| 131 | 0 | case EXECUTE_STATUS: |
| 132 | 0 | if (createService) { |
| 133 | 0 | service = ServiceFactory.newService(name, description, |
| 134 | 0 | rateType, baseRate, minDurationInMinute, |
| 135 | 0 | careAboutMinDuration, maxDurationInMinute, |
| 136 | 0 | careAboutMaxDuration); |
| 137 | 0 | InternetCafeManager.getInstance().addService(service); |
| 138 | 0 | setStatus(SUCCESS_STATUS); |
| 139 | 0 | } else { |
| 140 | 0 | service.setName(name); |
| 141 | 0 | service.setDescription(description); |
| 142 | 0 | service.setRateType(rateType); |
| 143 | 0 | service.setBaseRate(baseRate); |
| 144 | 0 | service.setMinDurationInMinute(minDurationInMinute); |
| 145 | 0 | service.setCareAboutMinDuration(careAboutMinDuration); |
| 146 | 0 | service.setMaxDurationInMinute(maxDurationInMinute); |
| 147 | 0 | service.setCareAboutMaxDuration(careAboutMaxDuration); |
| 148 | 0 | setStatus(SUCCESS_STATUS); |
| 149 | 0 | } |
| 150 | } | |
| 151 | 0 | } |
| 152 | 0 | |
| 153 | /** | |
| 154 | * @return Returns the servicePanel. | |
| 155 | */ | |
| 156 | private ServicePanel getServicePanel() { | |
| 157 | 0 | return servicePanel; |
| 158 | } | |
| 159 | ||
| 160 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |