|
|
@ -50,9 +50,6 @@ public class DefaultStatsService implements StatsService {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private ApprovedSiteService approvedSiteService;
|
|
|
|
private ApprovedSiteService approvedSiteService;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private ClientDetailsEntityService clientService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// stats cache
|
|
|
|
// stats cache
|
|
|
|
private Supplier<Map<String, Integer>> summaryCache = createSummaryCache();
|
|
|
|
private Supplier<Map<String, Integer>> summaryCache = createSummaryCache();
|
|
|
|
|
|
|
|
|
|
|
@ -66,18 +63,6 @@ public class DefaultStatsService implements StatsService {
|
|
|
|
}, 10, TimeUnit.MINUTES);
|
|
|
|
}, 10, TimeUnit.MINUTES);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Supplier<Map<String, Integer>> byClientIdCache = createByClientIdCache();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Supplier<Map<String, Integer>> createByClientIdCache() {
|
|
|
|
|
|
|
|
return Suppliers.memoizeWithExpiration(new Supplier<Map<String, Integer>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Map<String, Integer> get() {
|
|
|
|
|
|
|
|
return computeByClientId();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, 10, TimeUnit.MINUTES);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Map<String, Integer> getSummaryStats() {
|
|
|
|
public Map<String, Integer> getSummaryStats() {
|
|
|
|
return summaryCache.get();
|
|
|
|
return summaryCache.get();
|
|
|
@ -104,66 +89,26 @@ public class DefaultStatsService implements StatsService {
|
|
|
|
return e;
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
|
|
|
* @see org.mitre.openid.connect.service.StatsService#calculateByClientId()
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Map<String, Integer> getByClientId() {
|
|
|
|
|
|
|
|
return byClientIdCache.get();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, Integer> computeByClientId() {
|
|
|
|
|
|
|
|
// get all approved sites
|
|
|
|
|
|
|
|
Collection<ApprovedSite> allSites = approvedSiteService.getAll();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Multiset<String> clientIds = HashMultiset.create();
|
|
|
|
|
|
|
|
for (ApprovedSite approvedSite : allSites) {
|
|
|
|
|
|
|
|
clientIds.add(approvedSite.getClientId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Integer> counts = getEmptyClientCountMap();
|
|
|
|
|
|
|
|
for (String clientId : clientIds) {
|
|
|
|
|
|
|
|
ClientDetailsEntity client = clientService.loadClientByClientId(clientId);
|
|
|
|
|
|
|
|
counts.put(client.getClientId(), clientIds.count(clientId));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return counts;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.mitre.openid.connect.service.StatsService#countForClientId(java.lang.String)
|
|
|
|
* @see org.mitre.openid.connect.service.StatsService#countForClientId(java.lang.String)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ClientStat getCountForClientId(String id) {
|
|
|
|
public ClientStat getCountForClientId(String clientId) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Collection<ApprovedSite> approvedSites = approvedSiteService.getByClientId(clientId);
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Integer> counts = getByClientId();
|
|
|
|
|
|
|
|
ClientStat stat = new ClientStat();
|
|
|
|
ClientStat stat = new ClientStat();
|
|
|
|
stat.setApprovedSiteCount(counts.get(id));
|
|
|
|
stat.setApprovedSiteCount(approvedSites.size());
|
|
|
|
|
|
|
|
|
|
|
|
return stat;
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Create a new map of all client ids set to zero
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private Map<String, Integer> getEmptyClientCountMap() {
|
|
|
|
|
|
|
|
Map<String, Integer> counts = new HashMap<>();
|
|
|
|
|
|
|
|
Collection<ClientDetailsEntity> clients = clientService.getAllClients();
|
|
|
|
|
|
|
|
for (ClientDetailsEntity client : clients) {
|
|
|
|
|
|
|
|
counts.put(client.getClientId(), 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return counts;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Reset both stats caches on a trigger (before the timer runs out). Resets the timers.
|
|
|
|
* Reset both stats caches on a trigger (before the timer runs out). Resets the timers.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void resetCache() {
|
|
|
|
public void resetCache() {
|
|
|
|
summaryCache = createSummaryCache();
|
|
|
|
summaryCache = createSummaryCache();
|
|
|
|
byClientIdCache = createByClientIdCache();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|