use of org.gluu.oxtrust.model.AuthenticationChartDto in project oxTrust by GluuFederation.
the class MetricService method genereateAuthenticationChartDto.
public AuthenticationChartDto genereateAuthenticationChartDto(int countDays) {
String key = OxTrustConstants.CACHE_METRICS_KEY + "#home";
AuthenticationChartDto authenticationChartDto = (AuthenticationChartDto) cacheService.get(OxTrustConstants.CACHE_METRICS_NAME, key);
if (authenticationChartDto != null) {
return authenticationChartDto;
}
Map<MetricType, List<? extends MetricEntry>> entries = findAuthenticationMetrics(ApplicationType.OX_AUTH, -countDays);
Map<MetricType, List<? extends MetricEntry>> yearlyEntris = findAuthenticationMetrics(ApplicationType.OX_AUTH, -YEARLY);
Map<String, Long> yearlySuccessStats = calculateCounterStatistics(YEARLY, (List<CounterMetricEntry>) yearlyEntris.get(MetricType.OXAUTH_USER_AUTHENTICATION_SUCCESS));
Long yearlySuccessfullRequest = yearlySuccessStats.values().stream().mapToLong(Long::valueOf).sum();
Map<String, Long> yearlyFailureStats = calculateCounterStatistics(YEARLY, (List<CounterMetricEntry>) yearlyEntris.get(MetricType.OXAUTH_USER_AUTHENTICATION_FAILURES));
Long yearlyFailsRequest = yearlyFailureStats.values().stream().mapToLong(Long::valueOf).sum();
String[] labels = new String[countDays + 1];
Long[] values = new Long[countDays + 1];
Map<String, Long> successStats = calculateCounterStatistics(countDays, (List<CounterMetricEntry>) entries.get(MetricType.OXAUTH_USER_AUTHENTICATION_SUCCESS));
labels = successStats.keySet().toArray(labels);
values = successStats.values().toArray(values);
authenticationChartDto = new AuthenticationChartDto();
authenticationChartDto.setLabels(labels);
authenticationChartDto.setSuccess(values);
Map<String, Long> failureStats = calculateCounterStatistics(countDays, (List<CounterMetricEntry>) entries.get(MetricType.OXAUTH_USER_AUTHENTICATION_FAILURES));
values = new Long[countDays];
authenticationChartDto.setFailure(failureStats.values().toArray(values));
authenticationChartDto.setYearlyRequest(yearlySuccessfullRequest + yearlyFailsRequest);
cacheService.put(key, authenticationChartDto);
return authenticationChartDto;
}
Aggregations