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.Arrays;
|
13
|
import java.util.EnumSet;
|
14
|
import java.util.List;
|
15
|
import java.util.Set;
|
16
|
import java.util.Stack;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import org.hibernate.Session;
|
20
|
import org.hibernate.Transaction;
|
21
|
import org.springframework.beans.factory.annotation.Autowired;
|
22
|
import org.springframework.security.core.Authentication;
|
23
|
import org.springframework.transaction.TransactionStatus;
|
24
|
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
25
|
|
26
|
import com.vaadin.server.SystemError;
|
27
|
import com.vaadin.spring.annotation.SpringComponent;
|
28
|
import com.vaadin.spring.annotation.ViewScope;
|
29
|
import com.vaadin.ui.Button;
|
30
|
import com.vaadin.ui.Label;
|
31
|
import com.vaadin.ui.UI;
|
32
|
import com.vaadin.ui.VerticalLayout;
|
33
|
import com.vaadin.ui.Window;
|
34
|
|
35
|
import eu.etaxonomy.cdm.api.service.INameService;
|
36
|
import eu.etaxonomy.cdm.api.service.IRegistrationService;
|
37
|
import eu.etaxonomy.cdm.api.service.idminter.IdentifierMinter.Identifier;
|
38
|
import eu.etaxonomy.cdm.api.service.idminter.RegistrationIdentifierMinter;
|
39
|
import eu.etaxonomy.cdm.ext.common.ExternalServiceException;
|
40
|
import eu.etaxonomy.cdm.ext.registration.messages.IRegistrationMessageService;
|
41
|
import eu.etaxonomy.cdm.model.common.User;
|
42
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
|
43
|
import eu.etaxonomy.cdm.model.name.Rank;
|
44
|
import eu.etaxonomy.cdm.model.name.Registration;
|
45
|
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
|
46
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
47
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
48
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
49
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
50
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
|
51
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.Operation;
|
52
|
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
|
53
|
import eu.etaxonomy.cdm.service.CdmStore;
|
54
|
import eu.etaxonomy.cdm.service.IRegistrationWorkingSetService;
|
55
|
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItem;
|
56
|
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.EditorActionContext;
|
57
|
import eu.etaxonomy.cdm.vaadin.event.EditorActionTypeFilter;
|
58
|
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
|
59
|
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
|
60
|
import eu.etaxonomy.cdm.vaadin.event.RegistrationEditorAction;
|
61
|
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
|
62
|
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEventEntityTypeFilter;
|
63
|
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
|
64
|
import eu.etaxonomy.cdm.vaadin.event.TypeDesignationWorkingsetEditorAction;
|
65
|
import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkingsetAction;
|
66
|
import eu.etaxonomy.cdm.vaadin.model.EntityReference;
|
67
|
import eu.etaxonomy.cdm.vaadin.model.TypedEntityReference;
|
68
|
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
|
69
|
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
|
70
|
import eu.etaxonomy.cdm.vaadin.theme.EditValoTheme;
|
71
|
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
|
72
|
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator;
|
73
|
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager.TypeDesignationWorkingSetType;
|
74
|
import eu.etaxonomy.cdm.vaadin.view.name.NameTypeDesignationPopupEditor;
|
75
|
import eu.etaxonomy.cdm.vaadin.view.name.SpecimenTypeDesignationWorkingsetPopupEditor;
|
76
|
import eu.etaxonomy.cdm.vaadin.view.name.TaxonNamePopupEditor;
|
77
|
import eu.etaxonomy.cdm.vaadin.view.name.TaxonNamePopupEditorMode;
|
78
|
import eu.etaxonomy.cdm.vaadin.view.name.TypeDesignationWorkingsetEditorIdSet;
|
79
|
import eu.etaxonomy.cdm.vaadin.view.reference.ReferencePopupEditor;
|
80
|
import eu.etaxonomy.vaadin.mvp.AbstractPopupEditor;
|
81
|
import eu.etaxonomy.vaadin.mvp.AbstractPresenter;
|
82
|
import eu.etaxonomy.vaadin.mvp.AbstractView;
|
83
|
import eu.etaxonomy.vaadin.mvp.BeanInstantiator;
|
84
|
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent;
|
85
|
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent.Reason;
|
86
|
|
87
|
/**
|
88
|
* @author a.kohlbecker
|
89
|
* @since Mar 3, 2017
|
90
|
*
|
91
|
*/
|
92
|
@SpringComponent
|
93
|
@ViewScope
|
94
|
public class RegistrationWorkingsetPresenter extends AbstractPresenter<RegistrationWorkingsetView> {
|
95
|
|
96
|
private static final long serialVersionUID = 1L;
|
97
|
|
98
|
@Autowired
|
99
|
private IRegistrationWorkingSetService regWorkingSetService;
|
100
|
|
101
|
@Autowired
|
102
|
private RegistrationIdentifierMinter minter;
|
103
|
|
104
|
@Autowired
|
105
|
private IRegistrationMessageService messageService;
|
106
|
|
107
|
/**
|
108
|
* @return the regWorkingSetService
|
109
|
*/
|
110
|
public IRegistrationWorkingSetService getWorkingSetService() {
|
111
|
return regWorkingSetService;
|
112
|
}
|
113
|
|
114
|
private RegistrationWorkingSet workingset;
|
115
|
|
116
|
private TaxonName newTaxonNameForRegistration = null;
|
117
|
|
118
|
private RegistrationDTO newRegistrationDTOWithExistingName;
|
119
|
|
120
|
private RegistrationDTO newNameTypeDesignationTarget;
|
121
|
|
122
|
|
123
|
/**
|
124
|
*
|
125
|
*/
|
126
|
public RegistrationWorkingsetPresenter() {
|
127
|
}
|
128
|
|
129
|
/**
|
130
|
* Always create a new Store
|
131
|
*
|
132
|
* @return
|
133
|
*/
|
134
|
protected CdmStore<Registration, IRegistrationService> getRegistrationStore(){
|
135
|
return new CdmStore<Registration, IRegistrationService>(getRepo(), getRepo().getRegistrationService());
|
136
|
}
|
137
|
|
138
|
/**
|
139
|
* Always create a new Store
|
140
|
*
|
141
|
* @return
|
142
|
*/
|
143
|
protected CdmStore<TaxonName, INameService> getTaxonNameStore(){
|
144
|
return new CdmStore<TaxonName, INameService>(getRepo(), getRepo().getNameService());
|
145
|
}
|
146
|
|
147
|
|
148
|
/**
|
149
|
* @param taxonNameId
|
150
|
* @return
|
151
|
*/
|
152
|
protected Registration createNewRegistrationForName(Integer taxonNameId) {
|
153
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
154
|
// move into RegistrationWorkflowStateMachine
|
155
|
TransactionStatus txStatus = getRepo().startTransaction();
|
156
|
|
157
|
Identifier<String> identifiers = minter.mint();
|
158
|
if(identifiers.getIdentifier() == null){
|
159
|
throw new RuntimeException("RegistrationIdentifierMinter configuration incomplete.");
|
160
|
}
|
161
|
Registration reg = Registration.NewInstance(
|
162
|
identifiers.getIdentifier(),
|
163
|
identifiers.getLocalId(),
|
164
|
taxonNameId != null ? getRepo().getNameService().find(taxonNameId) : null,
|
165
|
null);
|
166
|
Authentication authentication = currentSecurityContext().getAuthentication();
|
167
|
reg.setSubmitter((User)authentication.getPrincipal());
|
168
|
EntityChangeEvent event = getRegistrationStore().saveBean(reg, (AbstractView) getView());
|
169
|
UserHelper.fromSession().createAuthorityForCurrentUser(Registration.class, event.getEntityId(), Operation.UPDATE, RegistrationStatus.PREPARATION.name());
|
170
|
getRepo().commitTransaction(txStatus);
|
171
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
172
|
return getRepo().getRegistrationService().load(event.getEntityId(), Arrays.asList(new String []{"blockedBy"}));
|
173
|
}
|
174
|
|
175
|
|
176
|
/**
|
177
|
* @param doReload TODO
|
178
|
*
|
179
|
*/
|
180
|
protected void refreshView(boolean doReload) {
|
181
|
if(workingset == null){
|
182
|
return; // nothing to do
|
183
|
}
|
184
|
if(doReload){
|
185
|
loadWorkingSet(workingset.getCitationId());
|
186
|
}
|
187
|
getView().setWorkingset(workingset);
|
188
|
}
|
189
|
|
190
|
|
191
|
/**
|
192
|
* {@inheritDoc}
|
193
|
*/
|
194
|
@Override
|
195
|
public void handleViewEntered() {
|
196
|
|
197
|
super.handleViewEntered();
|
198
|
|
199
|
loadWorkingSet(getView().getCitationID());
|
200
|
getView().setWorkingset(workingset);
|
201
|
|
202
|
// PagingProviders and CacheGenerator for the existingNameCombobox
|
203
|
CdmFilterablePagingProvider<TaxonName, TaxonName> pagingProvider = new CdmFilterablePagingProvider<TaxonName, TaxonName>(
|
204
|
getRepo().getNameService());
|
205
|
CdmTitleCacheCaptionGenerator<TaxonName> titleCacheGenerator = new CdmTitleCacheCaptionGenerator<TaxonName>();
|
206
|
getView().getAddExistingNameCombobox().setCaptionGenerator(titleCacheGenerator);
|
207
|
getView().getAddExistingNameCombobox().loadFrom(pagingProvider, pagingProvider, pagingProvider.getPageSize());
|
208
|
|
209
|
// update the messages
|
210
|
User user = UserHelper.fromSession().user();
|
211
|
for (Integer registrationId : getView().getRegistrationItemMap().keySet()) {
|
212
|
Button messageButton = getView().getRegistrationItemMap().get(registrationId).regItemButtons.getMessagesButton();
|
213
|
|
214
|
RegistrationDTO regDto = workingset.getRegistrationDTO(registrationId).get();
|
215
|
try {
|
216
|
int messageCount = messageService.countActiveMessagesFor(regDto.registration(), user);
|
217
|
|
218
|
boolean activeMessages = messageCount > 0;
|
219
|
boolean currentUserIsSubmitter = regDto.getSubmitterUserName().equals(UserHelper.fromSession().userName());
|
220
|
boolean currentUserIsCurator = UserHelper.fromSession().userIsRegistrationCurator();
|
221
|
messageButton.setEnabled(false);
|
222
|
if(currentUserIsCurator){
|
223
|
if(currentUserIsSubmitter){
|
224
|
messageButton.setDescription("No point sending messages to your self.");
|
225
|
} else {
|
226
|
messageButton.setEnabled(true);
|
227
|
messageButton.setDescription("Open the messages dialog.");
|
228
|
}
|
229
|
} else {
|
230
|
messageButton.setDescription("Sorry, only a curator can start a conversation.");
|
231
|
}
|
232
|
if(activeMessages){
|
233
|
messageButton.setEnabled(true);
|
234
|
messageButton.addStyleName(EditValoTheme.BUTTON_HIGHLITE);
|
235
|
String who = currentUserIsSubmitter ? "curator" : "submitter";
|
236
|
messageButton.setDescription("The " + who + " is looking forward to your reply.");
|
237
|
|
238
|
}
|
239
|
} catch (ExternalServiceException e) {
|
240
|
messageButton.setComponentError(new SystemError(e.getMessage(), e));
|
241
|
}
|
242
|
}
|
243
|
|
244
|
}
|
245
|
|
246
|
|
247
|
/**
|
248
|
* @param referenceID
|
249
|
*/
|
250
|
protected void loadWorkingSet(Integer referenceID) {
|
251
|
try {
|
252
|
workingset = getWorkingSetService().loadWorkingSetByReferenceID(referenceID);
|
253
|
} catch (RegistrationValidationException error) {
|
254
|
logger.error(error);
|
255
|
Window errorDialog = new Window("Validation Error");
|
256
|
errorDialog.setModal(true);
|
257
|
VerticalLayout subContent = new VerticalLayout();
|
258
|
subContent.setMargin(true);
|
259
|
errorDialog.setContent(subContent);
|
260
|
subContent.addComponent(new Label(error.getMessage()));
|
261
|
UI.getCurrent().addWindow(errorDialog);
|
262
|
}
|
263
|
if(workingset == null || workingset.getCitationId() == null){
|
264
|
Reference citation = getRepo().getReferenceService().find(referenceID);
|
265
|
workingset = new RegistrationWorkingSet(citation);
|
266
|
}
|
267
|
}
|
268
|
|
269
|
|
270
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
|
271
|
public void onReferenceEditorActionAdd(ReferenceEditorAction event) {
|
272
|
|
273
|
if(!checkFromOwnView(event)){
|
274
|
return;
|
275
|
}
|
276
|
|
277
|
ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
|
278
|
popup.withReferenceTypes(RegistrationUIDefaults.PRINTPUB_REFERENCE_TYPES);
|
279
|
popup.loadInEditor(null);
|
280
|
}
|
281
|
|
282
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
|
283
|
public void onReferenceEditorActionEdit(ReferenceEditorAction event) {
|
284
|
|
285
|
if(!checkFromOwnView(event)){
|
286
|
return;
|
287
|
}
|
288
|
ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class, getView());
|
289
|
popup.withReferenceTypes(RegistrationUIDefaults.PRINTPUB_REFERENCE_TYPES);
|
290
|
popup.withDeleteButton(true);
|
291
|
popup.loadInEditor(event.getEntityId());
|
292
|
}
|
293
|
|
294
|
@EventBusListenerMethod
|
295
|
public void onDoneWithReferencePopupEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
|
296
|
if(event.getPopup() instanceof ReferencePopupEditor){
|
297
|
if(event.getReason().equals(Reason.SAVE)){
|
298
|
refreshView(true);
|
299
|
}
|
300
|
}
|
301
|
}
|
302
|
|
303
|
@EventBusListenerMethod
|
304
|
public void onDoneWithSpecimenTypeDesignationWorkingsetPopupEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
|
305
|
if(event.getPopup() instanceof SpecimenTypeDesignationWorkingsetPopupEditor){
|
306
|
if(event.getReason().equals(Reason.SAVE)){
|
307
|
refreshView(true);
|
308
|
}
|
309
|
}
|
310
|
}
|
311
|
|
312
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
|
313
|
public void onRegistrationEditorAction(RegistrationEditorAction event) {
|
314
|
|
315
|
if(!checkFromOwnView(event)){
|
316
|
return;
|
317
|
}
|
318
|
|
319
|
RegistrationPopupEditor popup = getNavigationManager().showInPopup(RegistrationPopupEditor.class, getView());
|
320
|
popup.loadInEditor(event.getEntityId());
|
321
|
}
|
322
|
|
323
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
|
324
|
public void onTaxonNameEditorActionEdit(TaxonNameEditorAction event) {
|
325
|
|
326
|
if(!checkFromOwnView(event)){
|
327
|
return;
|
328
|
}
|
329
|
|
330
|
TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView());
|
331
|
popup.setParentEditorActionContext(event.getContext());
|
332
|
popup.withDeleteButton(true);
|
333
|
configureTaxonNameEditor(popup);
|
334
|
popup.loadInEditor(event.getEntityId());
|
335
|
if(event.getSourceComponent() != null){
|
336
|
popup.setReadOnly(event.getSourceComponent().isReadOnly());
|
337
|
}
|
338
|
|
339
|
}
|
340
|
|
341
|
|
342
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
|
343
|
public void onTaxonNameEditorActionAdd(TaxonNameEditorAction event) {
|
344
|
|
345
|
if(!checkFromOwnView(event)){
|
346
|
return;
|
347
|
}
|
348
|
|
349
|
newTaxonNameForRegistration = TaxonNameFactory.NewNameInstance(RegistrationUIDefaults.NOMENCLATURAL_CODE, Rank.SPECIES());
|
350
|
newTaxonNameForRegistration.setNomenclaturalReference(getRepo().getReferenceService().find(workingset.getCitationId()));
|
351
|
EntityChangeEvent nameSaveEvent = getTaxonNameStore().saveBean(newTaxonNameForRegistration, (AbstractView) getView());
|
352
|
newTaxonNameForRegistration = getRepo().getNameService().find(nameSaveEvent.getEntityId());
|
353
|
TaxonNamePopupEditor popup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView());
|
354
|
popup.setParentEditorActionContext(event.getContext());
|
355
|
popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE,CRUD.DELETE));
|
356
|
popup.withDeleteButton(true);
|
357
|
configureTaxonNameEditor(popup);
|
358
|
popup.loadInEditor(newTaxonNameForRegistration.getId());
|
359
|
}
|
360
|
|
361
|
/**
|
362
|
* TODO consider putting this into a Configurer Bean per UIScope.
|
363
|
* In the configurator bean this methods popup papamerter should be of the type
|
364
|
* AbstractPopupEditor
|
365
|
*
|
366
|
* @param popup
|
367
|
*/
|
368
|
protected void configureTaxonNameEditor(TaxonNamePopupEditor popup) {
|
369
|
popup.enableMode(TaxonNamePopupEditorMode.suppressReplacementAuthorshipData);
|
370
|
popup.enableMode(TaxonNamePopupEditorMode.nomenclaturalReferenceSectionEditingOnly);
|
371
|
popup.enableMode(TaxonNamePopupEditorMode.requireNomenclaturalReference);
|
372
|
}
|
373
|
|
374
|
/**
|
375
|
* Creates a new <code>Registration</code> for a new name that has just been edited
|
376
|
* using the <code>TaxonNamePopupEditor</code>. The new name was previously created
|
377
|
* in this presenter as <code>newTaxonNameForRegistration</code> (see {@link #onTaxonNameEditorActionAdd(TaxonNameEditorAction)})
|
378
|
* and is either filled with data (<code>Reason.SAVE</code>) or it is still empty
|
379
|
* (<code>Reason.CANCEL</code>).
|
380
|
*
|
381
|
*
|
382
|
* @param event
|
383
|
* @throws RegistrationValidationException
|
384
|
*/
|
385
|
@EventBusListenerMethod
|
386
|
public void onDoneWithTaxonnameEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
|
387
|
if(event.getPopup() instanceof TaxonNamePopupEditor){
|
388
|
TransactionStatus txStatus = getRepo().startTransaction();
|
389
|
if(event.getReason().equals(Reason.SAVE)){
|
390
|
if(newTaxonNameForRegistration != null){
|
391
|
int taxonNameId = newTaxonNameForRegistration.getId();
|
392
|
getRepo().getSession().refresh(newTaxonNameForRegistration);
|
393
|
Registration reg = createNewRegistrationForName(taxonNameId);
|
394
|
// reload workingset into current session
|
395
|
loadWorkingSet(workingset.getCitationId());
|
396
|
workingset.add(reg);
|
397
|
}
|
398
|
refreshView(true);
|
399
|
} else if(event.getReason().equals(Reason.CANCEL)){
|
400
|
if(newTaxonNameForRegistration != null){
|
401
|
// clean up
|
402
|
getTaxonNameStore().deleteBean(newTaxonNameForRegistration, (AbstractView) getView());
|
403
|
}
|
404
|
}
|
405
|
getRepo().commitTransaction(txStatus);
|
406
|
newTaxonNameForRegistration = null;
|
407
|
}
|
408
|
}
|
409
|
|
410
|
|
411
|
/**
|
412
|
* Creates a new Registration for an exiting (previously published name).
|
413
|
*
|
414
|
* @param event
|
415
|
* @throws RegistrationValidationException
|
416
|
*/
|
417
|
@EventBusListenerMethod
|
418
|
public void onRegistrationWorkflowEventActionStart(RegistrationWorkingsetAction event) throws RegistrationValidationException {
|
419
|
|
420
|
if(!event.isStart()){
|
421
|
return;
|
422
|
}
|
423
|
|
424
|
getView().getAddExistingNameCombobox().commit();
|
425
|
TaxonName typifiedName = getView().getAddExistingNameCombobox().getValue();
|
426
|
if(typifiedName != null){
|
427
|
Registration newRegistrationWithExistingName = createNewRegistrationForName(null);
|
428
|
Reference citation = getRepo().getReferenceService().find(workingset.getCitationId());
|
429
|
newRegistrationDTOWithExistingName = new RegistrationDTO(newRegistrationWithExistingName, typifiedName, citation);
|
430
|
workingset.add(newRegistrationDTOWithExistingName);
|
431
|
// tell the view to update the workingset
|
432
|
getView().setWorkingset(workingset);
|
433
|
getView().getAddExistingNameRegistrationButton().setEnabled(false);
|
434
|
getView().getAddExistingNameRegistrationButton().setDescription("You first need to add a type designation to the previously created registration.");
|
435
|
} else {
|
436
|
logger.error("Seletced name is NULL");
|
437
|
}
|
438
|
|
439
|
}
|
440
|
|
441
|
|
442
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
|
443
|
public void onTypeDesignationsEditorActionEdit(TypeDesignationWorkingsetEditorAction event) {
|
444
|
|
445
|
if(!checkFromOwnView(event)){
|
446
|
return;
|
447
|
}
|
448
|
|
449
|
if(event.getWorkingSetType() == TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET ){
|
450
|
SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class, getView());
|
451
|
popup.setParentEditorActionContext(event.getContext());
|
452
|
popup.withDeleteButton(true);
|
453
|
popup.loadInEditor(new TypeDesignationWorkingsetEditorIdSet(event.getRegistrationId(), event.getBaseEntityRef()));
|
454
|
if(event.getSourceComponent() != null){
|
455
|
// propagate readonly state from source component to popup
|
456
|
popup.setReadOnly(event.getSourceComponent().isReadOnly());
|
457
|
}
|
458
|
} else {
|
459
|
NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class, getView());
|
460
|
popup.setParentEditorActionContext(event.getContext());
|
461
|
popup.withDeleteButton(true);
|
462
|
popup.loadInEditor(new TypeDesignationWorkingsetEditorIdSet(event.getRegistrationId(), event.getBaseEntityRef()));
|
463
|
|
464
|
popup.getCitationCombobox().setEnabled(false);
|
465
|
popup.getTypifiedNamesComboboxSelect().setEnabled(false);
|
466
|
|
467
|
if(event.getSourceComponent() != null){
|
468
|
// propagate readonly state from source component to popup
|
469
|
popup.setReadOnly(event.getSourceComponent().isReadOnly());
|
470
|
}
|
471
|
newNameTypeDesignationTarget = workingset.getRegistrationDTO(event.getRegistrationId()).get();
|
472
|
}
|
473
|
}
|
474
|
|
475
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
|
476
|
public void onTypeDesignationWorkingsetAdd(TypeDesignationWorkingsetEditorAction event) {
|
477
|
|
478
|
if(event.getSourceComponent() != null){
|
479
|
return;
|
480
|
}
|
481
|
|
482
|
if(event.getWorkingSetType() == TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET){
|
483
|
SpecimenTypeDesignationWorkingsetPopupEditor popup = getNavigationManager().showInPopup(SpecimenTypeDesignationWorkingsetPopupEditor.class, getView());
|
484
|
popup.setParentEditorActionContext(event.getContext());
|
485
|
TypeDesignationWorkingsetEditorIdSet identifierSet;
|
486
|
Integer typifiedNameId;
|
487
|
if(newRegistrationDTOWithExistingName != null){
|
488
|
typifiedNameId = newRegistrationDTOWithExistingName.getTypifiedNameRef().getId();
|
489
|
} else {
|
490
|
RegistrationDTO registrationDTO = workingset.getRegistrationDTO(event.getRegistrationId()).get();
|
491
|
EntityReference typifiedNameRef = registrationDTO.getTypifiedNameRef();
|
492
|
if(typifiedNameRef != null){
|
493
|
// case for registrations without name, in which case the typifiedName is only defined via the typedesignations
|
494
|
typifiedNameId = typifiedNameRef.getId();
|
495
|
} else {
|
496
|
// case of registrations with a name in the nomenclatural act.
|
497
|
typifiedNameId = registrationDTO.getNameRef().getId();
|
498
|
}
|
499
|
}
|
500
|
identifierSet = new TypeDesignationWorkingsetEditorIdSet(
|
501
|
event.getRegistrationId(),
|
502
|
getView().getCitationID(),
|
503
|
typifiedNameId
|
504
|
);
|
505
|
popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
506
|
popup.loadInEditor(identifierSet);
|
507
|
popup.withDeleteButton(true);
|
508
|
if(event.getSourceComponent() != null){
|
509
|
// propagate readonly state from source component to popup
|
510
|
popup.setReadOnly(event.getSourceComponent().isReadOnly());
|
511
|
}
|
512
|
} else {
|
513
|
NameTypeDesignationPopupEditor popup = getNavigationManager().showInPopup(NameTypeDesignationPopupEditor.class, getView());
|
514
|
popup.setParentEditorActionContext(event.getContext());
|
515
|
popup.withDeleteButton(true);
|
516
|
popup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
517
|
newNameTypeDesignationTarget = workingset.getRegistrationDTO(event.getRegistrationId()).get();
|
518
|
popup.setBeanInstantiator(new BeanInstantiator<NameTypeDesignation>() {
|
519
|
|
520
|
@Override
|
521
|
public NameTypeDesignation createNewBean() {
|
522
|
|
523
|
TaxonName typifiedName = getRepo().getNameService().load(event.getTypifiedNameId(), Arrays.asList(new String[]{"typeDesignations", "homotypicalGroup"}));
|
524
|
NameTypeDesignation nameTypeDesignation = NameTypeDesignation.NewInstance();
|
525
|
nameTypeDesignation.setCitation(newNameTypeDesignationTarget.getCitation());
|
526
|
nameTypeDesignation.getTypifiedNames().add(typifiedName);
|
527
|
return nameTypeDesignation;
|
528
|
}
|
529
|
});
|
530
|
popup.loadInEditor(null);
|
531
|
popup.getCitationCombobox().setEnabled(false);
|
532
|
popup.getTypifiedNamesComboboxSelect().setEnabled(false);
|
533
|
if(event.getSourceComponent() != null){
|
534
|
// propagate readonly state from source component to popup
|
535
|
popup.setReadOnly(event.getSourceComponent().isReadOnly());
|
536
|
}
|
537
|
}
|
538
|
}
|
539
|
|
540
|
/**
|
541
|
* Performs final actions after a TypeDesignationEditor which has been
|
542
|
* opened to add a TypeDesignation to a Registration object which was
|
543
|
* created for an previously published name. Prior adding a typedesignation,
|
544
|
* the according Registration object is dangling, that has no association to
|
545
|
* any entity denoting an nomenclatural act which has a reference to a
|
546
|
* publication. This means that the registration object is not in the
|
547
|
* working set.
|
548
|
*
|
549
|
*
|
550
|
* @param event
|
551
|
* @throws RegistrationValidationException
|
552
|
*/
|
553
|
@EventBusListenerMethod
|
554
|
public void onDoneWithTypeDesignationEditor(DoneWithPopupEvent event) throws RegistrationValidationException{
|
555
|
if(event.getPopup() instanceof SpecimenTypeDesignationWorkingsetPopupEditor){
|
556
|
if(event.getReason().equals(Reason.SAVE)){
|
557
|
refreshView(true);
|
558
|
} else if(event.getReason().equals(Reason.CANCEL)){
|
559
|
// noting to do
|
560
|
}
|
561
|
newRegistrationDTOWithExistingName = null;
|
562
|
} else if(event.getPopup() instanceof NameTypeDesignationPopupEditor){
|
563
|
if(event.getReason().equals(Reason.SAVE)){
|
564
|
UUID uuid = ((NameTypeDesignationPopupEditor)event.getPopup()).getBean().getUuid();
|
565
|
|
566
|
Session session = getRepo().getSessionFactory().openSession();
|
567
|
Transaction txstate = session.beginTransaction();
|
568
|
TypeDesignationBase<?> nameTypeDesignation = getRepo().getNameService().loadTypeDesignation(uuid, Arrays.asList(""));
|
569
|
// only load the typeDesignations with the registration so that the typified name can not be twice in the session
|
570
|
// otherwise multiple representation problems might occur
|
571
|
Registration registration = getRepo().getRegistrationService().load(newNameTypeDesignationTarget.getUuid(), Arrays.asList("typeDesignations"));
|
572
|
registration.getTypeDesignations().add(nameTypeDesignation);
|
573
|
session.merge(registration);
|
574
|
txstate.commit();
|
575
|
session.close();
|
576
|
|
577
|
refreshView(true);
|
578
|
} else if(event.getReason().equals(Reason.CANCEL)){
|
579
|
// noting to do
|
580
|
}
|
581
|
newNameTypeDesignationTarget = null;
|
582
|
}
|
583
|
// ignore other editors
|
584
|
}
|
585
|
|
586
|
|
587
|
@EventBusListenerMethod(filter = ShowDetailsEventEntityTypeFilter.RegistrationWorkingSet.class)
|
588
|
public void onShowDetailsEventForRegistrationWorkingSet(ShowDetailsEvent<RegistrationWorkingSet,?> event) {
|
589
|
|
590
|
if(event.getProperty().equals(RegistrationItem.VALIDATION_PROBLEMS)){
|
591
|
List<String> messages = new ArrayList<>();
|
592
|
for(RegistrationDTO dto : workingset.getRegistrationDTOs()){
|
593
|
dto.getValidationProblems().forEach(m -> messages.add(dto.getSummary() + ": " + m));
|
594
|
}
|
595
|
getView().openDetailsPopup("Validation Problems", messages);
|
596
|
}
|
597
|
}
|
598
|
|
599
|
@EventBusListenerMethod
|
600
|
public void onEntityChangeEvent(EntityChangeEvent event){
|
601
|
if(workingset == null){
|
602
|
return;
|
603
|
}
|
604
|
if(Reference.class.isAssignableFrom(event.getEntityType())){
|
605
|
if(workingset.getCitationId().equals(event.getEntityId())){
|
606
|
refreshView(true);
|
607
|
}
|
608
|
} else
|
609
|
if(Registration.class.isAssignableFrom(event.getEntityType())){
|
610
|
if(workingset.getRegistrations().stream().anyMatch(reg -> reg.getId() == event.getEntityId())){
|
611
|
refreshView(true);
|
612
|
}
|
613
|
} else
|
614
|
if(TaxonName.class.isAssignableFrom(event.getEntityType())){
|
615
|
if(event.getType().equals(EntityChangeEvent.Type.CREATED)){
|
616
|
// new name! create a blocking registration
|
617
|
Stack<EditorActionContext>context = ((AbstractPopupEditor)event.getSourceView()).getEditorActionContext();
|
618
|
EditorActionContext rootContext = context.get(0);
|
619
|
if(rootContext.getParentView().equals(getView())){
|
620
|
Registration blockingRegistration = createNewRegistrationForName(event.getEntityId());
|
621
|
TypedEntityReference<Registration> regReference = (TypedEntityReference<Registration>)rootContext.getParentEntity();
|
622
|
Registration registration = getRepo().getRegistrationService().load(regReference.getId(), Arrays.asList("$", "blockedBy"));
|
623
|
registration.getBlockedBy().add(blockingRegistration);
|
624
|
getRepo().getRegistrationService().saveOrUpdate(registration);
|
625
|
logger.debug("Blocking registration created");
|
626
|
} else {
|
627
|
logger.debug("Nn blocking registration, since a new name for a new registration has been created");
|
628
|
}
|
629
|
}
|
630
|
if(workingset.getRegistrationDTOs().stream().anyMatch(reg ->
|
631
|
reg.getTypifiedNameRef() != null
|
632
|
&& reg.getTypifiedNameRef().getId() == event.getEntityId())){
|
633
|
refreshView(true);
|
634
|
}
|
635
|
} else
|
636
|
if(TypeDesignationBase.class.isAssignableFrom(event.getEntityType())){
|
637
|
if(workingset.getRegistrationDTOs().stream().anyMatch(
|
638
|
reg -> reg.getTypeDesignations() != null && reg.getTypeDesignations().stream().anyMatch(
|
639
|
td -> td.getId() == event.getEntityId()
|
640
|
)
|
641
|
)
|
642
|
){
|
643
|
refreshView(true);
|
644
|
}
|
645
|
}
|
646
|
}
|
647
|
|
648
|
|
649
|
@EventBusListenerMethod(filter = ShowDetailsEventEntityTypeFilter.RegistrationDTO.class)
|
650
|
public void onShowDetailsEventForRegistrationDTO(ShowDetailsEvent<RegistrationDTO, Integer> event) {
|
651
|
|
652
|
// FIXME check from own view!!!
|
653
|
if(getView() == null){
|
654
|
return;
|
655
|
}
|
656
|
|
657
|
Integer registrationId = event.getIdentifier();
|
658
|
|
659
|
RegistrationDTO regDto = getWorkingSetService().loadDtoById(registrationId);
|
660
|
if(event.getProperty().equals(RegistrationItem.BLOCKED_BY)){
|
661
|
|
662
|
Set<RegistrationDTO> blockingRegs = getWorkingSetService().loadBlockingRegistrations(registrationId);
|
663
|
getView().setBlockingRegistrations(registrationId, blockingRegs);
|
664
|
} else if(event.getProperty().equals(RegistrationItem.MESSAGES)){
|
665
|
|
666
|
RegistrationMessagesPopup popup = getNavigationManager().showInPopup(RegistrationMessagesPopup.class, getView());
|
667
|
popup.loadMessagesFor(regDto.getId());
|
668
|
|
669
|
} else if(event.getProperty().equals(RegistrationItem.VALIDATION_PROBLEMS)){
|
670
|
getView().openDetailsPopup("Validation Problems", regDto.getValidationProblems());
|
671
|
}
|
672
|
|
673
|
|
674
|
}
|
675
|
|
676
|
}
|