use of org.kuali.kfs.kim.impl.common.delegate.DelegateMemberAttributeData in project cu-kfs by CU-CommunityApps.
the class RoleServiceImpl method createDelegateMember.
@CacheEvict(value = { Role.CACHE_NAME, RoleMembership.CACHE_NAME, RoleMember.CACHE_NAME, DelegateMember.CACHE_NAME, RoleResponsibility.CACHE_NAME, DelegateType.CACHE_NAME }, allEntries = true)
@Override
public DelegateMember createDelegateMember(DelegateMember delegateMember) throws IllegalArgumentException, IllegalStateException {
// ensure object not empty
incomingParamCheck(delegateMember, "delegateMember");
// check key is null
if (delegateMember.getDelegationMemberId() != null) {
throw new IllegalStateException("the delegate member already exists: " + delegateMember.getDelegationMemberId());
}
// check delegate exists
String delegationId = delegateMember.getDelegationId();
incomingParamCheck(delegationId, "delegationId");
DelegateType delegate = getKimDelegationImpl(delegationId);
if (delegate == null) {
throw new IllegalStateException("the delegate does not exist: " + delegationId);
}
// check member exists
String memberId = delegateMember.getMemberId();
incomingParamCheck(memberId, "memberId");
Principal kPrincipal = KimApiServiceLocator.getIdentityService().getPrincipal(memberId);
if (kPrincipal == null) {
throw new IllegalStateException("the user does not exist: " + memberId);
}
// create member delegate
String kimTypeId = getRoleLite(delegate.getRoleId()).getKimTypeId();
List<DelegateMemberAttributeData> attrBos = KimAttributeData.createFrom(DelegateMemberAttributeData.class, delegateMember.getAttributes(), kimTypeId);
delegateMember.setAttributeDetails(attrBos);
return getResponsibilityInternalService().saveDelegateMember(delegateMember);
}
use of org.kuali.kfs.kim.impl.common.delegate.DelegateMemberAttributeData in project cu-kfs by CU-CommunityApps.
the class RoleServiceImpl method updateDelegateMember.
@CacheEvict(value = { Role.CACHE_NAME, RoleMembership.CACHE_NAME, RoleMember.CACHE_NAME, DelegateMember.CACHE_NAME, RoleResponsibility.CACHE_NAME, DelegateType.CACHE_NAME }, allEntries = true)
@Override
public DelegateMember updateDelegateMember(DelegateMember delegateMember) throws IllegalArgumentException, IllegalStateException {
// check delegateMember not empty
incomingParamCheck(delegateMember, "delegateMember");
// check delegate exists
String delegationId = delegateMember.getDelegationId();
incomingParamCheck(delegationId, "delegationId");
DelegateType delegate = getKimDelegationImpl(delegationId);
DelegateMember originalDelegateMember = null;
String delegationMemberId = delegateMember.getDelegationMemberId();
if (StringUtils.isNotEmpty(delegationMemberId)) {
originalDelegateMember = getDelegateMember(delegateMember.getDelegationMemberId());
}
if (delegate == null) {
throw new IllegalStateException("the delegate does not exist: " + delegationId);
}
// save the delegateMember (actually updates)
String kimTypeId = getRoleLite(delegate.getRoleId()).getKimTypeId();
List<DelegateMemberAttributeData> attrBos = KimAttributeData.createFrom(DelegateMemberAttributeData.class, delegateMember.getAttributes(), kimTypeId);
List<DelegateMemberAttributeData> updateAttrBos = new ArrayList<>();
boolean matched = false;
if (originalDelegateMember != null) {
delegateMember.setVersionNumber(originalDelegateMember.getVersionNumber());
for (DelegateMemberAttributeData newDelegateMemberAttrData : attrBos) {
for (DelegateMemberAttributeData oldDelegateMemberAttrData : originalDelegateMember.getAttributeDetails()) {
if (newDelegateMemberAttrData.getKimTypeId().equals(oldDelegateMemberAttrData.getKimTypeId()) && newDelegateMemberAttrData.getKimAttributeId().equals(oldDelegateMemberAttrData.getKimAttributeId())) {
newDelegateMemberAttrData.setAssignedToId(oldDelegateMemberAttrData.getAssignedToId());
newDelegateMemberAttrData.setVersionNumber(oldDelegateMemberAttrData.getVersionNumber());
newDelegateMemberAttrData.setId(oldDelegateMemberAttrData.getId());
updateAttrBos.add(newDelegateMemberAttrData);
matched = true;
break;
}
}
if (!matched) {
updateAttrBos.add(newDelegateMemberAttrData);
} else {
matched = false;
}
}
}
delegateMember.setAttributeDetails(updateAttrBos);
return getResponsibilityInternalService().saveDelegateMember(delegateMember);
}
Aggregations