Search in sources :

Example 26 with CacheEvict

use of org.springframework.cache.annotation.CacheEvict in project cu-kfs by CU-CommunityApps.

the class PermissionServiceImpl method updatePermission.

@CacheEvict(value = { Permission.CACHE_NAME, PermissionTemplate.CACHE_NAME }, allEntries = true)
@Override
public Permission updatePermission(Permission permission) throws IllegalArgumentException, IllegalStateException {
    incomingParamCheck(permission, "permission");
    Permission oldPermission = getPermissionImpl(permission.getId());
    if (StringUtils.isBlank(permission.getId()) || oldPermission == null) {
        throw new IllegalStateException("the permission does not exist: " + permission);
    }
    List<PermissionAttribute> oldAttrBos = oldPermission.getAttributeDetails();
    // put old attributes in map for easier updating
    Map<String, PermissionAttribute> oldAttrMap = new HashMap<>();
    for (PermissionAttribute oldAttr : oldAttrBos) {
        oldAttrMap.put(oldAttr.getKimAttribute().getAttributeName(), oldAttr);
    }
    List<PermissionAttribute> newAttrBos = new ArrayList<>();
    for (String key : permission.getAttributes().keySet()) {
        if (oldAttrMap.containsKey(key)) {
            PermissionAttribute updatedAttr = oldAttrMap.get(key);
            updatedAttr.setAttributeValue(permission.getAttributes().get(key));
            newAttrBos.add(updatedAttr);
        } else {
            newAttrBos.addAll(KimAttributeData.createFrom(PermissionAttribute.class, Collections.singletonMap(key, permission.getAttributes().get(key)), permission.getTemplate().getKimTypeId()));
        }
    }
    if (CollectionUtils.isNotEmpty(newAttrBos)) {
        if (null != permission.getAttributeDetails()) {
            permission.getAttributeDetails().clear();
        }
        permission.setAttributeDetails(newAttrBos);
    }
    if (permission.getTemplate() == null && permission.getTemplateId() != null) {
        permission.setTemplate(getPermissionTemplate(permission.getTemplateId()));
    }
    return businessObjectService.save(permission);
}
Also used : HashMap(java.util.HashMap) RolePermission(org.kuali.kfs.kim.impl.role.RolePermission) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 27 with CacheEvict

use of org.springframework.cache.annotation.CacheEvict in project fw-cloud-framework by liuweijw.

the class MenuServiceImpl method deleteMenu.

@Override
@Transactional
@CacheEvict(allEntries = true)
public Boolean deleteMenu(Integer menuId, String roleCode) {
    // 删除当前节点 -- 假删除
    QMenu qMenu = QMenu.menu;
    this.queryFactory.update(qMenu).set(qMenu.statu, CommonConstant.STATUS_DEL).where(qMenu.menuId.eq(menuId)).execute();
    // 删除父节点为当前节点的节点 -- 假删除
    this.queryFactory.update(qMenu).set(qMenu.statu, CommonConstant.STATUS_DEL).where(qMenu.pid.eq(menuId)).execute();
    return true;
}
Also used : QMenu(com.github.liuweijw.business.admin.domain.QMenu) CacheEvict(org.springframework.cache.annotation.CacheEvict) Transactional(org.springframework.transaction.annotation.Transactional)

Example 28 with CacheEvict

use of org.springframework.cache.annotation.CacheEvict in project fw-cloud-framework by liuweijw.

the class PermissionServiceImpl method updateRoleMenuPermissions.

