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 | ||
21 | package base.jdbs.ui.command; | |
22 | ||
23 | import java.util.Date; | |
24 | ||
25 | import org.apache.log4j.Logger; | |
26 | ||
27 | import ui.command.Command; | |
28 | import base.InternetCafe; | |
29 | import base.jdbs.BackupDescriptor; | |
30 | import base.jdbs.ConfigurationManager; | |
31 | import base.util.FileUtil; | |
32 | ||
33 | /** | |
34 | * @author skunk | |
35 | * | |
36 | */ | |
37 | 0 | public class DeleteExpiredBackupCommand extends Command { |
38 | ||
39 | 0 | private static final transient Logger logger = Logger |
40 | .getLogger(BuildBackupArtifactCommand.class.getName()); | |
41 | 0 | |
42 | 0 | public DeleteExpiredBackupCommand() { |
43 | 0 | } |
44 | ||
45 | /* | |
46 | * (non-Javadoc) | |
47 | * | |
48 | * @see ui.command.Command#prologo() | |
49 | */ | |
50 | @Override | |
51 | 0 | protected void prologo() { |
52 | 0 | InternetCafe.setStatusBarMessage("Deleting exired backups..."); |
53 | 0 | setStatus(EXECUTE_STATUS); |
54 | 0 | } |
55 | ||
56 | /* | |
57 | * (non-Javadoc) | |
58 | * | |
59 | * @see ui.command.Command#execution() | |
60 | */ | |
61 | @Override | |
62 | 0 | protected void execution() throws Exception { |
63 | 0 | switch (getStatus()) { |
64 | 0 | case ABORT_STATUS: |
65 | 0 | break; |
66 | 0 | case VETOED_STATUS: |
67 | 0 | break; |
68 | 0 | case EXECUTE_STATUS: |
69 | 0 | Date now = new Date(); |
70 | 0 | boolean result = false; |
71 | 0 | for (int i = 0; i < ConfigurationManager.getInstance() |
72 | 0 | .getRepository().getBackupDescriptor().length; i++) { |
73 | 0 | if (now.getTime() > ConfigurationManager.getInstance() |
74 | 0 | .getRepository().getBackupDescriptor()[i].getBackup() |
75 | .getExpirationDate().getTime()) { | |
76 | 0 | BackupDescriptor backupDescriptor = ConfigurationManager |
77 | .getInstance().getRepository() | |
78 | .getBackupDescriptor()[i]; | |
79 | 0 | ConfigurationManager.getInstance().getRepository() |
80 | 0 | .removeBackupDescriptor(backupDescriptor); |
81 | 0 | result = FileUtil.deleteDirectory(backupDescriptor |
82 | .getArtifactDirectory()); | |
83 | 0 | } |
84 | ||
85 | } | |
86 | ||
87 | 0 | if (result) |
88 | 0 | setStatus(SUCCESS_STATUS); |
89 | else | |
90 | 0 | setStatus(ERROR_STATUS); |
91 | break; | |
92 | 0 | } |
93 | 0 | } |
94 | 0 | |
95 | 0 | /* |
96 | * (non-Javadoc) | |
97 | 0 | * |
98 | 0 | * @see ui.command.Command#epilogue() |
99 | */ | |
100 | 0 | @Override |
101 | 0 | protected void epilogue() { |
102 | 0 | switch (getStatus()) { |
103 | 0 | case SUCCESS_STATUS: |
104 | 0 | InternetCafe |
105 | .setStatusBarMessage("Expired backups successfully deleted..."); | |
106 | 0 | break; |
107 | case ABORT_STATUS: | |
108 | 0 | InternetCafe.setStatusBarMessage("Command aborted by user..."); |
109 | 0 | break; |
110 | case ERROR_STATUS: | |
111 | 0 | InternetCafe.setStatusBarMessage("Command error..."); |
112 | 0 | break; |
113 | case VETOED_STATUS: | |
114 | 0 | InternetCafe.setStatusBarMessage("Command vetoed..."); |
115 | break; | |
116 | } | |
117 | 0 | } |
118 | ||
119 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |