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.beans.factory.annotation.Qualifier;
|
18
|
import org.springframework.context.event.EventListener;
|
19
|
|
20
|
import com.vaadin.server.SystemError;
|
21
|
import com.vaadin.spring.annotation.SpringComponent;
|
22
|
import com.vaadin.spring.annotation.ViewScope;
|
23
|
|
24
|
import eu.etaxonomy.cdm.model.name.Rank;
|
25
|
import eu.etaxonomy.cdm.model.name.Registration;
|
26
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
27
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
28
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
29
|
import eu.etaxonomy.cdm.service.IRegistrationWorkingSetService;
|
30
|
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
|
31
|
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
|
32
|
import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkflowEvent;
|
33
|
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
|
34
|
import eu.etaxonomy.cdm.vaadin.view.reference.ReferencePopupEditor;
|
35
|
import eu.etaxonomy.vaadin.mvp.AbstractPresenter;
|
36
|
|
37
|
/**
|
38
|
* @author a.kohlbecker
|
39
|
* @since Mar 3, 2017
|
40
|
*
|
41
|
*/
|
42
|
@SpringComponent
|
43
|
@ViewScope
|
44
|
public class RegistrationWorkflowPresenter extends AbstractPresenter<RegistrationWorkflowView> implements Serializable{
|
45
|
|
46
|
private static final long serialVersionUID = 1L;
|
47
|
|
48
|
@Autowired
|
49
|
@Qualifier(IRegistrationWorkingSetService.ACTIVE_IMPL)
|
50
|
private IRegistrationWorkingSetService workingSetService;
|
51
|
|
52
|
private RegistrationWorkingSet workingset;
|
53
|
|
54
|
/**
|
55
|
*
|
56
|
*/
|
57
|
public RegistrationWorkflowPresenter() {
|
58
|
}
|
59
|
|
60
|
@EventListener
|
61
|
protected void onRegistrationStartEvent(RegistrationWorkflowEvent event){
|
62
|
|
63
|
boolean HACK = true;
|
64
|
if(workingset != null && !HACK){
|
65
|
Logger.getLogger(RegistrationWorkflowPresenter.class).warn("Can't start a new workflow over an existing one.");
|
66
|
return;
|
67
|
}
|
68
|
|
69
|
if(event.isStart()) {
|
70
|
workingset = new RegistrationWorkingSet();
|
71
|
Registration reg = Registration.NewInstance();
|
72
|
reg.setName(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()));
|
73
|
getView().setHeaderText("New " + event.getType().name().toString()+ " Registration");
|
74
|
try {
|
75
|
workingset.add(reg);
|
76
|
} catch (RegistrationValidationException error) {
|
77
|
getView().getWorkflow().setComponentError(new SystemError(error));
|
78
|
}
|
79
|
} else {
|
80
|
try {
|
81
|
workingset = workingSetService.loadWorkingSetByRegistrationID(event.getRegistrationID());
|
82
|
} catch (RegistrationValidationException error) {
|
83
|
getView().getWorkflow().setComponentError(new SystemError(error));
|
84
|
}
|
85
|
getView().setHeaderText("Registration for " + workingset.getCitation());
|
86
|
}
|
87
|
if(workingset != null){
|
88
|
getView().setWorkingset(workingset);
|
89
|
//TODO add Blocking registrations to view
|
90
|
}
|
91
|
}
|
92
|
|
93
|
@EventListener(condition = "#event.eventType ==T(eu.etaxonomy.cdm.vaadin.event.EntityEventType).ADD")
|
94
|
public void onReferenceAddEvent(ReferenceEditorAction event) {
|
95
|
Reference reference = ReferenceFactory.newGeneric();
|
96
|
ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
|
97
|
popup.showInEditor(reference);
|
98
|
}
|
99
|
|
100
|
@EventListener(condition = "#event.eventType ==T(eu.etaxonomy.cdm.vaadin.event.EntityEventType).EDIT")
|
101
|
public void onReferenceEditEvent(ReferenceEditorAction event) {
|
102
|
Reference reference = getRepo().getReferenceService().find(event.getEntityId());
|
103
|
ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class);
|
104
|
popup.showInEditor(reference);
|
105
|
}
|
106
|
|
107
|
|
108
|
@EventListener(classes=ShowDetailsEvent.class, condition = "#event.entityType == T(eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet)")
|
109
|
public void onShowRegistrationWorkingSetMessages(ShowDetailsEvent<?,?> event) { // WARNING don't use more specific generic type arguments
|
110
|
List<String> messages = new ArrayList<>();
|
111
|
for(RegistrationDTO dto : workingset.getRegistrationDTOs()){
|
112
|
dto.getMessages().forEach(m -> messages.add(dto.getSummary() + ": " + m));
|
113
|
}
|
114
|
if(event.getProperty().equals("messages")){
|
115
|
getView().openDetailsPopup("Messages", messages);
|
116
|
}
|
117
|
}
|
118
|
|
119
|
@EventListener(classes=ShowDetailsEvent.class, condition = "#event.entityType == T(eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO)")
|
120
|
public void onShowRegistrationMessages(ShowDetailsEvent<?,?> event) { // WARNING don't use more specific generic type arguments
|
121
|
RegistrationDTO regDto = workingSetService.loadDtoById((Integer)event.getIdentifier());
|
122
|
if(event.getProperty().equals("messages")){
|
123
|
if(getView() != null){
|
124
|
getView().openDetailsPopup("Messages", regDto.getMessages());
|
125
|
}
|
126
|
}
|
127
|
}
|
128
|
|
129
|
}
|