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.operation;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.HashSet;
|
13
|
import java.util.List;
|
14
|
import java.util.Set;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.apache.logging.log4j.LogManager;
|
18
|
import org.apache.logging.log4j.Logger;
|
19
|
import org.eclipse.core.commands.ExecutionException;
|
20
|
import org.junit.Assert;
|
21
|
import org.junit.Ignore;
|
22
|
import org.junit.Test;
|
23
|
import org.unitils.dbunit.annotation.DataSet;
|
24
|
|
25
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
26
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
27
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
28
|
import eu.etaxonomy.cdm.api.service.config.NodeDeletionConfigurator.ChildHandling;
|
29
|
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
|
30
|
import eu.etaxonomy.cdm.api.service.config.TaxonNodeDeletionConfigurator;
|
31
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
32
|
import eu.etaxonomy.cdm.model.common.Language;
|
33
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
34
|
import eu.etaxonomy.cdm.model.metadata.SecReferenceHandlingEnum;
|
35
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
36
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
37
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
38
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
39
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
40
|
import eu.etaxonomy.taxeditor.navigation.navigator.e4.TreeNodeDropAdapterE4.MovingType;
|
41
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.ChangeAcceptedTaxonToSynonymOperation;
|
42
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.DeleteTaxonNodeOperation;
|
43
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveFactualDataOperation;
|
44
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation;
|
45
|
|
46
|
/**
|
47
|
* @author cmathew
|
48
|
* @date 9 Mar 2015
|
49
|
*/
|
50
|
@DataSet
|
51
|
public class TaxonNavigatorTest extends BaseOperationTest {
|
52
|
|
53
|
@SuppressWarnings("unused")
|
54
|
private static final Logger logger = LogManager.getLogger();
|
55
|
|
56
|
private ITaxonNodeService taxonNodeService = getRemoteApplicationController().getTaxonNodeService();
|
57
|
private ITaxonService taxonService = getRemoteApplicationController().getTaxonService();
|
58
|
private IClassificationService classificationService = getRemoteApplicationController().getClassificationService();
|
59
|
|
60
|
private Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
|
61
|
|
62
|
@Test
|
63
|
public void testChangeAcceptedTaxonToSynonym() throws ExecutionException {
|
64
|
|
65
|
UUID oldTaxonNodeNodeUuid = UUID.fromString("b85b5b78-6760-409f-ac91-bb89e95ff2a1");
|
66
|
UUID newAcceptedTaxonNodeUuid = UUID.fromString("6ad8e9e2-f5f6-41ad-aa30-f62a903650db");
|
67
|
|
68
|
TaxonNode oldTaxonNode = taxonNodeService.load(oldTaxonNodeNodeUuid);
|
69
|
TaxonName name = oldTaxonNode.getTaxon().getName();
|
70
|
|
71
|
|
72
|
TaxonNode newAcceptedTaxonNode = taxonNodeService.load(newAcceptedTaxonNodeUuid);
|
73
|
int countTargetSynonyms = newAcceptedTaxonNode.getTaxon().getSynonyms().size();
|
74
|
sessionOwner.addExpectedUpdatedObject(oldTaxonNode.getParent());
|
75
|
sessionOwner.addExpectedUpdatedObject(newAcceptedTaxonNode);
|
76
|
|
77
|
operation = new ChangeAcceptedTaxonToSynonymOperation(sessionOwner,
|
78
|
false,
|
79
|
oldTaxonNode.getUuid(),
|
80
|
newAcceptedTaxonNode.getUuid(), null, SecReferenceHandlingEnum.KeepOrWarn, true);
|
81
|
operation.execute(monitor, info);
|
82
|
newAcceptedTaxonNode = taxonNodeService.load(newAcceptedTaxonNodeUuid);
|
83
|
oldTaxonNode = taxonNodeService.load(oldTaxonNodeNodeUuid);
|
84
|
Assert.assertNull(oldTaxonNode);
|
85
|
Assert.assertEquals(countTargetSynonyms + 1,newAcceptedTaxonNode.getTaxon().getSynonyms().size());
|
86
|
Assert.assertEquals(name, newAcceptedTaxonNode.getTaxon().getSynonyms().iterator().next().getName());
|
87
|
}
|
88
|
|
89
|
@Test
|
90
|
@Ignore
|
91
|
public void testMoveTaxon() throws ExecutionException {
|
92
|
|
93
|
UUID taxonNodeToMoveUuid = UUID.fromString("b8439f51-6b96-445a-b401-7a836ba1cf58");
|
94
|
UUID newParentTreeNodeUuid = UUID.fromString("2f05d429-632d-4230-b9cb-70299360b470");
|
95
|
MovingType moveToParentNode = MovingType.CHILD;
|
96
|
|
97
|
TaxonNode taxonNodeToMove = taxonNodeService.load(taxonNodeToMoveUuid);
|
98
|
TaxonNode oldParent = taxonNodeToMove.getParent();
|
99
|
Set<UUID>uuids = new HashSet<>();
|
100
|
uuids.add(taxonNodeToMoveUuid);
|
101
|
// sessionOwner.addExpectedUpdatedObject(oldParent);
|
102
|
int childCount = oldParent.getCountChildren();
|
103
|
TaxonNode newParentTreeNode = taxonNodeService.load(newParentTreeNodeUuid);
|
104
|
// sessionOwner.addExpectedUpdatedObject(newParentTreeNode);
|
105
|
operation = new MoveTaxonOperation(sessionOwner,
|
106
|
false,
|
107
|
uuids,
|
108
|
newParentTreeNode.getUuid(),
|
109
|
moveToParentNode, SecReferenceHandlingEnum.KeepOrWarn, null);
|
110
|
operation.execute(monitor, info);
|
111
|
//TODO: fix this, because move taxon is now a longrunning task
|
112
|
// Assert.assertEquals(childCount-1, oldParent.getCountChildren());
|
113
|
// Assert.assertTrue(!oldParent.getChildNodes().contains(taxonNodeToMove));
|
114
|
// Assert.assertTrue(newParentTreeNode.getChildNodes().contains(taxonNodeToMove));
|
115
|
}
|
116
|
|
117
|
@Test
|
118
|
public void testMoveFactualData() throws ExecutionException {
|
119
|
UUID sourceTaxonUuid = UUID.fromString("e40854d7-143f-4054-b229-6ed4cedb4bff");
|
120
|
UUID targetTaxonUuid = UUID.fromString("b8402dc4-5050-4882-a147-01b71e0e47d6");
|
121
|
|
122
|
Taxon sourceTaxon = CdmBase.deproxy(taxonService.load(sourceTaxonUuid), Taxon.class);
|
123
|
Set<TaxonDescription> sourceDescriptions = new HashSet<>(sourceTaxon.getDescriptions());
|
124
|
sessionOwner.addExpectedUpdatedObject(sourceTaxon);
|
125
|
|
126
|
Taxon targetTaxon = CdmBase.deproxy(taxonService.load(targetTaxonUuid), Taxon.class);
|
127
|
int countTargetDescriptions = targetTaxon.getDescriptions().size();
|
128
|
sessionOwner.addExpectedUpdatedObject(targetTaxon);
|
129
|
|
130
|
operation = new MoveFactualDataOperation(sessionOwner,
|
131
|
false,
|
132
|
sourceTaxonUuid,
|
133
|
targetTaxonUuid, true);
|
134
|
operation.execute(monitor, info);
|
135
|
Assert.assertEquals(0, sourceTaxon.getDescriptions().size());
|
136
|
Assert.assertEquals(sourceDescriptions.size() + countTargetDescriptions, targetTaxon.getDescriptions().size());
|
137
|
Assert.assertTrue(targetTaxon.getDescriptions().containsAll(sourceDescriptions));
|
138
|
}
|
139
|
|
140
|
@Test
|
141
|
public void testDeleteTaxonNodeWithDeleteChildren() throws ExecutionException {
|
142
|
UUID taxonNodeUuid = UUID.fromString("2f05d429-632d-4230-b9cb-70299360b470");
|
143
|
TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
|
144
|
List<TaxonNode> childNodes = taxonNode.getChildNodes();
|
145
|
List<UUID> childNodeUuids = new ArrayList<UUID>();
|
146
|
for(TaxonNode childNode : childNodes) {
|
147
|
childNodeUuids.add(childNode.getUuid());
|
148
|
}
|
149
|
Assert.assertTrue(taxonNode.getCountChildren() > 0);
|
150
|
|
151
|
Set<TaxonNodeDto> nodes = new HashSet<>();
|
152
|
nodes.add(new TaxonNodeDto(taxonNode));
|
153
|
|
154
|
TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator();
|
155
|
configNodes.setChildHandling(ChildHandling.DELETE);
|
156
|
TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
|
157
|
config.setTaxonNodeConfig(configNodes);
|
158
|
|
159
|
sessionOwner.addExpectedUpdatedObject(taxonNode.getParent());
|
160
|
|
161
|
operation = new DeleteTaxonNodeOperation(sessionOwner,
|
162
|
false,
|
163
|
nodes,
|
164
|
null,
|
165
|
config);
|
166
|
operation.execute(monitor, info);
|
167
|
TaxonNode reloadedNode = taxonNodeService.load(taxonNode.getUuid());
|
168
|
Assert.assertNull(reloadedNode);
|
169
|
for(UUID childNodeUuid : childNodeUuids) {
|
170
|
TaxonNode reloadedChildNode = taxonNodeService.load(childNodeUuid);
|
171
|
Assert.assertNull(reloadedChildNode);
|
172
|
}
|
173
|
}
|
174
|
|
175
|
@Test
|
176
|
public void testDeleteTaxonNodes() throws ExecutionException {
|
177
|
UUID taxonNode1Uuid = UUID.fromString("99f03b56-67cd-4e01-9ceb-2362d48f9d07");
|
178
|
UUID taxonNode2Uuid = UUID.fromString("91698cec-615f-4472-9002-feda1a6acded");
|
179
|
UUID taxonNode3Uuid = UUID.fromString("4fe03763-b966-4361-8334-352f6f777588");
|
180
|
|
181
|
TaxonNode taxonNode1 = taxonNodeService.load(taxonNode1Uuid);
|
182
|
TaxonNode taxonNode2 = taxonNodeService.load(taxonNode2Uuid);
|
183
|
TaxonNode taxonNode3 = taxonNodeService.load(taxonNode3Uuid);
|
184
|
|
185
|
Set<TaxonNodeDto> nodes = new HashSet<>();
|
186
|
nodes.add(new TaxonNodeDto(taxonNode1));
|
187
|
nodes.add(new TaxonNodeDto(taxonNode2));
|
188
|
nodes.add(new TaxonNodeDto(taxonNode3));
|
189
|
|
190
|
TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
|
191
|
|
192
|
|
193
|
sessionOwner.addExpectedUpdatedObject(taxonNode1.getParent());
|
194
|
sessionOwner.addExpectedUpdatedObject(taxonNode2.getParent());
|
195
|
sessionOwner.addExpectedUpdatedObject(taxonNode3.getParent());
|
196
|
operation = new DeleteTaxonNodeOperation(sessionOwner,
|
197
|
false,
|
198
|
nodes,
|
199
|
null,
|
200
|
config);
|
201
|
operation.execute(monitor, info);
|
202
|
TaxonNode reloadedNode1 = taxonNodeService.load(taxonNode1.getUuid());
|
203
|
TaxonNode reloadedNode2 = taxonNodeService.load(taxonNode2.getUuid());
|
204
|
TaxonNode reloadedNode3 = taxonNodeService.load(taxonNode3.getUuid());
|
205
|
Assert.assertNull(reloadedNode1);
|
206
|
Assert.assertNull(reloadedNode2);
|
207
|
Assert.assertNull(reloadedNode3);
|
208
|
|
209
|
}
|
210
|
|
211
|
@Test
|
212
|
public void testDeleteTaxonNodeWithMovingChildrenToParentNode() throws ExecutionException {
|
213
|
UUID taxonNodeUuid = UUID.fromString("2f05d429-632d-4230-b9cb-70299360b470");
|
214
|
TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
|
215
|
TaxonNode parentTaxonNode = taxonNode.getParent();
|
216
|
List<TaxonNode> childNodes = taxonNode.getChildNodes();
|
217
|
List<UUID> childNodeUuids = new ArrayList<UUID>();
|
218
|
for(TaxonNode childNode : childNodes) {
|
219
|
childNodeUuids.add(childNode.getUuid());
|
220
|
}
|
221
|
Assert.assertTrue(taxonNode.getCountChildren() > 0);
|
222
|
|
223
|
Set<TaxonNodeDto> nodes = new HashSet<>();
|
224
|
nodes.add(new TaxonNodeDto(taxonNode));
|
225
|
|
226
|
TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator();
|
227
|
configNodes.setChildHandling(ChildHandling.MOVE_TO_PARENT);
|
228
|
TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
|
229
|
config.setTaxonNodeConfig(configNodes);
|
230
|
|
231
|
sessionOwner.addExpectedUpdatedObject(taxonNode.getParent());
|
232
|
operation = new DeleteTaxonNodeOperation(sessionOwner,
|
233
|
false,
|
234
|
nodes,
|
235
|
null,
|
236
|
config);
|
237
|
operation.execute(monitor, info);
|
238
|
TaxonNode reloadedNode = taxonNodeService.load(taxonNode.getUuid());
|
239
|
Assert.assertNull(reloadedNode);
|
240
|
List<TaxonNode> parentChildNodes = parentTaxonNode.getChildNodes();
|
241
|
List<UUID> parentChildNodeUuids = new ArrayList<UUID>();
|
242
|
for(TaxonNode parentChildNode : parentChildNodes) {
|
243
|
parentChildNodeUuids.add(parentChildNode.getUuid());
|
244
|
}
|
245
|
parentChildNodeUuids.containsAll(childNodeUuids);
|
246
|
|
247
|
}
|
248
|
|
249
|
@Test
|
250
|
@DataSet("TaxonNavigatorTest.testDeleteClassificationWithDeleteChildren.xml")
|
251
|
public void testDeleteClassificationWithDeleteChildren() throws ExecutionException {
|
252
|
UUID classificationUuid = UUID.fromString("0c2b5d25-7b15-4401-8b51-dd4be0ee5cab");
|
253
|
Classification classification = classificationService.load(classificationUuid);
|
254
|
TaxonNode rootNode = classification.getRootNode();
|
255
|
Set<TaxonNodeDto> nodes = new HashSet<>();
|
256
|
nodes.add(new TaxonNodeDto(classification.getRootNode()));
|
257
|
|
258
|
TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator();
|
259
|
configNodes.setChildHandling(ChildHandling.DELETE);
|
260
|
TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
|
261
|
config.setTaxonNodeConfig(configNodes);
|
262
|
|
263
|
operation = new DeleteTaxonNodeOperation(sessionOwner,
|
264
|
false,
|
265
|
nodes,
|
266
|
null,
|
267
|
config);
|
268
|
operation.execute(monitor, info);
|
269
|
|
270
|
Classification reloadedClassification = classificationService.load(classification.getUuid());
|
271
|
Assert.assertNull(reloadedClassification);
|
272
|
TaxonNode reloadedRootNode = taxonNodeService.load(rootNode.getUuid());
|
273
|
Assert.assertNull(reloadedRootNode);
|
274
|
|
275
|
}
|
276
|
|
277
|
|
278
|
}
|