Reduce dependency on Guava (#1589)
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -11,7 +11,7 @@ package org.eclipse.hawkbit.mgmt.rest.resource;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
|
||||
@@ -24,7 +24,6 @@ import org.eclipse.hawkbit.repository.report.model.SystemUsageReportWithTenants;
|
||||
import org.eclipse.hawkbit.repository.report.model.TenantUsage;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -106,7 +105,10 @@ public class MgmtSystemManagementResource implements MgmtSystemManagementRestApi
|
||||
public ResponseEntity<Collection<MgmtSystemCache>> getCaches() {
|
||||
final Collection<String> cacheNames = cacheManager.getCacheNames();
|
||||
return ResponseEntity
|
||||
.ok(cacheNames.stream().map(cacheManager::getCache).map(this::cacheRest).collect(Collectors.toList()));
|
||||
.ok(cacheNames.stream().map(cacheManager::getCache)
|
||||
.filter(Objects::nonNull)
|
||||
.map(cache -> new MgmtSystemCache(cache.getName(), Collections.emptyList()))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,21 +124,4 @@ public class MgmtSystemManagementResource implements MgmtSystemManagementRestApi
|
||||
cacheNames.forEach(cacheName -> cacheManager.getCache(cacheName).clear());
|
||||
return ResponseEntity.ok(cacheNames);
|
||||
}
|
||||
|
||||
private MgmtSystemCache cacheRest(final Cache cache) {
|
||||
final Object nativeCache = cache.getNativeCache();
|
||||
if (nativeCache instanceof com.google.common.cache.Cache) {
|
||||
return guavaCache(cache, nativeCache);
|
||||
} else {
|
||||
return new MgmtSystemCache(cache.getName(), Collections.emptyList());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private MgmtSystemCache guavaCache(final Cache cache, final Object nativeCache) {
|
||||
final com.google.common.cache.Cache<Object, Object> guavaCache = (com.google.common.cache.Cache<Object, Object>) nativeCache;
|
||||
final List<String> keys = guavaCache.asMap().keySet().stream().map(key -> key.toString())
|
||||
.collect(Collectors.toList());
|
||||
return new MgmtSystemCache(cache.getName(), keys);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user