Project

General

Profile

« Previous | Next » 

Revision 83a1a479

Added by Cherian Mathew almost 9 years ago

TaxonNavigator : added refresh of navigator on data change
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

View differences:

eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigator.java
37 37
import eu.etaxonomy.cdm.model.taxon.Classification;
38 38
import eu.etaxonomy.cdm.model.taxon.TaxonComparatorSearch;
39 39
import eu.etaxonomy.cdm.model.taxon.TaxonNaturalComparator;
40
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
40 41
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
41 42
import eu.etaxonomy.taxeditor.model.DataChangeBridge;
42 43
import eu.etaxonomy.taxeditor.model.IDataChangeBehavior;
......
171 172
     * Refresh this navigators viewer
172 173
     */
173 174
    public void refresh(Set objects) {
174

  
175 175
        for(Object obj : objects) {
176 176
            getCommonViewer().refresh(obj);
177 177
        }
......
519 519
     */
520 520
    @Override
521 521
    public void onChange(CdmChangeEvent event) {
522
        // TODO Auto-generated method stub
522
        for(CdmBase cb : event.getChangedObjects()) {
523
            if(cb instanceof TaxonNode) {
524
                getCommonViewer().refresh(cb);
525
            }
526
        }
523 527

  
524 528
    }
525 529
}
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorLabels.java
1
// $Id$
2
/**
3
* Copyright (C) 2015 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.navigation.navigator;
11

  
12
/**
13
 * @author cmathew
14
 * @date 19 Jun 2015
15
 *
16
 */
17
public interface TaxonNavigatorLabels {
18

  
19
    public static final String CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL = "Change Accepted Taxon to Synonym";
20
    public static final String MOVE_TAXON_LABEL = "Move Taxon";
21
    public static final String MOVE_FACTUAL_DATA_LABEL = "Move Factual Data";
22

  
23
    public static final String NO_TAXON_SELECTION_MESSAGE = "No taxon tree node selected for operation.";
24
    public static final String SINGLE_TAXON_SELECTION_MESSAGE = "The chosen operation is available only for a single taxon.";
25
    public static final String SOURCE_TAXON_HAS_CHILDREN_MESSAGE = "The chosen taxon must not have any childen. You need to move all childen to " +
26
            "another taxon node in the TaxonNavigator before attempting to turn the accepted " +
27
            "taxon into a synonym.";
28
    public static final String RELATED_EDITOR_NOT_CLOSED_MESSAGE = "Could not close related taxon name editor. " +
29
            "Please close it manually and try again.";
30
    public static final String SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE = "Selected object is not a taxon tree node";
31
    public static final String UNSAVED_CHANGES_MESSAGE = "There are unsaved changes in the source taxon. Please save first.";
32

  
33

  
34

  
35
}
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/RemotingChangeAcceptedTaxonToSynonymHandler.java
18 18
import eu.etaxonomy.cdm.api.conversation.ConversationHolderMock;
19 19
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
20 20
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
21
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
21 22
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingChangeAcceptedTaxonToSynonymOperation;
22 23
import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
23 24
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
......
34 35
    private static final Logger logger = Logger
35 36
            .getLogger(RemotingChangeAcceptedTaxonToSynonymHandler.class);
36 37

  
37
    private static final String CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL = "Change Accepted Taxon to Synonym";
38
    private static final String NO_TAXON_SELECTION_MESSAGE = "No taxon tree node selected for operation.";
39
    private static final String SINGLE_TAXON_SELECTION_MESSAGE = "The operation move accepted taxon to synonymy is available only for a single taxon.";
40
    private static final String SOURCE_TAXON_HAS_CHILDREN_MESSAGE = "The accepted taxon must not have any childen. You need to move all childen to " +
41
            "another taxon node in the TaxonNavigator before attempting to turn the accepted " +
42
            "taxon into a synonym.";
43
    private static final String RELATED_EDITOR_NOT_CLOSED_MESSAGE = "Could not close related taxon name editor " +
44
            "Please close it manually and try again.";
45
    private static final String SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE = "Selected object is not a taxon tree node";
46 38

  
47 39
    private ITaxonTreeNode oldTaxonNode;
