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.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 | */ | |
56 | 0 | public SaveUserDocumentCommand(DocumentPanel documentPanel, |
57 | 0 | Document document, boolean createDocument) { |
58 | 0 | this.documentPanel = documentPanel; |
59 | 0 | this.document = document; |
60 | 0 | this.createDocument = createDocument; |
61 | 0 | } |
62 | 0 | |
63 | 0 | /* |
64 | 0 | * (non-Javadoc) |
65 | 0 | * |
66 | 0 | * @see ui.command.Command#prologo() |
67 | 0 | */ |
68 | @Override | |
69 | protected void prologo() { | |
70 | 0 | type = getDocumentPanel().getDocumentType(); |
71 | 0 | number = getDocumentPanel().getDocumentNumber(); |
72 | 0 | releaseAuthority = getDocumentPanel().getDocumentReleaseAuthority(); |
73 | 0 | description = getDocumentPanel().getDocumentDescription(); |
74 | 0 | releaseDate = getDocumentPanel().getDocumentRelease(); |
75 | 0 | expirationDate = getDocumentPanel().getDocumentExpiration(); |
76 | 0 | imagePath = getDocumentPanel().getDocumentImagePath(); |
77 | 0 | if (isValidUserDocumentData(type, number, releaseAuthority, |
78 | 0 | description, releaseDate, expirationDate, imagePath)) |
79 | 0 | setStatus(EXECUTE_STATUS); |
80 | 0 | else |
81 | 0 | setStatus(ERROR_STATUS); |
82 | 0 | } |
83 | 0 | |
84 | 0 | private boolean isValidUserDocumentData(String type, String number, |
85 | 0 | String releaseAuthority, String description, Date releaseDate, |
86 | Date expirationDate, String imagePath) { | |
87 | 0 | |
88 | 0 | if (!Control.isValidDocumentNumber(type, number)) { |
89 | 0 | getDocumentPanel().setDocumentNumberError(true); |
90 | 0 | return false; |
91 | 0 | } else |
92 | 0 | getDocumentPanel().setDocumentNumberError(false); |
93 | 0 | |
94 | 0 | if (!Control.isValidDocumentDate(releaseDate, expirationDate)) { |
95 | 0 | getDocumentPanel().setDocumentDateError(true); |
96 | 0 | return false; |
97 | 0 | } else |
98 | 0 | getDocumentPanel().setDocumentDateError(false); |
99 | 0 | |
100 | 0 | return true; |
101 | 0 | } |
102 | 0 | |
103 | /* | |
104 | 0 | * (non-Javadoc) |
105 | * | |
106 | 0 | * @see ui.command.Command#execution() |
107 | */ | |
108 | @Override | |
109 | protected void execution() throws Exception { | |
110 | 0 | switch (getStatus()) { |
111 | 0 | case ERROR_STATUS: |
112 | 0 | break; |
113 | 0 | case VETOED_STATUS: |
114 | 0 | break; |
115 | 0 | case EXECUTE_STATUS: |
116 | 0 | if (createDocument) { |
117 | 0 | document = new Document(type, number, releaseAuthority, |
118 | 0 | description, releaseDate, expirationDate, imagePath); |
119 | 0 | setStatus(SUCCESS_STATUS); |
120 | 0 | } else { |
121 | 0 | document.setType(type); |
122 | 0 | document.setNumber(number); |
123 | 0 | document.setAuthority(releaseAuthority); |
124 | 0 | document.setDescription(description); |
125 | 0 | document.setRelease(releaseDate); |
126 | 0 | document.setExpiration(expirationDate); |
127 | 0 | document.setImagePath(imagePath); |
128 | 0 | setStatus(SUCCESS_STATUS); |
129 | 0 | } |
130 | 0 | break; |
131 | 0 | } |
132 | 0 | } |
133 | 0 | |
134 | 0 | /** |
135 | * @return Returns the documentPanel. | |
136 | */ | |
137 | private DocumentPanel getDocumentPanel() { | |
138 | 0 | return documentPanel; |
139 | } | |
140 | ||
141 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |