22
33import com .google .common .collect .ImmutableList ;
44import dashboard .control .Constants ;
5- import org .springframework .beans .factory .annotation .Autowired ;
65import org .springframework .beans .factory .annotation .Value ;
76import org .springframework .http .HttpHeaders ;
87import org .springframework .web .client .RestTemplate ;
98
9+ import java .net .URLEncoder ;
10+ import java .nio .charset .Charset ;
1011import java .util .List ;
1112import java .util .Optional ;
1213
1617@ SuppressWarnings ("unchecked" )
1718public class StatsImpl implements Stats , Constants {
1819
19- private RestTemplate restTemplate ;
20- private String baseUrl ;
20+ private final RestTemplate restTemplate ;
21+ private final String baseUrl ;
2122
22- @ Autowired
2323 public StatsImpl (@ Value ("${statsUser}" ) String user ,
2424 @ Value ("${statsPassword}" ) String password ,
2525 @ Value ("${statsBaseUrl}" ) String baseUrl ) {
@@ -37,25 +37,32 @@ public StatsImpl(@Value("${statsUser}") String user,
3737 }
3838
3939 public List <Object > loginTimeFrame (long from , long to , String scale , Optional <String > spEntityIdOptional ) {
40+ String idp = currentIdPEncoded ();
4041 StringBuilder url = new StringBuilder (String .format (
4142 "%s/public/login_time_frame?from=%s&to=%s&include_unique=true&scale=%s&epoch=ms&idp_id=%s" ,
42- baseUrl , from , to , scale , currentUserIdp () ));
43+ baseUrl , from , to , scale , idp ));
4344 spEntityIdOptional .ifPresent (spEntityId -> url .append (String .format ("&sp_id=%s" , spEntityId )));
4445 return restTemplate .getForEntity (url .toString (), List .class ).getBody ();
4546 }
4647
48+ private String currentIdPEncoded () {
49+ return URLEncoder .encode (currentUserIdp (), Charset .defaultCharset ());
50+ }
51+
4752 public List <Object > loginAggregated (String period , Optional <String > spEntityIdOptional ) {
53+ String idp = currentIdPEncoded ();
4854 StringBuilder url = new StringBuilder (String .format (
4955 "%s/public/login_aggregated?period=%s&include_unique=true&idp_id=%s&group_by=sp_id" ,
50- baseUrl , period , currentUserIdp () ));
56+ baseUrl , period , idp ));
5157 spEntityIdOptional .ifPresent (spEntityId -> url .append (String .format ("&sp_id=%s" , spEntityId )));
5258 return restTemplate .getForEntity (url .toString (), List .class ).getBody ();
5359 }
5460
5561 public List <Object > uniqueLoginCount (long from , long to , String spEntityId ) {
62+ String idp = currentIdPEncoded ();
5663 String url = String .format (
5764 "%s/public/unique_login_count?from=%s&to=%s&include_unique=true&epoch=ms&idp_id=%s&sp_id=%s" ,
58- baseUrl , from , to , currentUserIdp () , spEntityId );
65+ baseUrl , from , to , idp , spEntityId );
5966 return restTemplate .getForEntity (url , List .class ).getBody ();
6067 }
6168
0 commit comments