48 40

  
......
50 42
     * @param label
51 43
     */
52 44
    public RemotingChangeAcceptedTaxonToSynonymHandler() {
53
        super(CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL);
45
        super(TaxonNavigatorLabels.CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL);
54 46
    }
55 47
    /* (non-Javadoc)
56 48
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
......
62 54
        if(selection.size() > 1) {
63 55
            return new Status(IStatus.ERROR,
64 56
                    "unknown",
65
                    SINGLE_TAXON_SELECTION_MESSAGE);
57
                    TaxonNavigatorLabels.SINGLE_TAXON_SELECTION_MESSAGE);
66 58
        }
67 59

  
68 60
        // check for no taxon tree node selected
69 61
        if(selection.size() == 0) {
70 62
            return new Status(IStatus.ERROR,
71 63
                    "unknown",
72
                    NO_TAXON_SELECTION_MESSAGE);
64
                    TaxonNavigatorLabels.NO_TAXON_SELECTION_MESSAGE);
73 65
        }
74 66

  
75 67
        // check that selected object is a taxon node
......
79 71
        } else {
80 72
            return new Status(IStatus.ERROR,
81 73
                    "unknown",
82
                    SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
74
                    TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
83 75
        }
84 76
        // check that the source taxon node does not have children
85 77
        if(((TaxonNode)oldTaxonNode).getCountChildren() > 0) {
86 78
            return new Status(IStatus.ERROR,
87 79
                    "unknown",
88
                    SOURCE_TAXON_HAS_CHILDREN_MESSAGE);
80
                    TaxonNavigatorLabels.SOURCE_TAXON_HAS_CHILDREN_MESSAGE);
89 81

  
90 82
        }
91 83

  
......
94 86
        if(editorClosed != true) {
95 87
            return new Status(IStatus.ERROR,
96 88
                    "unknown",
97
                    RELATED_EDITOR_NOT_CLOSED_MESSAGE);
89
                    TaxonNavigatorLabels.RELATED_EDITOR_NOT_CLOSED_MESSAGE);
98 90
        }
99 91

  
100 92
        return Status.OK_STATUS;
......
120 112
        RemotingChangeAcceptedTaxonToSynonymOperation rcattso =
121 113
                new RemotingChangeAcceptedTaxonToSynonymOperation(event.getTrigger(),
122 114
                        false,
123
                        oldTaxonNode,
124
                        newAcceptedTaxonNode);
115
                        oldTaxonNode.getUuid(),
116
                        newAcceptedTaxonNode.getUuid());
125 117

  
126 118
        return rcattso;
127 119
    }
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/RemotingMoveFactualDataHandler.java
1
// $Id$
2
/**
3
* Copyright (C) 2015 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.navigation.navigator.handler;
11

  
12
import java.util.ArrayList;
13
import java.util.List;
14
import java.util.UUID;
15

  
16
import org.eclipse.core.commands.ExecutionEvent;
17
import org.eclipse.core.commands.operations.AbstractOperation;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.Status;
20
import org.eclipse.jface.viewers.TreeSelection;
21
import org.eclipse.swt.widgets.Display;
22
import org.eclipse.ui.PartInitException;
23
import org.eclipse.ui.handlers.HandlerUtil;
24

  
25
import eu.etaxonomy.cdm.api.conversation.ConversationHolderMock;
26
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
27
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
28
import eu.etaxonomy.taxeditor.editor.EditorUtil;
29
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
30
import eu.etaxonomy.taxeditor.model.AbstractUtility;
31
import eu.etaxonomy.taxeditor.model.MessagingUtils;
32
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
33
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
34
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveFactualDataOperation;
35
import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
36
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
37

  
38
/**
39
 * @author cmathew
40
 * @date 19 Jun 2015
41
 *
42
 */
