Project

General

Profile

Download (3.66 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.persistence.hibernate.permission.Role;
25
import eu.etaxonomy.cdm.service.IRegistrationWorkingSetService;
26
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
27
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
28
import eu.etaxonomy.cdm.vaadin.security.RolesAndPermissions;
29
import eu.etaxonomy.vaadin.mvp.AbstractPresenter;
30

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

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

    
47
    private static final long serialVersionUID = 5419947244621450665L;
48

    
49
    @Autowired
50
    private IRegistrationWorkingSetService workingSetService;
51

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

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

    
64
        // list all if the authenticated user is having the role CURATION of if it is an admin
65
        Authentication authentication = currentSecurityContext().getAuthentication();
66
        User submitter = null;
67
        if(!authentication.getAuthorities().stream().anyMatch(ga -> ga.equals(RolesAndPermissions.ROLE_CURATION) || ga.equals(Role.ROLE_ADMIN))){
68
            submitter = (User) authentication.getPrincipal();
69
        }
70

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

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

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

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

    
101
    }
102

    
103
}
(2-2/17)