Revision 63004250
Added by Katja Luther almost 2 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/SwapSynonymAndAcceptedOperation.java | ||
---|---|---|
9 | 9 |
package eu.etaxonomy.taxeditor.editor.name.operation; |
10 | 10 |
|
11 | 11 |
import java.util.ArrayList; |
12 |
import java.util.HashSet; |
|
12 | 13 |
import java.util.List; |
14 |
import java.util.Set; |
|
13 | 15 |
|
14 | 16 |
import org.eclipse.core.commands.ExecutionException; |
15 | 17 |
import org.eclipse.core.commands.operations.IUndoContext; |
... | ... | |
19 | 21 |
|
20 | 22 |
import eu.etaxonomy.cdm.api.service.ITaxonService; |
21 | 23 |
import eu.etaxonomy.cdm.api.service.UpdateResult; |
24 |
import eu.etaxonomy.cdm.model.media.ExternalLink; |
|
25 |
import eu.etaxonomy.cdm.model.media.ExternalLinkType; |
|
26 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
22 | 27 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
23 | 28 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
29 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
24 | 30 |
import eu.etaxonomy.taxeditor.editor.l10n.Messages; |
25 | 31 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
26 | 32 |
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation; |
... | ... | |
62 | 68 |
throws ExecutionException { |
63 | 69 |
|
64 | 70 |
monitor.worked(20); |
65 |
|
|
66 | 71 |
UpdateResult result = CdmStore.getService(ITaxonService.class).swapSynonymAndAcceptedTaxon(synonym.getUuid(), element.getUuid(), setNameInSource, false);//TODO |
67 |
element = (Taxon)result.getCdmEntity(); |
|
68 |
List<String> propertyPath = new ArrayList<>(); |
|
69 |
propertyPath.add("synonyms"); |
|
72 |
element = (Taxon)CdmStore.getService(ITaxonService.class).load(result.getCdmEntity().getUuid()); |
|
73 |
Synonym newSyn = null; |
|
74 |
if (!result.getUpdatedObjects().isEmpty()){ |
|
75 |
newSyn = (Synonym)CdmStore.getService(ITaxonService.class).load(result.getUpdatedObjects().iterator().next().getUuid()); |
|
76 |
} |
|
77 |
Reference accRef = element.getSec(); |
|
78 |
String accMicroRef = element.getSecMicroReference(); |
|
79 |
Set<ExternalLink> accLinks = new HashSet<>(); |
|
80 |
|
|
81 |
for (ExternalLink link: element.getSecSource().getLinks()){ |
|
82 |
accLinks.add(ExternalLink.NewInstance(ExternalLinkType.Unknown, link.getUri())); |
|
83 |
} |
|
84 |
if (newSyn != null ){ |
|
85 |
element.setSec(newSyn.getSec()); |
|
86 |
element.setSecMicroReference(newSyn.getSecMicroReference()); |
|
87 |
element.getSecSource().getLinks().clear(); |
|
88 |
for (ExternalLink link: newSyn.getSecSource().getLinks()){ |
|
89 |
element.getSecSource().addLink(ExternalLink.NewInstance(ExternalLinkType.Unknown, link.getUri())); |
|
90 |
} |
|
91 |
newSyn.setSec(accRef); |
|
92 |
newSyn.setSecMicroReference(accMicroRef); |
|
93 |
newSyn.getSecSource().getLinks().clear(); |
|
94 |
for (ExternalLink link: accLinks){ |
|
95 |
newSyn.getSecSource().addLink(link); |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
|
|
100 |
List<TaxonBase> mergeList = new ArrayList<>(); |
|
101 |
mergeList.add(element); |
|
102 |
mergeList.add(newSyn); |
|
70 | 103 |
|
104 |
CdmStore.getService(ITaxonService.class).merge(mergeList, true); |
|
71 | 105 |
monitor.worked(40); |
72 | 106 |
|
73 | 107 |
return postExecute(element); |
Also available in: Unified diff
ref #9668: hotfix for secundum handling when swap syn and accepted