43
public class RemotingMoveFactualDataHandler extends RemotingCdmHandler {
44

  
45

  
46
    private TaxonNode sourceTaxonNode;
47
    private TaxonNode targetTaxonNode;
48
    /**
49
     * @param label
50
     */
51
    public RemotingMoveFactualDataHandler() {
52
        super(TaxonNavigatorLabels.MOVE_FACTUAL_DATA_LABEL);
53
    }
54

  
55
    /* (non-Javadoc)
56
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
57
     */
58
    @Override
59
    public IStatus allowOperations(ExecutionEvent event) {
60
        TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
61
        // check that only a single taxon tree node has been selected
62
        if(selection.size() > 1) {
63
            return new Status(IStatus.ERROR,
64
                    "unknown",
65
                    TaxonNavigatorLabels.SINGLE_TAXON_SELECTION_MESSAGE);
66
        }
67

  
68
        // check for no taxon tree node selected
69
        if(selection.size() == 0) {
70
            return new Status(IStatus.ERROR,
71
                    "unknown",
72
                    TaxonNavigatorLabels.NO_TAXON_SELECTION_MESSAGE);
73
        }
74

  
75
        // check that selected object is a taxon node
76
        Object obj = selection.iterator().next();
77
        if(obj instanceof ITaxonTreeNode) {
78
            sourceTaxonNode = (TaxonNode)obj;
79
        } else {
80
            return new Status(IStatus.ERROR,
81
                    "unknown",
82
                    TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
83
        }
84

  
85
        if(NavigationUtil.isDirty(sourceTaxonNode)) {
86
            return new Status(IStatus.ERROR,
87
                    "unknown",
88
                    TaxonNavigatorLabels.UNSAVED_CHANGES_MESSAGE);
89
        }
90

  
91
        List<UUID> excludeTaxa = new ArrayList<UUID>();
92
        excludeTaxa.add(sourceTaxonNode.getTaxon().getUuid());
93

  
94
        targetTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event),
95
                new ConversationHolderMock(),
96
                "Choose the accepted taxon",
97
                excludeTaxa,
98
                null,
99
                null);
100

  
101
        if(targetTaxonNode == null) {
102
            return new Status(IStatus.CANCEL,
103
                    "unknown",
104
                    "");
105
        }
106
        if(NavigationUtil.isDirty(targetTaxonNode)){
107
            return new Status(IStatus.ERROR,
108
                    "unknown",
109
                    TaxonNavigatorLabels.UNSAVED_CHANGES_MESSAGE);
110
        }
111
        return Status.OK_STATUS;
112
    }
113

  
114
    /* (non-Javadoc)
115
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
116
     */
117
    @Override
118
    public AbstractOperation prepareOperation(ExecutionEvent event) {
119
        return new RemotingMoveFactualDataOperation(event.getTrigger(),
120
                false,
121
                sourceTaxonNode.getTaxon().getUuid(),
122
                targetTaxonNode.getTaxon().getUuid());
123
    }
124

  
125
    /* (non-Javadoc)
126
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
127
     */
128
    @Override
129
    public void onComplete() {
130
        Display.getDefault().asyncExec(new Runnable(){
131
            @Override
132
            public void run() {
133
                try {
134
                    //close and re-open to refresh factual data view
135
                    MultiPageTaxonEditor sourceEditor = (MultiPageTaxonEditor) EditorUtil.findEditorByTaxonNodeUuid(sourceTaxonNode.getUuid());
136
                    MultiPageTaxonEditor targetEditor = (MultiPageTaxonEditor) EditorUtil.findEditorByTaxonNodeUuid(targetTaxonNode.getUuid());
137
                    if(targetEditor != null){
138
                        AbstractUtility.close(sourceEditor);
139
                        AbstractUtility.close(targetEditor);
140
                    }
141
                    EditorUtil.openTaxonNode(sourceTaxonNode.getUuid());
142
                    EditorUtil.openTaxonNode(targetTaxonNode.getUuid());
143
                } catch (PartInitException e) {
144
                    MessagingUtils.error(this.getClass(), e);
145
                    throw new RuntimeException(e);
146
                } catch (Exception e) {
147
                    MessagingUtils.warningDialog("Could not create Taxon", this, e.getMessage());
148
                }
149
            }
150

  
151
        });
152

  
153
    }
154

  
155
}
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/RemotingMoveTaxonHandler.java
1
// $Id$
2
/**
3
 * Copyright (C) 2015 EDIT
4
 * European Distributed Institute of Taxonomy
5
 * http://www.e-taxonomy.eu
6
 *
7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 * See LICENSE.TXT at the top of this package for the full license terms.
9
 */
