| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.kuali.rice.kim.service.impl; |
| 17 |
|
|
| 18 |
|
import java.util.ArrayList; |
| 19 |
|
import java.util.Collection; |
| 20 |
|
import java.util.HashMap; |
| 21 |
|
import java.util.List; |
| 22 |
|
import java.util.Map; |
| 23 |
|
|
| 24 |
|
import javax.jws.WebService; |
| 25 |
|
|
| 26 |
|
import org.apache.commons.collections.CollectionUtils; |
| 27 |
|
import org.apache.commons.collections.Predicate; |
| 28 |
|
import org.apache.log4j.Logger; |
| 29 |
|
import org.kuali.rice.core.api.exception.RiceRuntimeException; |
| 30 |
|
import org.kuali.rice.kim.bo.entity.impl.KimEntityAffiliationImpl; |
| 31 |
|
import org.kuali.rice.kim.bo.group.dto.GroupInfo; |
| 32 |
|
import org.kuali.rice.kim.bo.group.impl.GroupAttributeDataImpl; |
| 33 |
|
import org.kuali.rice.kim.bo.group.impl.GroupMemberImpl; |
| 34 |
|
import org.kuali.rice.kim.bo.impl.GroupImpl; |
| 35 |
|
import org.kuali.rice.kim.service.GroupService; |
| 36 |
|
import org.kuali.rice.kim.service.GroupUpdateService; |
| 37 |
|
import org.kuali.rice.kim.service.KIMServiceLocator; |
| 38 |
|
import org.kuali.rice.kim.service.KIMServiceLocatorInternal; |
| 39 |
|
import org.kuali.rice.kim.util.KIMPropertyConstants; |
| 40 |
|
import org.kuali.rice.kim.util.KIMWebServiceConstants; |
| 41 |
|
import org.kuali.rice.kim.util.KimCommonUtilsInternal; |
| 42 |
|
import org.kuali.rice.kim.util.KimConstants.KimGroupMemberTypes; |
| 43 |
|
import org.kuali.rice.kns.service.KNSServiceLocator; |
| 44 |
|
import org.kuali.rice.kns.service.SequenceAccessorService; |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
@link |
| 48 |
|
|
| 49 |
|
@author |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
@WebService(endpointInterface = KIMWebServiceConstants.GroupUpdateService.INTERFACE_CLASS, serviceName = KIMWebServiceConstants.GroupUpdateService.WEB_SERVICE_NAME, portName = KIMWebServiceConstants.GroupUpdateService.WEB_SERVICE_PORT, targetNamespace = KIMWebServiceConstants.MODULE_TARGET_NAMESPACE) |
|
|
|
| 0% |
Uncovered Elements: 179 (179) |
Complexity: 40 |
Complexity Density: 0.33 |
|
| 53 |
|
public class GroupUpdateServiceImpl extends GroupServiceBase implements GroupUpdateService { |
| 54 |
|
|
| 55 |
|
private static final Logger LOG = Logger.getLogger(GroupUpdateServiceImpl.class); |
| 56 |
|
|
| 57 |
|
private SequenceAccessorService sequenceAccessorService; |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
@see |
| 61 |
|
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
| 62 |
0
|
public boolean addGroupToGroup(String childId, String parentId) {... |
| 63 |
0
|
if(childId.equals(parentId)) { |
| 64 |
0
|
throw new IllegalArgumentException("Can't add group to itself."); |
| 65 |
|
} |
| 66 |
|
|
| 67 |
0
|
if(isGroupMemberOfGroup(parentId, childId)) { |
| 68 |
0
|
throw new IllegalArgumentException("Circular group reference."); |
| 69 |
|
} |
| 70 |
|
|
| 71 |
0
|
GroupMemberImpl groupMember = new GroupMemberImpl(); |
| 72 |
0
|
groupMember.setGroupId(parentId); |
| 73 |
0
|
groupMember.setMemberTypeCode( KimGroupMemberTypes.GROUP_MEMBER_TYPE ); |
| 74 |
0
|
groupMember.setMemberId(childId); |
| 75 |
|
|
| 76 |
0
|
getBusinessObjectService().save(groupMember); |
| 77 |
0
|
getIdentityManagementNotificationService().groupUpdated(); |
| 78 |
|
|
| 79 |
0
|
return true; |
| 80 |
|
} |
| 81 |
|
|
| 82 |
|
|
| 83 |
|
@see |
| 84 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 85 |
0
|
public boolean addPrincipalToGroup(String principalId, String groupId) {... |
| 86 |
0
|
GroupMemberImpl groupMember = new GroupMemberImpl(); |
| 87 |
0
|
groupMember.setGroupId(groupId); |
| 88 |
0
|
groupMember.setMemberTypeCode( KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE ); |
| 89 |
0
|
groupMember.setMemberId(principalId); |
| 90 |
|
|
| 91 |
0
|
groupMember = (GroupMemberImpl)getBusinessObjectService().save(groupMember); |
| 92 |
0
|
KIMServiceLocatorInternal.getGroupInternalService().updateForUserAddedToGroup(groupMember.getMemberId(), groupMember.getGroupId()); |
| 93 |
0
|
getIdentityManagementNotificationService().groupUpdated(); |
| 94 |
0
|
return true; |
| 95 |
|
} |
| 96 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 97 |
0
|
public GroupInfo createGroup(GroupInfo groupInfo) {... |
| 98 |
0
|
GroupImpl group = new GroupImpl(); |
| 99 |
|
|
| 100 |
0
|
group = KimCommonUtilsInternal.copyInfoToGroup(groupInfo, group); |
| 101 |
|
|
| 102 |
0
|
saveGroup(group); |
| 103 |
|
|
| 104 |
0
|
GroupInfo newGroupInfo = getGroupInfoByName(groupInfo.getNamespaceCode(), groupInfo.getGroupName()); |
| 105 |
|
|
| 106 |
0
|
if(groupInfo.getAttributes() != null && groupInfo.getAttributes().size() > 0) { |
| 107 |
0
|
List<GroupAttributeDataImpl> groupAttributes = |
| 108 |
|
KimCommonUtilsInternal.copyInfoAttributesToGroupAttributes(groupInfo.getAttributes(), newGroupInfo.getGroupId(), newGroupInfo.getKimTypeId()); |
| 109 |
0
|
saveGroupAttributes(groupAttributes); |
| 110 |
|
} |
| 111 |
0
|
return getGroupInfo(newGroupInfo.getGroupId()); |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
|
| 115 |
|
|
| 116 |
|
@see |
| 117 |
|
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 2 |
Complexity Density: 0.17 |
|
| 118 |
0
|
public void removeAllGroupMembers(String groupId) {... |
| 119 |
0
|
GroupService groupService = KIMServiceLocator.getGroupService(); |
| 120 |
0
|
List<String> memberPrincipalsBefore = groupService.getMemberPrincipalIds(groupId); |
| 121 |
|
|
| 122 |
0
|
Collection<GroupMemberImpl> toDeactivate = getActiveGroupMembers(groupId, null, null); |
| 123 |
0
|
java.sql.Timestamp today = new java.sql.Timestamp(System.currentTimeMillis()); |
| 124 |
|
|
| 125 |
|
|
| 126 |
0
|
for (GroupMemberImpl aToDeactivate : toDeactivate) { |
| 127 |
0
|
aToDeactivate.setActiveToDate(today); |
| 128 |
|
} |
| 129 |
|
|
| 130 |
|
|
| 131 |
0
|
getBusinessObjectService().save(new ArrayList<GroupMemberImpl>(toDeactivate)); |
| 132 |
0
|
List<String> memberPrincipalsAfter = groupService.getMemberPrincipalIds(groupId); |
| 133 |
|
|
| 134 |
0
|
if (!CollectionUtils.isEmpty(memberPrincipalsAfter)) { |
| 135 |
|
|
| 136 |
0
|
LOG.warn("after attempting removal of all members, group with id '" + groupId + "' still has principal members"); |
| 137 |
|
} |
| 138 |
|
|
| 139 |
|
|
| 140 |
0
|
KIMServiceLocatorInternal.getGroupInternalService().updateForWorkgroupChange(groupId, memberPrincipalsBefore, memberPrincipalsAfter); |
| 141 |
0
|
getIdentityManagementNotificationService().groupUpdated(); |
| 142 |
|
} |
| 143 |
|
|
| 144 |
|
|
| 145 |
|
@see |
| 146 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
| 147 |
0
|
public boolean removeGroupFromGroup(String childId, String parentId) {... |
| 148 |
0
|
java.sql.Timestamp today = new java.sql.Timestamp(System.currentTimeMillis()); |
| 149 |
|
|
| 150 |
0
|
List<GroupMemberImpl> groupMembers = |
| 151 |
|
getActiveGroupMembers(parentId, childId, KimGroupMemberTypes.GROUP_MEMBER_TYPE); |
| 152 |
|
|
| 153 |
0
|
if(groupMembers.size() == 1) { |
| 154 |
0
|
GroupMemberImpl groupMember = groupMembers.get(0); |
| 155 |
0
|
groupMember.setActiveToDate(today); |
| 156 |
0
|
getBusinessObjectService().save(groupMember); |
| 157 |
0
|
getIdentityManagementNotificationService().groupUpdated(); |
| 158 |
0
|
return true; |
| 159 |
|
} |
| 160 |
|
|
| 161 |
0
|
return false; |
| 162 |
|
} |
| 163 |
|
|
| 164 |
|
|
| 165 |
|
@see |
| 166 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
| 167 |
0
|
@SuppressWarnings("unchecked")... |
| 168 |
|
public boolean removePrincipalFromGroup(String principalId, String groupId) { |
| 169 |
0
|
List<GroupMemberImpl> groupMembers = |
| 170 |
|
getActiveGroupMembers(groupId, principalId, KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE); |
| 171 |
|
|
| 172 |
0
|
if(groupMembers.size() == 1) { |
| 173 |
0
|
GroupMemberImpl member = groupMembers.iterator().next(); |
| 174 |
0
|
member.setActiveToDate(new java.sql.Timestamp(System.currentTimeMillis())); |
| 175 |
0
|
getBusinessObjectService().save(member); |
| 176 |
0
|
KIMServiceLocatorInternal.getGroupInternalService().updateForUserRemovedFromGroup(member.getMemberId(), member.getGroupId()); |
| 177 |
0
|
getIdentityManagementNotificationService().groupUpdated(); |
| 178 |
0
|
return true; |
| 179 |
|
} |
| 180 |
|
|
| 181 |
0
|
return false; |
| 182 |
|
} |
| 183 |
|
|
| 184 |
|
|
| 185 |
|
|
| 186 |
|
|
| 187 |
|
@see |
| 188 |
|
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0.33 |
|
| 189 |
0
|
public GroupInfo updateGroup(String groupId, GroupInfo groupInfo) {... |
| 190 |
|
|
| 191 |
0
|
GroupImpl group = getGroupImpl(groupId); |
| 192 |
|
|
| 193 |
0
|
if (group == null) { |
| 194 |
0
|
throw new IllegalArgumentException("Group not found for update."); |
| 195 |
|
} |
| 196 |
|
|
| 197 |
0
|
group = KimCommonUtilsInternal.copyInfoToGroup(groupInfo, group); |
| 198 |
|
|
| 199 |
|
|
| 200 |
0
|
Map<String,String> criteria = new HashMap<String,String>(); |
| 201 |
0
|
criteria.put(KIMPropertyConstants.Group.GROUP_ID, group.getGroupId()); |
| 202 |
0
|
getBusinessObjectService().deleteMatching(GroupAttributeDataImpl.class, criteria); |
| 203 |
|
|
| 204 |
|
|
| 205 |
0
|
group = saveGroup(group); |
| 206 |
|
|
| 207 |
|
|
| 208 |
0
|
if(groupInfo.getAttributes() != null && groupInfo.getAttributes().size() > 0) { |
| 209 |
0
|
List<GroupAttributeDataImpl> groupAttributes = |
| 210 |
|
KimCommonUtilsInternal.copyInfoAttributesToGroupAttributes(groupInfo.getAttributes(), group.getGroupId(), group.getKimTypeId()); |
| 211 |
0
|
saveGroupAttributes(groupAttributes); |
| 212 |
|
} |
| 213 |
|
|
| 214 |
0
|
return getGroupInfo(groupInfo.getGroupId()); |
| 215 |
|
} |
| 216 |
|
|
|
|
|
| 0% |
Uncovered Elements: 43 (43) |
Complexity: 11 |
Complexity Density: 0.44 |
|
| 217 |
0
|
protected GroupImpl saveGroup(GroupImpl group) {... |
| 218 |
0
|
if ( group == null ) { |
| 219 |
0
|
return null; |
| 220 |
0
|
} else if (group.getGroupId() != null) { |
| 221 |
|
|
| 222 |
0
|
GroupImpl oldGroup = getGroupImpl(group.getGroupId()); |
| 223 |
|
|
| 224 |
0
|
if (oldGroup != null) { |
| 225 |
|
|
| 226 |
0
|
java.sql.Timestamp activeTo = new java.sql.Timestamp(System.currentTimeMillis()); |
| 227 |
0
|
List<GroupMemberImpl> toReAdd = null; |
| 228 |
|
|
| 229 |
0
|
if (oldGroup.getMembers() != null) for (GroupMemberImpl member : oldGroup.getMembers()) { |
| 230 |
|
|
| 231 |
0
|
if (group.getMembers() == null || !group.getMembers().contains(member)) { |
| 232 |
|
|
| 233 |
0
|
member.setActiveToDate(activeTo); |
| 234 |
0
|
if (toReAdd == null) { toReAdd = new ArrayList<GroupMemberImpl>(); } |
| 235 |
|
|
| 236 |
0
|
toReAdd.add(member); |
| 237 |
|
} |
| 238 |
|
} |
| 239 |
|
|
| 240 |
|
|
| 241 |
0
|
if (toReAdd != null) { |
| 242 |
0
|
List<GroupMemberImpl> groupMembers = group.getMembers(); |
| 243 |
0
|
if (groupMembers == null) { groupMembers = new ArrayList<GroupMemberImpl>(toReAdd.size()); } |
| 244 |
0
|
group.setMembers(groupMembers); |
| 245 |
|
} |
| 246 |
|
} |
| 247 |
|
} |
| 248 |
|
|
| 249 |
|
|
| 250 |
|
|
| 251 |
0
|
SequenceAccessorService sas = getSequenceAccessorService(); |
| 252 |
0
|
if (group.getGroupId() == null) { |
| 253 |
0
|
group.setGroupId(sas.getNextAvailableSequenceNumber( |
| 254 |
|
"KRIM_GRP_ID_S", GroupImpl.class).toString()); |
| 255 |
|
} |
| 256 |
0
|
GroupImpl savedGroup = KIMServiceLocatorInternal.getGroupInternalService().saveWorkgroup(group); |
| 257 |
0
|
getIdentityManagementNotificationService().groupUpdated(); |
| 258 |
0
|
return savedGroup; |
| 259 |
|
} |
| 260 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 261 |
0
|
protected void saveGroupAttributes(List<GroupAttributeDataImpl> groupAttributes) {... |
| 262 |
0
|
if ( groupAttributes == null ) { |
| 263 |
0
|
return; |
| 264 |
|
} |
| 265 |
0
|
SequenceAccessorService sas = getSequenceAccessorService(); |
| 266 |
0
|
for (GroupAttributeDataImpl groupAttribute : groupAttributes) { |
| 267 |
0
|
if (groupAttribute.getAttributeDataId() == null) { |
| 268 |
0
|
groupAttribute.setAttributeDataId(sas.getNextAvailableSequenceNumber( |
| 269 |
|
"KRIM_GRP_ATTR_DATA_ID_S", KimEntityAffiliationImpl.class).toString()); |
| 270 |
|
} |
| 271 |
|
} |
| 272 |
0
|
getBusinessObjectService().save( groupAttributes ); |
| 273 |
|
} |
| 274 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 275 |
0
|
protected void deleteGroupAttribute(GroupAttributeDataImpl groupAttribute) {... |
| 276 |
0
|
if ( groupAttribute == null ) { |
| 277 |
0
|
return; |
| 278 |
|
} |
| 279 |
0
|
getBusinessObjectService().delete( groupAttribute ); |
| 280 |
|
} |
| 281 |
|
|
| 282 |
|
|
| 283 |
|
@link |
| 284 |
|
|
| 285 |
|
|
| 286 |
|
|
| 287 |
|
@param |
| 288 |
|
@param |
| 289 |
|
@param |
| 290 |
|
@return |
| 291 |
|
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.36 |
|
| 292 |
0
|
private List<GroupMemberImpl> getActiveGroupMembers(String parentId,... |
| 293 |
|
String childId, String memberType) { |
| 294 |
0
|
final java.sql.Date today = new java.sql.Date(System.currentTimeMillis()); |
| 295 |
|
|
| 296 |
0
|
if (childId != null && memberType == null) throw new RiceRuntimeException("memberType must be non-null if childId is non-null"); |
| 297 |
|
|
| 298 |
0
|
Map<String,Object> criteria = new HashMap<String,Object>(4); |
| 299 |
0
|
criteria.put(KIMPropertyConstants.GroupMember.GROUP_ID, parentId); |
| 300 |
|
|
| 301 |
0
|
if (childId != null) { |
| 302 |
0
|
criteria.put(KIMPropertyConstants.GroupMember.MEMBER_ID, childId); |
| 303 |
0
|
criteria.put(KIMPropertyConstants.GroupMember.MEMBER_TYPE_CODE, memberType); |
| 304 |
|
} |
| 305 |
|
|
| 306 |
0
|
Collection<GroupMemberImpl> groupMembers = getBusinessObjectService().findMatching(GroupMemberImpl.class, criteria); |
| 307 |
|
|
| 308 |
0
|
CollectionUtils.filter(groupMembers, new Predicate() { |
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 309 |
0
|
public boolean evaluate(Object object) {... |
| 310 |
0
|
GroupMemberImpl member = (GroupMemberImpl) object; |
| 311 |
|
|
| 312 |
0
|
return member.getActiveToDate() == null || today.before(member.getActiveToDate()); |
| 313 |
|
} |
| 314 |
|
}); |
| 315 |
|
|
| 316 |
0
|
return new ArrayList<GroupMemberImpl>(groupMembers); |
| 317 |
|
} |
| 318 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 319 |
0
|
protected SequenceAccessorService getSequenceAccessorService() {... |
| 320 |
0
|
if ( sequenceAccessorService == null ) { |
| 321 |
0
|
sequenceAccessorService = KNSServiceLocator.getSequenceAccessorService(); |
| 322 |
|
} |
| 323 |
0
|
return sequenceAccessorService; |
| 324 |
|
} |
| 325 |
|
|
| 326 |
|
} |