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