Project

General

Profile

« Previous | Next » 

Revision 65c80174

Added by Andreas Kohlbecker over 6 years ago

fix #7130 implementing registration list filters

View differences:

src/main/java/eu/etaxonomy/cdm/service/IRegistrationWorkingSetService.java
10 10

  
11 11
import java.util.Collection;
12 12

  
13
import eu.etaxonomy.cdm.api.service.pager.Pager;
13 14
import eu.etaxonomy.cdm.model.common.User;
14 15
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
15 16
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
......
29 30
     */
30 31
    public RegistrationDTO loadDtoById(Integer id);
31 32

  
33
    public Pager<RegistrationDTO> pageDTOs(Integer pageSize, Integer pageIndex);
32 34

  
33
    public Collection<RegistrationDTO> listDTOs();
34

  
35
    public Collection<RegistrationDTO> listDTOs(User submitter, Collection<RegistrationStatus> includedStatus);
35
    public Pager<RegistrationDTO> pageDTOs(User submitter, Collection<RegistrationStatus> includedStatus,
36
            String identifierFilterPattern, String taxonNameFilterPattern,
37
            Integer pageSize, Integer pageIndex);
36 38

  
37 39
    /**
38 40
     * @param referenceID
src/main/java/eu/etaxonomy/cdm/service/RegistrationWorkingSetService.java
24 24

  
25 25
import eu.etaxonomy.cdm.api.application.CdmRepository;
26 26
import eu.etaxonomy.cdm.api.service.pager.Pager;
27
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
27 28
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
28 29
import eu.etaxonomy.cdm.model.common.User;
29 30
import eu.etaxonomy.cdm.model.name.Registration;
......
127 128

  
128 129

  
129 130
    @Override
130
    public Collection<RegistrationDTO> listDTOs() {
131
    public Pager<RegistrationDTO> pageDTOs(Integer pageSize, Integer pageIndex) {
131 132

  
132
        List<Registration> regs = repo.getRegistrationService().list(null, PAGE_SIZE, 0, null, REGISTRATION_INIT_STRATEGY);
133

  
134
        List<RegistrationDTO> dtos = makeDTOs(regs);
135
        return dtos;
133
        return pageDTOs(null, null, null, null, pageSize, pageIndex);
136 134
    }
137 135

  
138 136
    /**
139 137
     * {@inheritDoc}
140 138
     */
141 139
    @Override
