TaxonNavigatorLabels : new interface with label strings used by taxon navigator handlers
RemotingChangeAcceptedTaxonToSynonymHandler : using TaxonNavigatorLabels
RemotingMoveFactualDataHandler : remoting version of move factual data handler
RemotingMoveFactualDataOperation : remoting version of move factual data operation
RemotingMoveTaxonHandler : remoting version of move taxon handler
RemotingMoveTaxonOperation : remoting version of move taxon operation
RemotingChangeAcceptedTaxonToSynonymOperation : replaced constructor input cdm entities to their uuids
RemotingCdmHandler : updated to handle other status severities and to handle warning status in post operation
RemotingCdmUpdateOperation : updated for warning status
TaxonNavigatorTest : added move taxon and move factual data tests
import eu.etaxonomy.cdm.model.taxon.Classification;
import eu.etaxonomy.cdm.model.taxon.TaxonComparatorSearch;
import eu.etaxonomy.cdm.model.taxon.TaxonNaturalComparator;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
import eu.etaxonomy.taxeditor.model.DataChangeBridge;
import eu.etaxonomy.taxeditor.model.IDataChangeBehavior;
* Refresh this navigators viewer
*/
public void refresh(Set objects) {
-
for(Object obj : objects) {
getCommonViewer().refresh(obj);
}
*/
@Override
public void onChange(CdmChangeEvent event) {
- // TODO Auto-generated method stub
+ for(CdmBase cb : event.getChangedObjects()) {
+ if(cb instanceof TaxonNode) {
+ getCommonViewer().refresh(cb);
+ }
+ }
}
}
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* 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.navigation.navigator;
+
+/**
+ * @author cmathew
+ * @date 19 Jun 2015
+ *
+ */
+public interface TaxonNavigatorLabels {
+
+ public static final String CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL = "Change Accepted Taxon to Synonym";
+ public static final String MOVE_TAXON_LABEL = "Move Taxon";
+ public static final String MOVE_FACTUAL_DATA_LABEL = "Move Factual Data";
+
+ public static final String NO_TAXON_SELECTION_MESSAGE = "No taxon tree node selected for operation.";
+ public static final String SINGLE_TAXON_SELECTION_MESSAGE = "The chosen operation is available only for a single taxon.";
+ public static final String SOURCE_TAXON_HAS_CHILDREN_MESSAGE = "The chosen taxon must not have any childen. You need to move all childen to " +
+ "another taxon node in the TaxonNavigator before attempting to turn the accepted " +
+ "taxon into a synonym.";
+ public static final String RELATED_EDITOR_NOT_CLOSED_MESSAGE = "Could not close related taxon name editor. " +
+ "Please close it manually and try again.";
+ public static final String SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE = "Selected object is not a taxon tree node";
+ public static final String UNSAVED_CHANGES_MESSAGE = "There are unsaved changes in the source taxon. Please save first.";
+
+
+
+}
import eu.etaxonomy.cdm.api.conversation.ConversationHolderMock;
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingChangeAcceptedTaxonToSynonymOperation;
import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
private static final Logger logger = Logger
.getLogger(RemotingChangeAcceptedTaxonToSynonymHandler.class);
- private static final String CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL = "Change Accepted Taxon to Synonym";
- private static final String NO_TAXON_SELECTION_MESSAGE = "No taxon tree node selected for operation.";
- private static final String SINGLE_TAXON_SELECTION_MESSAGE = "The operation move accepted taxon to synonymy is available only for a single taxon.";
- private static final String SOURCE_TAXON_HAS_CHILDREN_MESSAGE = "The accepted taxon must not have any childen. You need to move all childen to " +
- "another taxon node in the TaxonNavigator before attempting to turn the accepted " +
- "taxon into a synonym.";
- private static final String RELATED_EDITOR_NOT_CLOSED_MESSAGE = "Could not close related taxon name editor " +
- "Please close it manually and try again.";
- private static final String SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE = "Selected object is not a taxon tree node";
private ITaxonTreeNode oldTaxonNode;
* @param label
*/
public RemotingChangeAcceptedTaxonToSynonymHandler() {
- super(CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL);
+ super(TaxonNavigatorLabels.CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL);
}
/* (non-Javadoc)
* @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
if(selection.size() > 1) {
return new Status(IStatus.ERROR,
"unknown",
- SINGLE_TAXON_SELECTION_MESSAGE);
+ TaxonNavigatorLabels.SINGLE_TAXON_SELECTION_MESSAGE);
}
// check for no taxon tree node selected
if(selection.size() == 0) {
return new Status(IStatus.ERROR,
"unknown",
- NO_TAXON_SELECTION_MESSAGE);
+ TaxonNavigatorLabels.NO_TAXON_SELECTION_MESSAGE);
}
// check that selected object is a taxon node
} else {
return new Status(IStatus.ERROR,
"unknown",
- SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
+ TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
}
// check that the source taxon node does not have children
if(((TaxonNode)oldTaxonNode).getCountChildren() > 0) {
return new Status(IStatus.ERROR,
"unknown",
- SOURCE_TAXON_HAS_CHILDREN_MESSAGE);
+ TaxonNavigatorLabels.SOURCE_TAXON_HAS_CHILDREN_MESSAGE);
}
if(editorClosed != true) {
return new Status(IStatus.ERROR,
"unknown",
- RELATED_EDITOR_NOT_CLOSED_MESSAGE);
+ TaxonNavigatorLabels.RELATED_EDITOR_NOT_CLOSED_MESSAGE);
}
return Status.OK_STATUS;
RemotingChangeAcceptedTaxonToSynonymOperation rcattso =
new RemotingChangeAcceptedTaxonToSynonymOperation(event.getTrigger(),
false,
- oldTaxonNode,
- newAcceptedTaxonNode);
+ oldTaxonNode.getUuid(),
+ newAcceptedTaxonNode.getUuid());
return rcattso;
}
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* 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.navigation.navigator.handler;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.operations.AbstractOperation;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolderMock;
+import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
+import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
+import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveFactualDataOperation;
+import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
+
+/**
+ * @author cmathew
+ * @date 19 Jun 2015
+ *
+ */
+public class RemotingMoveFactualDataHandler extends RemotingCdmHandler {
+
+
+ private TaxonNode sourceTaxonNode;
+ private TaxonNode targetTaxonNode;
+ /**
+ * @param label
+ */
+ public RemotingMoveFactualDataHandler() {
+ super(TaxonNavigatorLabels.MOVE_FACTUAL_DATA_LABEL);
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
+ */
+ @Override
+ public IStatus allowOperations(ExecutionEvent event) {
+ TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
+ // check that only a single taxon tree node has been selected
+ if(selection.size() > 1) {
+ return new Status(IStatus.ERROR,
+ "unknown",
+ TaxonNavigatorLabels.SINGLE_TAXON_SELECTION_MESSAGE);
+ }
+
+ // check for no taxon tree node selected
+ if(selection.size() == 0) {
+ return new Status(IStatus.ERROR,
+ "unknown",
+ TaxonNavigatorLabels.NO_TAXON_SELECTION_MESSAGE);
+ }
+
+ // check that selected object is a taxon node
+ Object obj = selection.iterator().next();
+ if(obj instanceof ITaxonTreeNode) {
+ sourceTaxonNode = (TaxonNode)obj;
+ } else {
+ return new Status(IStatus.ERROR,
+ "unknown",
+ TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
+ }
+
+ if(NavigationUtil.isDirty(sourceTaxonNode)) {
+ return new Status(IStatus.ERROR,
+ "unknown",
+ TaxonNavigatorLabels.UNSAVED_CHANGES_MESSAGE);
+ }
+
+ List<UUID> excludeTaxa = new ArrayList<UUID>();
+ excludeTaxa.add(sourceTaxonNode.getTaxon().getUuid());
+
+ targetTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event),
+ new ConversationHolderMock(),
+ "Choose the accepted taxon",
+ excludeTaxa,
+ null,
+ null);
+
+ if(targetTaxonNode == null) {
+ return new Status(IStatus.CANCEL,
+ "unknown",
+ "");
+ }
+ if(NavigationUtil.isDirty(targetTaxonNode)){
+ return new Status(IStatus.ERROR,
+ "unknown",
+ TaxonNavigatorLabels.UNSAVED_CHANGES_MESSAGE);
+ }
+ return Status.OK_STATUS;
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
+ */
+ @Override
+ public AbstractOperation prepareOperation(ExecutionEvent event) {
+ return new RemotingMoveFactualDataOperation(event.getTrigger(),
+ false,
+ sourceTaxonNode.getTaxon().getUuid(),
+ targetTaxonNode.getTaxon().getUuid());
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
+ */
+ @Override
+ public void onComplete() {
+ Display.getDefault().asyncExec(new Runnable(){
+ @Override
+ public void run() {
+ try {
+ //close and re-open to refresh factual data view
+ MultiPageTaxonEditor sourceEditor = (MultiPageTaxonEditor) EditorUtil.findEditorByTaxonNodeUuid(sourceTaxonNode.getUuid());
+ MultiPageTaxonEditor targetEditor = (MultiPageTaxonEditor) EditorUtil.findEditorByTaxonNodeUuid(targetTaxonNode.getUuid());
+ if(targetEditor != null){
+ AbstractUtility.close(sourceEditor);
+ AbstractUtility.close(targetEditor);
+ }
+ EditorUtil.openTaxonNode(sourceTaxonNode.getUuid());
+ EditorUtil.openTaxonNode(targetTaxonNode.getUuid());
+ } catch (PartInitException e) {
+ MessagingUtils.error(this.getClass(), e);
+ throw new RuntimeException(e);
+ } catch (Exception e) {
+ MessagingUtils.warningDialog("Could not create Taxon", this, e.getMessage());
+ }
+ }
+
+ });
+
+ }
+
+}
--- /dev/null
+// $Id$
+/**
+ * Copyright (C) 2015 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * 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.navigation.navigator.handler;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.operations.AbstractOperation;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolderMock;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
+import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
+import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveTaxonOperation;
+import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
+
+/**
+ * @author cmathew
+ * @date 19 Jun 2015
+ *
+ */
+public class RemotingMoveTaxonHandler extends RemotingCdmHandler {
+
+ private TaxonNode oldTaxonNode;
+
+ public RemotingMoveTaxonHandler() {
+ super(TaxonNavigatorLabels.MOVE_TAXON_LABEL);
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
+ */
+ @Override
+ public IStatus allowOperations(ExecutionEvent event) {
+ TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
+ // check that only a single taxon tree node has been selected
+ if(selection.size() > 1) {
+ return new Status(IStatus.ERROR,
+ "unknown",
+ TaxonNavigatorLabels.SINGLE_TAXON_SELECTION_MESSAGE);
+ }
+
+ // check for no taxon tree node selected
+ if(selection.size() == 0) {
+ return new Status(IStatus.ERROR,
+ "unknown",
+ TaxonNavigatorLabels.NO_TAXON_SELECTION_MESSAGE);
+ }
+ // check that selected object is a taxon node
+ Object obj = selection.iterator().next();
+ if(obj instanceof TaxonNode) {
+ oldTaxonNode = (TaxonNode)obj;
+ } else {
+ return new Status(IStatus.ERROR,
+ "unknown",
+ TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
+ }
+ return Status.OK_STATUS;
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
+ */
+ @Override
+ public AbstractOperation prepareOperation(ExecutionEvent event) {
+ TaxonNode parentTaxonNode;
+
+ List<UUID> excludeTaxa = new ArrayList<UUID>();
+ excludeTaxa.add(oldTaxonNode.getUuid());
+
+ boolean moveToNewParent = true;
+
+ if (PreferencesUtil.getSortNodesNaturally()){
+ if(!MessageDialog.openQuestion(null, "Target node", "The choosen target node should be the parent?")){
+ moveToNewParent = false;
+ }
+ parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event),
+ new ConversationHolderMock(),
+ "Choose the taxon above the moved taxon.",
+ excludeTaxa,
+ null,
+ null);
+ } else {
+ parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event),
+ new ConversationHolderMock(),
+ "Choose new parent",
+ excludeTaxa,
+ null,
+ null);
+ }
+ if(parentTaxonNode != null){
+ if(NavigationUtil.isDirty(parentTaxonNode)){
+ MessageDialog.openWarning(HandlerUtil.getActiveShell(event),
+ "Unsaved Parent Taxon",
+ "There are unsaved changes in the parent taxon. Please save first.");
+ return null;
+ }
+
+ return new RemotingMoveTaxonOperation(event.getTrigger(),
+ false,
+ oldTaxonNode.getUuid(),
+ parentTaxonNode.getUuid(),
+ moveToNewParent);
+ }
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
+ */
+ @Override
+ public void onComplete() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
*/
package eu.etaxonomy.taxeditor.navigation.navigator.operation;
+import java.util.UUID;
+
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
import eu.etaxonomy.cdm.api.service.UpdateResult;
-import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
-import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
*/
public class RemotingChangeAcceptedTaxonToSynonymOperation extends RemotingCdmUpdateOperation {
- private final TaxonNode newAcceptedTaxonNode;
- private final ITaxonTreeNode oldTaxonNode;
+ private final UUID oldTaxonNodeUuid;
+ private final UUID newAcceptedTaxonNodeUuid;
+
- private final static String LABEL = "ChangeAcceptedTaxonToSynonymOperation";
+ private final static String LABEL = "Change Accepted Taxon to Synonym operation";
/**
* @param label
*/
public RemotingChangeAcceptedTaxonToSynonymOperation(Object source,
boolean async,
- ITaxonTreeNode oldTaxonNode,
- TaxonNode newAcceptedTaxonNode) {
+ UUID oldTaxonNodeUuid,
+ UUID newAcceptedTaxonNodeUuid) {
super(LABEL, Action.Update, source, async);
- this.oldTaxonNode = oldTaxonNode;
- this.newAcceptedTaxonNode = newAcceptedTaxonNode;
+ this.oldTaxonNodeUuid = oldTaxonNodeUuid;
+ this.newAcceptedTaxonNodeUuid = newAcceptedTaxonNodeUuid;
}
/* (non-Javadoc)
*/
@Override
protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
- return CdmApplicationState.getService(ITaxonNodeService.class).makeTaxonNodeASynonymOfAnotherTaxonNode(oldTaxonNode.getUuid(), newAcceptedTaxonNode.getUuid(), null, null, null);
+ return CdmApplicationState.getService(ITaxonNodeService.class).makeTaxonNodeASynonymOfAnotherTaxonNode(oldTaxonNodeUuid,
+ newAcceptedTaxonNodeUuid,
+ null,
+ null,
+ null);
}
}
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* 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.navigation.navigator.operation;
+
+import java.util.UUID;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
+import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
+import eu.etaxonomy.cdm.api.service.IDescriptionService;
+import eu.etaxonomy.cdm.api.service.UpdateResult;
+import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
+
+/**
+ * @author cmathew
+ * @date 19 Jun 2015
+ *
+ */
+public class RemotingMoveFactualDataOperation extends RemotingCdmUpdateOperation {
+
+ private final static String LABEL = "Move Factual Data operation";
+
+ private final UUID sourceTaxonUuid;
+ private final UUID targetParentTaxonUuid;
+
+ /**
+ * @param label
+ * @param action
+ * @param source
+ * @param async
+ */
+ public RemotingMoveFactualDataOperation(Object source,
+ boolean async,
+ UUID sourceTaxonUuid,
+ UUID targetParentTaxonUuid) {
+ super(LABEL, Action.Update, source, async);
+ this.sourceTaxonUuid = sourceTaxonUuid;
+ this.targetParentTaxonUuid = targetParentTaxonUuid;
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation#doUpdateExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+ */
+ @Override
+ protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
+ return CdmApplicationState.getService(IDescriptionService.class).moveTaxonDescriptions(sourceTaxonUuid,
+ targetParentTaxonUuid);
+ }
+
+}
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* 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.navigation.navigator.operation;
+
+import java.util.UUID;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
+import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
+import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
+import eu.etaxonomy.cdm.api.service.UpdateResult;
+import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
+
+/**
+ * @author cmathew
+ * @date 19 Jun 2015
+ *
+ */
+public class RemotingMoveTaxonOperation extends RemotingCdmUpdateOperation {
+
+ private final static String LABEL = "Move Taxon operation";
+
+ private final UUID taxonNodeToMoveUuid;
+ private final UUID newParentTreeNodeUuid;
+ private final boolean moveToParentNode;
+
+ public RemotingMoveTaxonOperation(Object source,
+ boolean async,
+ UUID taxonNodeToMoveUuid,
+ UUID newParentTreeNodeUuid,
+ boolean moveToParentNode) {
+ super(LABEL, Action.Update, source,async);
+ this.taxonNodeToMoveUuid = taxonNodeToMoveUuid;
+ this.newParentTreeNodeUuid = newParentTreeNodeUuid;
+ this.moveToParentNode = moveToParentNode;
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation#doUpdateExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+ */
+ @Override
+ protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
+ return CdmApplicationState.getService(ITaxonNodeService.class).moveTaxonNode(taxonNodeToMoveUuid,
+ newParentTreeNodeUuid,
+ moveToParentNode);
+ }
+
+}
if(op != null) {
AbstractUtility.executeOperation(op, this);
}
- } else {
+ } else if(allowStatus.getSeverity() == IStatus.ERROR ||
+ allowStatus.getSeverity() == IStatus.WARNING ||
+ allowStatus.getSeverity() == IStatus.INFO) {
MessagingUtils.warningDialog("Can not perform " + label, event.getTrigger(), allowStatus);
}
return null;
}
public void postOperation(IStatus status) {
- if(!status.isOK() && status.getException() != null) {
- ErrorDialog.openError(null, "Error executing " + label, null, status);
+
+ switch(status.getSeverity()) {
+ case IStatus.WARNING:
+ MessagingUtils.warningDialog("Operation successful but with warnings", null, status);
+ break;
+ case IStatus.ERROR:
+ ErrorDialog.openError(null, "Error executing operation", null, status);
+ break;
+ default:
}
+
onComplete();
}
package eu.etaxonomy.taxeditor.operation;
import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
protected IStatus onComplete(boolean success) {
if(updateResult != null) {
+ int statusFlag = IStatus.OK;
+
Collection<Exception> exceptions = updateResult.getExceptions();
- if(success && exceptions.isEmpty()) {
- return Status.OK_STATUS;
+ if(success && updateResult.isOk()) {
+ if(exceptions.isEmpty()) {
+ return Status.OK_STATUS;
+ } else {
+ statusFlag = IStatus.WARNING;
+ }
+ } else {
+ statusFlag = IStatus.ERROR;
}
Status[] childStatus = new Status[exceptions.size()];
int count = 0;
+ Set<String> messages = new HashSet<String>();
for(Exception ex : exceptions) {
- Status status = new Status(IStatus.ERROR,
+ Status status = new Status(statusFlag,
"unknown",
- IStatus.ERROR,
+ statusFlag,
ex.getLocalizedMessage(),
ex);
+ messages.add(ex.getLocalizedMessage());
childStatus[count] = status;
count++;
}
-
+ StringBuffer statusMsg = new StringBuffer();
+ for(String message : messages) {
+ statusMsg.append(message);
+ statusMsg.append(System.lineSeparator());
+ }
MultiStatus multiStatus = new MultiStatus("unknown",
- IStatus.ERROR,
+ statusFlag,
childStatus,
- getLabel() + " is in error",
+ statusMsg.toString(),
null);
return multiStatus;
}
*/
package eu.etaxonomy.cdm.model;
+import java.util.HashSet;
+import java.util.Set;
import java.util.UUID;
import org.apache.log4j.Logger;
import eu.etaxonomy.cdm.api.service.IClassificationService;
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
import eu.etaxonomy.cdm.api.service.ITaxonService;
+import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.description.TaxonDescription;
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingChangeAcceptedTaxonToSynonymOperation;
+import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveFactualDataOperation;
+import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveTaxonOperation;
import eu.etaxonomy.taxeditor.operations.BaseOperationTest;
/**
@Test
- public void changeAcceptedTaxonToSynonymTest() throws ExecutionException {
+ public void testChangeAcceptedTaxonToSynonym() throws ExecutionException {
UUID oldTaxonNodeNodeUuid = UUID.fromString("b85b5b78-6760-409f-ac91-bb89e95ff2a1");
TaxonNode oldTaxonNode = taxonNodeService.load(oldTaxonNodeNodeUuid);
TaxonNameBase name = oldTaxonNode.getTaxon().getName();
+
+
TaxonNode newAcceptedTaxonNode = taxonNodeService.load(newAcceptedTaxonNodeUuid);
- sessionOwner.addUpdatedObject(oldTaxonNode.getParent());
+ int countTargetSynonyms = newAcceptedTaxonNode.getTaxon().getSynonyms().size();
+ sessionOwner.addExpectedUpdatedObject(oldTaxonNode.getParent());
+
- Assert.assertEquals(0,newAcceptedTaxonNode.getTaxon().getSynonyms().size());
operation = new RemotingChangeAcceptedTaxonToSynonymOperation(sessionOwner,
false,
- oldTaxonNode,
- newAcceptedTaxonNode);
+ oldTaxonNode.getUuid(),
+ newAcceptedTaxonNode.getUuid());
operation.execute(monitor, info);
newAcceptedTaxonNode = taxonNodeService.load(newAcceptedTaxonNodeUuid);
- sessionOwner.addUpdatedObject(newAcceptedTaxonNode);
+ sessionOwner.addExpectedUpdatedObject(newAcceptedTaxonNode);
oldTaxonNode = taxonNodeService.load(oldTaxonNodeNodeUuid);
Assert.assertNull(oldTaxonNode);
- Assert.assertEquals(1,newAcceptedTaxonNode.getTaxon().getSynonyms().size());
+ Assert.assertEquals(countTargetSynonyms + 1,newAcceptedTaxonNode.getTaxon().getSynonyms().size());
Assert.assertEquals(name, newAcceptedTaxonNode.getTaxon().getSynonyms().iterator().next().getName());
}
@Test
- public void moveTaxonTest() {
+ public void testMoveTaxon() throws ExecutionException {
+
+ UUID taxonNodeToMoveUuid = UUID.fromString("b8439f51-6b96-445a-b401-7a836ba1cf58");
+ UUID newParentTreeNodeUuid = UUID.fromString("2f05d429-632d-4230-b9cb-70299360b470");
+ boolean moveToParentNode = true;
+
+ TaxonNode taxonNodeToMove = taxonNodeService.load(taxonNodeToMoveUuid);
+ TaxonNode oldParent = taxonNodeToMove.getParent();
+ sessionOwner.addExpectedUpdatedObject(oldParent);
+ int childCount = oldParent.getCountChildren();
+ TaxonNode newParentTreeNode = taxonNodeService.load(newParentTreeNodeUuid);
+ sessionOwner.addExpectedUpdatedObject(newParentTreeNode);
+ operation = new RemotingMoveTaxonOperation(sessionOwner,
+ false,
+ taxonNodeToMove.getUuid(),
+ newParentTreeNode.getUuid(),
+ moveToParentNode);
+ operation.execute(monitor, info);
+ Assert.assertEquals(childCount-1, oldParent.getCountChildren());
+ Assert.assertTrue(!oldParent.getChildNodes().contains(taxonNodeToMove));
+ Assert.assertTrue(newParentTreeNode.getChildNodes().contains(taxonNodeToMove));
+ }
+
+ @Test
+ public void testMoveFactualData() throws ExecutionException {
+ UUID sourceTaxonUuid = UUID.fromString("e40854d7-143f-4054-b229-6ed4cedb4bff");
+ UUID targetTaxonUuid = UUID.fromString("b8402dc4-5050-4882-a147-01b71e0e47d6");
+
+ Taxon sourceTaxon = CdmBase.deproxy(taxonService.load(sourceTaxonUuid), Taxon.class);
+ Set<TaxonDescription> sourceDescriptions = new HashSet(sourceTaxon.getDescriptions());
+ sessionOwner.addExpectedUpdatedObject(sourceTaxon);
+ Taxon targetTaxon = CdmBase.deproxy(taxonService.load(targetTaxonUuid), Taxon.class);
+ int countTargetDescriptions = targetTaxon.getDescriptions().size();
+ sessionOwner.addExpectedUpdatedObject(targetTaxon);
+
+ operation = new RemotingMoveFactualDataOperation(sessionOwner,
+ false,
+ sourceTaxonUuid,
+ targetTaxonUuid);
+ operation.execute(monitor, info);
+ Assert.assertEquals(0, sourceTaxon.getDescriptions().size());
+ Assert.assertEquals(sourceDescriptions.size() + countTargetDescriptions, targetTaxon.getDescriptions().size());
+ Assert.assertTrue(targetTaxon.getDescriptions().containsAll(sourceDescriptions));
}
this.updatedObjects = updatedObjects;
}
- public void addUpdatedObject(T updatedObject) {
+ public void addExpectedUpdatedObject(T updatedObject) {
if(updatedObjects == null) {
updatedObjects = new HashSet<T>();
}