1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.impl.role; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.joda.time.DateTime; |
20 | |
import org.kuali.rice.kim.api.group.GroupMember; |
21 | |
import org.kuali.rice.kim.impl.common.delegate.DelegateMemberBo; |
22 | |
import org.kuali.rice.kim.impl.common.delegate.DelegateTypeBo; |
23 | |
import org.kuali.rice.kim.impl.group.GroupMemberBo; |
24 | |
|
25 | |
import java.sql.Timestamp; |
26 | |
import java.util.ArrayList; |
27 | |
import java.util.HashSet; |
28 | |
import java.util.List; |
29 | |
import java.util.Set; |
30 | |
import java.util.concurrent.TimeUnit; |
31 | |
|
32 | 0 | public class RoleInternalServiceImpl extends RoleServiceBase implements RoleInternalService{ |
33 | |
@Override |
34 | |
public void principalInactivated(String principalId) { |
35 | 0 | if (StringUtils.isBlank(principalId)) { |
36 | 0 | throw new IllegalArgumentException("principalId is null or blank"); |
37 | |
} |
38 | |
|
39 | 0 | long oneDayInMillis = TimeUnit.DAYS.toMillis(1); |
40 | 0 | Timestamp yesterday = new Timestamp(System.currentTimeMillis() - oneDayInMillis); |
41 | |
|
42 | 0 | inactivatePrincipalRoleMemberships(principalId, yesterday); |
43 | 0 | inactivatePrincipalGroupMemberships(principalId, yesterday); |
44 | 0 | inactivatePrincipalDelegations(principalId, yesterday); |
45 | 0 | inactivateApplicationRoleMemberships(principalId, yesterday); |
46 | 0 | } |
47 | |
|
48 | |
@Override |
49 | |
public void roleInactivated(String roleId) { |
50 | 0 | if (StringUtils.isBlank(roleId)) { |
51 | 0 | throw new IllegalArgumentException("roleId is null or blank"); |
52 | |
} |
53 | |
|
54 | 0 | long oneDayInMillis = TimeUnit.DAYS.toMillis(1); |
55 | 0 | Timestamp yesterday = new Timestamp(System.currentTimeMillis() - oneDayInMillis); |
56 | |
|
57 | 0 | List<String> roleIds = new ArrayList<String>(); |
58 | 0 | roleIds.add(roleId); |
59 | 0 | inactivateRoleMemberships(roleIds, yesterday); |
60 | 0 | inactivateRoleDelegations(roleIds, yesterday); |
61 | 0 | inactivateMembershipsForRoleAsMember(roleIds, yesterday); |
62 | 0 | } |
63 | |
|
64 | |
private void inactivateRoleMemberships(List<String> roleIds, Timestamp yesterday) { |
65 | 0 | List<RoleMemberBo> roleMemberBoList = getStoredRoleMembersForRoleIds(roleIds, null, null); |
66 | 0 | for (RoleMemberBo roleMemberBo : roleMemberBoList) { |
67 | 0 | roleMemberBo.setActiveToDateValue(yesterday); |
68 | |
} |
69 | 0 | getBusinessObjectService().save(roleMemberBoList); |
70 | 0 | } |
71 | |
|
72 | |
private void inactivateRoleDelegations(List<String> roleIds, Timestamp yesterday) { |
73 | 0 | List<DelegateTypeBo> delegations = getStoredDelegationImplsForRoleIds(roleIds); |
74 | 0 | for (DelegateTypeBo delegation : delegations) { |
75 | 0 | delegation.setActive(false); |
76 | 0 | for (DelegateMemberBo delegationMember : delegation.getMembers()) { |
77 | 0 | delegationMember.setActiveToDateValue(yesterday); |
78 | |
} |
79 | |
} |
80 | 0 | getBusinessObjectService().save(delegations); |
81 | 0 | } |
82 | |
|
83 | |
private void inactivateMembershipsForRoleAsMember(List<String> roleIds, Timestamp yesterday) { |
84 | 0 | List<RoleMemberBo> roleMemberBoList = getStoredRoleMembershipsForRoleIdsAsMembers(roleIds, null); |
85 | 0 | for (RoleMemberBo roleMemberBo : roleMemberBoList) { |
86 | 0 | roleMemberBo.setActiveToDateValue(yesterday); |
87 | |
} |
88 | 0 | getBusinessObjectService().save(roleMemberBoList); |
89 | 0 | } |
90 | |
|
91 | |
@Override |
92 | |
public void groupInactivated(String groupId) { |
93 | 0 | if (StringUtils.isBlank(groupId)) { |
94 | 0 | throw new IllegalArgumentException("groupId is null or blank"); |
95 | |
} |
96 | |
|
97 | 0 | long oneDayInMillis = TimeUnit.DAYS.toMillis(1); |
98 | 0 | Timestamp yesterday = new Timestamp(System.currentTimeMillis() - oneDayInMillis); |
99 | |
|
100 | 0 | List<String> groupIds = new ArrayList<String>(); |
101 | 0 | groupIds.add(groupId); |
102 | 0 | inactivatePrincipalGroupMemberships(groupIds, yesterday); |
103 | 0 | inactivateGroupRoleMemberships(groupIds, yesterday); |
104 | 0 | } |
105 | |
|
106 | |
protected void inactivateApplicationRoleMemberships(String principalId, Timestamp yesterday) { |
107 | |
|
108 | 0 | } |
109 | |
|
110 | |
protected void inactivatePrincipalRoleMemberships(String principalId, Timestamp yesterday) { |
111 | |
|
112 | 0 | List<RoleMemberBo> roleMembers = getStoredRolePrincipalsForPrincipalIdAndRoleIds(null, principalId, null); |
113 | 0 | Set<String> roleIds = new HashSet<String>(roleMembers.size()); |
114 | 0 | for (RoleMemberBo roleMemberBo : roleMembers) { |
115 | 0 | roleMemberBo.setActiveToDateValue(yesterday); |
116 | 0 | roleIds.add(roleMemberBo.getRoleId()); |
117 | |
} |
118 | 0 | getBusinessObjectService().save(roleMembers); |
119 | 0 | } |
120 | |
|
121 | |
protected void inactivateGroupRoleMemberships(List<String> groupIds, Timestamp yesterday) { |
122 | 0 | List<RoleMemberBo> roleMemberBosOfGroupType = getStoredRoleGroupsForGroupIdsAndRoleIds(null, groupIds, null); |
123 | 0 | for (RoleMemberBo roleMemberbo : roleMemberBosOfGroupType) { |
124 | 0 | roleMemberbo.setActiveToDateValue(yesterday); |
125 | |
} |
126 | 0 | getBusinessObjectService().save(roleMemberBosOfGroupType); |
127 | 0 | } |
128 | |
|
129 | |
protected void inactivatePrincipalGroupMemberships(String principalId, Timestamp yesterday) { |
130 | 0 | List<GroupMember> groupMembers = getRoleDao().getGroupPrincipalsForPrincipalIdAndGroupIds(null, principalId); |
131 | 0 | List<GroupMemberBo> groupMemberBoList = new ArrayList<GroupMemberBo>(groupMembers.size()); |
132 | 0 | for (GroupMember gm : groupMembers) { |
133 | 0 | GroupMember.Builder builder = GroupMember.Builder.create(gm); |
134 | 0 | builder.setActiveToDate(new DateTime(yesterday.getTime())); |
135 | 0 | groupMemberBoList.add(GroupMemberBo.from(builder.build())); |
136 | 0 | } |
137 | 0 | getBusinessObjectService().save(groupMemberBoList); |
138 | 0 | } |
139 | |
|
140 | |
protected void inactivatePrincipalGroupMemberships(List<String> groupIds, Timestamp yesterday) { |
141 | 0 | List<GroupMember> groupMembers = getRoleDao().getGroupMembers(groupIds); |
142 | 0 | List<GroupMemberBo> groupMemberBoList = new ArrayList<GroupMemberBo>(groupMembers.size()); |
143 | 0 | for (GroupMember groupMember : groupMembers) { |
144 | 0 | GroupMember.Builder builder = GroupMember.Builder.create(groupMember); |
145 | 0 | builder.setActiveToDate(new DateTime(yesterday.getTime())); |
146 | 0 | groupMemberBoList.add(GroupMemberBo.from(builder.build())); |
147 | 0 | } |
148 | 0 | getBusinessObjectService().save(groupMemberBoList); |
149 | 0 | } |
150 | |
|
151 | |
protected void inactivatePrincipalDelegations(String principalId, Timestamp yesterday) { |
152 | 0 | List<DelegateMemberBo> delegationMembers = getStoredDelegationPrincipalsForPrincipalIdAndDelegationIds(null, |
153 | |
principalId); |
154 | 0 | for (DelegateMemberBo delegateMemberBo : delegationMembers) { |
155 | 0 | delegateMemberBo.setActiveToDateValue(yesterday); |
156 | |
} |
157 | 0 | getBusinessObjectService().save(delegationMembers); |
158 | 0 | } |
159 | |
} |