Coverage details for ui.command.IO.SaveServiceCommand

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 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) {
590        super();
600        // TODO Auto-generated constructor stub
610        this.servicePanel = servicePanel;
620        this.service = service;
630        this.createService = createService;
640    }
650 
66     /*
67      * (non-Javadoc)
68      *
69      * @see ui.command.Command#prologo()
70      */
71     @Override
72     protected void prologo() {
730        name = getServicePanel().getServiceName();
740        description = getServicePanel().getServiceDescription();
750        rateType = getServicePanel().getServiceRateType();
760        baseRate = getServicePanel().getServiceBaseRate();
770        minDurationInMinute = getServicePanel().getServiceMinDurationInMinute();
780        careAboutMinDuration = getServicePanel()
790                .getServiceCareAboutMinDuration();
800        maxDurationInMinute = getServicePanel().getServiceMaxDurationInMinute();
810        careAboutMaxDuration = getServicePanel()
820                .getServiceCareAboutMaxDuration();
830        if (isValidServiceData(name, description, rateType, baseRate,
840                minDurationInMinute, careAboutMinDuration, maxDurationInMinute,
850                careAboutMaxDuration))
860            setStatus(EXECUTE_STATUS);
870        else
880            setStatus(ERROR_STATUS);
890    }
900 
91     private boolean isValidServiceData(String name, String description,
92             String rateType, double baseRate, int minDurationInMinute,
93             boolean careAboutMinDuration, int maxDurationInMinute,
94             boolean careAboutMaxDuration) {
950        if (name == null || name.length() == 0) {
960            this.getServicePanel().setNameError(true);
970            return false;
980        } else
990            this.getServicePanel().setNameError(false);
1000 
1010        if (baseRate < 0) {
1020            this.getServicePanel().setBaseRateError(true);
1030            return false;
1040        } else
1050            this.getServicePanel().setBaseRateError(false);
1060 
1070        if (!Control
1080                .isValidServiceMinMaxDuration(minDurationInMinute,
1090                        careAboutMinDuration, maxDurationInMinute,
1100                        careAboutMaxDuration)) {
1110            this.getServicePanel().setMinMaxDurationError(true);
1120            return false;
1130        } else
1140            this.getServicePanel().setMinMaxDurationError(false);
1150 
1160        return true;
1170    }
118  
119     /*
120      * (non-Javadoc)
121      *
122      * @see ui.command.Command#execution()
123      */
124     @Override
125     protected void execution() throws Exception {
1260        switch (getStatus()) {
1270        case ERROR_STATUS:
1280            break;
1290        case VETOED_STATUS:
1300            break;
1310        case EXECUTE_STATUS:
1320            if (createService) {
1330                service = ServiceFactory.newService(name, description,
1340                        rateType, baseRate, minDurationInMinute,
1350                        careAboutMinDuration, maxDurationInMinute,
1360                        careAboutMaxDuration);
1370                InternetCafeManager.getInstance().addService(service);
1380                setStatus(SUCCESS_STATUS);
1390            } else {
1400                service.setName(name);
1410                service.setDescription(description);
1420                service.setRateType(rateType);
1430                service.setBaseRate(baseRate);
1440                service.setMinDurationInMinute(minDurationInMinute);
1450                service.setCareAboutMinDuration(careAboutMinDuration);
1460                service.setMaxDurationInMinute(maxDurationInMinute);
1470                service.setCareAboutMaxDuration(careAboutMaxDuration);
1480                setStatus(SUCCESS_STATUS);
1490            }
150         }
1510    }
1520    
153     /**
154      * @return Returns the servicePanel.
155      */
156     private ServicePanel getServicePanel() {
1570        return servicePanel;
158     }
159  
160 }

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.