use of org.kuali.kfs.coa.identity.KfsKimDocDelegateMember in project cu-kfs by CU-CommunityApps.
the class OrgReviewRoleServiceImpl method getDelegationMembersToSave.
protected List<KfsKimDocDelegateMember> getDelegationMembersToSave(OrgReviewRole orr) {
KfsKimDocDelegateMember delegationMember = null;
if (orr.isEdit() && StringUtils.isNotBlank(orr.getDelegationMemberId())) {
delegationMember = new KfsKimDocDelegateMember(KimApiServiceLocator.getRoleService().getDelegationMemberById(orr.getDelegationMemberId()));
}
if (delegationMember == null) {
delegationMember = new KfsKimDocDelegateMember();
if (StringUtils.isNotEmpty(orr.getRoleMemberRoleNamespaceCode()) && StringUtils.isNotEmpty(orr.getRoleMemberRoleName())) {
String roleId = KimApiServiceLocator.getRoleService().getRoleIdByNamespaceCodeAndName(orr.getRoleMemberRoleNamespaceCode(), orr.getRoleMemberRoleName());
delegationMember.setMemberId(roleId);
delegationMember.setType(MemberType.ROLE);
} else if (StringUtils.isNotEmpty(orr.getGroupMemberGroupNamespaceCode()) && StringUtils.isNotEmpty(orr.getGroupMemberGroupName())) {
Group groupInfo = KimApiServiceLocator.getGroupService().getGroupByNamespaceCodeAndName(orr.getGroupMemberGroupNamespaceCode(), orr.getGroupMemberGroupName());
delegationMember.setMemberId(groupInfo.getId());
delegationMember.setType(MemberType.GROUP);
} else if (StringUtils.isNotEmpty(orr.getPrincipalMemberPrincipalName())) {
Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(orr.getPrincipalMemberPrincipalName());
delegationMember.setMemberId(principal.getPrincipalId());
delegationMember.setType(MemberType.PRINCIPAL);
}
}
delegationMember.setDelegationType(DelegationType.fromCode(orr.getDelegationTypeCode()));
delegationMember.setAttributes(getAttributes(orr, orr.getKimTypeId()));
if (orr.getActiveFromDate() != null) {
delegationMember.setActiveFromDate(new DateTime(orr.getActiveFromDate()));
}
if (orr.getActiveToDate() != null) {
delegationMember.setActiveToDate(new DateTime(orr.getActiveToDate()));
}
delegationMember.setRoleMemberId(orr.getRoleMemberId());
return Collections.singletonList(delegationMember);
}
use of org.kuali.kfs.coa.identity.KfsKimDocDelegateMember in project cu-kfs by CU-CommunityApps.
the class OrgReviewRoleServiceImpl method saveDelegateMemberToKim.
protected void saveDelegateMemberToKim(OrgReviewRole orr) {
if (LOG.isDebugEnabled()) {
LOG.debug("Saving delegate member from OrgReviewRole: " + orr);
}
RoleService roleService = KimApiServiceLocator.getRoleService();
// Save delegation(s)
List<KfsKimDocDelegateMember> delegationMembers = getDelegationMembersToSave(orr);
for (KfsKimDocDelegateMember dm : delegationMembers) {
// retrieve the delegate type so it can be updated
DelegationType delegationType = dm.getDelegationType();
DelegateType delegateType = roleService.getDelegateTypeByRoleIdAndDelegateTypeCode(orr.getRoleId(), delegationType);
if (shouldCreateNewDelegateType(delegateType)) {
DelegateType newDelegateType = new DelegateType();
newDelegateType.setRoleId(orr.getRoleId());
newDelegateType.setDelegationType(delegationType);
newDelegateType.setDelegationMembers(new ArrayList<>(1));
// ensure this is set (for new delegation types)
newDelegateType.setKimTypeId(orr.getKimTypeId());
delegateType = roleService.createDelegateType(newDelegateType);
if (LOG.isDebugEnabled()) {
LOG.debug("No DelegateType in KIM. Created new one: " + delegateType);
}
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Pulled DelegateType from KIM: " + delegateType);
}
}
boolean foundExistingMember = false;
DelegateMember addedMember = null;
// check for an existing delegation member given its unique ID if found, update that record
if (StringUtils.isNotBlank(dm.getDelegationMemberId())) {
DelegateMember member = roleService.getDelegationMemberById(dm.getDelegationMemberId());
if (member != null) {
foundExistingMember = true;
if (LOG.isDebugEnabled()) {
LOG.debug("Found existing delegate member - updating existing record. " + member);
}
// KFSMI-9628 : fixing issue with the delegate switch from primary to secondary
// IN this case, we need to delete the member from the "other" delegate type
// need to determine what the "existing" type was
DelegateType originalDelegateType = roleService.getDelegateTypeByDelegationId(member.getDelegationId());
// if they are the same, we can just update the existing record
if (originalDelegateType.getDelegationType().equals(dm.getDelegationType())) {
updateDelegateMemberFromDocDelegateMember(member, dm);
addedMember = roleService.updateDelegateMember(member);
} else {
// Otherwise, we need to remove the old one and add a new one
// Remove old
roleService.removeDelegateMembers(Collections.singletonList(member));
// add new
DelegateMember newMember = new DelegateMember();
newMember.setDelegationId(delegateType.getDelegationId());
updateDelegateMemberFromDocDelegateMember(newMember, dm);
addedMember = roleService.createDelegateMember(newMember);
}
}
}
// if we did not find one, then we need to create a new member
if (!foundExistingMember) {
if (LOG.isDebugEnabled()) {
LOG.debug("No existing delegate member found, adding as a new delegate: " + dm);
}
DelegateMember newMember = new DelegateMember();
newMember.setDelegationId(delegateType.getDelegationId());
updateDelegateMemberFromDocDelegateMember(newMember, dm);
addedMember = roleService.createDelegateMember(newMember);
}
if (addedMember != null) {
orr.setDelegationMemberId(addedMember.getDelegationMemberId());
}
}
}
Aggregations