Project

General

Profile

1
package eu.dnetlib.client;
2

    
3
import eu.dnetlib.goldoa.domain.User;
4
import eu.dnetlib.goldoa.domain.UserRole;
5

    
6
import java.util.List;
7

    
8
/**
9
 * Created by stefania on 4/8/15.
10
 */
11
public class Utils {
12

    
13
    public static boolean currentUserHasRoleApproved(String roleId) {
14

    
15
        List<UserRole> personRoles = GoldOAPortal.currentUser.getRoles();
16
        for(UserRole personRole : personRoles) {
17

    
18
            if(personRole.getPk().getRole().getId().equals(roleId) && personRole.isApproved())
19
                return true;
20
        }
21

    
22
        return false;
23
    }
24

    
25
    public static boolean currentUserHasRole(String roleId) {
26

    
27
        List<UserRole> personRoles = GoldOAPortal.currentUser.getRoles();
28
        for(UserRole personRole : personRoles) {
29
            if(personRole.getPk().getRole().getId().equals(roleId))
30
                return true;
31
        }
32

    
33
        return false;
34
    }
35

    
36
    public static boolean isRoleApprovedForCurrentUser(String roleId) {
37

    
38
        List<UserRole> personRoles = GoldOAPortal.currentUser.getRoles();
39
        for(UserRole personRole : personRoles) {
40
            if(personRole.getPk().getRole().getId().equals(roleId))
41
                return personRole.isApproved();
42
        }
43

    
44
        return false;
45
    }
46

    
47

    
48
    public static boolean userHasRole(User user, String roleId) {
49

    
50
        List<UserRole> personRoles = user.getRoles();
51
        for(UserRole personRole : personRoles) {
52
            if(personRole.getPk().getRole().getId().equals(roleId))
53
                return true;
54
        }
55

    
56
        return false;
57
    }
58

    
59
    public static boolean isRoleApprovedForUser(User user, String roleId) {
60

    
61
        List<UserRole> personRoles = user.getRoles();
62
        for(UserRole personRole : personRoles) {
63
            if(personRole.getPk().getRole().getId().equals(roleId))
64
                return personRole.isApproved();
65
        }
66

    
67
        return false;
68
    }
69

    
70

    
71
}
(22-22/22)