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