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.presenter.registration;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.List;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.springframework.beans.factory.annotation.Autowired;
|
16
|
import org.springframework.context.event.EventListener;
|
17
|
|
18
|
import com.vaadin.server.SystemError;
|
19
|
import com.vaadin.spring.annotation.SpringComponent;
|
20
|
import com.vaadin.spring.annotation.ViewScope;
|
21
|
|
22
|
import eu.etaxonomy.cdm.mock.Registration;
|
23
|
import eu.etaxonomy.cdm.mock.RegistrationService;
|
24
|
import eu.etaxonomy.cdm.model.name.Rank;
|
25
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
26
|
import eu.etaxonomy.cdm.vaadin.event.ReferenceEvent;
|
27
|
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
|
28
|
import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkflowEvent;
|
29
|
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
|
30
|
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationWorkflowView;
|
31
|
import eu.etaxonomy.vaadin.mvp.AbstractPresenter;
|
32
|
|
33
|
/**
|
34
|
* @author a.kohlbecker
|
35
|
* @since Mar 3, 2017
|
36
|
*
|
37
|
*/
|
38
|
@SpringComponent
|
39
|
@ViewScope
|
40
|
public class RegistrationWorkflowPresenter extends AbstractPresenter<RegistrationWorkflowView> {
|
41
|
|
42
|
|
43
|
@Autowired
|
44
|
private RegistrationService serviceMock;
|
45
|
|
46
|
private RegistrationWorkingSet workingset;
|
47
|
|
48
|
/**
|
49
|
*
|
50
|
*/
|
51
|
public RegistrationWorkflowPresenter() {
|
52
|
}
|
53
|
|
54
|
@EventListener
|
55
|
protected void onRegistrationStartEvent(RegistrationWorkflowEvent event){
|
56
|
|
57
|
if(workingset != null){
|
58
|
Logger.getLogger(RegistrationWorkflowPresenter.class).warn("Cant start a new workflow over an existing one.");
|
59
|
return;
|
60
|
}
|
61
|
|
62
|
|
63
|
if(event.isStart()) {
|
64
|
workingset = new RegistrationWorkingSet();
|
65
|
Registration reg = new Registration();
|
66
|
reg.setName(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()));
|
67
|
getView().setHeaderText("New " + event.getType().name().toString()+ " Registration");
|
68
|
try {
|
69
|
workingset.add(reg);
|
70
|
} catch (RegistrationValidationException error) {
|
71
|
getView().getWorkflow().setComponentError(new SystemError(error));
|
72
|
}
|
73
|
} else {
|
74
|
try {
|
75
|
workingset = serviceMock.loadWorkingSetByRegistrationID(event.getRegistrationID());
|
76
|
} catch (RegistrationValidationException error) {
|
77
|
getView().getWorkflow().setComponentError(new SystemError(error));
|
78
|
}
|
79
|
getView().setHeaderText("Registration for " + workingset.getCitation());
|
80
|
}
|
81
|
if(workingset != null){
|
82
|
getView().setWorkingset(workingset);
|
83
|
//TODO add Blocking registrations to view
|
84
|
}
|
85
|
}
|
86
|
|
87
|
// @EventListener(condition = "#event.eventType ==T(eu.etaxonomy.cdm.vaadin.event.EventType).ADD")
|
88
|
// public void onReferenceAddEvent(ReferenceEvent event) {
|
89
|
// getView().openReferenceEditor(null);
|
90
|
// }
|
91
|
|
92
|
@EventListener(condition = "#event.eventType ==T(eu.etaxonomy.cdm.vaadin.event.EntityEventType).EDIT")
|
93
|
public void onReferenceEditEvent(ReferenceEvent event) {
|
94
|
getView().openReferenceEditor(null);
|
95
|
}
|
96
|
|
97
|
|
98
|
@EventListener(classes=ShowDetailsEvent.class, condition = "#event.entityType == T(eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet)")
|
99
|
public void onShowRegistrationWorkingSetMessages(ShowDetailsEvent<?,?> event) { // WARNING don't use more specific generic type arguments
|
100
|
List<String> messages = new ArrayList<>();
|
101
|
for(RegistrationDTO dto : workingset.getRegistrationDTOs()){
|
102
|
dto.getMessages().forEach(m -> messages.add(dto.getSummary() + ": " + m));
|
103
|
}
|
104
|
if(event.getProperty().equals("messages")){
|
105
|
getView().openDetailsPopup("Messages", messages);
|
106
|
}
|
107
|
}
|
108
|
|
109
|
@EventListener(classes=ShowDetailsEvent.class, condition = "#event.entityType == T(eu.etaxonomy.cdm.vaadin.presenter.registration.RegistrationDTO)")
|
110
|
public void onShowRegistrationMessages(ShowDetailsEvent<?,?> event) { // WARNING don't use more specific generic type arguments
|
111
|
RegistrationDTO regDto = serviceMock.loadDtoById((Integer)event.getIdentifier());
|
112
|
if(event.getProperty().equals("messages")){
|
113
|
getView().openDetailsPopup("Messages", regDto.getMessages());
|
114
|
}
|
115
|
}
|
116
|
|
117
|
}
|