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.cdm.vaadin.view.registration;
|
10
|
|
11
|
import java.io.Serializable;
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.springframework.beans.factory.annotation.Autowired;
|
17
|
import org.springframework.context.event.EventListener;
|
18
|
|
19
|
import com.vaadin.server.SystemError;
|
20
|
import com.vaadin.spring.annotation.SpringComponent;
|
21
|
import com.vaadin.spring.annotation.ViewScope;
|
22
|
|
23
|
import eu.etaxonomy.cdm.model.name.Rank;
|
24
|
import eu.etaxonomy.cdm.model.name.Registration;
|
25
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
26
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
27
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
28
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
29
|
import eu.etaxonomy.cdm.service.IRegistrationWorkingSetService;
|
30
|
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
|
31
|
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
|
32
|
import eu.etaxonomy.cdm.vaadin.event.RegistrationEditorAction;
|
33
|
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
|
34
|
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
|
35
|
import eu.etaxonomy.cdm.vaadin.event.TypeDesignationWorkingsetEditorAction;
|
36
|
import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkflowEvent;
|
37
|
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
|
38
|
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager.TypeDesignationWorkingSetType;
|
39
|
import eu.etaxonomy.cdm.vaadin.view.name.RegistrationAndWorkingsetId;
|
40
|
import eu.etaxonomy.cdm.vaadin.view.name.SpecimenTypeDesignationWorkingsetPopupEditor;
|
41
|
import eu.etaxonomy.cdm.vaadin.view.name.TaxonNamePopupEditor;
|
42
|
import eu.etaxonomy.cdm.vaadin.view.reference.ReferencePopupEditor;
|
43
|
import eu.etaxonomy.vaadin.mvp.AbstractPresenter;
|
44
|
|
45
|
/**
|
46
|
* @author a.kohlbecker
|
47
|
* @since Mar 3, 2017
|
48
|
*
|
49
|
*/
|
50
|
@SpringComponent
|
51
|
@ViewScope
|
52
|
public class RegistrationWorkflowPresenter extends AbstractPresenter<RegistrationWorkflowView> implements Serializable{
|
53
|
|
54
|
private static final long serialVersionUID = 1L;
|
55
|
|
56
|
@Autowired
|
57
|
private IRegistrationWorkingSetService workingSetService;
|
58
|
|
59
|
/**
|
60
|
* @return the workingSetService
|
61
|
*/
|
62
|
public IRegistrationWorkingSetService getWorkingSetService() {
|
63
|
ensureBoundConversation();
|
64
|
return workingSetService;
|
65
|
}
|
66
|
|
67
|
private RegistrationWorkingSet workingset;
|
68
|
|
69
|
|
70
|
/**
|
71
|
*
|
72
|
*/
|
73
|
public RegistrationWorkflowPresenter() {
|
74
|
}
|
75
|
|
76
|
@EventListener
|
77
|
protected void onRegistrationStartEvent(RegistrationWorkflowEvent event){
|
78
|
|
79
|
boolean HACK = true;
|
80
|
if(workingset != null && !HACK){
|
81
|
Logger.getLogger(RegistrationWorkflowPresenter.class).warn("Can't start a new workflow over an existing one.");
|
82
|
return;
|
83
|
}
|
84
|
|
85
|
if(event.isStart()) {
|
86
|
workingset = new RegistrationWorkingSet();
|
87
|
Registration reg = Registration.NewInstance();
|
88
|
reg.setName(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()));
|
89
|
getView().setHeaderText("New Registration");
|
90
|
try {
|
91
|
workingset.add(reg);
|
92
|
} catch (RegistrationValidationException error) {
|
93
|
getView().getWorkflow().setComponentError(new SystemError(error));
|
94
|
}
|
95
|
getView().setWorkingset(workingset);
|
96
|
} else {
|
97
|
Integer citationID = event.getCitationID();
|
98
|
presentWorkingSetByRegID(citationID);
|
99
|
}
|
100
|
|
101
|
}
|
102
|
|
103
|
/**
|
104
|
* @param registrationID
|
105
|
* @deprecated use other method working sets should only be addressed by the referenceID
|
106
|
*/
|
107
|
@Deprecated
|
108
|
private void presentWorkingSetByRegID(Integer citationID) {
|
109
|
try {
|
110
|
workingset = getWorkingSetService().loadWorkingSetByCitationID(citationID);
|
111
|
} catch (RegistrationValidationException error) {
|
112
|
getView().getWorkflow().setComponentError(new SystemError(error));
|
113
|
}
|
114
|
getView().setHeaderText("Registrations in " + workingset.getCitation());
|
115
|
getView().setWorkingset(workingset);
|
116
|
}
|
117
|
|
118
|
/**
|
119
|
* @param registrationID
|
120
|
*/
|
121
|
private void presentWorkingSet(Integer referenceID) {
|
122
|
try {
|
123
|
workingset = getWorkingSetService().loadWorkingSetByReferenceID(referenceID);
|
124
|
} catch (RegistrationValidationException error) {
|
125
|
getView().getWorkflow().setComponentError(new SystemError(error));
|
126
|
}
|
127
|
getView().setHeaderText("Registration for " + workingset.getCitation());
|
128
|
getView().setWorkingset(workingset);
|
129
|
}
|
130
|
|
131
|
@EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).ADD && #event.sourceComponent == null")
|
132
|
public void onReferenceEditorActionAdd(ReferenceEditorAction event) {
|
133
|
ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
|
134
|
popup.loadInEditor(null);
|
135
|
}
|
136
|
|
137
|
@EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).EDIT && #event.sourceComponent == null")
|
138
|
public void onReferenceEditorActionEdit(ReferenceEditorAction event) {
|
139
|
ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
|
140
|
popup.withDeleteButton(true);
|
141
|
popup.loadInEditor(event.getEntityId());
|
142
|
}
|
143
|
|
144
|
@EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).EDIT && #event.sourceComponent == null")
|
145
|
public void onRegistrationEditorAction(RegistrationEditorAction event) {
|
146
|
RegistrationPopupEditor popup = getNavigationManager().showInPopup(RegistrationPopupEditor.class);
|
147
|
popup.loadInEditor(event.getEntityId());
|
148
|
}
|
149
|
|
150
|
@EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).EDIT && #event.sourceComponent == null")
|
151
|
public void onTaxonNameEditorAction(TaxonNameEditorAction event) {
|
152
|
|
153
|
TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class);
|
154
|
popup.withDeleteButton(true);
|
155
|
// disable NomReferenceCombobox:
|
156
|
// the in the registration application inReferences should only edited centrally
|
157
|
popup.getNomReferenceCombobox().setEnabled(false);
|
158
|
popup.loadInEditor(event.getEntityId());
|
159
|
|
160
|
|
161
|
}
|
162
|
|
163
|
@EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).EDIT && #event.sourceComponent == null")
|
164
|
public void onTypeDesignationsEditorActionEdit(TypeDesignationWorkingsetEditorAction event) {
|
165
|
|
166
|
if(event.getWorkingSetType() == TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET ){
|
167
|
SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class);
|
168
|
popup.loadInEditor(new RegistrationAndWorkingsetId(event.getRegistrationId(), event.getEntityId()));
|
169
|
} else {
|
170
|
// TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET
|
171
|
// FIXME implement NameTypeDesignationWorkingsetPopupEditor
|
172
|
}
|
173
|
|
174
|
}
|
175
|
|
176
|
@EventListener(condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action).ADD && #event.sourceComponent == null")
|
177
|
public void onTypeDesignationsEditorActionAdd(TypeDesignationWorkingsetEditorAction event) {
|
178
|
|
179
|
if(event.getWorkingSetType() == TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET){
|
180
|
SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class);
|
181
|
popup.loadInEditor(null);
|
182
|
popup.withDeleteButton(true);
|
183
|
}
|
184
|
}
|
185
|
|
186
|
@EventListener(classes=ShowDetailsEvent.class, condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet)")
|
187
|
public void onShowRegistrationWorkingSetMessages(ShowDetailsEvent<?,?> event) { // WARNING don't use more specific generic type arguments
|
188
|
List<String> messages = new ArrayList<>();
|
189
|
for(RegistrationDTO dto : workingset.getRegistrationDTOs()){
|
190
|
dto.getMessages().forEach(m -> messages.add(dto.getSummary() + ": " + m));
|
191
|
}
|
192
|
if(event.getProperty().equals("messages")){
|
193
|
getView().openDetailsPopup("Messages", messages);
|
194
|
}
|
195
|
}
|
196
|
|
197
|
@EventListener(classes=ShowDetailsEvent.class, condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO)")
|
198
|
public void onShowRegistrationMessages(ShowDetailsEvent<?,?> event) { // WARNING don't use more specific generic type arguments
|
199
|
RegistrationDTO regDto = workingSetService.loadDtoById((Integer)event.getIdentifier());
|
200
|
if(event.getProperty().equals("messages")){
|
201
|
if(getView() != null){
|
202
|
getView().openDetailsPopup("Messages", regDto.getMessages());
|
203
|
}
|
204
|
}
|
205
|
}
|
206
|
|
207
|
@EventListener
|
208
|
public void onEntityChangeEvent(EntityChangeEvent event){
|
209
|
if(Reference.class.isAssignableFrom(event.getEntityType())){
|
210
|
if(workingset.getCitationId().equals(event.getEntityId())){
|
211
|
refreshView();
|
212
|
}
|
213
|
} else
|
214
|
if(Registration.class.isAssignableFrom(event.getEntityType())){
|
215
|
if(workingset.getRegistrations().stream().anyMatch(reg -> reg.getId() == event.getEntityId())){
|
216
|
refreshView();
|
217
|
}
|
218
|
} else
|
219
|
if(TaxonName.class.isAssignableFrom(event.getEntityType())){
|
220
|
if(workingset.getRegistrationDTOs().stream().anyMatch(reg ->
|
221
|
reg.getTypifiedName() != null
|
222
|
&& reg.getTypifiedName().getId() == event.getEntityId())){
|
223
|
refreshView();
|
224
|
}
|
225
|
} else
|
226
|
if(TypeDesignationBase.class.isAssignableFrom(event.getEntityType())){
|
227
|
if(workingset.getRegistrationDTOs().stream().anyMatch(
|
228
|
reg -> reg.getTypeDesignations().stream().anyMatch(
|
229
|
td -> td.getId() == event.getEntityId()
|
230
|
)
|
231
|
)
|
232
|
){
|
233
|
refreshView();
|
234
|
}
|
235
|
}
|
236
|
|
237
|
}
|
238
|
|
239
|
/**
|
240
|
*
|
241
|
*/
|
242
|
protected void refreshView() {
|
243
|
presentWorkingSet(workingset.getCitationId());
|
244
|
}
|
245
|
|
246
|
}
|