Project

General

Profile

« Previous | Next » 

Revision 86b2da34

Added by Andreas Kohlbecker almost 7 years ago

ref #6169 filtering registration list by role, user and status in the 2 ListView modes

View differences:

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

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

  
13 14
import org.springframework.beans.factory.annotation.Autowired;
14 15
import org.springframework.beans.factory.annotation.Qualifier;
15 16
import org.springframework.context.event.EventListener;
17
import org.springframework.security.core.Authentication;
16 18

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

  
20 22
import eu.etaxonomy.cdm.mock.IRegistrationWorkingSetService;
23
import eu.etaxonomy.cdm.model.common.User;
24
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
25
import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
21 26
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
27
import eu.etaxonomy.cdm.vaadin.security.RolesAndPermissions;
22 28
import eu.etaxonomy.vaadin.mvp.AbstractPresenter;
23 29

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

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

  
33 46
    private static final long serialVersionUID = 5419947244621450665L;
34 47

  
35 48
    @Autowired
......
38 51

  
39 52
    @Override
40 53
    public void handleViewEntered() {
41
        // TransactionStatus tx = getRepo().startTransaction(); // no longer needed since AbstractPresenter is caring for tranactions in this case
42 54
        getView().populate(listRegistrations());
43
        // getRepo().commitTransaction(tx);
44 55
    }
45 56

  
46 57
    /**
58
     * FIXME write test !!!!!!!!!!!!!!!!!
59
     *
47 60
     * @return
48 61
     */
49 62
    private Collection<RegistrationDTO> listRegistrations() {
50
        Collection<RegistrationDTO> dtos = workingSetService.listDTOs();
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);
51 82
        return dtos;
52 83
    }
53 84

  

Also available in: Unified diff