Coverage details for ui.command.IO.SaveUserDocumentCommand

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.DocumentPanel;
26 import base.Control;
27 import base.user.Document;
28  
29 public class SaveUserDocumentCommand extends Command {
30  
31     private DocumentPanel documentPanel;
32  
33     private Document document;
34  
35     private boolean createDocument;
36  
37     private String type;
38  
39     private String number;
40  
41     private String releaseAuthority;
42  
43     private String description;
44  
45     private Date releaseDate;
46  
47     private Date expirationDate;
48  
49     private String imagePath;
50  
51     /**
52      * @param documentPanel
53      * @param document
54      * @param createDocument
55      */
560    public SaveUserDocumentCommand(DocumentPanel documentPanel,
570            Document document, boolean createDocument) {
580        this.documentPanel = documentPanel;
590        this.document = document;
600        this.createDocument = createDocument;
610    }
620 
630    /*
640     * (non-Javadoc)
650     *
660     * @see ui.command.Command#prologo()
670     */
68     @Override
69     protected void prologo() {
700        type = getDocumentPanel().getDocumentType();
710        number = getDocumentPanel().getDocumentNumber();
720        releaseAuthority = getDocumentPanel().getDocumentReleaseAuthority();
730        description = getDocumentPanel().getDocumentDescription();
740        releaseDate = getDocumentPanel().getDocumentRelease();
750        expirationDate = getDocumentPanel().getDocumentExpiration();
760        imagePath = getDocumentPanel().getDocumentImagePath();
770        if (isValidUserDocumentData(type, number, releaseAuthority,
780                description, releaseDate, expirationDate, imagePath))
790            setStatus(EXECUTE_STATUS);
800        else
810            setStatus(ERROR_STATUS);
820    }
830 
840    private boolean isValidUserDocumentData(String type, String number,
850            String releaseAuthority, String description, Date releaseDate,
86             Date expirationDate, String imagePath) {
870 
880        if (!Control.isValidDocumentNumber(type, number)) {
890            getDocumentPanel().setDocumentNumberError(true);
900            return false;
910        } else
920            getDocumentPanel().setDocumentNumberError(false);
930 
940        if (!Control.isValidDocumentDate(releaseDate, expirationDate)) {
950            getDocumentPanel().setDocumentDateError(true);
960            return false;
970        } else
980            getDocumentPanel().setDocumentDateError(false);
990 
1000        return true;
1010    }
1020 
103     /*
1040     * (non-Javadoc)
105      *
1060     * @see ui.command.Command#execution()
107      */
108     @Override
109     protected void execution() throws Exception {
1100        switch (getStatus()) {
1110        case ERROR_STATUS:
1120            break;
1130        case VETOED_STATUS:
1140            break;
1150        case EXECUTE_STATUS:
1160            if (createDocument) {
1170                document = new Document(type, number, releaseAuthority,
1180                        description, releaseDate, expirationDate, imagePath);
1190                setStatus(SUCCESS_STATUS);
1200            } else {
1210                document.setType(type);
1220                document.setNumber(number);
1230                document.setAuthority(releaseAuthority);
1240                document.setDescription(description);
1250                document.setRelease(releaseDate);
1260                document.setExpiration(expirationDate);
1270                document.setImagePath(imagePath);
1280                setStatus(SUCCESS_STATUS);
1290            }
1300            break;
1310        }
1320    }
1330    
1340    /**
135      * @return Returns the documentPanel.
136      */
137     private DocumentPanel getDocumentPanel() {
1380        return documentPanel;
139     }
140  
141 }

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.