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.EnumSet;
|
12
|
|
13
|
import org.apache.commons.lang3.StringUtils;
|
14
|
import org.springframework.beans.factory.annotation.Autowired;
|
15
|
import org.springframework.security.core.Authentication;
|
16
|
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
17
|
|
18
|
import com.vaadin.spring.annotation.SpringComponent;
|
19
|
import com.vaadin.spring.annotation.ViewScope;
|
20
|
import com.vaadin.ui.TextField;
|
21
|
|
22
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
23
|
import eu.etaxonomy.cdm.model.common.User;
|
24
|
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
|
25
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
26
|
import eu.etaxonomy.cdm.service.IRegistrationWorkingSetService;
|
27
|
import eu.etaxonomy.cdm.vaadin.component.CdmBeanItemContainerFactory;
|
28
|
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
|
29
|
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
|
30
|
import eu.etaxonomy.cdm.vaadin.event.UpdateResultsEvent;
|
31
|
import eu.etaxonomy.vaadin.mvp.AbstractPresenter;
|
32
|
|
33
|
/**
|
34
|
*
|
35
|
* @author a.kohlbecker
|
36
|
* @since Mar 3, 2017
|
37
|
*
|
38
|
*/
|
39
|
@SpringComponent
|
40
|
@ViewScope
|
41
|
public class ListPresenter extends AbstractPresenter<ListView> {
|
42
|
|
43
|
private static final EnumSet<RegistrationStatus> inProgressStatus = EnumSet.of(
|
44
|
RegistrationStatus.PREPARATION,
|
45
|
RegistrationStatus.CURATION,
|
46
|
RegistrationStatus.READY
|
47
|
);
|
48
|
|
49
|
private static final long serialVersionUID = 5419947244621450665L;
|
50
|
|
51
|
@Autowired
|
52
|
private IRegistrationWorkingSetService workingSetService;
|
53
|
|
54
|
/**
|
55
|
* @return the workingSetService
|
56
|
*/
|
57
|
public IRegistrationWorkingSetService getWorkingSetService() {
|
58
|
return workingSetService;
|
59
|
}
|
60
|
|
61
|
|
62
|
@Override
|
63
|
public void handleViewEntered() {
|
64
|
|
65
|
if(getNavigationManager().getCurrentViewParameters().get(0).equals(ListView.Mode.inProgress.name())){
|
66
|
getView().setViewMode(ListViewBean.Mode.inProgress);
|
67
|
getView().getStatusFilter().setVisible(false);
|
68
|
} else {
|
69
|
getView().setViewMode(ListViewBean.Mode.all);
|
70
|
}
|
71
|
|
72
|
CdmBeanItemContainerFactory selectFieldFactory = new CdmBeanItemContainerFactory(getRepo());
|
73
|
|
74
|
if(getView().getSubmitterFilter() != null){
|
75
|
getView().getSubmitterFilter().setContainerDataSource(selectFieldFactory.buildBeanItemContainer(User.class));
|
76
|
getView().getSubmitterFilter().setItemCaptionPropertyId("username");
|
77
|
}
|
78
|
|
79
|
getView().populate(pageRegistrations(null, null));
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* FIXME write test !!!!!!!!!!!!!!!!!
|
84
|
*
|
85
|
* @return
|
86
|
*/
|
87
|
private Pager<RegistrationDTO> pageRegistrations(TextField textFieldOverride, String alternativeText) {
|
88
|
|
89
|
// list all if the authenticated user is having the role CURATION of if it is an admin
|
90
|
Authentication authentication = currentSecurityContext().getAuthentication();
|
91
|
|
92
|
// prepare the filters
|
93
|
String identifierFilter;
|
94
|
if(textFieldOverride != null && textFieldOverride == getView().getIdentifierFilter()){
|
95
|
identifierFilter = alternativeText;
|
96
|
} else {
|
97
|
identifierFilter = getView().getIdentifierFilter().getValue();
|
98
|
}
|
99
|
String nameFilter;
|
100
|
if(textFieldOverride != null && textFieldOverride == getView().getTaxonNameFilter()){
|
101
|
nameFilter = alternativeText;
|
102
|
} else {
|
103
|
nameFilter = getView().getTaxonNameFilter().getValue();
|
104
|
}
|
105
|
User submitter = null;
|
106
|
if(getView().getSubmitterFilter() != null){
|
107
|
Object o = getView().getSubmitterFilter().getValue();
|
108
|
if(o != null){
|
109
|
submitter = (User)o;
|
110
|
}
|
111
|
} else {
|
112
|
submitter = (User) authentication.getPrincipal();
|
113
|
}
|
114
|
EnumSet<RegistrationStatus> includeStatus = inProgressStatus;
|
115
|
if(getView().getViewMode().equals(ListView.Mode.all)){
|
116
|
includeStatus = null;
|
117
|
Object o = getView().getStatusFilter().getValue();
|
118
|
if(o != null){
|
119
|
includeStatus = EnumSet.of((RegistrationStatus)o);
|
120
|
}
|
121
|
}
|
122
|
|
123
|
Pager<RegistrationDTO> dtoPager = getWorkingSetService().pageDTOs(
|
124
|
submitter,
|
125
|
includeStatus,
|
126
|
StringUtils.trimToNull(identifierFilter),
|
127
|
StringUtils.trimToNull(nameFilter),
|
128
|
null,
|
129
|
null);
|
130
|
return dtoPager;
|
131
|
}
|
132
|
|
133
|
@EventBusListenerMethod
|
134
|
public void onShowDetailsEvent(ShowDetailsEvent<?,?> event) {
|
135
|
|
136
|
if(event.getEntityType().equals(RegistrationDTO.class)){
|
137
|
RegistrationDTO regDto = getWorkingSetService().loadDtoById((Integer)event.getIdentifier());
|
138
|
if(event.getProperty().equals("messages")){
|
139
|
if(getView() != null){
|
140
|
getView().openDetailsPopup("Messages", regDto.getMessages());
|
141
|
}
|
142
|
}
|
143
|
}
|
144
|
}
|
145
|
|
146
|
@EventBusListenerMethod
|
147
|
public void onEntityChangeEvent(EntityChangeEvent event){
|
148
|
if(event.getEntityType().isAssignableFrom(Reference.class)){
|
149
|
// TODO update component showing the according reference, is there a Vaadin event supporting this?
|
150
|
}
|
151
|
}
|
152
|
|
153
|
@EventBusListenerMethod
|
154
|
public void onUpdateResultsEvent(UpdateResultsEvent event){
|
155
|
getView().populate(pageRegistrations(event.getField(), event.getNewText()));
|
156
|
}
|
157
|
|
158
|
}
|