10
package eu.etaxonomy.taxeditor.navigation.navigator.handler;
11

  
12
import java.util.ArrayList;
13
import java.util.List;
14
import java.util.UUID;
15

  
16
import org.eclipse.core.commands.ExecutionEvent;
17
import org.eclipse.core.commands.operations.AbstractOperation;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.Status;
20
import org.eclipse.jface.dialogs.MessageDialog;
21
import org.eclipse.jface.viewers.TreeSelection;
22
import org.eclipse.ui.handlers.HandlerUtil;
23

  
24
import eu.etaxonomy.cdm.api.conversation.ConversationHolderMock;
25
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
26
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
27
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
28
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveTaxonOperation;
29
import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
30
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
31
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
32

  
33
/**
34
 * @author cmathew
35
 * @date 19 Jun 2015
36
 *
37
 */
38
public class RemotingMoveTaxonHandler extends RemotingCdmHandler {
39

  
40
    private TaxonNode oldTaxonNode;
41

  
42
    public RemotingMoveTaxonHandler() {
43
        super(TaxonNavigatorLabels.MOVE_TAXON_LABEL);
44
    }
45

  
46
    /* (non-Javadoc)
47
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
48
     */
49
    @Override
50
    public IStatus allowOperations(ExecutionEvent event) {
51
        TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
52
        // check that only a single taxon tree node has been selected
53
        if(selection.size() > 1) {
54
            return new Status(IStatus.ERROR,
55
                    "unknown",
56
                    TaxonNavigatorLabels.SINGLE_TAXON_SELECTION_MESSAGE);
57
        }
58

  
59
        // check for no taxon tree node selected
60
        if(selection.size() == 0) {
61
            return new Status(IStatus.ERROR,
62
                    "unknown",
63
                    TaxonNavigatorLabels.NO_TAXON_SELECTION_MESSAGE);
64
        }
65
        // check that selected object is a taxon node
66
        Object obj = selection.iterator().next();
67
        if(obj instanceof TaxonNode) {
68
            oldTaxonNode = (TaxonNode)obj;
69
        } else {
70
            return new Status(IStatus.ERROR,
71
                    "unknown",
72
                    TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
73
        }
74
        return Status.OK_STATUS;
75
    }
76

  
77
    /* (non-Javadoc)
78
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
79
     */
80
    @Override
81
    public AbstractOperation prepareOperation(ExecutionEvent event) {
82
        TaxonNode parentTaxonNode;
83

  
84
        List<UUID> excludeTaxa = new ArrayList<UUID>();
85
        excludeTaxa.add(oldTaxonNode.getUuid());
86

  
87
        boolean moveToNewParent = true;
88

  
89
        if (PreferencesUtil.getSortNodesNaturally()){
90
            if(!MessageDialog.openQuestion(null, "Target node", "The choosen target node should be the parent?")){
91
                moveToNewParent = false;
92
            }
93
            parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event),
94
                    new ConversationHolderMock(),
95
                    "Choose the taxon above the moved taxon.",
96
                    excludeTaxa,
97
                    null,
98
                    null);
99
        } else {
100
            parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event),
101
                    new ConversationHolderMock(),
102
                    "Choose new parent",
103
                    excludeTaxa,
104
                    null,
105
                    null);
106
        }
107
        if(parentTaxonNode != null){
108
            if(NavigationUtil.isDirty(parentTaxonNode)){
109
                MessageDialog.openWarning(HandlerUtil.getActiveShell(event),
110
                        "Unsaved Parent Taxon",
111
                        "There are unsaved changes in the parent taxon. Please save first.");
112
                return null;
113
            }
114

  
115
            return new RemotingMoveTaxonOperation(event.getTrigger(),
116
                    false,
117
                    oldTaxonNode.getUuid(),
118
                    parentTaxonNode.getUuid(),
119
                    moveToNewParent);
120
        }
121

  
122
        return null;
123
    }
124

  
125
    /* (non-Javadoc)
126
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
127
     */
