2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.name
.operation
;
12 //import java.util.UUID;
13 //>>>>>>> Stashed changes
14 import java
.util
.UUID
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
18 import org
.eclipse
.core
.runtime
.IAdaptable
;
19 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
20 import org
.eclipse
.core
.runtime
.IStatus
;
22 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
23 import eu
.etaxonomy
.cdm
.api
.service
.UpdateResult
;
24 import eu
.etaxonomy
.cdm
.model
.metadata
.SecReferenceHandlingSwapEnum
;
26 //import eu.etaxonomy.cdm.model.metadata.SecReferenceHandlingEnum;
27 //>>>>>>> Stashed changes
28 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
30 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
31 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
32 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostTaxonOperation
;
33 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
34 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
35 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
38 * <p>SwapSynonymAndAcceptedOperation class.</p>
43 public class SwapSynonymAndAcceptedOperation
extends AbstractPostTaxonOperation
{
45 private final Synonym synonym
;
47 private SecReferenceHandlingSwapEnum secHandling
;
48 private boolean setNameInSource
;
50 private UUID newSecAcc
= null;
51 private UUID newSecSyn
= null;
54 * <p>Constructor for SwapSynonymAndAcceptedOperation.</p>
56 * @param label a {@link java.lang.String} object.
57 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
58 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
59 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
60 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
62 public SwapSynonymAndAcceptedOperation(String label
, IUndoContext undoContext
,
63 Taxon taxon
, Synonym synonym
, IPostOperationEnabled postOperationEnabled
,
64 ICdmEntitySessionEnabled cdmEntitySessionEnabled
, boolean setNameInSource
, SecReferenceHandlingSwapEnum secHandling
, UUID newSecAcc
, UUID newSecSyn
) {
65 super(Messages
.SwapSynonymAndAcceptedOperation_SWAP_SYN_ACC_TAXON
, undoContext
, taxon
, postOperationEnabled
, cdmEntitySessionEnabled
);
66 this.setNameInSource
= setNameInSource
;
67 this.secHandling
= secHandling
;
68 this.synonym
= synonym
;
69 this.newSecAcc
= newSecAcc
;
70 this.newSecSyn
= newSecSyn
;
74 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
75 throws ExecutionException
{
78 /*<<<<<<< Updated upstream
79 // UpdateResult result = CdmStore.getService(ITaxonService.class).swapSynonymAndAcceptedTaxon(synonym.getUuid(), element.getUuid(), setNameInSource, false);//TODO
80 UpdateResult result = CdmStore.getService(ITaxonService.class).swapSynonymAndAcceptedTaxon(synonym.getUuid(), element.getUuid(), setNameInSource, false, secHandling, newSecAcc, newSecSyn);//TODO
81 //note: without reload a multiple representations exceptions appears, not yet tested why
82 Taxon newTaxon = (Taxon)CdmStore.getService(ITaxonService.class).load(result.getCdmEntity().getUuid());
83 Synonym newSyn = null;
84 for (CdmBase cdmBase : result.getUpdatedObjects()){
85 if (cdmBase instanceof Synonym){
86 newSyn = (Synonym)cdmBase;
90 //for some reason simple cloning of the secundum source does not work if external links exist (throws exception because an OriginalSourceBase_id in an AuditTable (probably OriginalSourceBase_ExternalLink) becomes null)
92 //remember oldAcc secSource info
93 Reference oldAccRef = newTaxon.getSec();
94 String oldAccMicroRef = newTaxon.getSecMicroReference();
95 Set<ExternalLink> oldAccLinks = new HashSet<>();
96 if (newTaxon.getSecSource()!= null){
97 for (ExternalLink link: newTaxon.getSecSource().getLinks()){
98 oldAccLinks.add(link.clone());
102 if (newSyn != null ){
103 //adapt new taxon secSource info
104 newTaxon.setSec(newSyn.getSec());
105 newTaxon.setSecMicroReference(newSyn.getSecMicroReference());
106 if (newTaxon.getSecSource() != null){
107 newTaxon.getSecSource().getLinks().clear();
108 if (newSyn.getSecSource() != null){
109 for (ExternalLink link: newSyn.getSecSource().getLinks()){
110 newTaxon.getSecSource().addLink(link.clone());
115 //adapt new synonym secSource info
116 newSyn.setSec(oldAccRef);
117 newSyn.setSecMicroReference(oldAccMicroRef);
118 if (newSyn.getSecSource()!= null){
119 newSyn.getSecSource().getLinks().clear();
120 for (ExternalLink link: oldAccLinks){
121 newSyn.getSecSource().addLink(link);
126 List<TaxonBase> mergeList = new ArrayList<>();
127 mergeList.add(newTaxon);
128 mergeList.add(newSyn);
131 UpdateResult result
= CdmStore
.getService(ITaxonService
.class).swapSynonymAndAcceptedTaxon(synonym
.getUuid(), element
.getUuid(), setNameInSource
, false, secHandling
, newSecAcc
, newSecSyn
);//TODO
132 //>>>>>>> Stashed changes
136 return postExecute(element
);
140 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
141 throws ExecutionException
{
142 return execute(monitor
, info
);
146 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
147 throws ExecutionException
{
148 MessagingUtils
.error(this.getClass(), Messages
.SwapSynonymAndAcceptedOperation_NOT_IMPLEMENTED
, null);