X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/blobdiff_plain/4b94c9cfe0df4ec8f83395b88d8420c5791a93b4..f13ee83283d374d07509fa7de1e9c893395a8fa2:/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/SwapSynonymAndAcceptedOperation.java diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/SwapSynonymAndAcceptedOperation.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/SwapSynonymAndAcceptedOperation.java index 507b2cfe5..f486d35d8 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/SwapSynonymAndAcceptedOperation.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/SwapSynonymAndAcceptedOperation.java @@ -1,4 +1,3 @@ -// $Id$ /** * Copyright (C) 2007 EDIT * European Distributed Institute of Taxonomy @@ -7,9 +6,13 @@ * The contents of this file are subject to the Mozilla Public License Version 1.1 * See LICENSE.TXT at the top of this package for the full license terms. */ - package eu.etaxonomy.taxeditor.editor.name.operation; +//======= +//import java.util.UUID; +//>>>>>>> Stashed changes +import java.util.UUID; + import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.operations.IUndoContext; import org.eclipse.core.runtime.IAdaptable; @@ -18,9 +21,13 @@ import org.eclipse.core.runtime.IStatus; import eu.etaxonomy.cdm.api.service.ITaxonService; import eu.etaxonomy.cdm.api.service.UpdateResult; +import eu.etaxonomy.cdm.model.metadata.SecReferenceHandlingSwapEnum; +//======= +//import eu.etaxonomy.cdm.model.metadata.SecReferenceHandlingEnum; +//>>>>>>> Stashed changes import eu.etaxonomy.cdm.model.taxon.Synonym; -import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType; import eu.etaxonomy.cdm.model.taxon.Taxon; +import eu.etaxonomy.taxeditor.editor.l10n.Messages; import eu.etaxonomy.taxeditor.model.MessagingUtils; import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation; import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; @@ -32,13 +39,16 @@ import eu.etaxonomy.taxeditor.store.CdmStore; * * @author n.hoffmann * @created 23.04.2009 - * @version 1.0 */ public class SwapSynonymAndAcceptedOperation extends AbstractPostTaxonOperation { private final Synonym synonym; - // TODO store the old relationship for undo reasons - private SynonymRelationshipType synonymRelationshipType; + + private SecReferenceHandlingSwapEnum secHandling; + private boolean setNameInSource; + + private UUID newSecAcc = null; + private UUID newSecSyn = null; /** *

Constructor for SwapSynonymAndAcceptedOperation.

@@ -51,48 +61,91 @@ public class SwapSynonymAndAcceptedOperation extends AbstractPostTaxonOperation */ public SwapSynonymAndAcceptedOperation(String label, IUndoContext undoContext, Taxon taxon, Synonym synonym, IPostOperationEnabled postOperationEnabled, - ICdmEntitySessionEnabled cdmEntitySessionEnabled) { - super("Swap Synonym And Accepted Taxon Operation", undoContext, taxon, postOperationEnabled, cdmEntitySessionEnabled); - + ICdmEntitySessionEnabled cdmEntitySessionEnabled, boolean setNameInSource, SecReferenceHandlingSwapEnum secHandling, UUID newSecAcc, UUID newSecSyn) { + super(Messages.SwapSynonymAndAcceptedOperation_SWAP_SYN_ACC_TAXON, undoContext, taxon, postOperationEnabled, cdmEntitySessionEnabled); + this.setNameInSource = setNameInSource; + this.secHandling = secHandling; this.synonym = synonym; + this.newSecAcc = newSecAcc; + this.newSecSyn = newSecSyn; } - /* (non-Javadoc) - * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) - */ - /** {@inheritDoc} */ @Override public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { monitor.worked(20); +/*<<<<<<< Updated upstream +// UpdateResult result = CdmStore.getService(ITaxonService.class).swapSynonymAndAcceptedTaxon(synonym.getUuid(), element.getUuid(), setNameInSource, false);//TODO + UpdateResult result = CdmStore.getService(ITaxonService.class).swapSynonymAndAcceptedTaxon(synonym.getUuid(), element.getUuid(), setNameInSource, false, secHandling, newSecAcc, newSecSyn);//TODO + //note: without reload a multiple representations exceptions appears, not yet tested why + Taxon newTaxon = (Taxon)CdmStore.getService(ITaxonService.class).load(result.getCdmEntity().getUuid()); + Synonym newSyn = null; + for (CdmBase cdmBase : result.getUpdatedObjects()){ + if (cdmBase instanceof Synonym){ + newSyn = (Synonym)cdmBase; + } + } - UpdateResult result = CdmStore.getService(ITaxonService.class).swapSynonymAndAcceptedTaxon(synonym.getUuid(), element.getUuid()); + //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) + + //remember oldAcc secSource info + Reference oldAccRef = newTaxon.getSec(); + String oldAccMicroRef = newTaxon.getSecMicroReference(); + Set oldAccLinks = new HashSet<>(); + if (newTaxon.getSecSource()!= null){ + for (ExternalLink link: newTaxon.getSecSource().getLinks()){ + oldAccLinks.add(link.clone()); + } + } + + if (newSyn != null ){ + //adapt new taxon secSource info + newTaxon.setSec(newSyn.getSec()); + newTaxon.setSecMicroReference(newSyn.getSecMicroReference()); + if (newTaxon.getSecSource() != null){ + newTaxon.getSecSource().getLinks().clear(); + if (newSyn.getSecSource() != null){ + for (ExternalLink link: newSyn.getSecSource().getLinks()){ + newTaxon.getSecSource().addLink(link.clone()); + } + } + } + + //adapt new synonym secSource info + newSyn.setSec(oldAccRef); + newSyn.setSecMicroReference(oldAccMicroRef); + if (newSyn.getSecSource()!= null){ + newSyn.getSecSource().getLinks().clear(); + for (ExternalLink link: oldAccLinks){ + newSyn.getSecSource().addLink(link); + } + } + } + + List mergeList = new ArrayList<>(); + mergeList.add(newTaxon); + mergeList.add(newSyn); + */ +//======= + UpdateResult result = CdmStore.getService(ITaxonService.class).swapSynonymAndAcceptedTaxon(synonym.getUuid(), element.getUuid(), setNameInSource, false, secHandling, newSecAcc, newSecSyn);//TODO +//>>>>>>> Stashed changes monitor.worked(40); return postExecute(element); } - /* (non-Javadoc) - * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) - */ - /** {@inheritDoc} */ @Override public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - // TODO Auto-generated method stub return execute(monitor, info); } - /* (non-Javadoc) - * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) - */ - /** {@inheritDoc} */ @Override public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - MessagingUtils.error(this.getClass(), "Not yet implemented", null); + MessagingUtils.error(this.getClass(), Messages.SwapSynonymAndAcceptedOperation_NOT_IMPLEMENTED, null); return null; } }