Project

General

Profile

« Previous | Next » 

Revision 45522

Added by Tsampikos Livisianos almost 8 years ago

rev

View differences:

modules/dnet-openaire-usage-stats-api/src/main/java/eu/dnetlib/usagestats/controllers/UsageStatsController.java
10 10
import eu.dnetlib.usagestats.repos.ProjectRepo;
11 11
import eu.dnetlib.usagestats.repos.ResultRepo;
12 12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.stereotype.Controller;
13 14
import org.springframework.transaction.annotation.Transactional;
14 15
import org.springframework.web.bind.annotation.CrossOrigin;
15 16
import org.springframework.web.bind.annotation.PathVariable;
......
41 42
    @Autowired
42 43
    UsageReport report;
43 44

  
45
    @RequestMapping(value = "/", method = RequestMethod.GET)
46
    public String defaultMap(){
47
        return "<body><center>" +
48
                "<h2>OpenAIRE SUSHI lite Client</h2>" +
49
                "<h3> Supported Reports</h3>" +
50
                "<ul>" +
51
                "<li><a href=\"/stats/AR1/\">AR1 Report</a></li>" +
52
	            "<li><a href=\"/stats/IR1/\">IR1 Report</a></li>" +
53
                "<li><a href=\"/stats/RR1/\">RR1 Report</a></li>" +
54
                "</ul>" +
55
                "</center></body>";
56
    }
44 57

  
58
    @RequestMapping(value = "/AR1", method = RequestMethod.GET)
59
    public String ar1Map(){
60
        return "<body>" +
61
                "<h2>OpenAIRE SUSHI lite Client</h2>" +
62
	            "<form action=\"/stats/GetReport/\" method=\"get\">" +
63
                "<h3>Report Request</h3>" +
64
                "Report Name: " +
65
                "<select name='Report'>" +
66
                "<option value='AR1'>AR1</option>" +
67
                "</select>" +
68
                "<br />" +
69
                "Release:" +
70
                "<select name='Release'>" +
71
                "<option value=\"4\">4</option>" +
72
                "</select>" +
73
                "<br />" +
74
                "<input type=\"text\" name=\"RequestorID\" value=\"anonymous\">" +
75
                "<h3>Report Filters</h3>" +
76
                "<h4>DateRange</h4>" +
77
                "<p>Valid date formats: yyyy-mm-dd or yyyy-mm<br />" +
78
                "Defaults to the last available month if no dates are provided" +
79
                "</p>" +
80
                "BeginDate:<input type=\"text\" name=\"BeginDate\" value=\"2016-03\" style=\"width: 80px; padding:2px\"/>" +
81
                "<br />" +
82
                "EndDate:<input type=\"text\" name=\"EndDate\" value=\"2016-06\"  style=\"width: 80px; padding:2px\"/>" +
83
                "<h4>Filters</h4>" +
84
                "<p>You must provide either a Repository Identifier or an Item Identifier</p>" +
85
                //"<p>Repository Identifier format: namespace:value<br />" +
86
                //"namespace must be either be openaire or repoid<br />" +
87
                //"value is the integer value assigned by CORE or IRUS-UK" +
88
                //"</p>" +
89

  
90
                "RepositoryIdentifier:" +
91
                "<input type=\"text\" name=\"RepositoryIdentifier\">" +
92
                "<br />" +
93
                "ItemIdentifier:" +
94
                "<input type=\"text\" name=\"ItemIdentifier\" value=\"openaire:od_________7::fb90de6f20d79783d05749d8f60417d5\">" +
95

  
96
                //"<p>You may also limit the results to include or exclude items that have a DOI<br />" +
97
                //"Valid values: Yes or No</p>" +
98
                //"hasDOI:" +
99
                //"<select name='hasDOI'>" +
100
                //"<option value=\"\">Not applicable</option>" +
101
                //"<option value=\"Yes\">Yes</option>" +
102
                //"<option value=\"No\">No</option>" +
103
                //"</select>" +
104

  
105
                "<h3>Report Attributes</h3>" +
106
                "<p>Valid Granularity values: Monthly or Totals</p>" +
107
                "Granularity:" +
108
                "<select name='Granularity'>" +
109
                "<option value=\"Monthly\">Monthly</option>" +
110
                "<option value=\"Totals\">Totals</option>" +
111
                "</select>" +
112
                //"<p>The format in which the response is to be returned defaults to JSON unless a callback function name is entered in which case JSONP is returned.</p>" +
113
                //"<input type=\"text\" name=\"Callback\">" +
114
                "<p>The Pretty attribute is just for humans playing with the API and looking at results in a browser.</p>" +
115
                "<p><input type=\"checkbox\" name=\"Pretty\" value=\"Pretty\" checked=\"checked\">Pretty print json(p) for humans</p>" +
116
                "<input type=\"submit\" class=\"button\" value=\"GetReport\"/>" +
117
                "</form>" +
118
                "</body>";
119
    }
120

  
121
    @RequestMapping(value = "/IR1", method = RequestMethod.GET)
122
    public String ir1Map(){
123
        return "<body>" +
124
                "<h2>OpenAIRE SUSHI lite Client</h2>" +
125
                "<form action=\"/stats/GetReport/\" method=\"get\">" +
126
                "<h3>Report Request</h3>" +
127
                "Report Name: " +
128
                "<select name='Report'>" +
129
                "<option value='IR1'>IR1</option>" +
130
                "</select>" +
131
                "<br />" +
132
                "Release:" +
133
                "<select name='Release'>" +
134
                "<option value=\"4\">4</option>" +
135
                "</select>" +
136
                "<br />" +
137
                "<input type=\"text\" name=\"RequestorID\" value=\"anonymous\">" +
138
                "<h3>Report Filters</h3>" +
139
                "<h4>DateRange</h4>" +
140
                "<p>Valid date formats: yyyy-mm-dd or yyyy-mm<br />" +
141
                "Defaults to the last available month if no dates are provided" +
142
                "</p>" +
143
                "BeginDate:<input type=\"text\" name=\"BeginDate\" value=\"2016-03\" style=\"width: 80px; padding:2px\"/>" +
144
                "<br />" +
145
                "EndDate:<input type=\"text\" name=\"EndDate\" value=\"2016-06\"  style=\"width: 80px; padding:2px\"/>" +
146
                "<h4>Filters</h4>" +
147
                "<p>You must provide either a Repository Identifier or an Item Identifier</p>" +
148
                //"<p>Repository Identifier format: namespace:value<br />" +
149
                //"namespace must be either be openaire or repoid<br />" +
150
                //"value is the integer value assigned by CORE or IRUS-UK" +
151
                //"</p>" +
152

  
153
                "RepositoryIdentifier:" +
154
                "<input type=\"text\" name=\"RepositoryIdentifier\" value=\"repoid:20\">" +
155
                "<br />" +
156
                "ItemIdentifier:" +
157
                "<input type=\"text\" name=\"ItemIdentifier\">" +
158

  
159
                "<p>Optional filter to only show results for a single item type, e.g. article, book, etc.</p>" +
160
                "ItemDataType:" +
161
                "<select name='ItemDataType'>" +
162
                "<option value=\"\">--- Select ItemDataType ---</option>" +
163
                "<option value='Annotation'>Annotation</option>" +
164
                "<option value='Article'>Article</option>" +
165
                "<option value='Bachelor thesis'>Bachelor thesis</option>" +
166
                "<option value='Book'>Book</option>" +
167
                "<option value='clinical trial'>clinical trial</option>" +
168
                "<option value='Collection'>Collection</option>" +
169
                "<option value='Conference object'>Conference object</option>" +
170
                "<option value='Contribution for newspaper or weekly magazine'>Contribution for newspaper or weekly magazine</option>" +
171
                "<option value='Dataset'>Dataset</option>" +
172
                "<option value='Doctoral thesis'>Doctoral thesis</option>" +
173
                "<option value='Event'>Event</option>" +
174
                "<option value='External research report'>External research report</option>" +
175
                "<option value='Film'>Film</option>" +
176
                "<option value='Image'>Image</option>" +
177
                "<option value='InteractiveResource'>InteractiveResource</option>" +
178
                "<option value='Internal report'>Internal report</option>" +
179
                "<option value='Lecture'>Lecture</option>" +
180
                "<option value='Master thesis'>Master thesis</option>" +
181
                "<option value='Newsletter'>Newsletter</option>" +
182
                "<option value='Other'>Other</option>" +
183
                "<option value='Part of book or chapter of book'>Part of book or chapter of book</option>" +
184
                "<option value='Patent'>Patent</option>" +
185
                "<option value='PhysicalObject'>PhysicalObject</option>" +
186
                "<option value='Preprint'>Preprint</option>" +
187
                "<option value='Report'>Report</option>" +
188
                "<option value='Research'>Research</option>" +
189
                "<option value='Review'>Review</option>" +
190
                "<option value='Software'>Software</option>" +
191
                "<option value='Sound'>Sound</option>" +
192
                "<option value='Unknown'>Unknown</option>" +
193
                "</select>" +
194

  
195
                //"<p>You may also limit the results to include or exclude items that have a DOI<br />" +
196
                //"Valid values: Yes or No</p>" +
197
                //"hasDOI:" +
198
                //"<select name='hasDOI'>" +
199
                //"<option value=\"\">Not applicable</option>" +
200
                //"<option value=\"Yes\">Yes</option>" +
201
                //"<option value=\"No\">No</option>" +
202
                //"</select>" +
203

  
204
                "<h3>Report Attributes</h3>" +
205
                "<p>Valid Granularity values: Monthly or Totals</p>" +
206
                "Granularity:" +
207
                "<select name='Granularity'>" +
208
                "<option value=\"Monthly\">Monthly</option>" +
209
                "<option value=\"Totals\">Totals</option>" +
210
                "</select>" +
211
                //"<p>The format in which the response is to be returned defaults to JSON unless a callback function name is entered in which case JSONP is returned.</p>" +
212
                //"<input type=\"text\" name=\"Callback\">" +
213
                "<p>The Pretty attribute is just for humans playing with the API and looking at results in a browser.</p>" +
214
                "<p><input type=\"checkbox\" name=\"Pretty\" value=\"Pretty\" checked=\"checked\">Pretty print json(p) for humans</p>" +
215
                "<input type=\"submit\" class=\"button\" value=\"GetReport\"/>" +
216
                "</form>" +
217
                "</body>";
218
    }