128
    @Override
129
    public void onComplete() {
130
        // TODO Auto-generated method stub
131

  
132
    }
133

  
134
}
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/RemotingChangeAcceptedTaxonToSynonymOperation.java
9 9
*/
10 10
package eu.etaxonomy.taxeditor.navigation.navigator.operation;
11 11

  
12
import java.util.UUID;
13

  
12 14
import org.eclipse.core.runtime.IAdaptable;
13 15
import org.eclipse.core.runtime.IProgressMonitor;
14 16

  
......
16 18
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
17 19
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
18 20
import eu.etaxonomy.cdm.api.service.UpdateResult;
19
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
20
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
21 21
import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
22 22

  
23 23

  
......
28 28
 */
29 29
public class RemotingChangeAcceptedTaxonToSynonymOperation extends RemotingCdmUpdateOperation {
30 30

  
31
    private final TaxonNode newAcceptedTaxonNode;
32
    private final ITaxonTreeNode oldTaxonNode;
31
    private final UUID oldTaxonNodeUuid;
32
    private final UUID newAcceptedTaxonNodeUuid;
33

  
33 34

  
34
    private final static String LABEL = "ChangeAcceptedTaxonToSynonymOperation";
35
    private final static String LABEL = "Change Accepted Taxon to Synonym operation";
35 36

  
36 37
    /**
37 38
     * @param label
38 39
     */
39 40
    public RemotingChangeAcceptedTaxonToSynonymOperation(Object source,
40 41
            boolean async,
41
            ITaxonTreeNode oldTaxonNode,
42
            TaxonNode newAcceptedTaxonNode) {
42
            UUID oldTaxonNodeUuid,
43
            UUID newAcceptedTaxonNodeUuid) {
43 44
        super(LABEL, Action.Update, source, async);
44
        this.oldTaxonNode = oldTaxonNode;
45
        this.newAcceptedTaxonNode = newAcceptedTaxonNode;
45
        this.oldTaxonNodeUuid = oldTaxonNodeUuid;
46
        this.newAcceptedTaxonNodeUuid = newAcceptedTaxonNodeUuid;
46 47
    }
47 48

  
48 49
    /* (non-Javadoc)
......
50 51
     */
51 52
    @Override
52 53
    protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
53
        return CdmApplicationState.getService(ITaxonNodeService.class).makeTaxonNodeASynonymOfAnotherTaxonNode(oldTaxonNode.getUuid(), newAcceptedTaxonNode.getUuid(), null, null, null);
54
        return CdmApplicationState.getService(ITaxonNodeService.class).makeTaxonNodeASynonymOfAnotherTaxonNode(oldTaxonNodeUuid,
55
                newAcceptedTaxonNodeUuid,
56
                null,
57
                null,
58
                null);
54 59
    }
55 60

  
56 61
}
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/RemotingMoveFactualDataOperation.java
1
// $Id$
2
/**
3
* Copyright (C) 2015 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.navigation.navigator.operation;
11

  
12
import java.util.UUID;
13

  
14
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.core.runtime.IProgressMonitor;
16

  
17
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
18
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
19
import eu.etaxonomy.cdm.api.service.IDescriptionService;
20
import eu.etaxonomy.cdm.api.service.UpdateResult;
21
import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
22

  
23
/**
24
 * @author cmathew
25
 * @date 19 Jun 2015
26
 *
27
 */
28
public class RemotingMoveFactualDataOperation extends RemotingCdmUpdateOperation {
29

  
30
    private final static String LABEL = "Move Factual Data operation";
31

  
32
    private final UUID sourceTaxonUuid;
33
    private final UUID targetParentTaxonUuid;
34

  
35
    /**
36
     * @param label
37
     * @param action
38
     * @param source
39
     * @param async
40
     */
41
    public RemotingMoveFactualDataOperation(Object source,
42
            boolean async,
43
            UUID sourceTaxonUuid,
44
            UUID targetParentTaxonUuid) {
45
        super(LABEL, Action.Update, source, async);
46
        this.sourceTaxonUuid = sourceTaxonUuid;
47
        this.targetParentTaxonUuid = targetParentTaxonUuid;
48
    }
49

  
50
    /* (non-Javadoc)
51
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation#doUpdateExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
52
     */
53
    @Override
54
    protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
55
        return CdmApplicationState.getService(IDescriptionService.class).moveTaxonDescriptions(sourceTaxonUuid,
56
                targetParentTaxonUuid);
57
    }
