Search in sources :

Example 21 with CacheEvict

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;
}
Also used : User(com.github.liuweijw.business.admin.domain.User) AuthUser(com.github.liuweijw.system.api.model.AuthUser) QUser(com.github.liuweijw.business.admin.domain.QUser) QUserRole(com.github.liuweijw.business.admin.domain.QUserRole) UserRole(com.github.liuweijw.business.admin.domain.UserRole) QUserRole(com.github.liuweijw.business.admin.domain.QUserRole) Date(java.util.Date) CacheEvict(org.springframework.cache.annotation.CacheEvict) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with CacheEvict

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;
}
Also used : User(com.github.liuweijw.business.admin.domain.User) AuthUser(com.github.liuweijw.system.api.model.AuthUser) QUser(com.github.liuweijw.business.admin.domain.QUser) QUserRole(com.github.liuweijw.business.admin.domain.QUserRole) UserRole(com.github.liuweijw.business.admin.domain.UserRole) Date(java.util.Date) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) CacheEvict(org.springframework.cache.annotation.CacheEvict) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with CacheEvict

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);
}
Also used : DelegateMemberAttributeData(org.kuali.kfs.kim.impl.common.delegate.DelegateMemberAttributeData) DelegateType(org.kuali.kfs.kim.impl.common.delegate.DelegateType) Principal(org.kuali.kfs.kim.impl.identity.principal.Principal) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 24 with CacheEvict

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);
}
Also used : DelegateMemberAttributeData(org.kuali.kfs.kim.impl.common.delegate.DelegateMemberAttributeData) DelegateMember(org.kuali.kfs.kim.impl.common.delegate.DelegateMember) ArrayList(java.util.ArrayList) DelegateType(org.kuali.kfs.kim.impl.common.delegate.DelegateType) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 25 with CacheEvict

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);
}
Also used : GroupService(org.kuali.kfs.kim.api.group.GroupService) Timestamp(java.sql.Timestamp) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Aggregations

CacheEvict (org.springframework.cache.annotation.CacheEvict)53 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)14 Transactional (org.springframework.transaction.annotation.Transactional)13 Date (java.util.Date)8 ArrayList (java.util.ArrayList)6 CacheInfoEvict (org.entando.entando.aps.system.services.cache.CacheInfoEvict)5 QUser (com.github.liuweijw.business.admin.domain.QUser)3 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)3 ConnectorRequestContext (com.netflix.metacat.common.server.connectors.ConnectorRequestContext)3 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)3 QMenu (com.github.liuweijw.business.admin.domain.QMenu)2 QRole (com.github.liuweijw.business.admin.domain.QRole)2 QUserRole (com.github.liuweijw.business.admin.domain.QUserRole)2 Role (com.github.liuweijw.business.admin.domain.Role)2 User (com.github.liuweijw.business.admin.domain.User)2 UserRole (com.github.liuweijw.business.admin.domain.UserRole)2 AuthUser (com.github.liuweijw.system.api.model.AuthUser)2 RoleMenuDO (io.github.tesla.ops.system.domain.RoleMenuDO)2 Connection (java.sql.Connection)2 HashMap (java.util.HashMap)2