Project

General

Profile

Download (5.04 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.EnumSet;
12

    
13
import org.apache.commons.lang3.StringUtils;
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.api.service.pager.Pager;
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.service.IRegistrationWorkingSetService;
26
import eu.etaxonomy.cdm.vaadin.component.CdmBeanItemContainerFactory;
27
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
28
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
29
import eu.etaxonomy.cdm.vaadin.event.UpdateResultsEvent;
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
    private IRegistrationWorkingSetService workingSetService;
52

    
53
    /**
54
     * @return the workingSetService
55
     */
56
    public IRegistrationWorkingSetService getWorkingSetService() {
57
        return workingSetService;
58
    }
59

    
60
    @Override
61
    public void handleViewEntered() {
62

    
63
        if(getNavigationManager().getCurrentViewParameters().get(0).equals(ListView.Mode.inProgress.name())){
64
            getView().setViewMode(ListViewBean.Mode.inProgress);
65
            getView().getStatusFilter().setVisible(false);
66
        } else {
67
            getView().setViewMode(ListViewBean.Mode.all);
68
        }
69

    
70
        CdmBeanItemContainerFactory selectFieldFactory = new CdmBeanItemContainerFactory(getRepo());
71

    
72
        if(getView().getSubmitterFilter() != null){
73
            getView().getSubmitterFilter().setContainerDataSource(selectFieldFactory.buildBeanItemContainer(User.class));
74
            getView().getSubmitterFilter().setItemCaptionPropertyId("username");
75
        }
76

    
77
        getView().populate(pageRegistrations());
78
    }
79

    
80
    /**
81
     * FIXME write test !!!!!!!!!!!!!!!!!
82
     *
83
     * @return
84
     */
85
    private Pager<RegistrationDTO> pageRegistrations() {
86

    
87
        // list all if the authenticated user is having the role CURATION of if it is an admin
88
        Authentication authentication = currentSecurityContext().getAuthentication();
89

    
90
        // prepare the filters
91
        String identifierFilter = getView().getIdentifierFilter().getValue();
92
        String nameFilter = getView().getTaxonNameFilter().getValue();
93
        User submitter = null;
94
        if(getView().getSubmitterFilter() != null){
95
            Object o = getView().getSubmitterFilter().getValue();
96
            if(o != null){
97
                submitter = (User)o;
98
            }
99
        } else {
100
            submitter = (User) authentication.getPrincipal();
101
        }
102
        EnumSet<RegistrationStatus> includeStatus = inProgressStatus;
103
        if(getView().getViewMode().equals(ListView.Mode.all)){
104
            includeStatus = null;
105
            Object o = getView().getStatusFilter().getValue();
106
            if(o != null){
107
                includeStatus = EnumSet.of((RegistrationStatus)o);
108
            }
109
        }
110

    
111
        Pager<RegistrationDTO> dtoPager = getWorkingSetService().pageDTOs(
112
                submitter,
113
                includeStatus,
114
                StringUtils.trimToNull(identifierFilter),
115
                StringUtils.trimToNull(nameFilter),
116
                null,
117
                null);
118
        return dtoPager;
119
    }
120

    
121
    @EventListener(classes=ShowDetailsEvent.class, condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO)")
122
    public void onShowDetailsEvent(ShowDetailsEvent<?,?> event) { // WARNING don't use more specific generic type arguments
123
        RegistrationDTO regDto = getWorkingSetService().loadDtoById((Integer)event.getIdentifier());
124
        if(event.getProperty().equals("messages")){
125
            if(getView() != null){
126
                getView().openDetailsPopup("Messages", regDto.getMessages());
127
            }
128
        }
129
    }
130

    
131
    @EventListener
132
    public void onEntityChangeEvent(EntityChangeEvent event){
133
        if(event.getEntityType().isAssignableFrom(Reference.class)){
134
            // TODO update component showing the according reference, is there a Vaadin event supporting this?
135
        }
136
    }
137

    
138
    @EventListener
139
    public void onUpdateResultsEvent(UpdateResultsEvent event){
140
        getView().populate(pageRegistrations());
141
    }
142

    
143
}
(2-2/19)