Project

General

Profile

« Previous | Next » 

Revision 53121

Add number on stats

View differences:

modules/uoa-repository-manager-service/branches/dev-api/src/main/java/eu/dnetlib/repo/manager/service/controllers/StatsApiImpl.java
1 1
package eu.dnetlib.repo.manager.service.controllers;
2 2

  
3
import com.mongodb.util.JSON;
3 4
import org.apache.log4j.Logger;
4 5
import org.json.JSONArray;
5 6
import org.json.JSONException;
......
72 73
        String publications = getTotalByType("other",baseAddress,"/publications/count");
73 74
        String datasets = getTotalByType("other",baseAddress,"/datasets/count");
74 75
        String software = getTotalByType("other",baseAddress,"/software/count");
75
        JSONObject usagestats = getUsageStatsTotal();
76
        JSONObject lastYearUsagestats = getLastYearUsageStatsTotal();
77
        Integer usagestats = getUsageStatsTotal();
76 78

  
77 79

  
78 80
        HashMap<String,Object> stats = new HashMap<>();
......
85 87
        stats.put("datasets",datasets);
86 88
        stats.put("software",software);
87 89

  
90
        stats.put("lastYearUsagestats",lastYearUsagestats.toString());
88 91
        stats.put("usagestats",usagestats.toString());
89 92

  
90 93

  
......
110 113

  
111 114
    }
112 115

  
113
    private JSONObject getUsageStatsTotal() throws JSONException {
116
    private JSONObject getLastYearUsageStatsTotal() throws JSONException {
117

  
114 118
        UriComponents uriComponents = UriComponentsBuilder
115 119
                .fromHttpUrl(usagestatsBaseAddress + "/totals")
116 120
                .build().encode();
......
129 133
        usagestats.put("year",year);
130 134

  
131 135
        return usagestats;
136

  
132 137
    }
138

  
139
    private Integer getUsageStatsTotal() throws JSONException {
140
        UriComponents uriComponents = UriComponentsBuilder
141
                .fromHttpUrl(usagestatsBaseAddress + "/totals")
142
                .build().encode();
143

  
144
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
145

  
146
        JSONObject resultSet = new JSONObject(rs);
147

  
148
        String downloads = resultSet.getString("downloads");
149
        String views = resultSet.getString("views");
150

  
151

  
152
        return Integer.valueOf(downloads) + Integer.valueOf(views);
153
    }
133 154
}

Also available in: Unified diff