219

  
220
    @RequestMapping(value = "/RR1", method = RequestMethod.GET)
221
    public String rr1Map(){
222
        return "<body>" +
223
                "<h2>OpenAIRE SUSHI lite Client</h2>" +
224
                "<form action=\"/stats/GetReport/\" method=\"get\">" +
225
                "<h3>Report Request</h3>" +
226
                "Report Name: " +
227
                "<select name='Report'>" +
228
                "<option value='RR1'>RR1</option>" +
229
                "</select>" +
230
                "<br />" +
231
                "Release:" +
232
                "<select name='Release'>" +
233
                "<option value=\"4\">4</option>" +
234
                "</select>" +
235
                "<br />" +
236
                "<input type=\"text\" name=\"RequestorID\" value=\"anonymous\">" +
237
                "<h3>Report Filters</h3>" +
238
                "<h4>DateRange</h4>" +
239
                "<p>Valid date formats: yyyy-mm-dd or yyyy-mm<br />" +
240
                "Defaults to the last available month if no dates are provided" +
241
                "</p>" +
242
                "BeginDate:<input type=\"text\" name=\"BeginDate\" value=\"2016-03\" style=\"width: 80px; padding:2px\"/>" +
243
                "<br />" +
244
                "EndDate:<input type=\"text\" name=\"EndDate\" value=\"2016-06\"  style=\"width: 80px; padding:2px\"/>" +
245
                "<h4>Filters</h4>" +
246
                "<p>You must provide either a Repository Identifier or an Item Identifier</p>" +
247
                //"<p>Repository Identifier format: namespace:value<br />" +
248
                //"namespace must be either be openaire or repoid<br />" +
249
                //"value is the integer value assigned by CORE or IRUS-UK" +
250
                //"</p>" +
251

  
252
                "RepositoryIdentifier:" +
253
                "<input type=\"text\" name=\"RepositoryIdentifier\">" +
254
                "<br />" +
255

  
256
                "<p>Optional filter to only show results for a single item type, e.g. article, book, etc.</p>" +
257
                "ItemDataType:" +
258
                "<select name='ItemDataType'>" +
259
                "<option value=\"\">--- Select ItemDataType ---</option>" +
260
                "<option value='Annotation'>Annotation</option>" +
261
                "<option value='Article'>Article</option>" +
262
                "<option value='Bachelor thesis'>Bachelor thesis</option>" +
263
                "<option value='Book'>Book</option>" +
264
                "<option value='clinical trial'>clinical trial</option>" +
265
                "<option value='Collection'>Collection</option>" +
266
                "<option value='Conference object'>Conference object</option>" +
267
                "<option value='Contribution for newspaper or weekly magazine'>Contribution for newspaper or weekly magazine</option>" +
268
                "<option value='Dataset'>Dataset</option>" +
269
                "<option value='Doctoral thesis'>Doctoral thesis</option>" +
270
                "<option value='Event'>Event</option>" +
271
                "<option value='External research report'>External research report</option>" +
272
                "<option value='Film'>Film</option>" +
273
                "<option value='Image'>Image</option>" +
274
                "<option value='InteractiveResource'>InteractiveResource</option>" +
275
                "<option value='Internal report'>Internal report</option>" +
276
                "<option value='Lecture'>Lecture</option>" +
277
                "<option value='Master thesis'>Master thesis</option>" +
278
                "<option value='Newsletter'>Newsletter</option>" +
279
                "<option value='Other'>Other</option>" +
280
                "<option value='Part of book or chapter of book'>Part of book or chapter of book</option>" +
281
                "<option value='Patent'>Patent</option>" +
282
                "<option value='PhysicalObject'>PhysicalObject</option>" +
283
                "<option value='Preprint'>Preprint</option>" +
284
                "<option value='Report'>Report</option>" +
285
                "<option value='Research'>Research</option>" +
286
                "<option value='Review'>Review</option>" +
287
                "<option value='Software'>Software</option>" +
288
                "<option value='Sound'>Sound</option>" +
289
                "<option value='Unknown'>Unknown</option>" +
290
                "</select>" +
291

  
292
                //"<p>You may also limit the results to include or exclude items that have a DOI<br />" +
293
                //"Valid values: Yes or No</p>" +
294
                //"hasDOI:" +
295
                //"<select name='hasDOI'>" +
296
                //"<option value=\"\">Not applicable</option>" +
297
                //"<option value=\"Yes\">Yes</option>" +
298
                //"<option value=\"No\">No</option>" +
299
                //"</select>" +
300

  
301
                "<h3>Report Attributes</h3>" +
302
                "<p>Valid Granularity values: Monthly or Totals</p>" +
303
                "Granularity:" +
304
                "<select name='Granularity'>" +
305
                "<option value=\"Monthly\">Monthly</option>" +
306
                "<option value=\"Totals\">Totals</option>" +
307
                "</select>" +
308
                //"<p>The format in which the response is to be returned defaults to JSON unless a callback function name is entered in which case JSONP is returned.</p>" +
309
                //"<input type=\"text\" name=\"Callback\">" +
310
                "<p>The Pretty attribute is just for humans playing with the API and looking at results in a browser.</p>" +
311
                "<p><input type=\"checkbox\" name=\"Pretty\" value=\"Pretty\" checked=\"checked\">Pretty print json(p) for humans</p>" +
312
                "<input type=\"submit\" class=\"button\" value=\"GetReport\"/>" +
313
                "</form>" +
314
                "</body>";
315
    }
316

  
45 317
    //Counter Compliant Report kai kala
46 318
    @RequestMapping(value = "/GetReport/", method = RequestMethod.GET)
