Project

General

Profile

« Previous | Next » 

Revision 2ba67e3f

Added by Cherian Mathew about 9 years ago

EditConceptRelationshipComposite : updated ui, added save + cancel + drag&drop functionality
ConceptRelationshipComposite : using the EditConceptRelationshipComposite
StatusComposite : set drag&drop mode
ConceptRelationshipPresenter, EditConceptRelationshipPresenter : moved create, update, edit methods to EditConceptRelationshipPresenter
ConceptRelationshipPresenterTest, EditConceptRelationshipPresenterTest(xml) : moved tests to EditConceptRelationshipPresenterTest

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/component/ConceptRelationshipComposite.java
9 9
*/
10 10
package eu.etaxonomy.cdm.vaadin.component;
11 11

  
12
import java.util.UUID;
13

  
14 12
import org.json.JSONException;
15 13

  
16 14
import com.vaadin.annotations.AutoGenerated;
17 15
import com.vaadin.ui.Alignment;
18 16
import com.vaadin.ui.Button;
17
import com.vaadin.ui.Button.ClickEvent;
18
import com.vaadin.ui.Button.ClickListener;
19 19
import com.vaadin.ui.CustomComponent;
20 20
import com.vaadin.ui.HorizontalLayout;
21 21
import com.vaadin.ui.Notification;
22 22
import com.vaadin.ui.Notification.Type;
23
import com.vaadin.ui.UI;
23 24
import com.vaadin.ui.VerticalLayout;
25
import com.vaadin.ui.Window;
24 26

  
27
import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
25 28
import eu.etaxonomy.cdm.vaadin.jscomponent.D3ConceptRelationshipTree;
26 29
import eu.etaxonomy.cdm.vaadin.presenter.ConceptRelationshipPresenter;
30
import eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent;
31
import eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener;
27 32
import eu.etaxonomy.cdm.vaadin.session.ISelectionListener;
28 33
import eu.etaxonomy.cdm.vaadin.session.SelectionEvent;
29 34
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinSessionUtilities;
......
34 39
 * @date 9 Apr 2015
35 40
 *
36 41
 */