58

  
59
}
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/RemotingMoveTaxonOperation.java
1
// $Id$
2
/**
3
* Copyright (C) 2015 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.navigation.navigator.operation;
11

  
12
import java.util.UUID;
13

  
14
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.core.runtime.IProgressMonitor;
16

  
17
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
18
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
19
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
20
import eu.etaxonomy.cdm.api.service.UpdateResult;
21
import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
22

  
23
/**
24
 * @author cmathew
25
 * @date 19 Jun 2015
26
 *
27
 */
28
public class RemotingMoveTaxonOperation extends RemotingCdmUpdateOperation {
29

  
30
    private final static String LABEL = "Move Taxon operation";
31

  
32
    private final UUID taxonNodeToMoveUuid;
33
    private final UUID newParentTreeNodeUuid;
34
    private final boolean moveToParentNode;
35

  
36
    public RemotingMoveTaxonOperation(Object source,
37
            boolean async,
38
            UUID taxonNodeToMoveUuid,
39
            UUID newParentTreeNodeUuid,
40
            boolean moveToParentNode) {
41
        super(LABEL, Action.Update, source,async);
42
        this.taxonNodeToMoveUuid = taxonNodeToMoveUuid;
43
        this.newParentTreeNodeUuid = newParentTreeNodeUuid;
44
        this.moveToParentNode = moveToParentNode;
45
    }
46

  
47
    /* (non-Javadoc)
48
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation#doUpdateExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
49
     */
50
    @Override
51
    protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
52
        return CdmApplicationState.getService(ITaxonNodeService.class).moveTaxonNode(taxonNodeToMoveUuid,
53
                newParentTreeNodeUuid,
54
                moveToParentNode);
55
    }
56

  
57
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/RemotingCdmHandler.java
43 43
            if(op != null) {
44 44
                AbstractUtility.executeOperation(op, this);
45 45
            }
46
        } else {
46
        } else if(allowStatus.getSeverity() == IStatus.ERROR ||
47
                allowStatus.getSeverity() == IStatus.WARNING ||
48
                allowStatus.getSeverity() == IStatus.INFO) {
47 49
            MessagingUtils.warningDialog("Can not perform " + label, event.getTrigger(), allowStatus);
48 50
        }
49 51
        return null;
50 52
    }
