1
|
/**
|
2
|
* Copyright (C) 2017 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.bulkeditor.operation;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.List;
|
13
|
|
14
|
import org.eclipse.core.commands.ExecutionException;
|
15
|
import org.eclipse.core.runtime.IAdaptable;
|
16
|
import org.eclipse.core.runtime.IProgressMonitor;
|
17
|
import org.eclipse.core.runtime.IStatus;
|
18
|
import org.eclipse.core.runtime.Status;
|
19
|
import org.eclipse.ui.IEditorPart;
|
20
|
|
21
|
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
|
22
|
import eu.etaxonomy.cdm.api.service.IAgentService;
|
23
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
24
|
import eu.etaxonomy.cdm.model.agent.Person;
|
25
|
import eu.etaxonomy.cdm.model.agent.Team;
|
26
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
27
|
import eu.etaxonomy.cdm.strategy.merge.MergeException;
|
28
|
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
|
29
|
import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
|
30
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
31
|
import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
|
32
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
33
|
|
34
|
/**
|
35
|
* @author k.luther
|
36
|
* @date 10.05.2017
|
37
|
*
|
38
|
*/
|
39
|
public class ConvertPerson2TeamOperation extends RemotingCdmUpdateOperation {
|
40
|
List<Person> persons;
|
41
|
List<Team> teams;
|
42
|
IEditorPart editor;
|
43
|
|
44
|
/**
|
45
|
* @param label
|
46
|
* @param editor
|
47
|
* @param undoContext
|
48
|
* @param element
|
49
|
*/
|
50
|
public ConvertPerson2TeamOperation(String label, List<Person> persons, boolean async, IEditorPart editor) {
|
51
|
super(label, Action.Update, persons, async);
|
52
|
this.persons = persons;
|
53
|
this.editor = editor;
|
54
|
this.teams = new ArrayList<Team>();
|
55
|
}
|
56
|
|
57
|
/**
|
58
|
* {@inheritDoc}
|
59
|
*/
|
60
|
@Override
|
61
|
public UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
62
|
UpdateResult result = new UpdateResult();
|
63
|
try {
|
64
|
for (Person person: persons){
|
65
|
UpdateResult resultTemp = CdmStore.getService(IAgentService.class).convertPerson2Team(person.getUuid());
|
66
|
result.includeResult(resultTemp);
|
67
|
result.addUpdatedObject(resultTemp.getCdmEntity());
|
68
|
|
69
|
}
|
70
|
for (CdmBase team:result.getUpdatedObjects()){
|
71
|
|
72
|
teams.add((Team)team);
|
73
|
}
|
74
|
} catch (IllegalArgumentException e) {
|
75
|
MessagingUtils.errorDialog("Can not convert Person into a Team", null, e.getLocalizedMessage(), TaxeditorBulkeditorPlugin.PLUGIN_ID,e, true);
|
76
|
} catch (MergeException e) {
|
77
|
MessagingUtils.informationDialog("Convert not possible", "Person can not be transformed into team as it is already part of a team.");
|
78
|
}
|
79
|
return result;
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* {@inheritDoc}
|
84
|
*/
|
85
|
@Override
|
86
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
87
|
// TODO Auto-generated method stub
|
88
|
return null;
|
89
|
}
|
90
|
|
91
|
/**
|
92
|
* {@inheritDoc}
|
93
|
*/
|
94
|
@Override
|
95
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
96
|
// TODO Auto-generated method stub
|
97
|
return null;
|
98
|
}
|
99
|
|
100
|
@Override
|
101
|
protected IStatus onComplete(boolean success) {
|
102
|
|
103
|
((BulkEditor) editor).getSearchBar().updateEditorInput();
|
104
|
return Status.OK_STATUS;
|
105
|
}
|
106
|
|
107
|
|
108
|
|
109
|
}
|