ref #6190 removing svn property place holder in first line of code - java files
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / operation / RemotingDeleteTaxonNodeOperation.java
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.Action;
20 import eu.etaxonomy.cdm.api.service.UpdateResult;
21 import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
22 import eu.etaxonomy.cdm.model.taxon.Classification;
23 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
24 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
25 import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
26
27 /**
28 * @author cmathew
29 * @date 22 Jun 2015
30 *
31 */
32 public class RemotingDeleteTaxonNodeOperation extends RemotingCdmUpdateOperation {
33
34 private final static String LABEL = "Delete Taxon Node operation";
35
36 private final Set<ITaxonTreeNode> treeNodes;
37 private final TaxonDeletionConfigurator config;
38
39 /**
40 * @param label
41 * @param action
42 * @param source
43 * @param async
44 */
45 public RemotingDeleteTaxonNodeOperation(Object source,
46 boolean async,
47 Set<ITaxonTreeNode> treeNodes,
48 TaxonDeletionConfigurator config) {
49 super(LABEL, Action.Delete, source, async);
50 this.treeNodes = treeNodes;
51 this.config = config;
52 }
53
54 /* (non-Javadoc)
55 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation#doUpdateExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
56 */
57 @Override
58 protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
59
60
61 if(treeNodes.size() == 1) {
62 // when single node this is either a taxon or a classification
63 ITaxonTreeNode node = treeNodes.iterator().next();
64 if(node instanceof TaxonNode) {
65 return CdmApplicationState.getCurrentAppConfig().getTaxonNodeService().deleteTaxonNode(((TaxonNode)node).getUuid(), config);
66 } else if(node instanceof Classification) {
67 entityType = Classification.class;
68 return CdmApplicationState.getCurrentAppConfig().getClassificationService().delete(((Classification)node).getUuid());
69 }
70 } else {
71 // when list we assume all are taxon nodes
72 Set<UUID> treeNodeUuids = new HashSet<UUID>();
73 ITaxonTreeNode entity = null;
74 for(ITaxonTreeNode treeNode : treeNodes) {
75 if(entity == null) {
76 entity = treeNode;
77 }
78 treeNodeUuids.add(treeNode.getUuid());
79 }
80
81 return CdmApplicationState.getCurrentAppConfig().getTaxonNodeService().deleteTaxonNodes(treeNodeUuids, new TaxonDeletionConfigurator());
82 }
83 return null;
84 }
85
86 }