37
public class ConceptRelationshipComposite extends CustomComponent implements ISelectionListener {
42
public class ConceptRelationshipComposite extends CustomComponent implements ISelectionListener, ICdmChangeListener {
38 43

  
39 44
    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
40 45

  
......
53 58

  
54 59
    private final IConceptRelationshipComponentListener listener;
55 60

  
56
    private UUID currentFromTaxonUuid;
61
    private IdUuidName fromTaxonIun;
62

  
63
    private static final String CREATE_NEW_CR_TITLE = "Create New Concept Relationship";
57 64

  
58 65
    /**
59 66
     * The constructor should first build the main layout, set the
......
67 74
        setCompositionRoot(mainLayout);
68 75

  
69 76
        CdmVaadinSessionUtilities.getCurrentSelectionService().register(this);
77
        CdmVaadinSessionUtilities.getCurrentCdmDataChangeService().register(this);
70 78
        listener = new ConceptRelationshipPresenter(d3ConceptRelationShipTree);
79

  
80
        addUIListeners();
81
        init();
82

  
83
    }
84

  
85

  
86
    private void init() {
87
        initD3ConceptRelationShipTree();
88
    }
89

  
90
    private void initD3ConceptRelationShipTree() {
71 91
        d3ConceptRelationShipTree.setImmediate(true);
92
    }
72 93

  
94
    private void addUIListeners() {
95
        addNewButtonListener();
96
    }
97

  
98
    private void addNewButtonListener() {
99
        newButton.addClickListener(new ClickListener() {
100

  
101
            @Override
102
            public void buttonClick(ClickEvent event) {
103
                showEditConceptRelationshipWindow(CREATE_NEW_CR_TITLE);
104
            }
105
        });
106
    }
107

  
108
    private void showEditConceptRelationshipWindow(String windowTitle) {
109
        Window dialog = new Window(windowTitle);
110
        dialog.setModal(false);
111
        dialog.setClosable(false);
112
        dialog.setResizable(false);
113
        UI.getCurrent().addWindow(dialog);
114

  
115
        EditConceptRelationshipComposite ecrc = new EditConceptRelationshipComposite(dialog,fromTaxonIun, null, null);
116
        dialog.setContent(ecrc);
117
    }
118

  
119
    private void refreshRelationshipView() {
120
        if(fromTaxonIun != null) {
121
            try {
122
                listener.refreshRelationshipView(fromTaxonIun);
123
            } catch (JSONException e) {
124
                Notification.show("Error generating concept relation JSON",  e.getMessage(), Type.WARNING_MESSAGE);
125
            }
126
        }
73 127
    }
74 128

  
75 129
    /* (non-Javadoc)
......
78 132
    @Override
79 133
    public void onSelect(SelectionEvent event) {
80 134
        if(event.getSourceType().equals(StatusComposite.class)) {
81
            currentFromTaxonUuid = (UUID)event.getSelectedObjects().get(0);
82
            try {
83
                listener.refreshRelationshipView(currentFromTaxonUuid);
84
            } catch (JSONException e) {
85
               Notification.show("Error generating concept relation JSON",  e.getMessage(), Type.WARNING_MESSAGE);
86
            }
135
            fromTaxonIun = (IdUuidName)event.getSelectedObjects().get(0);
136
            refreshRelationshipView();
137
        }
138

  
139
    }
140

  
141

  
142

  
143
    /* (non-Javadoc)
144
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onCreate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
145
     */
146
    @Override
147
    public void onCreate(CdmChangeEvent event) {
148
        if(event.getSourceType().equals(EditConceptRelationshipComposite.class)) {
149
            refreshRelationshipView();
87 150
        }
88 151

  
89 152
    }
90 153

  
154

  
155
    /* (non-Javadoc)
156
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onUpdate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
157
     */
158
    @Override
159
    public void onUpdate(CdmChangeEvent event) {
160
        // TODO Auto-generated method stub
161

  
162
    }
163

  
164

  
165
    /* (non-Javadoc)
166
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onDelete(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
167
     */
168
    @Override
169
    public void onDelete(CdmChangeEvent event) {
170
        // TODO Auto-generated method stub
171

  
172
    }
91 173
    @AutoGenerated
92 174
    private VerticalLayout buildMainLayout() {
93 175
        // common part: create layout
......
156 238
        return updateHorizontalLayout;
157 239
    }
158 240

  
241

  
159 242
}
src/main/java/eu/etaxonomy/cdm/vaadin/component/EditConceptRelationshipComposite.java
10 10
package eu.etaxonomy.cdm.vaadin.component;
11 11

  
12 12
import java.sql.SQLException;
13
import java.util.Arrays;
14
import java.util.UUID;
13 15

  
14 16
import com.vaadin.annotations.AutoGenerated;
15
import com.vaadin.server.FontAwesome;
17
import com.vaadin.data.Container.Hierarchical;
18
import com.vaadin.data.Validator.EmptyValueException;
19
import com.vaadin.event.Transferable;
20
import com.vaadin.event.dd.DragAndDropEvent;
21
import com.vaadin.event.dd.DropHandler;
22
import com.vaadin.event.dd.acceptcriteria.AcceptAll;
23
import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
24
import com.vaadin.server.Page;
16 25
import com.vaadin.ui.Alignment;
17 26
import com.vaadin.ui.Button;
27
import com.vaadin.ui.Button.ClickEvent;
28
import com.vaadin.ui.Button.ClickListener;
18 29
import com.vaadin.ui.ComboBox;
19 30
import com.vaadin.ui.CustomComponent;
31
import com.vaadin.ui.DragAndDropWrapper;
20 32
import com.vaadin.ui.HorizontalLayout;
21 33
import com.vaadin.ui.Label;
34
import com.vaadin.ui.Notification;
35
import com.vaadin.ui.Notification.Type;
36
import com.vaadin.ui.TextField;
37
import com.vaadin.ui.TreeTable;
38
import com.vaadin.ui.UI;
22 39
import com.vaadin.ui.VerticalLayout;
40
import com.vaadin.ui.Window;
23 41

  
24 42
import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
43
import eu.etaxonomy.cdm.vaadin.container.LeafNodeTaxonContainer;
25 44
import eu.etaxonomy.cdm.vaadin.presenter.EditConceptRelationshipPresenter;
45
import eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent;
46
import eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent.Action;
47
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinOperation;
48
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinUtilities;
26 49

  
27 50
/**
28 51
 * @author cmathew
......
36 59
    @AutoGenerated
37 60
    private VerticalLayout mainLayout;
38 61
    @AutoGenerated
62
    private CdmProgressComponent cdmProgressComponent;
63
    @AutoGenerated
39 64
    private HorizontalLayout saveCancelHLayout;
40 65
    @AutoGenerated
41 66
    private Button cancelButton;
......
44 69
    @AutoGenerated
45 70
    private HorizontalLayout horizontalLayout;
46 71
    @AutoGenerated
47
    private VerticalLayout toTaxonVLayout;
48
    @AutoGenerated
49
    private Label toTaxonValue;
50
    @AutoGenerated
51
    private Label toTaxonLabeL;
52
    @AutoGenerated
53 72
    private VerticalLayout typeVLayout;
54 73
    @AutoGenerated
55 74
    private ComboBox conceptRComboBox;
......
61 80
    private Label fromTaxonValue;
62 81
    @AutoGenerated
63 82
    private Label fromTaxonLabel;
83
    private VerticalLayout toTaxonVLayout;
84
    private Label toTaxonLabeL;
85
    private TextField toTaxonTextField;
86
    private DragAndDropWrapper toTaxonLayoutWrapper;
87

  
64 88
    private final EditConceptRelationshipPresenter presenter;
65 89

  
66
    private final IdUuidName fromTaxonIdUuidName, taxonRTypeIdUuidName, toTaxonIdUuidName;
90
    private IdUuidName fromTaxonIdUuidName, taxonRTypeIdUuidName, toTaxonIdUuidName;
91

  
92
    private final Window dialog;
67 93

  
68 94
    private final static String CHOOSE_TREL_TYPE = "Choose Type ...";
95
    private final static String DRAG_TAXON_HINT = "Drag Taxon here ...";
69 96

  
70 97
    /**
71 98
     * The constructor should first build the main layout, set the
......
74 101
     * The constructor will not be automatically regenerated by the
75 102
     * visual editor.
76 103
     */
77
    public EditConceptRelationshipComposite(IdUuidName fromTaxonIdUuidName,
104
    public EditConceptRelationshipComposite(Window dialog,
105
            IdUuidName fromTaxonIdUuidName,
78 106
            IdUuidName taxonRTypeIdUuidName,
79 107
            IdUuidName toTaxonIdUuidName) {
108

  
80 109
        buildMainLayout();
110
        buildToTaxon();
81 111
        setCompositionRoot(mainLayout);
82 112

  
83 113
        this.presenter = new EditConceptRelationshipPresenter();
114
        this.dialog = dialog;
84 115
        this.fromTaxonIdUuidName = fromTaxonIdUuidName;
85 116
        this.taxonRTypeIdUuidName = taxonRTypeIdUuidName;
86 117
        this.toTaxonIdUuidName = toTaxonIdUuidName;
87 118

  
119
        addUIListeners();
88 120
        init();
89 121
    }
90 122

  
91 123
    private void init() {
124
        initFromTaxonLabel();
92 125
        initConceptRComboBox();
126
        initToTaxon();
93 127
    }
94 128

  
95 129
    private void initFromTaxonLabel() {
96
        fromTaxonLabel.setValue(fromTaxonIdUuidName.getName());
130
        fromTaxonValue.setValue(fromTaxonIdUuidName.getName());
97 131
    }
98 132

  
99 133
    private void initConceptRComboBox() {
100 134
        conceptRComboBox.setImmediate(true);
135

  
136
        conceptRComboBox.setItemCaptionPropertyId("titleCache");
101 137
        try {
102 138
            conceptRComboBox.setContainerDataSource(presenter.loadTaxonRelationshipTypeContainer());
103 139
        } catch (SQLException e) {
......
111 147
        }
112 148
    }
113 149

  
114
    private void initToTaxonLabel() {
150
    private void buildToTaxon() {
151
        toTaxonVLayout = buildToTaxonVLayout();
152
        toTaxonLayoutWrapper = new DragAndDropWrapper(toTaxonVLayout);
153
        toTaxonLayoutWrapper.setImmediate(false);
154
        toTaxonLayoutWrapper.setWidth("-1px");
155
        toTaxonLayoutWrapper.setHeight("-1px");
156

  
157
        toTaxonLayoutWrapper.setDropHandler(new DropHandler() {
158

  
159
            @Override
160
            public AcceptCriterion getAcceptCriterion() {
161
                return AcceptAll.get();
162
            }
163

  
164
            @Override
165
            public void drop(DragAndDropEvent event) {
166
                // Wrapper for the object that is dragged
167
                Transferable t = event.getTransferable();
168

  
169
                // Make sure the drag source is a status composite tree table
170
                if (t.getSourceComponent() instanceof TreeTable) {
171
                    TreeTable table = (TreeTable)t.getSourceComponent();
172
                    Hierarchical containerDataSource = table.getContainerDataSource();
173
                    if(containerDataSource instanceof LeafNodeTaxonContainer) {
174
                        LeafNodeTaxonContainer lntc = (LeafNodeTaxonContainer)containerDataSource;
175
                        Object sourceItemId = t.getData("itemId");
176
                        String toName = (String)lntc.getProperty(sourceItemId, LeafNodeTaxonContainer.NAME_ID).getValue();
177
                        toTaxonIdUuidName = new IdUuidName(sourceItemId,
178
                                lntc.getUuid(sourceItemId),
179
                                toName);
180
                        toTaxonTextField.setValue(toName);
181
                    }
182
                }
183
            }
184
        });
185

  
186
        horizontalLayout.addComponent(toTaxonLayoutWrapper);
187
        horizontalLayout.setComponentAlignment(toTaxonLayoutWrapper, new Alignment(48));
188

  
189
    }
190

  
191
    private void initToTaxon() {
115 192
        if(toTaxonIdUuidName == null) {
116
            toTaxonValue.setIcon(FontAwesome.QUESTION);
117
            toTaxonValue.setValue("");
193
            toTaxonTextField.setValue(DRAG_TAXON_HINT);
118 194
        } else {
119
            toTaxonValue.setIcon(null);
120
            toTaxonValue.setValue(toTaxonIdUuidName.getName());
195
            toTaxonTextField.setValue(toTaxonIdUuidName.getName());
121 196
        }
122 197
    }
123 198

  
199
    private void addUIListeners() {
200
        addSaveButtonListener();
201
        addCancelButtonListener();
202

  
203
    }
204

  
205
    private void addSaveButtonListener() {
206
        saveButton.addClickListener(new ClickListener() {
207

  
208
            @Override
209
            public void buttonClick(ClickEvent event) {
210

  
211

  
212
                try {
213
                    conceptRComboBox.validate();
214
                    toTaxonTextField.validate();
215
                } catch (EmptyValueException e) {
216
                    Notification notification = new Notification("Invalid input", "Neither Relationship Type nor To Taxon can be empty", Type.WARNING_MESSAGE);
217
                    notification.setDelayMsec(2000);
218
                    notification.show(Page.getCurrent());
219
                    return;
220
                }
221

  
222
                CdmVaadinUtilities.setEnabled(mainLayout, false, null);
223

  
224
                CdmVaadinUtilities.exec(new CdmVaadinOperation(500, cdmProgressComponent) {
225
                    @Override
226
                    public boolean execute() {
227
                        setProgress("Saving New Concept Relationship");
228
                        UUID relTypeUuid = presenter.getTaxonRTypeContainer().getUuid(conceptRComboBox.getValue());
229
                        presenter.createRelationship(fromTaxonIdUuidName.getUuid(), relTypeUuid, toTaxonIdUuidName.getUuid());
230
                        fireEvent(new CdmChangeEvent(Action.Create, Arrays.asList((Object)relTypeUuid), EditConceptRelationshipComposite.class));
231
                        return true;
232
                    }
233

  
234
                    @Override
235
                    public void postOpUIUpdate(boolean success) {
236
                        if(success) {
237
                            UI.getCurrent().removeWindow(dialog);
238
                        } else {
239
                            CdmVaadinUtilities.setEnabled(mainLayout, true, null);
240
                        }
241
                    }
242
                });
243
            }
244
        });
245
    }
246

  
247
    private void addCancelButtonListener() {
248
        cancelButton.addClickListener(new ClickListener() {
249

  
250
            @Override
251
            public void buttonClick(ClickEvent event) {
252
                UI.getCurrent().removeWindow(dialog);
253

  
254
            }
255
        });
256
    }
257

  
258

  
259
    private VerticalLayout buildToTaxonVLayout() {
260
        // common part: create layout
261
        toTaxonVLayout = new VerticalLayout();
262
        toTaxonVLayout.setImmediate(false);
263
        toTaxonVLayout.setWidth("-1px");
264
        toTaxonVLayout.setHeight("-1px");
265
        toTaxonVLayout.setMargin(false);
266
        toTaxonVLayout.setSpacing(true);
267

  
268
        // toTaxonLabeL
269
        toTaxonLabeL = new Label();
270
        toTaxonLabeL.setImmediate(false);
271
        toTaxonLabeL.setWidth("-1px");
272
        toTaxonLabeL.setHeight("-1px");
273
        toTaxonLabeL.setValue("To Taxon");
274
        toTaxonVLayout.addComponent(toTaxonLabeL);
275
        toTaxonVLayout.setComponentAlignment(toTaxonLabeL, new Alignment(48));
276

  
277
        // toTaxonTextField
278
        toTaxonTextField = new TextField();
279
        toTaxonTextField.setImmediate(false);
280
        toTaxonTextField.setWidth("-1px");
281
        toTaxonTextField.setHeight("-1px");
282
        toTaxonTextField.setInvalidAllowed(false);
283
        toTaxonTextField.setRequired(true);
284
        toTaxonTextField.setInputPrompt("Drag Taxon here ...");
285
        toTaxonVLayout.addComponent(toTaxonTextField);
286
        toTaxonVLayout.setComponentAlignment(toTaxonTextField, new Alignment(48));
287

  
288
        return toTaxonVLayout;
289
    }
290

  
124 291
    @AutoGenerated
125 292
    private VerticalLayout buildMainLayout() {
126 293
        // common part: create layout
127 294
        mainLayout = new VerticalLayout();
128 295
        mainLayout.setImmediate(false);
129
        mainLayout.setWidth("640px");
130
        mainLayout.setHeight("140px");
131
        mainLayout.setMargin(true);
296
        mainLayout.setWidth("602px");
297
        mainLayout.setHeight("170px");
298
        mainLayout.setMargin(false);
299
        mainLayout.setSpacing(true);
132 300

  
133 301
        // top-level component properties
134
        setWidth("640px");
135
        setHeight("140px");
302
        setWidth("602px");
303
        setHeight("170px");
136 304

  
137 305
        // horizontalLayout
138 306
        horizontalLayout = buildHorizontalLayout();
......
143 311
        mainLayout.addComponent(saveCancelHLayout);
144 312
        mainLayout.setComponentAlignment(saveCancelHLayout, new Alignment(48));
145 313

  
314
        // cdmProgressComponent
315
        cdmProgressComponent = new CdmProgressComponent();
316
        cdmProgressComponent.setImmediate(false);
317
        cdmProgressComponent.setWidth("-1px");
318
        cdmProgressComponent.setHeight("-1px");
319
        mainLayout.addComponent(cdmProgressComponent);
320
        mainLayout.setComponentAlignment(cdmProgressComponent, new Alignment(48));
321

  
146 322
        return mainLayout;
147 323
    }
148 324

  
......
164 340
        // typeVLayout
165 341
        typeVLayout = buildTypeVLayout();
166 342
        horizontalLayout.addComponent(typeVLayout);
343
        horizontalLayout.setExpandRatio(typeVLayout, 1.0f);
167 344
        horizontalLayout.setComponentAlignment(typeVLayout, new Alignment(48));
168 345

  
169
        // toTaxonVLayout
170
        toTaxonVLayout = buildToTaxonVLayout();
171
        horizontalLayout.addComponent(toTaxonVLayout);
172
        horizontalLayout.setComponentAlignment(toTaxonVLayout, new Alignment(48));
173

  
174 346
        return horizontalLayout;
175 347
    }
176 348

  
......
182 354
        fromTaxonVLayout.setWidth("-1px");
183 355
        fromTaxonVLayout.setHeight("-1px");
184 356
        fromTaxonVLayout.setMargin(false);
357
        fromTaxonVLayout.setSpacing(true);
185 358

  
186 359
        // fromTaxonLabel
187 360
        fromTaxonLabel = new Label();
......
212 385
        typeVLayout.setWidth("-1px");
213 386
        typeVLayout.setHeight("-1px");
214 387
        typeVLayout.setMargin(false);
388
        typeVLayout.setSpacing(true);
215 389

  
216 390
        // typeLabel
217 391
        typeLabel = new Label();
......
227 401
        conceptRComboBox.setImmediate(false);
228 402
        conceptRComboBox.setWidth("-1px");
229 403
        conceptRComboBox.setHeight("-1px");
404
        conceptRComboBox.setRequired(true);
230 405
        typeVLayout.addComponent(conceptRComboBox);
231 406
        typeVLayout.setComponentAlignment(conceptRComboBox, new Alignment(48));
232 407

  
233 408
        return typeVLayout;
234 409
    }
235 410

  
236
    @AutoGenerated
237
    private VerticalLayout buildToTaxonVLayout() {
238
        // common part: create layout
239
        toTaxonVLayout = new VerticalLayout();
240
        toTaxonVLayout.setImmediate(false);
241
        toTaxonVLayout.setWidth("-1px");
242
        toTaxonVLayout.setHeight("-1px");
243
        toTaxonVLayout.setMargin(false);
244

  
245
        // toTaxonLabeL
246
        toTaxonLabeL = new Label();
247
        toTaxonLabeL.setImmediate(false);
248
        toTaxonLabeL.setWidth("-1px");
249
        toTaxonLabeL.setHeight("-1px");
250
        toTaxonLabeL.setValue("To Taxon");
251
        toTaxonVLayout.addComponent(toTaxonLabeL);
252
        toTaxonVLayout.setComponentAlignment(toTaxonLabeL, new Alignment(48));
253

  
254
        // toTaxonValue
255
        toTaxonValue = new Label();
256
        toTaxonValue.setImmediate(false);
257
        toTaxonValue.setWidth("-1px");
258
        toTaxonValue.setHeight("-1px");
259
        toTaxonValue.setValue("Taxon Name");
260
        toTaxonVLayout.addComponent(toTaxonValue);
261
        toTaxonVLayout.setComponentAlignment(toTaxonValue, new Alignment(48));
262

  
263
        return toTaxonVLayout;
264
    }
265

  
266 411
    @AutoGenerated
267 412
    private HorizontalLayout buildSaveCancelHLayout() {
268 413
        // common part: create layout
src/main/java/eu/etaxonomy/cdm/vaadin/component/NewTaxonBaseComposite.java
114 114
    }
115 115

  
116 116
    public void init() {
117

  
118 117
        initSecComboBox();
119

  
120 118
    }
121 119

  
122

  
123 120
    private void initSecComboBox() {
124 121

  
125 122
        secComboBox.setNullSelectionAllowed(false);
src/main/java/eu/etaxonomy/cdm/vaadin/component/StatusComposite.java
49 49
import com.vaadin.ui.Notification.Type;
50 50
import com.vaadin.ui.Table;
51 51
import com.vaadin.ui.Table.ColumnHeaderMode;
52
import com.vaadin.ui.Table.TableDragMode;
52 53
import com.vaadin.ui.TextField;
53 54
import com.vaadin.ui.TreeTable;
54 55
import com.vaadin.ui.UI;
......
176 177
        taxaTreeTable.setSelectable(true);
177 178
        taxaTreeTable.setMultiSelect(taxaTreeTableMultiSelectMode);
178 179
        taxaTreeTable.setImmediate(false);
179

  
180
        taxaTreeTable.setDragMode(TableDragMode.ROW);
180 181
        if(listener != null) {
181 182
            List<String> columnIds = new ArrayList<String>();
182 183
            columnIds.add(LeafNodeTaxonContainer.NAME_ID);
......
184 185
            columnIds.add(LeafNodeTaxonContainer.PB_ID);
185 186
            taxaTreeTable.setColumnWidth(LeafNodeTaxonContainer.PB_ID, 25);
186 187

  
187

  
188 188
            taxaTreeTable.addGeneratedColumn(LeafNodeTaxonContainer.PB_ID, new TaxonTableCheckBoxGenerator());
189 189
            try {
190 190
                taxaTreeTable.setContainerDataSource(listener.loadTaxa(classificationId), columnIds);
191 191
            } catch (SQLException e) {
192
              //TODO : throw up warning dialog
192
                //TODO : throw up warning dialog
193 193
                e.printStackTrace();
194 194
            }
195 195

  
......
223 223
        taxaTreeTable.addActionHandler(new Action.Handler() {
224 224
            @Override
225 225
            public Action[] getActions(final Object target, final Object sender) {
226
                    return new Action[] { changeAcceptedTaxonToSynonymAction };
226
                return new Action[] { changeAcceptedTaxonToSynonymAction };
227 227
            }
228 228

  
229 229
            @Override
......
346 346
            @Override
347 347
            public void layoutClick(LayoutClickEvent event) {
348 348
                if (event.getChildComponent() == searchTextField && searchTextField.getValue().equals(FILTER_TAXA_INPUT)) {
349
                   searchTextField.setValue("");
349
                    searchTextField.setValue("");
350 350
                }
351 351
            }
352 352
        });
......
388 388
                Object itemId = event.getItemId();
389 389
                if(!listener.isSynonym(itemId)) {
390 390
                    UUID taxonUuid = listener.getCurrentLeafNodeTaxonContainer().getUuid(itemId);
391
                    String taxonName = (String)listener.getCurrentLeafNodeTaxonContainer().getProperty(itemId, LeafNodeTaxonContainer.NAME_ID).getValue();
392
                    Object idUuidName = new IdUuidName(itemId, taxonUuid, taxonName);
391 393
                    CdmVaadinSessionUtilities.getCurrentSelectionService()
392
                    .fireSelectionEvent(new SelectionEvent(Arrays.asList((Object)taxonUuid), StatusComposite.class), true);
394
                    .fireSelectionEvent(new SelectionEvent(Arrays.asList(idUuidName), StatusComposite.class), true);
393 395
                }
394 396
                taxaTreeTable.setValue(itemId);
395 397
            }
......
476 478

  
477 479
            @Override
478 480
            public void textChange(TextChangeEvent event) {
479
               listener.setNameFilter(event.getText());
480
               updateInViewLabel();
481
                listener.setNameFilter(event.getText());
482
                updateInViewLabel();
481 483
            }
482 484

  
483 485
        });
