Coverage details for base.jdbs.ui.command.RestoreBackupArtifactCommand

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  
21 package base.jdbs.ui.command;
22  
23 import java.io.File;
24 import java.security.KeyStore;
25  
26 import org.apache.log4j.Logger;
27  
28 import ui.command.Command;
29 import base.InternetCafe;
30 import base.jdbs.BackupDescriptor;
31 import base.jdbs.ConfigurationManager;
32 import base.jdbs.cryptography.asymmetric.AsymmetricKeyRing;
33 import base.jdbs.cryptography.asymmetric.KeyPair;
34 import base.jdbs.cryptography.symmetric.SymmetricKey;
35  
36 /**
37  * @author skunk
38  *
39  */
400public class RestoreBackupArtifactCommand extends Command {
41     
420    private static final transient Logger logger = Logger.getLogger(RestoreBackupArtifactCommand.class.getName());
43  
44     private final String guId;
450    private File outputDirectory = null;
46     
470    public RestoreBackupArtifactCommand(String guId){
480        this.guId = guId;
490    }
50     /*
51      * (non-Javadoc)
52      *
53      * @see ui.command.Command#prologo()
54      */
55     @Override
56     protected void prologo() {
570        InternetCafe.setStatusBarMessage("Restoring a backup from the JDBS repository...");
580        javax.swing.JFileChooser outputDirectoryChooser = new javax.swing.JFileChooser();
590        outputDirectoryChooser.setDialogTitle("Select the output directory where the backup must be restored...");
600        outputDirectoryChooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
610        outputDirectoryChooser.setApproveButtonText("Select");
620        outputDirectoryChooser.setMultiSelectionEnabled(true);
63  
640        if (outputDirectoryChooser.showOpenDialog(null) == javax.swing.JFileChooser.APPROVE_OPTION){
650            this.outputDirectory = outputDirectoryChooser.getSelectedFile();
660            if(!outputDirectory.isDirectory())
67             {
680                logger.warn("Chosen output directory is not a directory!");
690                setStatus(ERROR_STATUS);
70             }
710            logger.debug("Output Directory: "+outputDirectory);
72  
730        }else setStatus(ABORT_STATUS);
74  
750        setStatus(EXECUTE_STATUS);
760    }
77  
78     /*
79      * (non-Javadoc)
80      *
81      * @see ui.command.Command#execution()
82      */
83     @Override
84     protected void execution() throws Exception {
850        switch (getStatus()) {
86         case ABORT_STATUS:
870            break;
88         case VETOED_STATUS:
890            break;
90         case EXECUTE_STATUS:
910            AsymmetricKeyRing asymmetricKeyRing = new AsymmetricKeyRing(ConfigurationManager.getInstance().getUser());
920            KeyStore keyStore = asymmetricKeyRing.retrieve(ConfigurationManager.getInstance().getKeyRingLocation(),"password");
93  
940            KeyPair keyPair = asymmetricKeyRing.getAllKeyPair()[0];
950            SymmetricKey symmetricKey = new SymmetricKey("password");
960            BackupDescriptor backupDescriptor = ConfigurationManager.getInstance().getRepository().getBackupDescriptorByGuId(guId);
970            if(backupDescriptor != null){
980                base.jdbs.BackupArtifactDisassembler.disassemblyBackupArtifact(symmetricKey, keyPair, backupDescriptor, this.outputDirectory);
990                setStatus(SUCCESS_STATUS);
1000            }
1010            else setStatus(ERROR_STATUS);
102             break;
103         }
1040    }
105  
106     /*
107      * (non-Javadoc)
108      *
109      * @see ui.command.Command#epilogue()
110      */
111     @Override
112     protected void epilogue() {
1130        switch (getStatus()) {
114         case SUCCESS_STATUS:
1150            InternetCafe.setStatusBarMessage("JDBS Successfully exited...");
1160            break;
117         case ABORT_STATUS:
1180            InternetCafe.setStatusBarMessage("Command aborted by user...");
1190            break;
120         case ERROR_STATUS:
1210            InternetCafe.setStatusBarMessage("Command error...");
1220            break;
123         case VETOED_STATUS:
1240            InternetCafe.setStatusBarMessage("Command vetoed...");
125             break;
126         }
1270    }
128  
129 }
130  

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.