/** * Returns <code>true</code> if the user is associated with the named regular role. * * @param userId the primary key of the user * @param companyId the primary key of the company * @param name the name of the role * @param inherited whether to include the user's inherited roles in the search * @return <code>true</code> if the user is associated with the regular role; <code>false</code> * otherwise * @throws PortalException if a role with the name could not be found in the company or if a * default user for the company could not be found * @throws SystemException if a system exception occurred */ @ThreadLocalCachable public boolean hasUserRole(long userId, long companyId, String name, boolean inherited) throws PortalException, SystemException { Role role = rolePersistence.findByC_N(companyId, name); if (role.getType() != RoleConstants.TYPE_REGULAR) { throw new IllegalArgumentException(name + " is not a regular role"); } long defaultUserId = userLocalService.getDefaultUserId(companyId); if (userId == defaultUserId) { if (name.equals(RoleConstants.GUEST)) { return true; } else { return false; } } if (inherited) { if (userPersistence.containsRole(userId, role.getRoleId())) { return true; } ThreadLocalCache<Integer> threadLocalCache = ThreadLocalCacheManager.getThreadLocalCache( Lifecycle.REQUEST, RoleLocalServiceImpl.class.getName()); String key = String.valueOf(role.getRoleId()).concat(String.valueOf(userId)); Integer value = threadLocalCache.get(key); if (value == null) { value = roleFinder.countByR_U(role.getRoleId(), userId); threadLocalCache.put(key, value); } if (value > 0) { return true; } else { return false; } } else { return userPersistence.containsRole(userId, role.getRoleId()); } }
public void afterReturning(MethodInvocation methodInvocation, Object result) throws Throwable { MethodTargetClassKey methodTargetClassKey = buildMethodTargetClassKey(methodInvocation); ThreadLocalCachable threadLocalCachable = findAnnotation(methodTargetClassKey); if (threadLocalCachable == _nullThreadLocalCacheable) { return; } ThreadLocalCache<Object> threadLocalCache = ThreadLocalCacheManager.getThreadLocalCache( threadLocalCachable.scope(), methodTargetClassKey.toString()); String cacheKey = _buildCacheKey(methodInvocation.getArguments()); if (result == null) { threadLocalCache.put(cacheKey, nullResult); } else { threadLocalCache.put(cacheKey, result); } }
public Object before(MethodInvocation methodInvocation) throws Throwable { MethodTargetClassKey methodTargetClassKey = buildMethodTargetClassKey(methodInvocation); ThreadLocalCachable threadLocalCachable = findAnnotation(methodTargetClassKey); if (threadLocalCachable == _nullThreadLocalCacheable) { return null; } ThreadLocalCache<?> threadLocalCache = ThreadLocalCacheManager.getThreadLocalCache( threadLocalCachable.scope(), methodTargetClassKey.toString()); String cacheKey = _buildCacheKey(methodInvocation.getArguments()); Object value = threadLocalCache.get(cacheKey); if (value == nullResult) { return null; } return value; }