......
489 491

  
490 492
            @Override
491 493
            public void buttonClick(ClickEvent event) {
492
               clearDynamicFilters();
493
               updateInViewLabel();
494
                clearDynamicFilters();
495
                updateInViewLabel();
494 496
            }
495 497

  
496 498
        });
......
509 511

  
510 512
            @Override
511 513
            public void buttonClick(ClickEvent event) {
512
               Set<Object> selectedItemIds = (Set)taxaTreeTable.getValue();
513
               if(selectedItemIds.isEmpty()) {
514
                   Notification.show("No Taxa / Synonyms selected", "Please select taxa or synonyms to delete", Type.WARNING_MESSAGE);
515
               } else {
516
                   Notification.show("Deleting selected Taxa / Synonyms", "Implement me", Type.WARNING_MESSAGE);
517
               }
514
                Set<Object> selectedItemIds = (Set)taxaTreeTable.getValue();
515
                if(selectedItemIds.isEmpty()) {
516
                    Notification.show("No Taxa / Synonyms selected", "Please select taxa or synonyms to delete", Type.WARNING_MESSAGE);
517
                } else {
518
                    Notification.show("Deleting selected Taxa / Synonyms", "Implement me", Type.WARNING_MESSAGE);
519
                }
518 520
            }
519 521

  
520 522
        });
