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 public class DeleteExpiredBackupCommand extends Command {
38
39 private static final transient Logger logger = Logger
40 .getLogger(BuildBackupArtifactCommand.class.getName());
41
42 public DeleteExpiredBackupCommand() {
43 }
44
45
46
47
48
49
50 @Override
51 protected void prologo() {
52 InternetCafe.setStatusBarMessage("Deleting exired backups...");
53 setStatus(EXECUTE_STATUS);
54 }
55
56
57
58
59
60
61 @Override
62 protected void execution() throws Exception {
63 switch (getStatus()) {
64 case ABORT_STATUS:
65 break;
66 case VETOED_STATUS:
67 break;
68 case EXECUTE_STATUS:
69 Date now = new Date();
70 boolean result = false;
71 for (int i = 0; i < ConfigurationManager.getInstance()
72 .getRepository().getBackupDescriptor().length; i++) {
73 if (now.getTime() > ConfigurationManager.getInstance()
74 .getRepository().getBackupDescriptor()[i].getBackup()
75 .getExpirationDate().getTime()) {
76 BackupDescriptor backupDescriptor = ConfigurationManager
77 .getInstance().getRepository()
78 .getBackupDescriptor()[i];
79 ConfigurationManager.getInstance().getRepository()
80 .removeBackupDescriptor(backupDescriptor);
81 result = FileUtil.deleteDirectory(backupDescriptor
82 .getArtifactDirectory());
83 }
84
85 }
86
87 if (result)
88 setStatus(SUCCESS_STATUS);
89 else
90 setStatus(ERROR_STATUS);
91 break;
92 }
93 }
94
95
96
97
98
99
100 @Override
101 protected void epilogue() {
102 switch (getStatus()) {
103 case SUCCESS_STATUS:
104 InternetCafe
105 .setStatusBarMessage("Expired backups successfully deleted...");
106 break;
107 case ABORT_STATUS:
108 InternetCafe.setStatusBarMessage("Command aborted by user...");
109 break;
110 case ERROR_STATUS:
111 InternetCafe.setStatusBarMessage("Command error...");
112 break;
113 case VETOED_STATUS:
114 InternetCafe.setStatusBarMessage("Command vetoed...");
115 break;
116 }
117 }
118
119 }