142
    public Collection<RegistrationDTO> listDTOs(User submitter, Collection<RegistrationStatus> includedStatus) {
140
    public Pager<RegistrationDTO> pageDTOs(User submitter, Collection<RegistrationStatus> includedStatus,
141
            String identifierFilterPattern, String taxonNameFilterPattern,
142
            Integer pageSize, Integer pageIndex) {
143

  
144
        if(pageSize == null){
145
            pageSize = PAGE_SIZE;
146
        }
143 147

  
144
        Pager<Registration> pager = repo.getRegistrationService().page(submitter, includedStatus, PAGE_SIZE, 0, null, REGISTRATION_INIT_STRATEGY);
148
        Pager<Registration> pager = repo.getRegistrationService().page(submitter, includedStatus,
149
                identifierFilterPattern, taxonNameFilterPattern,
150
                PAGE_SIZE, 0, null, REGISTRATION_INIT_STRATEGY);
145 151
        List<Registration> registrations = pager.getRecords();
146
        return makeDTOs(registrations);
152
        Pager<RegistrationDTO> dtoPager = new DefaultPagerImpl(pager.getCurrentIndex(), pager.getCount(), pager.getPageSize(), makeDTOs(registrations));
153
        return dtoPager;
147 154
    }
148 155

  
149 156
    /**
src/main/java/eu/etaxonomy/cdm/vaadin/event/UpdateResultsEvent.java
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.event;
10

  
11
import eu.etaxonomy.vaadin.mvp.AbstractView;
12

  
13
/**
14
 * @author a.kohlbecker
15
 * @since Dec 7, 2017
16
 *
17
 */
18
public class UpdateResultsEvent {
19

  
20
    private AbstractView sourceView = null;
21

  
22

  
23
    /**
24
     * @param sourceView
25
     */
26
    public UpdateResultsEvent(AbstractView sourceView) {
27
        super();
28
        this.sourceView = sourceView;
29
    }
30

  
31
    /**
32
     * @return the sourceView
33
     */
34
    public AbstractView getSourceView() {
35
        return sourceView;
36
    }
37

  
38
    /**
39
     * @param sourceView the sourceView to set
40
     */
41
    public void setSourceView(AbstractView sourceView) {
42
        this.sourceView = sourceView;
43
    }
44

  
45

  
46

  
47
}
src/main/java/eu/etaxonomy/cdm/vaadin/ui/RegistrationUI.java
33 33
import eu.etaxonomy.cdm.vaadin.toolbar.Toolbar;
34 34
import eu.etaxonomy.cdm.vaadin.view.RedirectToLoginView;
35 35
import eu.etaxonomy.cdm.vaadin.view.registration.DashBoardView;
36
import eu.etaxonomy.cdm.vaadin.view.registration.ListView;
36 37
import eu.etaxonomy.cdm.vaadin.view.registration.ListViewBean;
37 38
import eu.etaxonomy.cdm.vaadin.view.registration.StartRegistrationViewBean;
38 39
import eu.etaxonomy.vaadin.ui.MainMenu;
......
125 126
        mainMenu.addMenuComponent(phycoBankLogo);
126 127

  
127 128
        mainMenu.addMenuItem("New", FontAwesome.EDIT, StartRegistrationViewBean.NAME );
128
        mainMenu.addMenuItem("Continue", FontAwesome.ARROW_RIGHT, ListViewBean.NAME + "/" + ListViewBean.OPTION_IN_PROGRESS);
129
        mainMenu.addMenuItem("List", FontAwesome.TASKS, ListViewBean.NAME + "/" + ListViewBean.OPTION_ALL);
129
        mainMenu.addMenuItem("Continue", FontAwesome.ARROW_RIGHT, ListViewBean.NAME + "/" + ListView.Mode.inProgress.name());
130
        mainMenu.addMenuItem("List", FontAwesome.TASKS, ListViewBean.NAME + "/" + ListView.Mode.all.name());
130 131

  
131 132
        if(ToolbarDisplay.class.isAssignableFrom(viewDisplay.getClass())){
132 133
            ((ToolbarDisplay)viewDisplay).setToolbar(toolbar);
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/DashBoardView.java
37 37
    public DashBoardView() {
38 38
        Responsive.makeResponsive(dashboard);
39 39
        buttonNew.addClickListener(e -> eventBus.publishEvent(new NavigationEvent(StartRegistrationViewBean.NAME)));
40
        buttonContinue.addClickListener(e -> eventBus.publishEvent(new NavigationEvent(ListViewBean.NAME + "/" + ListViewBean.OPTION_IN_PROGRESS)));
41
        buttonList.addClickListener(e -> eventBus.publishEvent(new NavigationEvent(ListViewBean.NAME + "/" + ListViewBean.OPTION_ALL)));
40
        buttonContinue.addClickListener(e -> eventBus.publishEvent(new NavigationEvent(ListViewBean.NAME + "/" + ListView.Mode.inProgress.name())));
41
        buttonList.addClickListener(e -> eventBus.publishEvent(new NavigationEvent(ListViewBean.NAME + "/" + ListViewBean.Mode.all.name())));
42 42
    }
43 43

  
44 44
    /**
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/ListPresenter.java
8 8
*/
9 9
package eu.etaxonomy.cdm.vaadin.view.registration;
10 10

  
11
import java.util.Collection;
12 11
import java.util.EnumSet;
13 12

  
13
import org.apache.commons.lang3.StringUtils;
14 14
import org.springframework.beans.factory.annotation.Autowired;
15 15
import org.springframework.context.event.EventListener;
16 16
import org.springframework.security.core.Authentication;
......
18 18
import com.vaadin.spring.annotation.SpringComponent;
19 19
import com.vaadin.spring.annotation.ViewScope;
20 20

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

  
30 32
/**
......
57 59

  
58 60
    @Override
59 61
    public void handleViewEntered() {
60
        getView().populate(listRegistrations());
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
        getView().getSubmitterFilter().setContainerDataSource(selectFieldFactory.buildBeanItemContainer(User.class));
73
        getView().getSubmitterFilter().setItemCaptionPropertyId("username");
74

  
75
        getView().populate(pageRegistrations());
61 76
    }
62 77

  
63 78
    /**
......
65 80
     *
66 81
     * @return
67 82
     */
68
    private Collection<RegistrationDTO> listRegistrations() {
83
    private Pager<RegistrationDTO> pageRegistrations() {
69 84

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

  
88
        // prepare the filters
89
        String identifierFilter = getView().getIdentifierFilter().getValue();
90
        String nameFilter = getView().getTaxonNameFilter().getValue();
72 91
        User submitter = null;
73
        if(!(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin())) {
92
        if(getView().getSubmitterFilter() != null){
93
            Object o = getView().getSubmitterFilter().getValue();
94
            if(o != null){
95
                submitter = (User)o;
96
            }
97
        } else {
74 98
            submitter = (User) authentication.getPrincipal();
75 99
        }
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;
100
        EnumSet<RegistrationStatus> includeStatus = inProgressStatus;
101
        if(getView().getViewMode().equals(ListView.Mode.all)){
102
            includeStatus = null;
103
            Object o = getView().getStatusFilter().getValue();
104
            if(o != null){
105
                includeStatus = EnumSet.of((RegistrationStatus)o);
82 106
            }
83
        } catch (IndexOutOfBoundsException e){
84
            // no parameter provided:  IGNORE
85 107
        }
86 108

  
87
        Collection<RegistrationDTO> dtos = getWorkingSetService().listDTOs(submitter, includeStatus);
88
        return dtos;
109
        Pager<RegistrationDTO> dtoPager = getWorkingSetService().pageDTOs(
110
                submitter,
111
                includeStatus,
112
                StringUtils.trimToNull(identifierFilter),
113
                StringUtils.trimToNull(nameFilter),
114
                null,
115
                null);
116
        return dtoPager;
89 117
    }
90 118

  
91 119
    @EventListener(classes=ShowDetailsEvent.class, condition = "#event.type == T(eu.etaxonomy.cdm.vaadin.view.registration.RegistrationDTO)")
......
103 131
        if(event.getEntityType().isAssignableFrom(Reference.class)){
104 132
            // TODO update component showing the according reference, is there a Vaadin event supporting this?
105 133
        }
134
    }
106 135

  
136
    @EventListener
137
    public void onUpdateResultsEvent(UpdateResultsEvent event){
138
        getView().populate(pageRegistrations());
107 139
    }
108 140

  
109 141
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/ListView.java
8 8
*/
9 9
package eu.etaxonomy.cdm.vaadin.view.registration;
10 10

  
11
import java.util.Collection;
12 11
import java.util.List;
13 12

  
13
import com.vaadin.ui.ListSelect;
14
import com.vaadin.ui.TextField;
15

  
16
import eu.etaxonomy.cdm.api.service.pager.Pager;
14 17
import eu.etaxonomy.vaadin.mvp.ApplicationView;
15 18

  
16 19
/**
......
20 23
 */
21 24
public interface ListView extends ApplicationView<ListPresenter>{
22 25

  
26
    enum Mode {
27
        all,
28
        inProgress
29
    }
30

  
23 31
    /**
24 32
     * @param page
25 33
     */
26
    void populate(Collection<RegistrationDTO> registrations);
34
    void populate(Pager<RegistrationDTO> registrations);
27 35

  
28 36
    /**
29 37
     * @param messages
30 38
     */
31 39
    void openDetailsPopup(String caption, List<String> messages);
32 40

  
41
    /**
42
     * @return the identifierFilter
43
     */
44
    public TextField getIdentifierFilter();
45

  
46
    /**
47
     * @return the taxonNameFilter
48
     */
49
    public TextField getTaxonNameFilter();
50

  
51
    /**
52
     * @return the referenceFilter
53
     */
54
    public TextField getReferenceFilter();
55

  
56
    /**
57
     * @return the statusFilter
58
     */
59
    public ListSelect getStatusFilter();
60

  
61
    /**
62
     * @return the submitterFilter
63
     */
64
    public ListSelect getSubmitterFilter();
65

  
66
    /**
67
     * @param optionInProgress
68
     */
69
    void setViewMode(Mode mode);
70

  
71
    /**
72
     * @return
73
     */
74
    Mode getViewMode();
75

  
33 76

  
34 77
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/ListViewBean.java
9 9
package eu.etaxonomy.cdm.vaadin.view.registration;
10 10

  
11 11
import java.util.ArrayList;
12
import java.util.Arrays;
12 13
import java.util.Collection;
13 14
import java.util.List;
14 15

  
......
23 24
import com.vaadin.server.Page;
24 25
import com.vaadin.spring.annotation.SpringView;
25 26
import com.vaadin.ui.CssLayout;
27
import com.vaadin.ui.HorizontalLayout;
28
import com.vaadin.ui.Label;
29
import com.vaadin.ui.ListSelect;
26 30
import com.vaadin.ui.Notification;
31
import com.vaadin.ui.TextField;
27 32

  
33
import eu.etaxonomy.cdm.api.service.pager.Pager;
34
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
28 35
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItem;
36
import eu.etaxonomy.cdm.vaadin.event.UpdateResultsEvent;
29 37
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
30 38
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
31 39
import eu.etaxonomy.cdm.vaadin.view.AbstractPageView;
......
38 46
@SpringView(name=ListViewBean.NAME)
39 47
public class ListViewBean extends AbstractPageView<ListPresenter> implements ListView, View, AccessRestrictedView {
40 48

  
49

  
41 50
    private static final long serialVersionUID = 3543300933072824713L;
42 51

  
43 52
    public static final String NAME = "list";
44 53

  
45
    public static final String OPTION_ALL = "all";
46

  
47
    public static final String OPTION_IN_PROGRESS = "inprogress";
54
    Mode viewMode = Mode.all;
48 55

  
49 56
    private CssLayout listContainer;
50 57

  
51
    private CssLayout toolBar;
58
    private HorizontalLayout toolBar;
59

  
60
    private Label filterInstructionLabel = new Label("Filter the registrations by");
61

  
62
    private ListSelect statusFilter = null;
63

  
64
    private ListSelect submitterFilter = null; // must be null, the presenter relies on this
65

  
66
    private TextField identifierFilter = new TextField("Identifier");
67

  
68
    private TextField taxonNameFilter = new TextField("Name");
69

  
70
    private TextField referenceFilter = new TextField("Publication");
52 71

  
53 72
    public ListViewBean() {
54 73
        super();
......
56 75

  
57 76
    @Override
58 77
    protected void initContent() {
78

  
59 79
        getLayout().setId(NAME);
60
        toolBar = new CssLayout();
61
        toolBar.setWidth(100, Unit.PERCENTAGE);
80
        toolBar = new HorizontalLayout();
81

  
82
        toolBar.addComponent(filterInstructionLabel);
83

  
84
        if(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin()){
85

  
86
            submitterFilter = new ListSelect("Submitter");
87
            submitterFilter.setRows(1);
88
            submitterFilter.addValueChangeListener(e -> updateResults());
89
            toolBar.addComponent(submitterFilter);
90
        }
91

  
92
        if(viewMode.equals(Mode.all)){
93
            statusFilter = new ListSelect("Status", Arrays.asList(RegistrationStatus.values()));
94
            statusFilter.setNullSelectionAllowed(true);
95
            statusFilter.setRows(1);
96
            statusFilter.addValueChangeListener(e -> updateResults());
97
            toolBar.addComponent(statusFilter);
98
        }
99

  
100
        toolBar.addComponents(identifierFilter, taxonNameFilter);
101
        identifierFilter.addValueChangeListener(e -> updateResults());
102
        taxonNameFilter.addValueChangeListener(e -> updateResults());
103

  
104
        toolBar.setSpacing(true);
62 105
        addContentComponent(toolBar, null);
63 106

  
64 107
        listContainer = new CssLayout();
......
68 111

  
69 112
    }
70 113

  
114
    /**
115
     * @return
116
     */
117
    private void updateResults() {
118
        eventBus.publishEvent(new UpdateResultsEvent(this));
119
    }
120

  
71 121
    @Override
72 122
    protected String getHeaderText() {
73 123
        return "Registrations";
......
88 138
    }
89 139

  
90 140
    @Override
91
    public void populate(Collection<RegistrationDTO> registrations) {
141
    public void populate(Pager<RegistrationDTO> regDtoPager) {
92 142

  
93
        registrations = new ArrayList<RegistrationDTO>(registrations);
143
        ArrayList<RegistrationDTO> regDtos = new ArrayList<RegistrationDTO>(regDtoPager.getRecords());
94 144

  
95
        populateList(registrations);
145
        populateList(regDtos);
96 146
    }
97 147

  
98 148
    public void populateList(Collection<RegistrationDTO> registrations) {
99 149

  
150
        listContainer.removeAllComponents();
100 151
        boolean isCurator = UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin();
101 152
        for(RegistrationDTO regDto : registrations) {
102 153
            RegistrationItem item = new RegistrationItem(regDto, this);
......
156 207
        return null;
157 208
    }
158 209

  
210
    /**
211
     * @return the identifierFilter
212
     */
213
    @Override
214
    public TextField getIdentifierFilter() {
215
        return identifierFilter;
216
    }
217

  
218
    /**
219
     * @return the taxonNameFilter
220
     */
221
    @Override
222
    public TextField getTaxonNameFilter() {
223
        return taxonNameFilter;
224
    }
225

  
226
    /**
227
     * @return the referenceFilter
228
     */
229
    @Override
230
    public TextField getReferenceFilter() {
231
        return referenceFilter;
232
    }
233

  
234
    /**
235
     * @return the statusFilter
236
     */
237
    @Override
238
    public ListSelect getStatusFilter() {
239
        return statusFilter;
240
    }
241

  
242
    /**
243
     * @return the submitterFilter
244
     */
245
    @Override
246
    public ListSelect getSubmitterFilter() {
247
        return submitterFilter;
248
    }
249

  
250
    /**
251
     * {@inheritDoc}
252
     */
253
    @Override
254
    public void setViewMode(Mode mode) {
255
        viewMode = mode;
256
    }
257

  
258

  
259
    @Override
260
    public Mode getViewMode() {
261
        return viewMode;
262
    }
263

  
264

  
265

  
266

  
267

  
159 268

  
160 269

  
161 270
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationPopupEditor.java
34 34

  
35 35
    private static final long serialVersionUID = 5418275817834009509L;
36 36

  
37

  
38 37
    TextField identifierField;
39
    TextField specificIdentifierField;
40 38

  
39
    TextField specificIdentifierField;
41 40

  
42 41
    private ListSelect submitterField;
43 42

  
44

  
45 43
    private ListSelect institutionField;
46 44

  
47 45
    public RegistrationPopupEditor() {

Also available in: Unified diff