src/main/java/eu/etaxonomy/cdm/vaadin/jscomponent/D3ConceptRelationshipTree.java
56 56

  
57 57
    }
58 58

  
59
    public void updateConceptRelationshipTree(Taxon fromTaxon) throws JSONException {
59

  
60
    public void update(Taxon fromTaxon) throws JSONException {
60 61
        Set<TaxonRelationship> relationsFromThisTaxon = fromTaxon.getRelationsFromThisTaxon();
61 62

  
62 63
        Map<TaxonRelationshipType, List<Taxon>> relToTaxonMap = new HashMap<TaxonRelationshipType, List<Taxon>>();
......
107 108
        }
108 109

  
109 110

  
110
        setConceptRelationshipTree(fromTaxonJO.toString());;
111
        setConceptRelationshipTree(fromTaxonJO.toString());
111 112
    }
112 113

  
113 114
    public void setConceptRelationshipTree(String conceptRelationshipTree) {
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/ConceptRelationshipPresenter.java
9 9
*/
10 10
package eu.etaxonomy.cdm.vaadin.presenter;
11 11

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

  
15 12
import org.json.JSONException;
16 13
import org.springframework.transaction.TransactionStatus;
17 14

  
18 15
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
19 16
import eu.etaxonomy.cdm.api.service.ITaxonService;
20
import eu.etaxonomy.cdm.api.service.ITermService;
21 17
import eu.etaxonomy.cdm.model.common.CdmBase;
22 18
import eu.etaxonomy.cdm.model.taxon.Taxon;
23
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
24
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
25 19
import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
26 20
import eu.etaxonomy.cdm.vaadin.jscomponent.D3ConceptRelationshipTree;
27 21
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
......
37 31

  
38 32
    private final D3ConceptRelationshipTree crTree;
39 33
    private final ITaxonService taxonService;
40
    private final ITermService termService;
34

  
41 35
    private final ICdmApplicationConfiguration app;
42 36

  
43 37

  
......
45 39
        this.crTree = crTree;
46 40

  
47 41
        taxonService = CdmSpringContextHelper.getTaxonService();
48
        termService = CdmSpringContextHelper.getTermService();
49 42
        app = CdmSpringContextHelper.getApplicationConfiguration();
50 43
    }
51 44

  
52 45
    @Override