47 319
    public ReportResponseWrapper getReport(@RequestParam(value = "Report", defaultValue = "") String reportP, @RequestParam(value = "Release", defaultValue = "4") String release, @RequestParam(value = "RequestorID", defaultValue = "anonymous") String requestorId,
......
56 328
    /*@RequestMapping("/home/{error}")*/
57 329
    @CrossOrigin(methods = RequestMethod.GET, origins = "*")
58 330
    @RequestMapping(value = "/datasources/{datasourceId}/clicks")
59
    public ViewStats getDatasourceClicks(@PathVariable(value = "datasourceId") String datasourceId) throws Exception {
331
    public UsageStats getDatasourceClicks(@PathVariable(value = "datasourceId") String datasourceId) throws Exception {
60 332

  
61 333
        return datasourceRepo.getClicks(datasourceId);
62 334
    }
......
88 360

  
89 361
    @RequestMapping(value = "/projects/{projectId}/clicks")
90 362
    @CrossOrigin(methods = RequestMethod.GET, origins = "*")
91
    public ViewStats getProjectClicks(@PathVariable(value = "projectId") String projectId) throws Exception {
363
    public UsageStats getProjectClicks(@PathVariable(value = "projectId") String projectId) throws Exception {
92 364

  
93 365
        return projectRepo.getClicks(projectId);
94 366
    }
modules/dnet-openaire-usage-stats-api/src/main/java/eu/dnetlib/usagestats/repos/DatasourceRepo.java
21 21
    private Logger log = Logger.getLogger(this.getClass());
22 22

  
23 23

  
24
    public ViewStats getClicks(String id) {
24
    public UsageStats getClicks(String id) {
25 25

  
26 26
        //String query = "select d.id, d.name , sum (ds.numberofviews) from datasource d, usagestats.datasourcesstats ds " +
27 27
        //        "where ds.datasourceid=d.id and d.id=? group by d.id, d.name;";
28 28
        //String query = "select '5', maxcount from (select ooid.oid, count(*) as maxcount from usagestats.piwiklog pl, datasource_oids doid " +
29 29
        //        "where pl.entityid = doid.oid and doid.id=? group by doid.oid order by count(*) DESC limit 1) as temp";
30
        String query = "select sum(number_of_views) from datasource_stats where id=?";
30
        //String query = "select sum(number_of_views) from datasource_stats where id=?";
31
        /*
32
        String query = "select 'views', rvs.source, sum(rvs.sum) from repo_view_stats_monthly_clean rvs, datasource_results dr where rvs.id=dr.result and dr.id=? group by rvs.source " + 
33
            "UNION select 'views', '5', sum(rs.sum) from result_stats_monthly_clean rs, datasource_results dr where rs.id=dr.result and dr.id=?" +
34
            "UNION select 'downloads', rds.source, sum(rds.sum) from repo_download_stats_monthly_clean rds, datasource_results dr where rds.id=dr.result and dr.id=? group by rds.source";
35
        */
31 36

  
37
        String query = "select 'views', dp.openaire_id, dp.repo_name, sum(rvs.sum) from repo_view_stats_monthly_clean rvs, datasource_results dr, datasource_piwik dp where rvs.id=dr.result and dp.piwik_id=rvs.source and dr.id=dp.openaire_id and dr.id=? group by dp.openaire_id, dp.repo_name " + 
38
            "UNION select 'views', dp.openaire_id, dp.repo_name, sum(rs.sum) from result_stats_monthly_clean rs, datasource_results dr, datasource_piwik dp where rs.id=dr.result and dp.piwik_id='5' and dr.id=? group by dp.openaire_id, dp.repo_name " +
39
            "UNION select 'downloads', dp.openaire_id, dp.repo_name, sum(rds.sum) from repo_download_stats_monthly_clean rds, datasource_results dr, datasource_piwik dp where rds.id=dr.result and dp.openaire_id=dr.id and dp.piwik_id=rds.source and dr.id=? group by dp.openaire_id, dp.repo_name";
40

  
32 41
        List<String> values = new ArrayList<>();
33 42
        values.add(id);
43
        values.add(id);
44
        values.add(id);
34 45

  
35
        return executePreparedQuery2(query, values);
46
        return executePreparedQuery(query, values, "datasource");
36 47
    }
37 48

  
38 49

  
modules/dnet-openaire-usage-stats-api/src/main/java/eu/dnetlib/usagestats/repos/ResultRepo.java
27 27
        //        "where r.id=ro.id and pl.entityid=ro.oid and r.id=? and pl.source!= 5 group by  pl.source " +
28 28
        //        "UNION select '5', maxcount from (select ro.oid, count(*) as maxcount from result r, result_oids ro, usagestats.piwiklog pl " +
29 29
        //        "where r.id=ro.id and pl.entityid=ro.oid and r.id=? and pl.source=5 group by ro.oid order by count(*) DESC limit 1) as temp;";
30

  
31

  
32
        /*
30 33
        String query = "select 'views', rvs.source, sum(number_of_views) from repo_view_stats rvs, result_oids ro where rvs.id=ro.orid " +
31 34
                "and ro.id=? group by rvs.source " +
32 35
                "UNION select 'views', '5', sum(number_of_views) FROM result_stats rs WHERE rs.id=?" +
33 36
                "UNION select 'downloads', rds.source, sum(number_of_downloads) from repo_download_stats rds, result_oids ro where rds.id=ro.orid " +
34 37
                "and ro.id=? group by rds.source";
38
        */
39
        /*
40
        String query = "select 'views', dpo.\"OpenAIRE_ID\", sum(number_of_views) from repo_view_stats rvs, result_oids ro, \"DatasourcesPiwikOAIDs\" dpo where dpo.\"PiwikID\"=rvs.source and rvs.id=ro.orid " +
41
                "and ro.id=? group by dpo.\"OpenAIRE_ID\"" +
42
                "UNION select 'views', '5', sum(number_of_views) FROM result_stats rs WHERE rs.id=?" +
43
                "UNION select 'downloads', dpo.\"OpenAIRE_ID\", sum(number_of_downloads) from repo_download_stats rds, result_oids ro, \"DatasourcesPiwikOAIDs\" dpo where dpo.\"PiwikID\"=rds.source and rds.id=ro.orid " +
44
                "and ro.id=? group by dpo.\"OpenAIRE_ID\"";
45
                */
46
        String query = "select 'views', dp.openaire_id, dp.repo_name, sum(rvs.sum) from repo_view_stats_monthly_clean rvs, datasource_piwik dp where rvs.id=? and dp.piwik_id=rvs.source group by dp.openaire_id, dp.repo_name " +
47
                "UNION select 'views', dp.openaire_id, dp.repo_name, sum(rs.sum) FROM result_stats_monthly_clean rs, datasource_piwik dp WHERE rs.id=? and dp.piwik_id='5' group by dp.openaire_id, dp.repo_name " +
48
                "UNION select 'downloads', dp.openaire_id, dp.repo_name, sum(rds.sum) from repo_download_stats_monthly_clean rds, datasource_piwik dp where rds.id=? and dp.piwik_id=rds.source group by dp.openaire_id, dp.repo_name";
35 49

  
36 50
        List<String> values = new ArrayList<>();
37 51
        values.add(id);
38 52
        values.add(id);
39 53
        values.add(id);
40 54

  
41
        UsageStats results = executePreparedQuery(query, values);
55
        UsageStats results = executePreparedQuery(query, values, "result");
42 56

  
43 57
        return results;
44 58
        //if (!results.isEmpty()) return results.get(0);
modules/dnet-openaire-usage-stats-api/src/main/java/eu/dnetlib/usagestats/repos/BaseRepository.java
64 64
    }*/
65 65

  
66 66

  
67
    protected UsageStats executePreparedQuery(String query, List<String> values) {
67
    protected UsageStats executePreparedQuery(String query, List<String> values, String type) {
68 68
        UsageStats usageStats = new UsageStats();
69 69
        int total_views = 0;
70 70
        int total_downloads = 0;
......
82 82

  
83 83
            ResultSet rs = st.executeQuery();
84 84

  
85
            while (rs.next()) {
86
                if(rs.getString(3) != null && !rs.getString(3).equals("") && !rs.getString(3).equals("null")) {
87
                    if (rs.getString(1).equals("views")) {
88
                        //usageStats.addViews(rs.getString(2) + ":" + rs.getString(3));
89
                        usageStats.addViews(new RepoStats("",rs.getString(2),rs.getString(3)));
90
                        total_views += Integer.parseInt(rs.getString(3));
91
                    } else if (rs.getString(1).equals("downloads")) {
92
                        //usageStats.addDownloads(rs.getString(2) + ":" + rs.getString(3));
93
                        usageStats.addDownloads(new RepoStats("",rs.getString(2),rs.getString(3)));
94
                        total_downloads += Integer.parseInt(rs.getString(3));
85
            if(type.equals("result") || type.equals("datasource")){
86
                while (rs.next()) {
87
                    //if() {
88
                        if (rs.getString(1).equals("views") && rs.getString(4) != null && !rs.getString(4).equals("") && !rs.getString(4).equals("null")) {
89
                            //usageStats.addViews(rs.getString(2) + ":" + rs.getString(3));
90
                            //usageStats.addViews(new RepoStats("",rs.getString(2),rs.getString(3)));
91
                            usageStats.addViews(new RepoStats(rs.getString(3),rs.getString(2),rs.getString(4)));
92
                            total_views += Integer.parseInt(rs.getString(4));
93
                        } else if (rs.getString(1).equals("downloads") && rs.getString(4) != null && !rs.getString(4).equals("") && !rs.getString(4).equals("null")) {
94
                            //usageStats.addDownloads(rs.getString(2) + ":" + rs.getString(3));
95
                            //usageStats.addDownloads(new RepoStats("",rs.getString(2),rs.getString(3)));
96
                            usageStats.addDownloads(new RepoStats(rs.getString(3),rs.getString(2),rs.getString(4)));
97
                            total_downloads += Integer.parseInt(rs.getString(4));
98
                        }
99
                    //}
100
                    //UsageStats stats = new UsageStats();
101
                    //stats.setId(rs.getString(1));
102
                    //stats.setName(rs.getString(2));
103
                    //stats.setOid(rs.getString(3));
104
                    //stats.setSource(rs.getString(1));
105
                    //stats.setValue(rs.getInt(2));
106
                    //statsList.add(stats);
107
                }
108
            
109
                //if (total_views!= 0){
110
                //usageStats.addViews(new RepoStats("Total",Integer.toString(total_views)));
111
                usageStats.setTotal_views(Integer.toString(total_views));
112
                //}
113
                //if (total_downloads!= 0){
114
                //usageStats.addDownloads(new RepoStats("Total",Integer.toString(total_downloads)));
115
                usageStats.setTotal_downloads(Integer.toString(total_downloads));
116
                //}
117
            }
118
            else if(type.equals("project")){
119
                while(rs.next()){
120
                    if (rs.getString(1).equals("views") && rs.getString(2) != null && !rs.getString(2).equals("") && !rs.getString(2).equals("null")) {
121
                        total_views += Integer.parseInt(rs.getString(2));
122
                    } else if (rs.getString(1).equals("downloads") && rs.getString(2) != null && !rs.getString(2).equals("") && !rs.getString(2).equals("null")) {
123
                        total_downloads += Integer.parseInt(rs.getString(2));
95 124
                    }
96 125
                }
97
                //UsageStats stats = new UsageStats();
98
                //stats.setId(rs.getString(1));
99
                //stats.setName(rs.getString(2));
100
                //stats.setOid(rs.getString(3));
101
                //stats.setSource(rs.getString(1));
102
                //stats.setValue(rs.getInt(2));
103
                //statsList.add(stats);
126
                usageStats.setTotal_views(Integer.toString(total_views));
127
                usageStats.setTotal_downloads(Integer.toString(total_downloads));
104 128
            }
105
            //if (total_views!= 0){
106
                //usageStats.addViews(new RepoStats("Total",Integer.toString(total_views)));
107
            usageStats.setTotal_views(Integer.toString(total_views));
108
            //}
109
            //if (total_downloads!= 0){
110
                //usageStats.addDownloads(new RepoStats("Total",Integer.toString(total_downloads)));
111
            usageStats.setTotal_downloads(Integer.toString(total_downloads));
112
            //}
113 129

  
114 130
            rs.close();
115 131
            st.close();
......
175 191
            ResultSet rs;
176 192
            switch (split[0].toLowerCase()) {
177 193
                case "openaire":
178
                    st = connection.prepareStatement("select \"PiwikID\" from \"DatasourcesPiwikOAIDs\" where \"OpenAIRE_ID\"=?");
194
                    st = connection.prepareStatement("select piwik_id from datasource_piwik where openaire_id=?");
195
                    //st = connection.prepareStatement("select piwik_id from datasource where id=?");
179 196
                    st.setString(1, repositoryIdentifier.replaceFirst(split[0] + ":", ""));
180 197

  
181 198
                    rs = st.executeQuery();
......
188 205
                    return piwikid;
189 206

  
190 207
                case "repoid":
191
                    st = connection.prepareStatement("select \"PiwikID\" from \"DatasourcesPiwikOAIDs\" where \"PiwikID\"=?");
208
                    st = connection.prepareStatement("select piwik_id from datasource_piwik where piwik_id=?");
209
                    //st = connection.prepareStatement("select piwik_id from datasource where id=?");
192 210
                    st.setInt(1, Integer.parseInt(repositoryIdentifier.replaceFirst(split[0] + ":", "")));
193 211

  
194 212
                    rs = st.executeQuery();
......
278 296
            PreparedStatement st;
279 297
            if(itemDataType.equals("")) {
280 298
                st = connection.prepareStatement("select r.title, r.publisher, rc.type, r.source, r.id from result r, result_oids roid, result_classifications rc where r.id=roid.id and r.id=rc.id and roid.orid=? limit 1");
299
                //st = connection.prepareStatement("select r.title, r.publisher, rc.type, r.source, r.id, d.name from result r, result_oids roid, result_classifications rc, result_datasources rd, datasource d where rd.id=r.id and rd.datasource=d.id and r.id=roid.id and r.id=rc.id and roid.orid=? limit 1");
281 300
                st.setString(1, oid);
282 301
            }
283 302
            else{
284 303
                st = connection.prepareStatement("select r.title, r.publisher, rc.type, r.source, r.id from result r, result_oids roid, result_classifications rc where r.id=roid.id and r.id=rc.id and roid.orid=? and rc.type=? limit 1");
304
                //st = connection.prepareStatement("select r.title, r.publisher, rc.type, r.source, r.id, d.name from result r, result_oids roid, result_classifications rc, result_datasources rd, datasource d where rd.id=r.id and rd.datasource=d.id and r.id=roid.id and r.id=rc.id and roid.orid=? and rc.type=? limit 1");
285 305
                st.setString(1, oid);
286 306
                st.setString(2, itemDataType);
287 307
            }
......
291 311
            boolean hasData = false;
292 312
            while (rs.next()) {
293 313
                reportItem = new ReportItem(rs.getString(2),"", rs.getString(3),rs.getString(1));
314
                //reportItem = new ReportItem(rs.getString(2),rs.getString(6), rs.getString(3),rs.getString(1));
294 315
                reportItem.addIdentifier(new ItemIdentifier("URL",rs.getString(4)));
295 316
                reportItem.addIdentifier(new ItemIdentifier("OAI",oid));
296 317
                reportItem.addIdentifier(new ItemIdentifier("OPENAIRE",rs.getString(5)));
......
338 359

  
339 360
                //st = connection.prepareStatement("select extract('year' from date) ||'-'|| extract('month' from date) ||'-01' as new_date, sum(number_of_downloads) from repo_download_stats where id=? and date>=? and date<=? group by new_date order by new_date");
340 361
                if(repositoryIdentifier.equals("")) {
341
                    //st = connection.prepareStatement("select month, sum from repo_download_stats_monthly where id=? and month>=? and month<=? order by month;");
342
                    st = connection.prepareStatement("select d.date, case when sum is null then 0 else sum end as sum from (SELECT to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS date FROM generate_series(0, ?, 1) AS offs) d LEFT JOIN (select month, sum from repo_download_stats_monthly where id=? and month>=? and month<=?) rdsm ON d.date=rdsm.month;");
362
                    //st = connection.prepareStatement("select month, sum from repo_download_stats_monthly_sushi where id=? and month>=? and month<=? order by month;");
363
                    st = connection.prepareStatement("select d.date, case when sum is null then 0 else sum end as sum from (SELECT to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS date FROM generate_series(0, ?, 1) AS offs) d LEFT JOIN (select month, sum from repo_download_stats_monthly_sushi where id=? and month>=? and month<=?) rdsm ON d.date=rdsm.month;");
343 364
                }
344 365
                else{
345
                    //st = connection.prepareStatement("select month, sum from repo_download_stats_monthly where id=? and month>=? and month<=? and source=? order by month;");
346
                    st = connection.prepareStatement("select d.date, case when sum is null then 0 else sum end as sum from (SELECT to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS date FROM generate_series(0, ?, 1) AS offs) d LEFT JOIN (select month, sum from repo_download_stats_monthly where id=? and month>=? and month<=? and source=?) rdsm ON d.date=rdsm.month;");
366
                    //st = connection.prepareStatement("select month, sum from repo_download_stats_monthly_sushi where id=? and month>=? and month<=? and source=? order by month;");
367
                    st = connection.prepareStatement("select d.date, case when sum is null then 0 else sum end as sum from (SELECT to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS date FROM generate_series(0, ?, 1) AS offs) d LEFT JOIN (select month, sum from repo_download_stats_monthly_sushi where id=? and month>=? and month<=? and source=?) rdsm ON d.date=rdsm.month;");
347 368
                    st.setInt(6, Integer.parseInt(repositoryIdentifier));
348 369
                }
349 370
                st.setString(1, report_dateFormat.format(beginDate));
......
384 405
        }
385 406
        return 0;
386 407
    }
387
    protected int executeOidOLD(List<ReportItem> reportItems, String oid, String repositoryIdentifier, String itemDataType, Date beginDate, Date endDate, String granularity){
388
        ReportItem reportItem = null;
389
        SimpleDateFormat report_dateFormat = new SimpleDateFormat("yyyy-MM-dd");
390
        Boolean hasReports = false;
391 408

  
392
        try {
393
            Connection connection = dataSource.getConnection();
394
            PreparedStatement st;
395
            if(itemDataType.equals("")) {
396
                st = connection.prepareStatement("select r.title, r.publisher, rc.type, r.source, r.id from result r, result_oids roid, result_classifications rc where r.id=roid.id and r.id=rc.id and roid.orid=? limit 1");
397
                st.setString(1, oid);
398
            }
399
            else{
400
                st = connection.prepareStatement("select r.title, r.publisher, rc.type, r.source, r.id from result r, result_oids roid, result_classifications rc where r.id=roid.id and r.id=rc.id and roid.orid=? and rc.type=? limit 1");
401
                st.setString(1, oid);
402
                st.setString(2, itemDataType);
403
            }
404

  
405
            ResultSet rs = st.executeQuery();
406

  
407
            boolean hasData = false;
408
            while (rs.next()) {
409
                reportItem = new ReportItem(rs.getString(2),"", rs.getString(3),rs.getString(1));
410
                reportItem.addIdentifier(new ItemIdentifier("URL",rs.getString(4)));
411
                reportItem.addIdentifier(new ItemIdentifier("OAI",oid));
412
                reportItem.addIdentifier(new ItemIdentifier("OPENAIRE",rs.getString(5)));
413
                hasData = true;
414
            }
415
            rs.close();
416
            st.close();
417
            if(!hasData){
418
                connection.close();
419
                return -1;
420
            }
421
            //log.error(report_dateFormat.format(c.getTime()));
422
            if (granularity.toLowerCase().equals("totals")){
423
                if(repositoryIdentifier.equals("")) {
424
                    st = connection.prepareStatement("select sum(number_of_downloads) from repo_download_stats where id=? and date>=? and date<=?");
425
                }
426
                else{
427
                    st = connection.prepareStatement("select sum(number_of_downloads) from repo_download_stats where id=? and date>=? and date<=? and source=?");
428
                    st.setInt(4, Integer.parseInt(repositoryIdentifier));
429
                }
430
                st.setString(1, oid);
431
                //st.setString(2, sql_dateFormat.format(in_beginDate));
432
                //st.setString(3, sql_dateFormat.format(in_endDate));
433
                st.setDate(2, new java.sql.Date(beginDate.getTime()));
434
                st.setDate(3, new java.sql.Date(endDate.getTime()));
435
                //log.error(new SimpleDateFormat("yyyy-MM-dd").format(input_dateFormat.parse(beginDate)));
436

  
437
                log.error("qqqq: " + st);
438

  
439
                rs = st.executeQuery();
440
                while(rs.next()){
441
                    reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate), rs.getString(1)));
442
                    hasReports = true;
443
                }
444
                rs.close();
445
                st.close();
446
            }
447
            else if (granularity.toLowerCase().equals("monthly")){
448
                //st = connection.prepareStatement("select extract('year' from date) ||'-'|| extract('month' from date) ||'-01' as new_date, sum(number_of_downloads) from repo_download_stats where id=? and date>=? and date<=? group by new_date order by new_date");
449
                if(repositoryIdentifier.equals("")) {
450
                    st = connection.prepareStatement("select month, sum from repo_download_stats_monthly where id=? and month>=? and month<=? order by month;");
451
                }
452
                else{
453
                    st = connection.prepareStatement("select month, sum from repo_download_stats_monthly where id=? and month>=? and month<=? and source=? order by month;");
454
                    st.setInt(4, Integer.parseInt(repositoryIdentifier));
455
                }
456
                st.setString(1, oid);
457
                //st.setString(2, sql_dateFormat.format(in_beginDate));
458
                //st.setString(3, sql_dateFormat.format(in_endDate));
459
                //st.setDate(2, new java.sql.Date(beginDate.getTime()));
460
                //st.setDate(3, new java.sql.Date(endDate.getTime()));
461
                st.setString(2, new SimpleDateFormat("yyyy-MM-dd").format(beginDate));
462
                st.setString(3, new SimpleDateFormat("yyyy-MM-dd").format(endDate));
463

  
464
                log.error("qqqq: " + st);
465

  
466
                Calendar start = Calendar.getInstance();
467
                start.setTime(beginDate);
468
                Calendar end = Calendar.getInstance();
469
                end.setTime(endDate);
470
                Date date = start.getTime();
471

  
472
                rs = st.executeQuery();
473

  
474
                while(rs.next()){
475
                    hasReports = true;
476
                    Date rs_date = rs.getDate(1);
477
                    while(date.before(rs_date) && !date.equals(rs_date)){
478
                        Calendar temp_c = Calendar.getInstance();
479
                        temp_c.setTime(date);
480
                        temp_c.set(Calendar.DAY_OF_MONTH, temp_c.getActualMaximum(Calendar.DAY_OF_MONTH));
481
                        Date temp_endDate = temp_c.getTime();
482
                        reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(date), report_dateFormat.format(temp_endDate),"0"));
483
                        start.add(Calendar.MONTH, 1);
484
                        date = start.getTime();
485
                    }
486
                    Calendar temp_c = Calendar.getInstance();
487
                    temp_c.setTime(rs_date);
488
                    temp_c.set(Calendar.DAY_OF_MONTH, temp_c.getActualMaximum(Calendar.DAY_OF_MONTH));
489
                    Date temp_endDate = temp_c.getTime();
490
                    reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(rs_date), report_dateFormat.format(temp_endDate), rs.getString(2)));
491
                    start.add(Calendar.MONTH, 1);
492
                    date = start.getTime();
493
                }
494
                rs.close();
495
                st.close();
496

  
497
                for (; start.before(end); start.add(Calendar.MONTH, 1), date = start.getTime()) {
498
                    Calendar temp_c = Calendar.getInstance();
499
                    temp_c.setTime(date);
500
                    temp_c.set(Calendar.DAY_OF_MONTH, temp_c.getActualMaximum(Calendar.DAY_OF_MONTH));
501
                    Date temp_endDate = temp_c.getTime();
502
                    reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(date), report_dateFormat.format(temp_endDate),"0"));
503
                    //log.error("DATE: " + date + " TO: " + temp_endDate);
504

  
505
                }
506
            }
507

  
508
            connection.close();
509
        } catch (Exception e) {
510
            log.error("Cannot execute oid : " + e);
511
        }
