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.Collection;
|
12
|
import java.util.EnumSet;
|
13
|
|
14
|
import org.springframework.beans.factory.annotation.Autowired;
|
15
|
import org.springframework.beans.factory.annotation.Qualifier;
|
16
|
import org.springframework.context.event.EventListener;
|
17
|
import org.springframework.security.core.Authentication;
|
18
|
|
19
|
import com.vaadin.spring.annotation.SpringComponent;
|
20
|
import com.vaadin.spring.annotation.ViewScope;
|
21
|
|
22
|
import eu.etaxonomy.cdm.model.common.User;
|
23
|
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
|
24
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
25
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
|
26
|
import eu.etaxonomy.cdm.service.IRegistrationWorkingSetService;
|
27
|
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
|
28
|
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
|
29
|
import eu.etaxonomy.cdm.vaadin.security.RolesAndPermissions;
|
30
|
import eu.etaxonomy.vaadin.mvp.AbstractPresenter;
|
31
|
|
32
|
/**
|
33
|
*
|
34
|
* @author a.kohlbecker
|
35
|
* @since Mar 3, 2017
|
36
|
*
|
37
|
*/
|
38
|
@SpringComponent
|
39
|
@ViewScope
|
40
|
public class ListPresenter extends AbstractPresenter<ListView> {
|
41
|
|
42
|
private static final EnumSet<RegistrationStatus> inProgressStatus = EnumSet.of(
|
43
|
RegistrationStatus.PREPARATION,
|
44
|
RegistrationStatus.CURATION,
|
45
|
RegistrationStatus.READY
|
46
|
);
|
47
|
|
48
|
private static final long serialVersionUID = 5419947244621450665L;
|
49
|
|
50
|
@Autowired
|
51
|
@Qualifier(IRegistrationWorkingSetService.ACTIVE_IMPL)
|
52
|
private IRegistrationWorkingSetService workingSetService;
|
53
|
|
54
|
@Override
|
55
|
public void handleViewEntered() {
|
56
|
getView().populate(listRegistrations());
|
57
|
}
|
58
|
|
59
|
/**
|
60
|
* FIXME write test !!!!!!!!!!!!!!!!!
|
61
|
*
|
62
|
* @return
|
63
|
*/
|
64
|
private Collection<RegistrationDTO> listRegistrations() {
|
65
|
|
66
|
// list all if the authenticated user is having the role CURATION of if it is an admin
|
67
|
Authentication authentication = currentSecurityContext().getAuthentication();
|
68
|
User submitter = null;
|
69
|
if(!authentication.getAuthorities().stream().anyMatch(ga -> ga.equals(RolesAndPermissions.ROLE_CURATION) || ga.equals(Role.ROLE_ADMIN))){
|
70
|
submitter = (User) authentication.getPrincipal();
|
71
|
}
|
72
|
|
73
|
// determine whether to show all or only registrations in progress
|
74
|
EnumSet<RegistrationStatus> includeStatus = null;
|
75
|
try {
|
76
|
if(getNavigationManager().getCurrentViewParameters().get(0).equals(ListViewBean.OPTION_IN_PROGRESS)){
|
77
|
includeStatus = inProgressStatus;
|
78
|
}
|
79
|
} catch (IndexOutOfBoundsException e){
|
80
|
// no parameter provided: IGNORE
|
81
|
}
|
82
|
|
83
|
Collection<RegistrationDTO> dtos = workingSetService.listDTOs(submitter, includeStatus);
|
84
|
return dtos;
|
85
|
}
|
86
|
|
87
|
@EventListener(classes=ShowDetailsEvent.class, condition = "#event.entityType == T(eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO)")
|
88
|
public void onShowDetailsEvent(ShowDetailsEvent<?,?> event) { // WARNING don't use more specific generic type arguments
|
89
|
RegistrationDTO regDto = workingSetService.loadDtoById((Integer)event.getIdentifier());
|
90
|
if(event.getProperty().equals("messages")){
|
91
|
if(getView() != null){
|
92
|
getView().openDetailsPopup("Messages", regDto.getMessages());
|
93
|
}
|
94
|
}
|
95
|
}
|
96
|
|
97
|
@EventListener
|
98
|
public void onEntityChangeEvent(EntityChangeEvent event){
|
99
|
if(event.getEntityType().isAssignableFrom(Reference.class)){
|
100
|
// TODO update component showing the according reference, is there a Vaadin event supporting this?
|
101
|
}
|
102
|
|
103
|
}
|
104
|
|
105
|
}
|