53
    public void refreshRelationshipView(UUID taxonUuid) throws JSONException {
46
    public void refreshRelationshipView(IdUuidName taxonIun) throws JSONException {
54 47
        TransactionStatus tx = app.startTransaction();
55
        Taxon taxon = CdmBase.deproxy(taxonService.load(taxonUuid), Taxon.class);
56
        crTree.updateConceptRelationshipTree(taxon);
48
        Taxon taxon = CdmBase.deproxy(taxonService.load(taxonIun.getUuid()), Taxon.class);
49
        crTree.update(taxon);
57 50
        app.commitTransaction(tx);
58 51
    }
59 52

  
60
    public IdUuidName createRelationship(UUID fromTaxonUuid, UUID relTypeUuid, UUID toTaxonUuid) {
61
        TransactionStatus tx = app.startTransaction();
62
        Taxon fromTaxon = CdmBase.deproxy(taxonService.load(fromTaxonUuid), Taxon.class);
63
        Taxon toTaxon = CdmBase.deproxy(taxonService.load(toTaxonUuid), Taxon.class);
64
        TaxonRelationshipType relType = CdmBase.deproxy(termService.load(relTypeUuid), TaxonRelationshipType.class);
65
        TaxonRelationship tr = fromTaxon.addTaxonRelation(toTaxon, relType, null, null);
66
        app.commitTransaction(tx);
67
        return new IdUuidName(tr.getId(), tr.getUuid(), tr.getType().getTitleCache());
68
    }
69

  
70
    public void updateRelationship(UUID fromTaxonUuid, UUID taxonRelUuid, UUID newRelTypeUuid , UUID newToTaxonUuid) {
71
        TransactionStatus tx = app.startTransaction();
72
        Taxon fromTaxon = CdmBase.deproxy(taxonService.load(fromTaxonUuid), Taxon.class);
73
        for(TaxonRelationship tr : fromTaxon.getRelationsFromThisTaxon()) {
74
            if(tr.getUuid().equals(taxonRelUuid)) {
75
                if(newRelTypeUuid != null) {
76
                    TaxonRelationshipType relType = CdmBase.deproxy(termService.load(newRelTypeUuid), TaxonRelationshipType.class);
77
                    tr.setType(relType);
78
                }
79
                if(newToTaxonUuid != null) {
80
                    Taxon toTaxon = CdmBase.deproxy(taxonService.load(newToTaxonUuid), Taxon.class);
81
                    tr.setToTaxon(toTaxon);
82
                }
83
            }
84
        }
85
        app.commitTransaction(tx);
86
    }
87

  
88
    public void deleteRelationship(UUID fromTaxonUuid, UUID taxonRelUuid) {
89
        TransactionStatus tx = app.startTransaction();
90
        Taxon fromTaxon = CdmBase.deproxy(taxonService.load(fromTaxonUuid), Taxon.class);
91
        TaxonRelationship trToDelete = null;
92
        Set<TaxonRelationship> trList = fromTaxon.getRelationsFromThisTaxon();
93
        for(TaxonRelationship tr : trList) {
94
            if(tr.getUuid().equals(taxonRelUuid)) {
95
                trToDelete = tr;
96
            }
97
        }
98
        if(trToDelete != null) {
99
            trList.remove(trToDelete);
100
        }
101
        app.commitTransaction(tx);
102
    }
103 53

  
104 54
}
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/EditConceptRelationshipPresenter.java
10 10
package eu.etaxonomy.cdm.vaadin.presenter;
11 11

  
12 12
import java.sql.SQLException;
13
import java.util.Set;
14
import java.util.UUID;
15

  
16
import org.springframework.transaction.TransactionStatus;
13 17

  
14 18
import com.vaadin.data.util.filter.Compare;
15 19

  
20
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
21
import eu.etaxonomy.cdm.api.service.ITaxonService;
22
import eu.etaxonomy.cdm.api.service.ITermService;
23
import eu.etaxonomy.cdm.model.common.CdmBase;
24
import eu.etaxonomy.cdm.model.taxon.Taxon;
25
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
26
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
16 27
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
28
import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
29
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
17 30

  
18 31
/**
19 32
 * @author cmathew
......
25 38
    private CdmSQLContainer taxonRTypeContainer;
26 39
    private CdmSQLContainer taxonRContainer;
27 40

  
41
    private final ITaxonService taxonService;
42
    private final ITermService termService;
43
    private final ICdmApplicationConfiguration app;
44

  
45
    public EditConceptRelationshipPresenter() {
46
        taxonService = CdmSpringContextHelper.getTaxonService();
47
        termService = CdmSpringContextHelper.getTermService();
48
        app = CdmSpringContextHelper.getApplicationConfiguration();
49
    }
28 50

  
29 51
    public CdmSQLContainer loadTaxonRelationshipTypeContainer() throws SQLException {
30 52
        taxonRTypeContainer = CdmSQLContainer.newInstance("DefinedTermBase");
31 53
        taxonRTypeContainer.addContainerFilter(new Compare.Equal("DTYPE","TaxonRelationshipType"));
54
        taxonRTypeContainer.setPageLength(100);
32 55
        return taxonRTypeContainer;
33 56
    }
34 57

  
......
46 69
        return taxonRContainer;
47 70
    }
48 71

  
72
    public IdUuidName createRelationship(UUID fromTaxonUuid, UUID relTypeUuid, UUID toTaxonUuid) {
73
        TransactionStatus tx = app.startTransaction();
74
        Taxon fromTaxon = CdmBase.deproxy(taxonService.load(fromTaxonUuid), Taxon.class);
75
        Taxon toTaxon = CdmBase.deproxy(taxonService.load(toTaxonUuid), Taxon.class);
76
        TaxonRelationshipType relType = CdmBase.deproxy(termService.load(relTypeUuid), TaxonRelationshipType.class);
77
        TaxonRelationship tr = fromTaxon.addTaxonRelation(toTaxon, relType, null, null);
78
        app.commitTransaction(tx);
79
        return new IdUuidName(tr.getId(), tr.getUuid(), tr.getType().getTitleCache());
80
    }
81

  
82

  
83
    public void updateRelationship(UUID fromTaxonUuid, UUID taxonRelUuid, UUID newRelTypeUuid , UUID newToTaxonUuid) {
84
        TransactionStatus tx = app.startTransaction();
85
        Taxon fromTaxon = CdmBase.deproxy(taxonService.load(fromTaxonUuid), Taxon.class);
86
        for(TaxonRelationship tr : fromTaxon.getRelationsFromThisTaxon()) {
87
            if(tr.getUuid().equals(taxonRelUuid)) {
88
                if(newRelTypeUuid != null) {
89
                    TaxonRelationshipType relType = CdmBase.deproxy(termService.load(newRelTypeUuid), TaxonRelationshipType.class);
90
                    tr.setType(relType);
91
                }
92
                if(newToTaxonUuid != null) {
93
                    Taxon toTaxon = CdmBase.deproxy(taxonService.load(newToTaxonUuid), Taxon.class);
94
                    tr.setToTaxon(toTaxon);
95
                }
96
            }
97
        }
98
        app.commitTransaction(tx);
99
    }
100

  
101

  
102
    public void deleteRelationship(UUID fromTaxonUuid, UUID taxonRelUuid) {
103
        TransactionStatus tx = app.startTransaction();
104
        Taxon fromTaxon = CdmBase.deproxy(taxonService.load(fromTaxonUuid), Taxon.class);
105
        TaxonRelationship trToDelete = null;
106
        Set<TaxonRelationship> trList = fromTaxon.getRelationsFromThisTaxon();
107
        for(TaxonRelationship tr : trList) {
108
            if(tr.getUuid().equals(taxonRelUuid)) {
109
                trToDelete = tr;
110
            }
111
        }
112
        if(trToDelete != null) {
113
            trList.remove(trToDelete);
114
        }
115
        app.commitTransaction(tx);
116
    }
117

  
49 118
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/IConceptRelationshipComponentListener.java
9 9
*/
10 10
package eu.etaxonomy.cdm.vaadin.view;
11 11

  
12
import java.util.UUID;
13

  
14 12
import org.json.JSONException;
15 13

  
14
import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
15

  
16 16
/**
17 17
 * @author cmathew
18 18
 * @date 9 Apr 2015
......
24 24
     * @param taxonUuid
25 25
     * @throws JSONException
26 26
     */
27
    public void refreshRelationshipView(UUID taxonUuid) throws JSONException;
27
    public void refreshRelationshipView(IdUuidName taxonUuid) throws JSONException;