512
        if(hasReports) {
513
            reportItems.add(reportItem);
514
        }
515
        return 0;
516
    }
517

  
518 409
    protected int executeRepo(List<ReportItem> reportItems, String repositoryIdentifier, String itemDataType, Date beginDate, Date endDate, String granularity){
519 410
        SimpleDateFormat report_dateFormat = new SimpleDateFormat("yyyy-MM-dd");
520 411
        try {
......
524 415
            if (granularity.toLowerCase().equals("totals")) {
525 416
               if(repositoryIdentifier.equals("")){
526 417
                   if(itemDataType.equals("")){
527
                       st = connection.prepareStatement("select source, d.id, d.name, d.websiteurl, sum(number_of_downloads) from repo_download_stats rds, \"DatasourcesPiwikOAIDs\" dpo, datasource d  where rds.source=dpo.\"PiwikID\" and dpo.\"OpenAIRE_ID\"=d.id and rds.date>=? and rds.date<=? group by source, d.id, d.name, d.websiteurl order by source;");
418
                       st = connection.prepareStatement("select source, d.id, d.name, d.websiteurl, sum(number_of_downloads) from repo_download_stats rds, datasource_piwik dpo, datasource d  where rds.source=dpo.piwik_id and dpo.openaire_id=d.id and rds.date>=? and rds.date<=? group by source, d.id, d.name, d.websiteurl order by source;");
419
                       //st = connection.prepareStatement("select source, d.id, d.name, d.websiteurl, sum(number_of_downloads) from repo_download_stats rds, datasource d  where rds.source=d.piwik_id and rds.date>=? and rds.date<=? group by source, d.id, d.name, d.websiteurl order by source;");
528 420
                       st.setDate(1, new java.sql.Date(beginDate.getTime()));
529 421
                       st.setDate(2, new java.sql.Date(endDate.getTime()));
530 422
                   }
531 423
                   else{
532
                       st = connection.prepareStatement("select source, d.id, d.name, d.websiteurl, sum(number_of_downloads) from repo_download_stats rds, \"DatasourcesPiwikOAIDs\" dpo, datasource d, result_oids roid, result_classifications rc where roid.orid=rds.id and roid.id=rc.id and rds.source=dpo.\"PiwikID\" and dpo.\"OpenAIRE_ID\"=d.id and rds.date>=? and rds.date<=? and rc.type=? group by source, d.id, d.name, d.websiteurl order by source;");
424
                       st = connection.prepareStatement("select source, d.id, d.name, d.websiteurl, sum(number_of_downloads) from repo_download_stats rds, datsource_piwik dpo, datasource d, result_oids roid, result_classifications rc where roid.orid=rds.id and roid.id=rc.id and rds.source=dpo.piwik_id and dpo.openaire_id=d.id and rds.date>=? and rds.date<=? and rc.type=? group by source, d.id, d.name, d.websiteurl order by source;");
425
                       //st = connection.prepareStatement("select source, d.id, d.name, d.websiteurl, sum(number_of_downloads) from repo_download_stats rds, datasource d, result_oids roid, result_classifications rc where roid.orid=rds.id and roid.id=rc.id and rds.source=d.piwik_id and rds.date>=? and rds.date<=? and rc.type=? group by source, d.id, d.name, d.websiteurl order by source;");
533 426
                       st.setDate(1, new java.sql.Date(beginDate.getTime()));
534 427
                       st.setDate(2, new java.sql.Date(endDate.getTime()));
535 428
                       st.setString(3, itemDataType);
536 429
                   }
537 430
               } else {
538 431
                   if(itemDataType.equals("")){
539
                       st = connection.prepareStatement("select source, d.id, d.name, d.websiteurl, sum(number_of_downloads) from repo_download_stats rds, \"DatasourcesPiwikOAIDs\" dpo, datasource d  where rds.source=dpo.\"PiwikID\" and dpo.\"OpenAIRE_ID\"=d.id and rds.date>=? and rds.date<=? and rds.source=? group by rds.source, d.id, d.name, d.websiteurl;");
432
                       st = connection.prepareStatement("select source, d.id, d.name, d.websiteurl, sum(number_of_downloads) from repo_download_stats rds, datasource_piwik dpo, datasource d  where rds.source=dpo.piwik_id and dpo.openaire_id=d.id and rds.date>=? and rds.date<=? and rds.source=? group by rds.source, d.id, d.name, d.websiteurl;");
433
                       //st = connection.prepareStatement("select source, d.id, d.name, d.websiteurl, sum(number_of_downloads) from repo_download_stats rds, datasource d  where rds.source=d.piwik_id and rds.date>=? and rds.date<=? and rds.source=? group by rds.source, d.id, d.name, d.websiteurl;");
540 434
                       st.setDate(1, new java.sql.Date(beginDate.getTime()));
541 435
                       st.setDate(2, new java.sql.Date(endDate.getTime()));
542 436
                       st.setInt(3, Integer.parseInt(repositoryIdentifier));
543 437
                   }
544 438
                   else{
545
                       st = connection.prepareStatement("select source, d.id, d.name, d.websiteurl, sum(number_of_downloads) from repo_download_stats rds, \"DatasourcesPiwikOAIDs\" dpo, datasource d, result_oids roid, result_classifications rc where roid.orid=rds.id and roid.id=rc.id and rds.source=dpo.\"PiwikID\" and dpo.\"OpenAIRE_ID\"=d.id and rds.date>=? and rds.date<=? and rc.type=? and rds.source=? group by source, d.id, d.name, d.websiteurl;");
439
                       st = connection.prepareStatement("select source, d.id, d.name, d.websiteurl, sum(number_of_downloads) from repo_download_stats rds, datasource_piwik dpo, datasource d, result_oids roid, result_classifications rc where roid.orid=rds.id and roid.id=rc.id and rds.source=dpo.piwik_id and dpo.openaire_id=d.id and rds.date>=? and rds.date<=? and rc.type=? and rds.source=? group by source, d.id, d.name, d.websiteurl;");
440
                       //st = connection.prepareStatement("select source, d.id, d.name, d.websiteurl, sum(number_of_downloads) from repo_download_stats rds, datasource d, result_oids roid, result_classifications rc where roid.orid=rds.id and roid.id=rc.id and rds.source=d.piwik_id and rds.date>=? and rds.date<=? and rc.type=? and rds.source=? group by source, d.id, d.name, d.websiteurl;");
546 441
                       st.setDate(1, new java.sql.Date(beginDate.getTime()));
547 442
                       st.setDate(2, new java.sql.Date(endDate.getTime()));
548 443
                       st.setString(3, itemDataType);
......
573 468

  
574 469
                if(repositoryIdentifier.equals("")){
575 470
                    if(itemDataType.equals("")){
576
                        st = connection.prepareStatement("select dd.piwikid, dd.id, dd.name, dd.websiteurl, dd.new_date, case when rdm.tsum is null then 0 else rdm.tsum end FROM (select d.id, d.name, dpo.\"PiwikID\" AS piwikid, d.websiteurl, to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS new_date FROM \"DatasourcesPiwikOAIDs\" dpo, datasource d, generate_series(0, ?, 1) AS offs where dpo.\"OpenAIRE_ID\"=d.id order by d.id, new_date) dd LEFT JOIN (SELECT source, month, SUM(sum) as tsum FROM repo_download_stats_monthly where month>=? and month<=? group by source, month) rdm ON dd.new_date=rdm.month and rdm.source=dd.piwikid order by dd.piwikid, dd.new_date;");
471
                        st = connection.prepareStatement("select dd.piwikid, dd.id, dd.name, dd.websiteurl, dd.new_date, case when rdm.tsum is null then 0 else rdm.tsum end FROM (select d.id, d.name, dpo.piwik_id AS piwikid, d.websiteurl, to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS new_date FROM datasource_piwik dpo, datasource d, generate_series(0, ?, 1) AS offs where dpo.openaire_id=d.id order by d.id, new_date) dd LEFT JOIN (SELECT source, month, SUM(sum) as tsum FROM repo_download_stats_monthly_sushi where month>=? and month<=? group by source, month) rdm ON dd.new_date=rdm.month and rdm.source=dd.piwikid order by dd.piwikid, dd.new_date;");
472
                        //st = connection.prepareStatement("select dd.piwik_id, dd.id, dd.name, dd.websiteurl, dd.new_date, case when rdm.tsum is null then 0 else rdm.tsum end FROM (select d.id, d.name, d.piwik_id, d.websiteurl, to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS new_date FROM datasource d, generate_series(0, ?, 1) AS offs where d.piwik_id is not null order by d.id, new_date) dd LEFT JOIN (SELECT source, month, SUM(sum) as tsum FROM repo_download_stats_monthly_sushi where month>=? and month<=? group by source, month) rdm ON dd.new_date=rdm.month and rdm.source=dd.piwik_id order by dd.piwik_id, dd.new_date;");
577 473
                        st.setString(1, report_dateFormat.format(beginDate));
578 474
                        st.setInt(2, diffMonth);
579 475
                        st.setDate(3, new java.sql.Date(beginDate.getTime()));
580 476
                        st.setDate(4, new java.sql.Date(endDate.getTime()));
581 477
                    }
582 478
                    else{
583
                        st = connection.prepareStatement("select dd.piwikid, dd.id, dd.name, dd.websiteurl, dd.new_date, case when rdm.tsum is null then 0 else rdm.tsum end FROM (select d.id, d.name, dpo.\"PiwikID\" AS piwikid, d.websiteurl, to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS new_date FROM \"DatasourcesPiwikOAIDs\" dpo, datasource d, generate_series(0, ?, 1) AS offs where dpo.\"OpenAIRE_ID\"=d.id order by d.id, new_date) dd LEFT JOIN (SELECT rds.source, rds.month, SUM(rds.sum) as tsum FROM repo_download_stats_monthly rds, result_oids roid, result_classifications rc where rds.id=roid.orid and roid.id=rc.id and rc.type=? and rds.month>=? and rds.month<=? group by rds.source, rds.month) rdm ON dd.new_date=rdm.month and rdm.source=dd.piwikid order by dd.piwikid, dd.new_date;");
479
                        st = connection.prepareStatement("select dd.piwikid, dd.id, dd.name, dd.websiteurl, dd.new_date, case when rdm.tsum is null then 0 else rdm.tsum end FROM (select d.id, d.name, dpo.piwik_id AS piwikid, d.websiteurl, to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS new_date FROM datasource_piwik dpo, datasource d, generate_series(0, ?, 1) AS offs where dpo.openaire_id=d.id order by d.id, new_date) dd LEFT JOIN (SELECT rds.source, rds.month, SUM(rds.sum) as tsum FROM repo_download_stats_monthly_sushi rds, result_oids roid, result_classifications rc where rds.id=roid.orid and roid.id=rc.id and rc.type=? and rds.month>=? and rds.month<=? group by rds.source, rds.month) rdm ON dd.new_date=rdm.month and rdm.source=dd.piwikid order by dd.piwikid, dd.new_date;");
480
                        //st = connection.prepareStatement("select dd.piwik_id, dd.id, dd.name, dd.websiteurl, dd.new_date, case when rdm.tsum is null then 0 else rdm.tsum end FROM (select d.id, d.name, d.piwik_id, d.websiteurl, to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS new_date FROM datasource d, generate_series(0, ?, 1) AS offs where d.piwik_id is not null order by d.id, new_date) dd LEFT JOIN (SELECT rds.source, rds.month, SUM(rds.sum) as tsum FROM repo_download_stats_monthly_sushi rds, result_oids roid, result_classifications rc where rds.id=roid.orid and roid.id=rc.id and rc.type=? and rds.month>=? and rds.month<=? group by rds.source, rds.month) rdm ON dd.new_date=rdm.month and rdm.source=dd.piwik_id order by dd.piwik_id, dd.new_date;");
584 481
                        st.setString(1, report_dateFormat.format(beginDate));
585 482
                        st.setInt(2, diffMonth);
586 483
                        st.setString(3, itemDataType);
......
589 486
                    }
590 487
                } else {
591 488
                    if(itemDataType.equals("")){
592
                        st = connection.prepareStatement("select dd.piwikid, dd.id, dd.name, dd.websiteurl, dd.new_date, case when rdm.tsum is null then 0 else rdm.tsum end FROM (select d.id, d.name, dpo.\"PiwikID\" AS piwikid, d.websiteurl, to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS new_date FROM \"DatasourcesPiwikOAIDs\" dpo, datasource d, generate_series(0, ?, 1) AS offs where dpo.\"OpenAIRE_ID\"=d.id and dpo.\"PiwikID\"=? order by d.id, new_date) dd LEFT JOIN (SELECT source, month, SUM(sum) as tsum FROM repo_download_stats_monthly where source=? and month>=? and month<=? group by source, month) rdm ON dd.new_date=rdm.month and rdm.source=dd.piwikid order by dd.piwikid, dd.new_date;");
489
                        st = connection.prepareStatement("select dd.piwikid, dd.id, dd.name, dd.websiteurl, dd.new_date, case when rdm.tsum is null then 0 else rdm.tsum end FROM (select d.id, d.name, dpo.piwik_id AS piwikid, d.websiteurl, to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS new_date FROM datasource_piwik dpo, datasource d, generate_series(0, ?, 1) AS offs where dpo.openaire_id=d.id and dpo.piwik_id=? order by d.id, new_date) dd LEFT JOIN (SELECT source, month, SUM(sum) as tsum FROM repo_download_stats_monthly_sushi where source=? and month>=? and month<=? group by source, month) rdm ON dd.new_date=rdm.month and rdm.source=dd.piwikid order by dd.piwikid, dd.new_date;");
490
                        //st = connection.prepareStatement("select dd.piwik_id, dd.id, dd.name, dd.websiteurl, dd.new_date, case when rdm.tsum is null then 0 else rdm.tsum end FROM (select d.id, d.name, d.piwik_id, d.websiteurl, to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS new_date FROM datasource d, generate_series(0, ?, 1) AS offs where d.piwik_id=? order by d.id, new_date) dd LEFT JOIN (SELECT source, month, SUM(sum) as tsum FROM repo_download_stats_monthly_sushi where source=? and month>=? and month<=? group by source, month) rdm ON dd.new_date=rdm.month and rdm.source=dd.piwik_id order by dd.piwik_id, dd.new_date;");
593 491
                        st.setString(1, report_dateFormat.format(beginDate));
594 492
                        st.setInt(2, diffMonth);
595 493
                        st.setInt(3, Integer.parseInt(repositoryIdentifier));
......
598 496
                        st.setDate(6, new java.sql.Date(endDate.getTime()));
599 497
                    }
600 498
                    else{
601
                        st = connection.prepareStatement("select dd.piwikid, dd.id, dd.name, dd.websiteurl, dd.new_date, case when rdm.tsum is null then 0 else rdm.tsum end FROM (select d.id, d.name, dpo.\"PiwikID\" AS piwikid, d.websiteurl, to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS new_date FROM \"DatasourcesPiwikOAIDs\" dpo, datasource d, generate_series(0, ?, 1) AS offs where dpo.\"OpenAIRE_ID\"=d.id and dpo.\"PiwikID\"=? order by d.id, new_date) dd LEFT JOIN (SELECT rds.source, rds.month, SUM(rds.sum) as tsum FROM repo_download_stats_monthly rds, result_oids roid, result_classifications rc where rds.id=roid.orid and roid.id=rc.id and rc.type=? and rds.source=? and rds.month>=? and rds.month<=? group by source, month) rdm ON dd.new_date=rdm.month and rdm.source=dd.piwikid order by dd.piwikid, dd.new_date;");
499
                        st = connection.prepareStatement("select dd.piwikid, dd.id, dd.name, dd.websiteurl, dd.new_date, case when rdm.tsum is null then 0 else rdm.tsum end FROM (select d.id, d.name, dpo.piwik_id AS piwikid, d.websiteurl, to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS new_date FROM datasource_piwik dpo, datasource d, generate_series(0, ?, 1) AS offs where dpo.openaire_id=d.id and dpo.piwik_id=? order by d.id, new_date) dd LEFT JOIN (SELECT rds.source, rds.month, SUM(rds.sum) as tsum FROM repo_download_stats_monthly_sushi rds, result_oids roid, result_classifications rc where rds.id=roid.orid and roid.id=rc.id and rc.type=? and rds.source=? and rds.month>=? and rds.month<=? group by source, month) rdm ON dd.new_date=rdm.month and rdm.source=dd.piwikid order by dd.piwikid, dd.new_date;");
500
                        //st = connection.prepareStatement("select dd.piwik_id, dd.id, dd.name, dd.websiteurl, dd.new_date, case when rdm.tsum is null then 0 else rdm.tsum end FROM (select d.id, d.name, d.piwik_id, d.websiteurl, to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS new_date FROM datasource d, generate_series(0, ?, 1) AS offs where dpo.piwik_id=? order by d.id, new_date) dd LEFT JOIN (SELECT rds.source, rds.month, SUM(rds.sum) as tsum FROM repo_download_stats_monthly_sushi rds, result_oids roid, result_classifications rc where rds.id=roid.orid and roid.id=rc.id and rc.type=? and rds.source=? and rds.month>=? and rds.month<=? group by source, month) rdm ON dd.new_date=rdm.month and rdm.source=dd.piwik_id order by dd.piwik_id, dd.new_date;");
602 501
                        st.setString(1, report_dateFormat.format(beginDate));
603 502
                        st.setInt(2, diffMonth);
604 503
                        st.setInt(3, Integer.parseInt(repositoryIdentifier));
......
653 552
            if(granularity.toLowerCase().equals("totals")){
654 553
                if(itemDataType.equals("")) {
655 554
                    st = connection.prepareStatement("select rds.id, r.title, r.publisher, rc.type, r.source, r.id, sum(rds.number_of_downloads) from repo_download_stats rds, result r, result_oids roid, result_classifications rc where r.id=roid.id and r.id=rc.id and roid.orid=rds.id and rds.source=? and rds.date>=? and rds.date<=? group by rds.id, r.title, r.publisher, rc.type, r.source, r.id;");
555
                    //st = connection.prepareStatement("select rds.id, r.title, r.publisher, rc.type, r.source, d.name r.id, sum(rds.number_of_downloads) from repo_download_stats rds, result r, result_oids roid, result_classifications rc, result_datasources rd, datasource d where rd.id=r.id and rd.datasource=d.id and r.id=roid.id and r.id=rc.id and roid.orid=rds.id and rds.source=? and rds.date>=? and rds.date<=? group by rds.id, r.title, r.publisher, rc.type, r.source, d.name, r.id;");
656 556
                    st.setInt(1, Integer.parseInt(repositoryIdentifier));
657 557
                    st.setDate(2, new java.sql.Date(beginDate.getTime()));
658 558
                    st.setDate(3, new java.sql.Date(endDate.getTime()));
659 559
                }
660 560
                else{
661 561
                    st = connection.prepareStatement("select rds.id, r.title, r.publisher, rc.type, r.source, r.id, sum(rds.number_of_downloads) from repo_download_stats rds, result r, result_oids roid, result_classifications rc where r.id=roid.id and r.id=rc.id and roid.orid=rds.id and rds.source=? and rds.date>=? and rds.date<=? and rc.type=? group by rds.id, r.title, r.publisher, rc.type, r.source, r.id;");
562
                    //st = connection.prepareStatement("select rds.id, r.title, r.publisher, rc.type, r.source, d.name, r.id, sum(rds.number_of_downloads) from repo_download_stats rds, result r, result_oids roid, result_classifications rc, result_datasources rd, datasource d where rd.id=r.id and rd.datasource=d.id and r.id=roid.id and r.id=rc.id and roid.orid=rds.id and rds.source=? and rds.date>=? and rds.date<=? and rc.type=? group by rds.id, r.title, r.publisher, rc.type, r.source, d.name, r.id;");
662 563
                    st.setInt(1, Integer.parseInt(repositoryIdentifier));
663 564
                    st.setDate(2, new java.sql.Date(beginDate.getTime()));
664 565
                    st.setDate(3, new java.sql.Date(endDate.getTime()));
......
668 569

  
669 570
                while (rs.next()) {
670 571
                    ReportItem reportItem = new ReportItem(rs.getString(3), "", rs.getString(4), rs.getString(2));
572
                    //ReportItem reportItem = new ReportItem(rs.getString(3), rs.getString(6), rs.getString(4), rs.getString(2));
671 573
                    reportItem.addIdentifier(new ItemIdentifier("URL",rs.getString(5)));
672 574
                    reportItem.addIdentifier(new ItemIdentifier("OAI",rs.getString(1)));
673 575
                    reportItem.addIdentifier(new ItemIdentifier("OPENAIRE",rs.getString(6)));
576
                    //reportItem.addIdentifier(new ItemIdentifier("OPENAIRE",rs.getString(7)));
674 577
                    reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate), rs.getString(7)));
578
                    //reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate), rs.getString(8)));
675 579
                    reportItems.add(reportItem);
676 580
                }
677 581
                rs.close();
......
685 589
                int diffMonth = diffYear * 12 + endCalendar.get(Calendar.MONTH) - startCalendar.get(Calendar.MONTH);
686 590

  
687 591
                if(itemDataType.equals("")){
688
                    st = connection.prepareStatement("select d.orid, d.title, d.publisher, d.rctype, d.rsource, d.rid, d.new_date, case when rdm.sum is null then 0 else rdm.sum end from (select distinct roid.orid, r.title, r.publisher, rc.type as rctype, r.source as rsource, r.id as rid, to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS new_date from generate_series(0, ?, 1) AS offs, repo_download_stats_monthly rdsm, result r, result_oids roid, result_classifications rc where r.id=roid.id and r.id=rc.id and roid.orid=rdsm.id and rdsm.source=? and rdsm.month>=? and rdsm.month<=?) d LEFT JOIN (select id, month, sum from repo_download_stats_monthly where source=?) rdm ON d.new_date=rdm.month and d.orid=rdm.id order by d.orid, d.new_date;");
592
                    st = connection.prepareStatement("select d.orid, d.title, d.publisher, d.rctype, d.rsource, d.rid, d.new_date, case when rdm.sum is null then 0 else rdm.sum end from (select distinct roid.orid, r.title, r.publisher, rc.type as rctype, r.source as rsource, r.id as rid, to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS new_date from generate_series(0, ?, 1) AS offs, repo_download_stats_monthly_sushi rdsm, result r, result_oids roid, result_classifications rc where r.id=roid.id and r.id=rc.id and roid.orid=rdsm.id and rdsm.source=? and rdsm.month>=? and rdsm.month<=?) d LEFT JOIN (select id, month, sum from repo_download_stats_monthly_sushi where source=?) rdm ON d.new_date=rdm.month and d.orid=rdm.id order by d.orid, d.new_date;");
593
                    //st = connection.prepareStatement("select d.orid, d.title, d.publisher, d.rctype, d.rsource, d.name, d.rid, d.new_date, case when rdm.sum is null then 0 else rdm.sum end from (select distinct roid.orid, r.title, r.publisher, rc.type as rctype, r.source as rsource, d.name, r.id as rid, to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS new_date from generate_series(0, ?, 1) AS offs, result r, result_oids roid, result_classifications rc, result_datasources rd, datasource ds where rd.id=r.id and rd.datasource=ds.id and r.id=roid.id and r.id=rc.id ds.piwik_id=?) d LEFT JOIN (select id, month, sum from repo_download_stats_monthly_sushi where source=?) rdm ON d.new_date=rdm.month and d.orid=rdm.id order by d.orid, d.new_date;");
689 594
                    st.setString(1, report_dateFormat.format(beginDate));
690 595
                    st.setInt(2, diffMonth);
691 596
                    st.setInt(3, Integer.parseInt(repositoryIdentifier));
......
693 598
                    st.setDate(5, new java.sql.Date(endDate.getTime()));
694 599
                    st.setInt(6, Integer.parseInt(repositoryIdentifier));
695 600
                } else{
696
                    st = connection.prepareStatement("select d.orid, d.title, d.publisher, d.rctype, d.rsource, d.rid, d.new_date, case when rdm.sum is null then 0 else rdm.sum end from (select distinct roid.orid, r.title, r.publisher, rc.type as rctype, r.source as rsource, r.id as rid, to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS new_date from generate_series(0, ?, 1) AS offs, repo_download_stats_monthly rdsm, result r, result_oids roid, result_classifications rc where r.id=roid.id and r.id=rc.id and roid.orid=rdsm.id and rdsm.source=? and rc.type=? and rdsm.month>=? and rdsm.month<=?) d LEFT JOIN (select id, month, sum from repo_download_stats_monthly where source=?) rdm ON d.new_date=rdm.month and d.orid=rdm.id order by d.orid, d.new_date;");
601
                    st = connection.prepareStatement("select d.orid, d.title, d.publisher, d.rctype, d.rsource, d.rid, d.new_date, case when rdm.sum is null then 0 else rdm.sum end from (select distinct roid.orid, r.title, r.publisher, rc.type as rctype, r.source as rsource, r.id as rid, to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS new_date from generate_series(0, ?, 1) AS offs, repo_download_stats_monthly_sushi rdsm, result r, result_oids roid, result_classifications rc where r.id=roid.id and r.id=rc.id and roid.orid=rdsm.id and rdsm.source=? and rc.type=? and rdsm.month>=? and rdsm.month<=?) d LEFT JOIN (select id, month, sum from repo_download_stats_monthly_sushi where source=?) rdm ON d.new_date=rdm.month and d.orid=rdm.id order by d.orid, d.new_date;");
602
                    //st = connection.prepareStatement("select d.orid, d.title, d.publisher, d.rctype, d.rsource, d.name, d.rid, d.new_date, case when rdm.sum is null then 0 else rdm.sum end from (select distinct roid.orid, r.title, r.publisher, rc.type as rctype, r.source as rsource, d.name, r.id as rid, to_char(date_trunc('month', (?::date + interval '1 month'*offs)), 'YYYY-MM-DD') AS new_date from generate_series(0, ?, 1) AS offs, result r, result_oids roid, result_classifications rc, result_datasources rd, datasource ds where rd.id=r.id and rd.datasource=ds.id and r.id=roid.id and r.id=rc.id ds.piwik_id=? and rc.type=?) d LEFT JOIN (select id, month, sum from repo_download_stats_monthly_sushi where source=?) rdm ON d.new_date=rdm.month and d.orid=rdm.id order by d.orid, d.new_date;");
697 603
                    st.setString(1, report_dateFormat.format(beginDate));
698 604
                    st.setInt(2, diffMonth);
699 605
                    st.setInt(3, Integer.parseInt(repositoryIdentifier));
......
706 612

  
707 613
                while (rs.next()) {
708 614
                    ReportItem reportItem = new ReportItem(rs.getString(3), "", rs.getString(4), rs.getString(2));
615
                    //ReportItem reportItem = new ReportItem(rs.getString(3), rs.getString(6), rs.getString(4), rs.getString(2));
709 616
                    reportItem.addIdentifier(new ItemIdentifier("URL",rs.getString(5)));
710 617
                    reportItem.addIdentifier(new ItemIdentifier("OAI",rs.getString(1)));
711 618
                    reportItem.addIdentifier(new ItemIdentifier("OPENAIRE",rs.getString(6)));
619
                    //reportItem.addIdentifier(new ItemIdentifier("OPENAIRE",rs.getString(7)));
712 620
                    for(int i = 0; i <= diffMonth; i++) {
713 621
                        Calendar temp_c = Calendar.getInstance();
714 622
                        temp_c.setTime(rs.getDate(7));
715 623
                        temp_c.set(Calendar.DAY_OF_MONTH, temp_c.getActualMaximum(Calendar.DAY_OF_MONTH));
716 624
                        Date temp_endDate = temp_c.getTime();
717 625
                        reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(rs.getDate(7)), report_dateFormat.format(temp_endDate), rs.getString(8)));
626
                        //reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(rs.getDate(8)), report_dateFormat.format(temp_endDate), rs.getString(9)));
718 627
                        if(i != diffMonth) {
719 628
                            rs.next();
720 629
                        }
......
730 639
        }
731 640
        return 0;
732 641
    }
733

  
734
    protected int executeRepoOLD(List<ReportItem> reportItems, String repositoryIdentifier, String itemDataType, Date beginDate, Date endDate, String granularity){
735

  
736
        try {
737
            Connection connection = dataSource.getConnection();
738
            PreparedStatement st;
739
            if(itemDataType.equals("")) {
740
                st = connection.prepareStatement("select distinct id from repo_download_stats where source=? order by id");
741
                st.setInt(1, Integer.parseInt(repositoryIdentifier));
742
            }
743
            else{
744
                st = connection.prepareStatement("select distinct rds.id from repo_download_stats rds, result_oids roid, result_classifications rc where rds.id=roid.orid and roid.id=rc.id and rc.type=? order by rds.id");
745
                st.setInt(1, Integer.parseInt(repositoryIdentifier));
746
                st.setString(2, itemDataType);
747
            }
748

  
749
            ResultSet rs = st.executeQuery();
750

  
751
            while (rs.next()) {
752
                executeDoi(reportItems, rs.getString(1), repositoryIdentifier, itemDataType, beginDate, endDate, granularity);
753
            }
754
            rs.close();
755
            st.close();
756
            connection.close();
757

  
758
        } catch (Exception e){
759
            log.error("Cannot execute repo : " + e);
760
        }
761

  
762
        return 0;
763
    }
764 642
}
modules/dnet-openaire-usage-stats-api/src/main/java/eu/dnetlib/usagestats/repos/ProjectRepo.java
21 21
    private Logger log = Logger.getLogger(this.getClass());
22 22

  
23 23

  
24
    public ViewStats getClicks(String projectId) {
24
    //public ViewStats getClicks(String projectId) {
25
    public UsageStats getClicks(String projectId) {
25 26

  
26 27
        //String query = "select p.id, p.title, sum (ps.numberofviews) from project p, usagestats.projectsstats ps " +
27 28
        //        "where ps.projectid=p.id and p.id=? group by p.id, p.title;";
28 29
        //String query = "select '5', maxcount from (select pl.entityid, count(*) as maxcount from usagestats.piwiklog pl, project_oids poid " +
29 30
        //        "where pl.entityid = poid.oid and poid.id=? group by pl.entityid order by count(*) DESC limit 1) as temp;";
30
        String query = "select sum(number_of_views) from project_stats where id=?";
31
        //String query = "select sum(number_of_views) from project_stats where id=?";
32
        String query = "select 'views', sum(rvs.sum) from repo_view_stats_monthly_clean rvs, project_results pr where pr.result=rvs.id and pr.id=?" +
33
                "UNION select 'views', sum(rs.sum) from result_stats_monthly_clean rs, project_results pr where pr.result=rs.id and pr.id=?" +
34
            "UNION select 'downloads', sum(rds.sum) from repo_download_stats_monthly_clean rds, project_results pr where pr.result=rds.id and pr.id=?";
31 35

  
32 36
        List<String> values = new ArrayList<>();
33 37
        values.add(projectId);
38
        values.add(projectId);
39
        values.add(projectId);
34 40

  
35
        return executePreparedQuery2(query, values);
41
        return executePreparedQuery(query, values, "project");
36 42
    }
37 43

  
38 44

  
modules/dnet-openaire-usage-stats-api/src/main/java/eu/dnetlib/usagestats/report/UsageReport.java
22 22
        List<ReportItem> reportItems = new ArrayList<>();
23 23
        List<ReportException> reportExceptions = new ArrayList<>();
24 24

  
25
        if(!granularity.toLowerCase().equals("totals") && !granularity.toLowerCase().equals("monthly")){
26
            reportExceptions.add(new ReportException("3062", "Warning", "Invalid ReportAttribute Value", "Granularity: \'" + granularity + "\' unknown. Defaulting to Monthly"));
27
            granularity = "Monthly";
28
        }
29

  
25 30
        Date beginDateParsed = null;
26 31
        if(!beginDate.equals("")){
27 32
            beginDateParsed = tryParse(beginDate);
......
65 70
        if(endDateParsed == null){
66 71
            reportExceptions.add(new ReportException("3020", "Error", "Invalid Date Arguments", "End Date: " + endDate + " is not a valid date"));
67 72
        }
68

  
69 73
        if(beginDateParsed != null && endDateParsed != null && !beginDateParsed.before(endDateParsed)){
70 74
            reportExceptions.add(new ReportException("3020", "Error", "Invalid Date Arguments", "BeginDate \'" + new SimpleDateFormat("yyyy-MM-dd").format(beginDateParsed) + "\' is greater than EndDate \'" + new SimpleDateFormat("yyyy-MM-dd").format(endDateParsed)+ "\'"));
71 75
        }
72 76

  
73

  
74 77
        String repoid = "";
75 78
        if (!repositoryIdentifier.equals("")){
76 79
            repoid = executeRepoId(repositoryIdentifier);
......
78 81
                reportExceptions.add(new ReportException("3060", "Error", "Invalid Filter Value", "RepositoryIdentifier: " + repositoryIdentifier + " is not valid"));
79 82
            }
80 83
        }
81
        if(!granularity.toLowerCase().equals("totals") && !granularity.toLowerCase().equals("monthly")){
82
            reportExceptions.add(new ReportException("3062", "Warning", "Invalid ReportAttribute Value", "Granularity: \'" + granularity + "\' unknown. Defaulting to Monthly"));
83
            granularity = "Monthly";
84
        }
85 84
        String itemid = "";
86 85
        if(!itemIdentifier.equals("")){
87 86
            String[] split = itemIdentifier.split(":");
modules/dnet-openaire-usage-stats-api/src/main/java/eu/dnetlib/usagestats/report/ReportItem.java
1 1
package eu.dnetlib.usagestats.report;
2 2

  
3
import com.fasterxml.jackson.annotation.JsonInclude;
3 4
import com.fasterxml.jackson.annotation.JsonProperty;
4 5

  
5 6
import java.util.ArrayList;
......
30 31
        return itemIdentifiers;
31 32
    }
32 33

  
34
    @JsonInclude(JsonInclude.Include.NON_NULL)
33 35
    @JsonProperty("ItemPublisher")
34 36
    public String getItemPublisher() {
35 37
        return itemPublisher;
......
45 47
        return itemDataType;
46 48
    }
47 49

  
50
    @JsonInclude(JsonInclude.Include.NON_NULL)
48 51
    @JsonProperty("ItemName")
49 52
    public String getItemName() {
50 53
        return itemName;
modules/dnet-openaire-usage-stats-api/src/main/resources/application.properties
9 9
server.port=8080
10 10

  
11 11
spring.jackson.serialization.INDENT_OUTPUT=true
12

  
13
vendor.name=OpenAIRE
14
vendor.contact=OpenAIRE Helpdesk
15
vendor.email=helpdesk@openaire.eu

Also available in: Unified diff