/*
 * Autopsy Forensic Browser
 *
 * Copyright 2019 Basis Technology Corp.
 * Contact: carrier <at> sleuthkit <dot> org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.sleuthkit.autopsy.actions;

import java.awt.event.ActionEvent;
import java.util.logging.Level;
import javax.swing.AbstractAction;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService;
import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchServiceException;
import org.sleuthkit.datamodel.TskCoreException;

/**
 * Instances of this Action allow users to delete the specified data source.
 */
public final class DeleteDataSourceAction extends AbstractAction {

    private static final Logger logger = Logger.getLogger(DeleteDataSourceAction.class.getName());
    private final Long dataSourceId;

    @NbBundle.Messages({"DeleteDataSourceAction.name.text=Delete Data Source"})
    public DeleteDataSourceAction(Long dataSourceId) {
        super(Bundle.DeleteDataSourceAction_name_text());
        this.dataSourceId = dataSourceId;
    }

    @Override
    public void actionPerformed(ActionEvent event) {
        try {
            Case.getCurrentCaseThrows().getSleuthkitCase().deleteDataSource(dataSourceId);
            deleteDataSource(dataSourceId);
        } catch (NoCurrentCaseException | TskCoreException | KeywordSearchServiceException e) {
            logger.log(Level.WARNING, "Error Deleting Data source " + dataSourceId, e);
        }
    }

    private static void deleteDataSource(Long dataSourceId) throws KeywordSearchServiceException {
        try {
            KeywordSearchService kwsService = Lookup.getDefault().lookup(KeywordSearchService.class);
            kwsService.deleteDataSource(dataSourceId);
        } catch (KeywordSearchServiceException e) {
            logger.log(Level.WARNING, "KWS Error", e);
        }

    }
}

@@ -1301,22 +1301,8 @@
 ete 
-the specified 
 data
@@ -1308,16 +1308,17 @@
 a source
+s
 .%0A */%0Apu
@@ -1383,16 +1383,69 @@
 tion %7B%0A%0A
+    private static final long serialVersionUID = 1L;%0A
     priv
@@ -1551,33 +1551,197 @@
 ate 
-final Long dataSourceId;%0A
+long dataSourceID;%0A%0A    /**%0A     * Constructs an Action that allows a user to delete a data source.%0A     *%0A     * @param dataSourceID The object ID of the data source to be deleted.%0A     */
 %0A   
@@ -1761,16 +1761,25 @@
 ssages(%7B
+%0A        
 %22DeleteD
@@ -1823,16 +1823,21 @@
  Source%22
+%0A    
 %7D)%0A    p
@@ -1881,17 +1881,17 @@
 aSourceI
-d
+D
 ) %7B%0A    
@@ -1968,17 +1968,17 @@
 aSourceI
-d
+D
  = dataS
@@ -1983,17 +1983,17 @@
 aSourceI
-d
+D
 ;%0A    %7D%0A
@@ -2153,33 +2153,135 @@
 urce(dataSourceI
-d
+D);%0A            KeywordSearchService kwsService = Lookup.getDefault().lookup(KeywordSearchService.class
 );%0A            d
@@ -2279,16 +2279,27 @@
         
+kwsService.
 deleteDa
@@ -2310,33 +2310,33 @@
 urce(dataSourceI
-d
+D
 );%0A        %7D cat
@@ -2456,16 +2456,30 @@
 ARNING, 
+String.format(
 %22Error D
@@ -2486,17 +2486,17 @@
 eleting 
-D
+d
 ata sour
@@ -2502,11 +2502,21 @@
 rce 
-%22 +
+(obj_id=%25d)%22,
  dat
@@ -2523,17 +2523,18 @@
 aSourceI
-d
+D)
 , e);%0A  
@@ -2556,216 +2556,122 @@
     
-private static void deleteDataSource(Long dataSourceId) throws KeywordSearchServiceException %7B%0A        try %7B%0A            KeywordSearchService kwsService = Lookup.getDefault().lookup(KeywordSearchService.class
+@Override%0A    public Object clone() throws CloneNotSupportedException %7B%0A        Object clonedObject = super.clone(
 );%0A 
@@ -2677,37 +2677,59 @@
         
- 
-   kwsService.del
+((DeleteDataSourceAction) clonedObject).s
 et
-e
 DataSour
@@ -2722,33 +2722,40 @@
 t).setDataSource
-(
+ID(this.
 dataSourceId);%0A 
@@ -2749,17 +2749,17 @@
 aSourceI
-d
+D
 );%0A     
@@ -2765,122 +2765,137 @@
     
-%7D catch (KeywordSearchServiceException e) %7B%0A            logger.log(Level.WARNING, %22KWS Error%22, e);%0A        %7D%0A%0A    %7D
+return clonedObject;%0A    %7D%0A%0A    private void setDataSourceID(long dataSourceID) %7B%0A        this.dataSourceID = dataSourceID;%0A    %7D%0A
 %0A%7D%0A

Address IDE hints for DeleteDataSourceAction.java