28

  
28 29

  
29 30
}
src/test/java/eu/etaxonomy/cdm/vaadin/presenter/ConceptRelationshipPresenterTest.java
9 9
*/
10 10
package eu.etaxonomy.cdm.vaadin.presenter;
11 11

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

  
16 14
import org.apache.log4j.Logger;
......
21 19
import org.junit.Test;
22 20
import org.unitils.dbunit.annotation.DataSet;
23 21

  
24
import eu.etaxonomy.cdm.model.common.CdmBase;
25
import eu.etaxonomy.cdm.model.taxon.Taxon;
26
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
27 22
import eu.etaxonomy.cdm.vaadin.CdmVaadinBaseTest;
28 23
import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
29 24
import eu.etaxonomy.cdm.vaadin.jscomponent.D3ConceptRelationshipTree;
30
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
31 25

  
32 26
/**
33 27
 * @author cmathew
......
42 36
    private static ConceptRelationshipPresenter crp;
43 37
    private static D3ConceptRelationshipTree crTree;
44 38

  
45
    private static List<String> FROM_TAXON_INIT_STRATEGY = Arrays.asList(new String []{
46
            "relationsFromThisTaxon"
47
    });
48

  
49 39
    @BeforeClass
50 40
    public static void init() {
51 41
        crTree = new D3ConceptRelationshipTree();
......
56 46
    @Test
57 47
    public void testRefreshRelationshipView() throws JSONException {
58 48
        UUID taxonUuid = UUID.fromString("5f713f69-e03e-4a11-8a55-700fbbf44805");
59
        crp.refreshRelationshipView(taxonUuid);
49
        crp.refreshRelationshipView(new IdUuidName(null, taxonUuid, null));
60 50
        String expected = "{\"name\":\"Taxon D sec. ???\",\"children\":[{\"name\":\"Includes\",\"children\":[{\"name\":\"Taxon A sec. Journal Reference 1\",\"uuid\":\"eaac797e-cac7-4649-97cf-c7b580076895\"},{\"name\":\"Taxon B sec. ???\",\"uuid\":\"77e7d93e-75c6-4dd4-850d-7b5809654378\"}],\"uuid\":\"0501c385-cab1-4fbe-b945-fc747419bb13\"},{\"name\":\"Excludes\",\"children\":[{\"name\":\"Taxon C sec. ???\",\"uuid\":\"3d71c8b8-3bec-4f5f-ba23-6f9d55ef84e9\"}],\"uuid\":\"4535a63c-4a3f-4d69-9350-7bf02e2c23be\"}],\"uuid\":\"5f713f69-e03e-4a11-8a55-700fbbf44805\"}";
61 51
        Assert.assertEquals(expected, crTree.getState().getConceptRelationshipTree());
62 52

  
63 53
        taxonUuid = UUID.fromString("3d71c8b8-3bec-4f5f-ba23-6f9d55ef84e9");
64
        crp.refreshRelationshipView(taxonUuid);
54
        crp.refreshRelationshipView(new IdUuidName(null, taxonUuid, null));
65 55
        expected = "{\"name\":\"Taxon C sec. ???\",\"uuid\":\"3d71c8b8-3bec-4f5f-ba23-6f9d55ef84e9\"}";
66 56
        Assert.assertEquals(expected, crTree.getState().getConceptRelationshipTree());
67 57
    }
68 58

  
69
    @Test
70
    public void testCreateRelationship() {
71
        UUID fromTaxonUuid = UUID.fromString("77e7d93e-75c6-4dd4-850d-7b5809654378");
72
        UUID toTaxonUuid = UUID.fromString("5004a8e7-b907-4744-b67e-44ccb057ab3b");
73
        UUID relTypeUuid = UUID.fromString("60974c98-64ab-4574-bb5c-c110f6db634d");
74

  
75
        IdUuidName trId = crp.createRelationship(fromTaxonUuid, relTypeUuid, toTaxonUuid);
76

  
77
        Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
78
        Assert.assertEquals(1, taxon.getRelationsFromThisTaxon().size());
79

  
80
        Assert.assertEquals(trId.getUuid(),taxon.getRelationsFromThisTaxon().iterator().next().getUuid());
81
    }
82

  
83
    @Test
84
    public void testUpdateRelationship() {
85
        UUID fromTaxonUuid = UUID.fromString("666b484f-dc1e-4578-b404-86bc6d2e47fa");
86
        UUID taxonRelUuid = UUID.fromString("9634d870-bab1-4fdc-8845-c7e71aa8dc6b");
87
        UUID newToTaxonUuid = UUID.fromString("5004a8e7-b907-4744-b67e-44ccb057ab3b");
88
        UUID newRelTypeUuid = UUID.fromString("a8f03491-2ad6-4fae-a04c-2a4c117a2e9b");
89

  
90
        Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
91
        TaxonRelationship tr = getFromRelwithUuid(taxon, taxonRelUuid);
92

  
93
        UUID oldToTaxonUuid = tr.getToTaxon().getUuid();
94
        UUID oldRelTypeUuid = tr.getType().getUuid();
95

  
96
        Assert.assertNotNull(tr);
97
        Assert.assertNotEquals(newToTaxonUuid, oldToTaxonUuid);
98
        Assert.assertNotEquals(newRelTypeUuid, oldRelTypeUuid);
99

  
100
        // change both to taxon and relationship type
101
        crp.updateRelationship(fromTaxonUuid, taxonRelUuid, newRelTypeUuid, newToTaxonUuid);
102
        taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
103
        tr = getFromRelwithUuid(taxon, taxonRelUuid);
104

  
105
        Assert.assertNotNull(tr);
106
        Assert.assertEquals(newToTaxonUuid, tr.getToTaxon().getUuid());
107
        Assert.assertEquals(newRelTypeUuid, tr.getType().getUuid());
108

  
109
        // reset old values
110
        crp.updateRelationship(fromTaxonUuid, taxonRelUuid, oldRelTypeUuid, oldToTaxonUuid);
111

  
112
        // change only relationship type
113
        crp.updateRelationship(fromTaxonUuid, taxonRelUuid, newRelTypeUuid, null);
114
        taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
115
        tr = getFromRelwithUuid(taxon, taxonRelUuid);
116

  
117
        Assert.assertNotNull(tr);
118
        Assert.assertEquals(oldToTaxonUuid, tr.getToTaxon().getUuid());
119
        Assert.assertEquals(newRelTypeUuid, tr.getType().getUuid());
120

  
121
        // reset old values
122
        crp.updateRelationship(fromTaxonUuid, taxonRelUuid, oldRelTypeUuid, oldToTaxonUuid);
123

  
124
        // change only to taxon
125
        crp.updateRelationship(fromTaxonUuid, taxonRelUuid, null, newToTaxonUuid);
126
        taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
127
        tr = getFromRelwithUuid(taxon, taxonRelUuid);
128

  
129
        Assert.assertNotNull(tr);
130
        Assert.assertEquals(newToTaxonUuid, tr.getToTaxon().getUuid());
131
        Assert.assertEquals(oldRelTypeUuid, tr.getType().getUuid());
132

  
133
    }
134

  
135
    @Test
136
    public void testDeleteRelationship() {
137
        UUID fromTaxonUuid = UUID.fromString("5f713f69-e03e-4a11-8a55-700fbbf44805");
138
        UUID taxonRelUuid = UUID.fromString("cac9fa65-9b15-445f-80e4-56f77952f7ec");
139

  
140
        crp.deleteRelationship(fromTaxonUuid, taxonRelUuid);
141
        Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
142
        Assert.assertEquals(3, taxon.getRelationsFromThisTaxon().size());
143

  
144
        TaxonRelationship tr = getFromRelwithUuid(taxon, taxonRelUuid);
145
        Assert.assertNull(tr);
146

  
147
        fromTaxonUuid = UUID.fromString("666b484f-dc1e-4578-b404-86bc6d2e47fa");
148
        taxonRelUuid = UUID.fromString("9634d870-bab1-4fdc-8845-c7e71aa8dc6b");
149

  
150
        crp.deleteRelationship(fromTaxonUuid, taxonRelUuid);
151
        taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
152
        Assert.assertEquals(0, taxon.getRelationsFromThisTaxon().size());
153
    }
154

  
155
    public TaxonRelationship getFromRelwithUuid(Taxon taxon, UUID taxonRelUuid) {
156
        for(TaxonRelationship tr : taxon.getRelationsFromThisTaxon()) {
157
            if(tr.getUuid().equals(taxonRelUuid)) {
158
                return tr;
159
            }
160
        }
161
        return null;
162
    }
163 59
}
src/test/java/eu/etaxonomy/cdm/vaadin/presenter/EditConceptRelationshipPresenterTest.java
10 10
package eu.etaxonomy.cdm.vaadin.presenter;
11 11

  
12 12
import java.sql.SQLException;
13
import java.util.Arrays;
14
import java.util.List;
15
import java.util.UUID;
13 16

  
14 17
import org.apache.log4j.Logger;
15 18
import org.junit.Assert;
......
17 20
import org.junit.Test;
18 21
import org.unitils.dbunit.annotation.DataSet;
19 22

  
23
import eu.etaxonomy.cdm.model.common.CdmBase;
24
import eu.etaxonomy.cdm.model.taxon.Taxon;
25
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
20 26
import eu.etaxonomy.cdm.vaadin.CdmVaadinBaseTest;
21 27
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
28
import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
29
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
22 30

  
23 31
/**
24 32
 * @author cmathew
25 33
 * @date 13 Apr 2015
26 34
 *
27 35
 */
