Project

General

Profile

Download (3.56 KB) Statistics
| Branch: | Tag: | Revision:
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.context.event.EventListener;
16
import org.springframework.security.core.Authentication;
17

    
18
import com.vaadin.spring.annotation.SpringComponent;
19
import com.vaadin.spring.annotation.ViewScope;
20

    
21
import eu.etaxonomy.cdm.model.common.User;
22
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
23
import eu.etaxonomy.cdm.model.reference.Reference;
24
import eu.etaxonomy.cdm.service.IRegistrationWorkingSetService;
25
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
26
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
27
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
28
import eu.etaxonomy.vaadin.mvp.AbstractPresenter;
29

    
30
/**
31
 *
32
 * @author a.kohlbecker
33
 * @since Mar 3, 2017
34
 *
35
 */
36
@SpringComponent
37
@ViewScope
38
public class ListPresenter extends AbstractPresenter<ListView> {
39

    
40
    private static final EnumSet<RegistrationStatus> inProgressStatus = EnumSet.of(
41
            RegistrationStatus.PREPARATION,
42
            RegistrationStatus.CURATION,
43
            RegistrationStatus.READY
44
            );
45

    
46
    private static final long serialVersionUID = 5419947244621450665L;
47

    
48
    @Autowired
49
    private IRegistrationWorkingSetService workingSetService;
50

    
51
    @Override
52
    public void handleViewEntered() {
53
        getView().populate(listRegistrations());
54
    }
55

    
56
    /**
57
     * FIXME write test !!!!!!!!!!!!!!!!!
58
     *
59
     * @return
60
     */
61
    private Collection<RegistrationDTO> listRegistrations() {
62

    
63
        // list all if the authenticated user is having the role CURATION of if it is an admin
64
        Authentication authentication = currentSecurityContext().getAuthentication();
65
        User submitter = null;
66
        if(!(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin())) {
67
            submitter = (User) authentication.getPrincipal();
68
        }
69

    
70
        // determine whether to show all or only registrations in progress
71
        EnumSet<RegistrationStatus> includeStatus = null;
72
        try {
73
            if(getNavigationManager().getCurrentViewParameters().get(0).equals(ListViewBean.OPTION_IN_PROGRESS)){
74
                includeStatus = inProgressStatus;
75
            }
76
        } catch (IndexOutOfBoundsException e){
77
            // no parameter provided:  IGNORE
78
        }
79

    
80
        Collection<RegistrationDTO> dtos = workingSetService.listDTOs(submitter, includeStatus);
81
        return dtos;
82
    }
83

    
84
    @EventListener(classes=ShowDetailsEvent.class, condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO)")
85
    public void onShowDetailsEvent(ShowDetailsEvent<?,?> event) { // WARNING don't use more specific generic type arguments
86
        RegistrationDTO regDto = workingSetService.loadDtoById((Integer)event.getIdentifier());
87
        if(event.getProperty().equals("messages")){
88
            if(getView() != null){
89
                getView().openDetailsPopup("Messages", regDto.getMessages());
90
            }
91
        }
92
    }
93

    
94
    @EventListener
95
    public void onEntityChangeEvent(EntityChangeEvent event){
96
        if(event.getEntityType().isAssignableFrom(Reference.class)){
97
            // TODO update component showing the according reference, is there a Vaadin event supporting this?
98
        }
99

    
100
    }
101

    
102
}
(2-2/17)