51 53

  
52 54
    public void postOperation(IStatus status) {
53
        if(!status.isOK() && status.getException() != null) {
54
            ErrorDialog.openError(null, "Error executing " + label, null, status);
55

  
56
        switch(status.getSeverity()) {
57
        case IStatus.WARNING:
58
            MessagingUtils.warningDialog("Operation successful but with warnings", null, status);
59
            break;
60
        case IStatus.ERROR:
61
            ErrorDialog.openError(null, "Error executing operation", null, status);
62
            break;
63
        default:
55 64
        }
65

  
56 66
        onComplete();
57 67
    }
58 68

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/RemotingCdmUpdateOperation.java
10 10
package eu.etaxonomy.taxeditor.operation;
11 11

  
12 12
import java.util.Collection;
13
import java.util.HashSet;
14
import java.util.Set;
13 15

  
14 16
import org.eclipse.core.runtime.IAdaptable;
15 17
import org.eclipse.core.runtime.IProgressMonitor;
......
69 71
    protected IStatus onComplete(boolean success) {
70 72

  
71 73
        if(updateResult != null) {
74
            int statusFlag = IStatus.OK;
75

  
72 76
            Collection<Exception> exceptions = updateResult.getExceptions();
73
            if(success && exceptions.isEmpty()) {
74
                return Status.OK_STATUS;
77
            if(success && updateResult.isOk()) {
78
                if(exceptions.isEmpty()) {
79
                    return Status.OK_STATUS;
80
                } else {
81
                    statusFlag = IStatus.WARNING;
82
                }
83
            } else {
84
                statusFlag = IStatus.ERROR;
75 85
            }
76 86

  
77 87
            Status[] childStatus = new Status[exceptions.size()];
78 88
            int count = 0;
89
            Set<String> messages = new HashSet<String>();
79 90
            for(Exception ex : exceptions) {
80
                Status status = new Status(IStatus.ERROR,
91
                Status status = new Status(statusFlag,
81 92
                        "unknown",
82
                        IStatus.ERROR,
93
                        statusFlag,
83 94
                        ex.getLocalizedMessage(),
84 95
                        ex);
96
                messages.add(ex.getLocalizedMessage());
85 97
                childStatus[count] = status;
86 98
                count++;
87 99
            }
88

  
100
            StringBuffer statusMsg = new StringBuffer();
101
            for(String message : messages) {
102
                statusMsg.append(message);
103
                statusMsg.append(System.lineSeparator());
104
            }
89 105
            MultiStatus multiStatus = new MultiStatus("unknown",
90
                    IStatus.ERROR,
106
                    statusFlag,
91 107
                    childStatus,
92
                    getLabel() + " is in error",
108
                    statusMsg.toString(),
93 109
                    null);
94 110
            return multiStatus;
95 111
        }
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/cdm/model/TaxonNavigatorTest.java
9 9
 */
10 10
package eu.etaxonomy.cdm.model;
11 11

  
12
import java.util.HashSet;
13
import java.util.Set;
12 14
import java.util.UUID;
13 15

  
14 16
import org.apache.log4j.Logger;
......
20 22
import eu.etaxonomy.cdm.api.service.IClassificationService;
21 23
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
22 24
import eu.etaxonomy.cdm.api.service.ITaxonService;
25
import eu.etaxonomy.cdm.model.common.CdmBase;
23 26
import eu.etaxonomy.cdm.model.common.Language;
27
import eu.etaxonomy.cdm.model.description.TaxonDescription;
24 28
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
29
import eu.etaxonomy.cdm.model.taxon.Taxon;
25 30
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
26 31
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingChangeAcceptedTaxonToSynonymOperation;
32
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveFactualDataOperation;
33
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveTaxonOperation;
27 34
import eu.etaxonomy.taxeditor.operations.BaseOperationTest;
28 35

  
29 36
/**
......
45 52

  
46 53

  
47 54
    @Test
48
    public void changeAcceptedTaxonToSynonymTest() throws ExecutionException {
55
    public void testChangeAcceptedTaxonToSynonym() throws ExecutionException {
49 56

  
50 57

  
51 58
        UUID oldTaxonNodeNodeUuid = UUID.fromString("b85b5b78-6760-409f-ac91-bb89e95ff2a1");
......
53 60

  
54 61
        TaxonNode oldTaxonNode = taxonNodeService.load(oldTaxonNodeNodeUuid);
55 62
        TaxonNameBase name = oldTaxonNode.getTaxon().getName();
63

  
64

  
56 65
        TaxonNode newAcceptedTaxonNode = taxonNodeService.load(newAcceptedTaxonNodeUuid);
57
        sessionOwner.addUpdatedObject(oldTaxonNode.getParent());
66
        int countTargetSynonyms = newAcceptedTaxonNode.getTaxon().getSynonyms().size();
67
        sessionOwner.addExpectedUpdatedObject(oldTaxonNode.getParent());
68

  
58 69

  
59
        Assert.assertEquals(0,newAcceptedTaxonNode.getTaxon().getSynonyms().size());
60 70
        operation =  new RemotingChangeAcceptedTaxonToSynonymOperation(sessionOwner,
61 71
                false,
62
                oldTaxonNode,
63
                newAcceptedTaxonNode);
72
                oldTaxonNode.getUuid(),
73
                newAcceptedTaxonNode.getUuid());
64 74
        operation.execute(monitor, info);
65 75
        newAcceptedTaxonNode = taxonNodeService.load(newAcceptedTaxonNodeUuid);
66
        sessionOwner.addUpdatedObject(newAcceptedTaxonNode);
76
        sessionOwner.addExpectedUpdatedObject(newAcceptedTaxonNode);
67 77

  
68 78
        oldTaxonNode = taxonNodeService.load(oldTaxonNodeNodeUuid);
69 79
        Assert.assertNull(oldTaxonNode);
70
        Assert.assertEquals(1,newAcceptedTaxonNode.getTaxon().getSynonyms().size());
80
        Assert.assertEquals(countTargetSynonyms + 1,newAcceptedTaxonNode.getTaxon().getSynonyms().size());
71 81
        Assert.assertEquals(name, newAcceptedTaxonNode.getTaxon().getSynonyms().iterator().next().getName());
72 82

  
73 83

  
74 84
    }
75 85

  
76 86
    @Test
77
    public void moveTaxonTest() {
87
    public void testMoveTaxon() throws ExecutionException {
88

  
89
        UUID taxonNodeToMoveUuid = UUID.fromString("b8439f51-6b96-445a-b401-7a836ba1cf58");
90
        UUID newParentTreeNodeUuid = UUID.fromString("2f05d429-632d-4230-b9cb-70299360b470");
91
        boolean moveToParentNode = true;
92

  
93
        TaxonNode taxonNodeToMove = taxonNodeService.load(taxonNodeToMoveUuid);
94
        TaxonNode oldParent = taxonNodeToMove.getParent();
95
        sessionOwner.addExpectedUpdatedObject(oldParent);
96
        int childCount = oldParent.getCountChildren();
97
        TaxonNode newParentTreeNode = taxonNodeService.load(newParentTreeNodeUuid);
98
        sessionOwner.addExpectedUpdatedObject(newParentTreeNode);
99
        operation = new RemotingMoveTaxonOperation(sessionOwner,
100
                false,
101
                taxonNodeToMove.getUuid(),
102
                newParentTreeNode.getUuid(),
103
                moveToParentNode);
104
        operation.execute(monitor, info);
105
        Assert.assertEquals(childCount-1, oldParent.getCountChildren());
106
        Assert.assertTrue(!oldParent.getChildNodes().contains(taxonNodeToMove));
107
        Assert.assertTrue(newParentTreeNode.getChildNodes().contains(taxonNodeToMove));
108
    }
109

  
110
    @Test
111
    public void testMoveFactualData() throws ExecutionException {
112
        UUID sourceTaxonUuid = UUID.fromString("e40854d7-143f-4054-b229-6ed4cedb4bff");
113
        UUID targetTaxonUuid = UUID.fromString("b8402dc4-5050-4882-a147-01b71e0e47d6");
114

  
115
        Taxon sourceTaxon = CdmBase.deproxy(taxonService.load(sourceTaxonUuid), Taxon.class);
116
        Set<TaxonDescription> sourceDescriptions = new HashSet(sourceTaxon.getDescriptions());
117
        sessionOwner.addExpectedUpdatedObject(sourceTaxon);
78 118

  
119
        Taxon targetTaxon = CdmBase.deproxy(taxonService.load(targetTaxonUuid), Taxon.class);
120
        int countTargetDescriptions = targetTaxon.getDescriptions().size();
121
        sessionOwner.addExpectedUpdatedObject(targetTaxon);
122

  
123
        operation = new RemotingMoveFactualDataOperation(sessionOwner,
124
                false,
125
                sourceTaxonUuid,
126
                targetTaxonUuid);
127
        operation.execute(monitor, info);
128
        Assert.assertEquals(0, sourceTaxon.getDescriptions().size());
129
        Assert.assertEquals(sourceDescriptions.size() + countTargetDescriptions, targetTaxon.getDescriptions().size());
130
        Assert.assertTrue(targetTaxon.getDescriptions().containsAll(sourceDescriptions));
79 131
    }
80 132

  
81 133

  
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/session/MockSessionOwner.java
32 32
        this.updatedObjects = updatedObjects;
33 33
    }
34 34

  
35
    public void addUpdatedObject(T updatedObject) {
35
    public void addExpectedUpdatedObject(T updatedObject) {
36 36
        if(updatedObjects == null) {
37 37
            updatedObjects = new HashSet<T>();
38 38
        }

Also available in: Unified diff