28
@DataSet("ConceptRelationshipPresenterTest.xml")
36
@DataSet
29 37
public class EditConceptRelationshipPresenterTest extends CdmVaadinBaseTest {
30 38

  
31 39
    private static final Logger logger = Logger.getLogger(EditConceptRelationshipPresenterTest.class);
32 40
    public static EditConceptRelationshipPresenter ecrp;
33 41

  
42
    private static List<String> FROM_TAXON_INIT_STRATEGY = Arrays.asList(new String []{
43
            "relationsFromThisTaxon"
44
    });
34 45

  
35 46
    @BeforeClass
36 47
    public static void init() {
......
43 54
        Assert.assertEquals(27, container.size());
44 55
    }
45 56

  
57

  
58
    @Test
59
    public void testCreateRelationship() {
60
        UUID fromTaxonUuid = UUID.fromString("77e7d93e-75c6-4dd4-850d-7b5809654378");
61
        UUID toTaxonUuid = UUID.fromString("5004a8e7-b907-4744-b67e-44ccb057ab3b");
62
        UUID relTypeUuid = UUID.fromString("60974c98-64ab-4574-bb5c-c110f6db634d");
63

  
64
        IdUuidName trId =ecrp.createRelationship(fromTaxonUuid, relTypeUuid, toTaxonUuid);
65

  
66
        Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
67
        Assert.assertEquals(1, taxon.getRelationsFromThisTaxon().size());
68

  
69
        Assert.assertEquals(trId.getUuid(),taxon.getRelationsFromThisTaxon().iterator().next().getUuid());
70
    }
71

  
72
    @Test
73
    public void testUpdateRelationship() {
74
        UUID fromTaxonUuid = UUID.fromString("666b484f-dc1e-4578-b404-86bc6d2e47fa");
75
        UUID taxonRelUuid = UUID.fromString("9634d870-bab1-4fdc-8845-c7e71aa8dc6b");
76
        UUID newToTaxonUuid = UUID.fromString("5004a8e7-b907-4744-b67e-44ccb057ab3b");
77
        UUID newRelTypeUuid = UUID.fromString("a8f03491-2ad6-4fae-a04c-2a4c117a2e9b");
78

  
79
        Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
80
        TaxonRelationship tr = getFromRelwithUuid(taxon, taxonRelUuid);
81

  
82
        UUID oldToTaxonUuid = tr.getToTaxon().getUuid();
83
        UUID oldRelTypeUuid = tr.getType().getUuid();
84

  
85
        Assert.assertNotNull(tr);
86
        Assert.assertNotEquals(newToTaxonUuid, oldToTaxonUuid);
87
        Assert.assertNotEquals(newRelTypeUuid, oldRelTypeUuid);
88

  
89
        // change both to taxon and relationship type
90
       ecrp.updateRelationship(fromTaxonUuid, taxonRelUuid, newRelTypeUuid, newToTaxonUuid);
91
        taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
92
        tr = getFromRelwithUuid(taxon, taxonRelUuid);
93

  
94
        Assert.assertNotNull(tr);
95
        Assert.assertEquals(newToTaxonUuid, tr.getToTaxon().getUuid());
96
        Assert.assertEquals(newRelTypeUuid, tr.getType().getUuid());
97

  
98
        // reset old values
99
       ecrp.updateRelationship(fromTaxonUuid, taxonRelUuid, oldRelTypeUuid, oldToTaxonUuid);
100

  
101
        // change only relationship type
102
       ecrp.updateRelationship(fromTaxonUuid, taxonRelUuid, newRelTypeUuid, null);
103
        taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
104
        tr = getFromRelwithUuid(taxon, taxonRelUuid);
105

  
106
        Assert.assertNotNull(tr);
107
        Assert.assertEquals(oldToTaxonUuid, tr.getToTaxon().getUuid());
108
        Assert.assertEquals(newRelTypeUuid, tr.getType().getUuid());
109

  
110
        // reset old values
111
       ecrp.updateRelationship(fromTaxonUuid, taxonRelUuid, oldRelTypeUuid, oldToTaxonUuid);
112

  
113
        // change only to taxon
114
       ecrp.updateRelationship(fromTaxonUuid, taxonRelUuid, null, newToTaxonUuid);
115
        taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
116
        tr = getFromRelwithUuid(taxon, taxonRelUuid);
117

  
118
        Assert.assertNotNull(tr);
119
        Assert.assertEquals(newToTaxonUuid, tr.getToTaxon().getUuid());
120
        Assert.assertEquals(oldRelTypeUuid, tr.getType().getUuid());
121

  
122
    }
123

  
46 124
    @Test
47
    public void testLoadTaxonRelationshipContainer() throws SQLException {
48
        CdmSQLContainer container = ecrp.loadTaxonRelationshipContainer(30);
49
        Assert.assertEquals(3, container.size());
125
    public void testDeleteRelationship() {
126
        UUID fromTaxonUuid = UUID.fromString("5f713f69-e03e-4a11-8a55-700fbbf44805");
127
        UUID taxonRelUuid = UUID.fromString("cac9fa65-9b15-445f-80e4-56f77952f7ec");
128

  
129
       ecrp.deleteRelationship(fromTaxonUuid, taxonRelUuid);
130
        Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
131
        Assert.assertEquals(3, taxon.getRelationsFromThisTaxon().size());
132

  
133
        TaxonRelationship tr = getFromRelwithUuid(taxon, taxonRelUuid);
134
        Assert.assertNull(tr);
135

  
136
        fromTaxonUuid = UUID.fromString("666b484f-dc1e-4578-b404-86bc6d2e47fa");
137
        taxonRelUuid = UUID.fromString("9634d870-bab1-4fdc-8845-c7e71aa8dc6b");
138

  
139
       ecrp.deleteRelationship(fromTaxonUuid, taxonRelUuid);
140
        taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(fromTaxonUuid,FROM_TAXON_INIT_STRATEGY),Taxon.class);
141
        Assert.assertEquals(0, taxon.getRelationsFromThisTaxon().size());
142
    }
143

  
144
    public TaxonRelationship getFromRelwithUuid(Taxon taxon, UUID taxonRelUuid) {
145
        for(TaxonRelationship tr : taxon.getRelationsFromThisTaxon()) {
146
            if(tr.getUuid().equals(taxonRelUuid)) {
147
                return tr;
148
            }
149
        }
150
        return null;
50 151
    }
51 152
}
src/test/resources/eu/etaxonomy/cdm/vaadin/presenter/EditConceptRelationshipPresenterTest.xml
1
<?xml version="1.0" encoding="UTF-8"?><!--
2
  generated by Jailer 4.3, Thu Apr 16 11:02:58 CEST 2015 from cmathew@cmbgbm-t530
