use of org.springframework.cache.annotation.CacheEvict in project fw-cloud-framework by liuweijw.
the class UserServiceImpl method updateUserAndRoleDept.
@Override
@Transactional
@CacheEvict(allEntries = true)
public boolean updateUserAndRoleDept(UserForm userForm) {
if (null == userForm.getUserId() || userForm.getUserId() <= 0)
return Boolean.FALSE;
User user = userRepository.findUserByUserId(userForm.getUserId());
if (null == user)
return false;
user.setStatu(userForm.getStatu());
user.setUpdateTime(new Date());
user.setUserId(userForm.getUserId());
user.setDeptId(userForm.getDeptId());
user.setUsername(userForm.getUsername());
user.setMobile(userForm.getMobile());
userRepository.save(user);
QUserRole qUserRole = QUserRole.userRole;
this.queryFactory.delete(qUserRole).where(qUserRole.userId.eq(userForm.getUserId())).execute();
UserRole uRole = new UserRole();
uRole.setRoleId(userForm.getRoleId());
uRole.setUserId(userForm.getUserId());
this.userRoleRepository.saveAndFlush(uRole);
return true;
}
use of org.springframework.cache.annotation.CacheEvict in project fw-cloud-framework by liuweijw.
the class UserServiceImpl method addUserAndRoleDept.
@Override
@Transactional
@CacheEvict(allEntries = true)
public boolean addUserAndRoleDept(UserForm userForm) {
User user = new User();
user.setCreateTime(new Date());
user.setStatu(0);
user.setDeptId(userForm.getDeptId());
user.setPassword(new BCryptPasswordEncoder().encode(userForm.getPassword().trim()));
user.setUpdateTime(new Date());
user.setUsername(userForm.getUsername().trim());
user.setMobile(userForm.getMobile());
User dbUser = this.userRepository.saveAndFlush(user);
UserRole uRole = new UserRole();
uRole.setRoleId(userForm.getRoleId());
uRole.setUserId(dbUser.getUserId());
this.userRoleRepository.saveAndFlush(uRole);
return true;
}
use of org.springframework.cache.annotation.CacheEvict 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.springframework.cache.annotation.CacheEvict 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);
}
use of org.springframework.cache.annotation.CacheEvict in project cu-kfs by CU-CommunityApps.
the class GroupServiceImpl method removeAllMembers.
@CacheEvict(value = { GroupMember.CACHE_NAME, Role.CACHE_NAME }, allEntries = true)
@Override
public void removeAllMembers(String groupId) throws IllegalArgumentException {
incomingParamCheck(groupId, "groupId");
GroupService groupService = KimApiServiceLocator.getGroupService();
List<String> memberPrincipalsBefore = groupService.getMemberPrincipalIds(groupId);
Collection<GroupMember> toDeactivate = getActiveGroupMembers(groupId, null, null);
Timestamp today = new Timestamp(System.currentTimeMillis());
// Set principals as inactive
for (GroupMember aToDeactivate : toDeactivate) {
aToDeactivate.setActiveToDateValue(today);
}
// Save
this.businessObjectService.save(new ArrayList<>(toDeactivate));
List<String> memberPrincipalsAfter = groupService.getMemberPrincipalIds(groupId);
if (!memberPrincipalsAfter.isEmpty()) {
// should never happen!
LOG.warn("after attempting removal of all members, group with id '" + groupId + "' still has principal members");
}
// do updates
KimImplServiceLocator.getGroupInternalService().updateForWorkgroupChange(groupId, memberPrincipalsBefore, memberPrincipalsAfter);
}
Aggregations