Project

General

Profile

Download (3.72 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
    /**
52
     * @return the workingSetService
53
     */
54
    public IRegistrationWorkingSetService getWorkingSetService() {
55
        return workingSetService;
56
    }
57

    
58
    @Override
59
    public void handleViewEntered() {
60
        getView().populate(listRegistrations());
61
    }
62

    
63
    /**
64
     * FIXME write test !!!!!!!!!!!!!!!!!
65
     *
66
     * @return
67
     */
68
    private Collection<RegistrationDTO> listRegistrations() {
69

    
70
        // list all if the authenticated user is having the role CURATION of if it is an admin
71
        Authentication authentication = currentSecurityContext().getAuthentication();
72
        User submitter = null;
73
        if(!(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin())) {
74
            submitter = (User) authentication.getPrincipal();
75
        }
76

    
77
        // determine whether to show all or only registrations in progress
78
        EnumSet<RegistrationStatus> includeStatus = null;
79
        try {
80
            if(getNavigationManager().getCurrentViewParameters().get(0).equals(ListViewBean.OPTION_IN_PROGRESS)){
81
                includeStatus = inProgressStatus;
82
            }
83
        } catch (IndexOutOfBoundsException e){
84
            // no parameter provided:  IGNORE
85
        }
86

    
87
        Collection<RegistrationDTO> dtos = getWorkingSetService().listDTOs(submitter, includeStatus);
88
        return dtos;
89
    }
90

    
91
    @EventListener(classes=ShowDetailsEvent.class, condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO)")
92
    public void onShowDetailsEvent(ShowDetailsEvent<?,?> event) { // WARNING don't use more specific generic type arguments
93
        RegistrationDTO regDto = getWorkingSetService().loadDtoById((Integer)event.getIdentifier());
94
        if(event.getProperty().equals("messages")){
95
            if(getView() != null){
96
                getView().openDetailsPopup("Messages", regDto.getMessages());
97
            }
98
        }
99
    }
100

    
101
    @EventListener
102
    public void onEntityChangeEvent(EntityChangeEvent event){
103
        if(event.getEntityType().isAssignableFrom(Reference.class)){
104
            // TODO update component showing the according reference, is there a Vaadin event supporting this?
105
        }
106

    
107
    }
108

    
109
}
(2-2/19)