1
|
/**
|
2
|
* Copyright (C) 2015 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.navigation.navigator.operation;
|
10
|
|
11
|
import java.util.HashSet;
|
12
|
import java.util.Set;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.eclipse.core.runtime.IAdaptable;
|
16
|
import org.eclipse.core.runtime.IProgressMonitor;
|
17
|
|
18
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
19
|
import eu.etaxonomy.cdm.api.application.CdmChangeEvent;
|
20
|
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
|
21
|
import eu.etaxonomy.cdm.api.service.DeleteResult;
|
22
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
23
|
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
|
24
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
25
|
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
|
26
|
import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
|
27
|
|
28
|
/**
|
29
|
* @author cmathew
|
30
|
* @date 22 Jun 2015
|
31
|
*
|
32
|
*/
|
33
|
public class RemotingDeleteTaxonNodeOperation extends RemotingCdmUpdateOperation {
|
34
|
|
35
|
private final static String LABEL = Messages.RemotingDeleteTaxonNodeOperation_DELETE_OP;
|
36
|
|
37
|
private final Set<TaxonNodeDto> treeNodes;
|
38
|
private final Set<TaxonNodeDto> classifications;
|
39
|
private final TaxonDeletionConfigurator config;
|
40
|
|
41
|
/**
|
42
|
* @param label
|
43
|
* @param action
|
44
|
* @param source
|
45
|
* @param async
|
46
|
*/
|
47
|
public RemotingDeleteTaxonNodeOperation(Object source,
|
48
|
boolean async,
|
49
|
Set<TaxonNodeDto> treeNodes,
|
50
|
Set<TaxonNodeDto> classifications,
|
51
|
TaxonDeletionConfigurator config) {
|
52
|
super(LABEL, Action.Delete, source, async);
|
53
|
this.treeNodes = treeNodes;
|
54
|
this.classifications = classifications;
|
55
|
this.config = config;
|
56
|
}
|
57
|
|
58
|
/* (non-Javadoc)
|
59
|
* @see eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation#doUpdateExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
60
|
*/
|
61
|
@Override
|
62
|
protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
|
63
|
DeleteResult result = new DeleteResult();
|
64
|
|
65
|
if(treeNodes.size() == 1) {
|
66
|
// when single node this is either a taxon or a classification
|
67
|
TaxonNodeDto node = treeNodes.iterator().next();
|
68
|
if(node.getTaxonUuid() == null) {
|
69
|
result = CdmApplicationState.getCurrentAppConfig().getClassificationService().delete(node.getClassificationUUID());
|
70
|
}else{
|
71
|
result = CdmApplicationState.getCurrentAppConfig().getTaxonNodeService().deleteTaxonNode((node).getUuid(), config);
|
72
|
}
|
73
|
// } else if(node.getType().equals( Classification.class)) {
|
74
|
// entityType = Classification.class;
|
75
|
// return CdmApplicationState.getCurrentAppConfig().getClassificationService().delete(node.getUuid());
|
76
|
// }
|
77
|
} else {
|
78
|
// when list we assume all are taxon nodes
|
79
|
Set<UUID> treeNodeUuids = new HashSet<UUID>();
|
80
|
Set<UUID> classificationsUuids = new HashSet<UUID>();
|
81
|
if (treeNodes != null){
|
82
|
for(TaxonNodeDto treeNode : treeNodes) {
|
83
|
treeNodeUuids.add(treeNode.getUuid());
|
84
|
}
|
85
|
}
|
86
|
if (classifications != null){
|
87
|
for(TaxonNodeDto treeNode : classifications) {
|
88
|
classificationsUuids.add(treeNode.getClassificationUUID());
|
89
|
}
|
90
|
}
|
91
|
|
92
|
if (!treeNodeUuids.isEmpty()){
|
93
|
result.includeResult(CdmApplicationState.getCurrentAppConfig().getTaxonNodeService().deleteTaxonNodes(treeNodeUuids, new TaxonDeletionConfigurator()));
|
94
|
}
|
95
|
if (!classificationsUuids.isEmpty()){
|
96
|
for (UUID classificationUuid: classificationsUuids){
|
97
|
result.includeResult(CdmApplicationState.getCurrentAppConfig().getClassificationService().delete(classificationUuid, config));
|
98
|
}
|
99
|
}
|
100
|
|
101
|
|
102
|
|
103
|
}
|
104
|
CdmApplicationState.getCurrentDataChangeService()
|
105
|
.fireChangeEvent(new CdmChangeEvent(Action.Delete, result.getUpdatedObjects(), this), true);
|
106
|
return result;
|
107
|
}
|
108
|
|
109
|
}
|