3
  
4
  Extraction Model:  TaxonBase where DTYPE="Taxon" (extractionmodel/by-example/SbE-TaxonBase-11-02-08-379.csv)
5
  Database URL:      jdbc:mysql://127.0.0.1:3306/local-redlist
6
  Database User:     root
7
  
8
  Exported Rows:     25
9
      Reference                      2
10
      TaxonBase                      9
11
      TaxonNameBase                  9
12
      TaxonRelationship              5
13
  
14
--><dataset>
15
  <TaxonBase DTYPE="Taxon" id="10" created="2015-03-09 15:49:22.0" uuid="666b484f-dc1e-4578-b404-86bc6d2e47fa" updated="2015-03-09 15:49:25.0" protectedtitlecache="false" titleCache="Taxon A sec. Book Reference 1" doubtful="false" publish="false" usenamecache="false" excluded="false" taxonstatusunknown="false" taxonomicchildrencount="0" unplaced="true" createdby_id="10" updatedby_id="10"  sec_id="20"/>
16
  <TaxonBase DTYPE="Taxon" id="13" created="2015-03-09 15:51:11.0" uuid="77e7d93e-75c6-4dd4-850d-7b5809654378" updated="2015-03-09 15:51:14.0" protectedtitlecache="false" titleCache="Taxon B sec. ???" doubtful="false" publish="true" usenamecache="false" excluded="false" taxonstatusunknown="false" taxonomicchildrencount="0" unplaced="false" createdby_id="10" updatedby_id="10" />
17
  <TaxonBase DTYPE="Taxon" id="14" created="2015-03-09 15:51:24.0" uuid="b38d0d73-9a20-4894-99bb-2148ee6b10d0" updated="2015-04-09 13:50:03.0" protectedtitlecache="false" titleCache="Taxon C sec. ???" doubtful="false" publish="true" usenamecache="false" excluded="false" taxonstatusunknown="false" taxonomicchildrencount="0" unplaced="false" createdby_id="10" updatedby_id="10" />
18
  <TaxonBase DTYPE="Taxon" id="16" created="2015-03-09 15:52:34.0" uuid="eaac797e-cac7-4649-97cf-c7b580076895" updated="2015-03-09 15:52:42.0" protectedtitlecache="false" titleCache="Taxon A sec. Journal Reference 1" doubtful="false" publish="true" usenamecache="false" excluded="false" taxonstatusunknown="false" taxonomicchildrencount="0" unplaced="true" createdby_id="10" updatedby_id="10"  sec_id="21"/>
19
  <TaxonBase DTYPE="Taxon" id="19" created="2015-03-09 15:53:21.0" uuid="5004a8e7-b907-4744-b67e-44ccb057ab3b" updated="2015-03-09 15:53:23.0" protectedtitlecache="false" titleCache="Taxon B sec. ???" doubtful="false" publish="true" usenamecache="false" excluded="false" taxonstatusunknown="false" taxonomicchildrencount="0" unplaced="false" createdby_id="10" updatedby_id="10" />
20
  <TaxonBase DTYPE="Taxon" id="20" created="2015-03-09 15:53:30.0" uuid="3d71c8b8-3bec-4f5f-ba23-6f9d55ef84e9" updated="2015-03-09 15:53:32.0" protectedtitlecache="false" titleCache="Taxon C sec. ???" doubtful="false" publish="true" usenamecache="false" excluded="false" taxonstatusunknown="false" taxonomicchildrencount="0" unplaced="false" createdby_id="10" updatedby_id="10" />
21
  <TaxonBase DTYPE="Taxon" id="30" created="2015-03-10 13:40:30.0" uuid="5f713f69-e03e-4a11-8a55-700fbbf44805" updated="2015-04-09 13:50:03.0" protectedtitlecache="false" titleCache="Taxon D sec. ???" doubtful="false" publish="true" usenamecache="false" excluded="false" taxonstatusunknown="false" taxonomicchildrencount="0" unplaced="false" createdby_id="10" updatedby_id="10" />
22
  <TaxonBase DTYPE="Taxon" id="50" created="2015-04-15 14:53:53.0" uuid="84e99e24-f50a-4726-92d0-6088430c492a" updated="2015-04-15 14:54:07.0" protectedtitlecache="false" titleCache="Taxon E sec. ???" doubtful="false" publish="true" usenamecache="false" excluded="false" taxonstatusunknown="false" taxonomicchildrencount="0" unplaced="false" createdby_id="10" updatedby_id="10" />
23
  <TaxonBase DTYPE="Taxon" id="51" created="2015-04-15 14:54:26.0" uuid="c25e0366-32a6-4283-8e5e-4fe908d567cf" updated="2015-04-15 14:54:28.0" protectedtitlecache="false" titleCache="Taxon F sec. ???" doubtful="false" publish="true" usenamecache="false" excluded="false" taxonstatusunknown="false" taxonomicchildrencount="0" unplaced="false" createdby_id="10" updatedby_id="10" />
24

  
25
  <Reference id="20" created="2015-04-02 09:42:49.0" uuid="b7dbc26f-30a0-49e2-9ca6-bbeeefbb9909" updated="2015-04-02 09:42:53.0" protectedtitlecache="true" titleCache="Book Reference 1" abbrevtitlecache="" nomenclaturallyrelevant="false" parsingproblem="0" problemends="-1" problemstarts="-1" protectedabbrevtitlecache="false" refType="BK" createdby_id="10" updatedby_id="10"/>
26
  <Reference id="21" created="2015-04-02 09:43:04.0" uuid="300ac33d-478a-4a89-ab83-6d89c5142e41" updated="2015-04-02 09:43:07.0" protectedtitlecache="true" titleCache="Journal Reference 1" abbrevtitlecache="" nomenclaturallyrelevant="false" parsingproblem="0" problemends="-1" problemstarts="-1" protectedabbrevtitlecache="false" refType="JOU" createdby_id="10" updatedby_id="10"/>
27

  
28
  <TaxonRelationship id="10" created="2015-04-09 13:38:54.0" uuid="cac9fa65-9b15-445f-80e4-56f77952f7ec" updated="2015-04-09 13:38:58.0" doubtful="false" createdby_id="10" updatedby_id="10" relatedfrom_id="30" relatedto_id="16" type_id="934"/>
29
  <TaxonRelationship id="20" created="2015-04-09 13:48:02.0" uuid="1bbe7234-ad32-4ddc-8395-1b70c3bd2f63" updated="2015-04-09 13:48:11.0" doubtful="false" createdby_id="10" updatedby_id="10" relatedfrom_id="30" relatedto_id="13" type_id="934"/>
30
  <TaxonRelationship id="22" created="2015-04-09 13:49:34.0" uuid="9634d870-bab1-4fdc-8845-c7e71aa8dc6b" updated="2015-04-09 13:49:36.0" doubtful="false" createdby_id="10" updatedby_id="10" relatedfrom_id="10" relatedto_id="16" type_id="935"/>
31
  <TaxonRelationship id="23" created="2015-04-09 13:50:16.0" uuid="4ba71ff4-fdaa-49dd-a797-68e598a961f8" updated="2015-04-09 13:50:33.0" doubtful="false" createdby_id="10" updatedby_id="10" relatedfrom_id="30" relatedto_id="20" type_id="924"/>
32
  <TaxonRelationship id="30" created="2015-04-15 14:54:50.0" uuid="823782d2-5da1-4755-a8fc-dff83e7e05c6" updated="2015-04-15 14:54:56.0" doubtful="false" createdby_id="10" updatedby_id="10" relatedfrom_id="30" relatedto_id="50" type_id="934"/>
33

  
34
  
35
</dataset>

Also available in: Unified diff