@Override
@CacheEvict(value = { AdminCacheKey.PERMISSION_INFO, AdminCacheKey.MENU_INFO, AdminCacheKey.MODULE_INFO, AdminCacheKey.ROLE_INFO }, allEntries = true)
@Transactional
public boolean updateRoleMenuPermissions(String roleCode, String... permissions) {
    Role role = roleService.findRoleByCode(roleCode.trim());
    if (null == role)
        return false;
    // 菜单集合
    Map<Integer, List<String>> roleMenuIdList = new HashMap<Integer, List<String>>();
    for (String permission : permissions) {
        if (!permission.contains("|"))
            continue;
        String[] menuPermissions = permission.split("\\|");
        Integer menuId = WebUtils.parseStrToInteger(menuPermissions[0], null);
        if (null == menuId || StringHelper.isBlank(menuPermissions[1]))
            continue;
        if (!roleMenuIdList.containsKey(menuId)) {
            roleMenuIdList.put(menuId, new ArrayList<String>());
        }
        roleMenuIdList.get(menuId).add(menuPermissions[1].trim());
    }
    // 删除RoleMenu和RoleMenuPermission
    this.delRoleMenuPermission(role.getRoleId());
    if (roleMenuIdList.size() > 0) {
        roleMenuIdList.forEach((menuId, menuPermissions) -> {
            RoleMenu menuRole = new RoleMenu();
            menuRole.setMenuId(menuId);
            menuRole.setRoleId(role.getRoleId());
            menuRole = roleMenuRepository.saveAndFlush(menuRole);
            Integer menuRoleId = menuRole.getId();
            menuPermissions.forEach(p -> {
                String permission = p.trim();
                if (permission.contains("_")) {
                    RoleMenuPermission roleMenuPermission = new RoleMenuPermission();
                    roleMenuPermission.setRoleMenuId(menuRoleId);
                    roleMenuPermission.setPermission(permission);
                    roleMenuPermissionRepository.saveAndFlush(roleMenuPermission);
                }
            });
        });
    }
    return true;
}
Also used : Role(com.github.liuweijw.business.admin.domain.Role) QRoleMenuPermission(com.github.liuweijw.business.admin.domain.QRoleMenuPermission) RoleMenuPermission(com.github.liuweijw.business.admin.domain.RoleMenuPermission) HashMap(java.util.HashMap) QRoleMenu(com.github.liuweijw.business.admin.domain.QRoleMenu) RoleMenu(com.github.liuweijw.business.admin.domain.RoleMenu) ArrayList(java.util.ArrayList) List(java.util.List) CacheEvict(org.springframework.cache.annotation.CacheEvict) Transactional(org.springframework.transaction.annotation.Transactional)

Example 29 with CacheEvict

use of org.springframework.cache.annotation.CacheEvict in project topjava10 by JavaWebinar.

the class UserServiceImpl method update.

@CacheEvict(value = "users", allEntries = true)
@Transactional
@Override
public void update(UserTo userTo) {
    User user = updateFromTo(get(userTo.getId()), userTo);
    repository.save(prepareToSave(user));
}
Also used : AuthorizedUser(ru.javawebinar.topjava.AuthorizedUser) User(ru.javawebinar.topjava.model.User) CacheEvict(org.springframework.cache.annotation.CacheEvict) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with CacheEvict

use of org.springframework.cache.annotation.CacheEvict in project tesla by linking12.

the class RoleServiceImpl method update.

@CacheEvict(value = CACHE_NAME, key = ROLE_ALL_KEY)
@Override
public int update(RoleDO role) {
    int r = roleMapper.update(role);
    List<Long> menuIds = role.getMenuIds();
    Long roleId = role.getRoleId();
    roleMenuMapper.removeByRoleId(roleId);
    List<RoleMenuDO> rms = new ArrayList<>();
    for (Long menuId : menuIds) {
        RoleMenuDO rmDo = new RoleMenuDO();
        rmDo.setRoleId(roleId);
        rmDo.setMenuId(menuId);
        rms.add(rmDo);
    }
    if (rms.size() > 0) {
        roleMenuMapper.batchSave(rms);
    }
    return r;
}
Also used : ArrayList(java.util.ArrayList) RoleMenuDO(io.github.tesla.ops.system.domain.RoleMenuDO) 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