1
|
package eu.dnetlib.usagestats.repositories;
|
2
|
|
3
|
import org.apache.log4j.Logger;
|
4
|
import org.springframework.data.redis.core.HashOperations;
|
5
|
import org.springframework.data.redis.core.RedisTemplate;
|
6
|
import org.springframework.stereotype.Repository;
|
7
|
|
8
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
9
|
|
10
|
import eu.dnetlib.usagestats.portal.MonthlyStats;
|
11
|
import eu.dnetlib.usagestats.portal.RepositoryStats;
|
12
|
import eu.dnetlib.usagestats.portal.TotalStats;
|
13
|
import eu.dnetlib.usagestats.portal.UsageStats;
|
14
|
import eu.dnetlib.usagestats.portal.YearlyStats;
|
15
|
import eu.dnetlib.usagestats.sushilite.domain.ItemIdentifier;
|
16
|
import eu.dnetlib.usagestats.sushilite.domain.ItemPerformance;
|
17
|
import eu.dnetlib.usagestats.sushilite.domain.ReportItem;
|
18
|
|
19
|
import org.apache.commons.dbutils.DbUtils;
|
20
|
|
21
|
import javax.sql.DataSource;
|
22
|
|
23
|
import java.security.MessageDigest;
|
24
|
import java.sql.Array;
|
25
|
import java.sql.Connection;
|
26
|
import java.sql.PreparedStatement;
|
27
|
import java.sql.ResultSet;
|
28
|
import java.sql.Types;
|
29
|
import java.text.SimpleDateFormat;
|
30
|
import java.util.ArrayList;
|
31
|
import java.util.Calendar;
|
32
|
import java.util.Date;
|
33
|
import java.util.HashMap;
|
34
|
import java.util.List;
|
35
|
import javax.persistence.QueryHint;
|
36
|
|
37
|
@Repository
|
38
|
public class UsageStatsRepository {
|
39
|
|
40
|
private final DataSource usageStatsDB;
|
41
|
|
42
|
private final HashOperations<String, String, String> jedis;
|
43
|
|
44
|
private final Logger log = Logger.getLogger(this.getClass());
|
45
|
|
46
|
public UsageStatsRepository(DataSource usageStatsDB, RedisTemplate<String, String> redisTemplate) {
|
47
|
this.usageStatsDB = usageStatsDB;
|
48
|
this.jedis = redisTemplate.opsForHash();
|
49
|
}
|
50
|
|
51
|
private static String MD5(String string) throws java.security.NoSuchAlgorithmException {
|
52
|
MessageDigest md = MessageDigest.getInstance("MD5");
|
53
|
md.update(string.getBytes());
|
54
|
|
55
|
byte byteData[] = md.digest();
|
56
|
StringBuilder sb = new StringBuilder();
|
57
|
for (byte aByteData : byteData) {
|
58
|
sb.append(Integer.toString((aByteData & 0xff) + 0x100, 16).substring(1));
|
59
|
}
|
60
|
|
61
|
return sb.toString();
|
62
|
}
|
63
|
|
64
|
private static String toJson(Object o) throws com.fasterxml.jackson.core.JsonProcessingException {
|
65
|
ObjectMapper objectMapper = new ObjectMapper();
|
66
|
return objectMapper.writeValueAsString(o);
|
67
|
}
|
68
|
|
69
|
private static UsageStats fromJson(String string) throws java.io.IOException {
|
70
|
ObjectMapper objectMapper = new ObjectMapper();
|
71
|
return objectMapper.readValue(string, UsageStats.class);
|
72
|
}
|
73
|
|
74
|
/*
|
75
|
private static List<ReportItem> reportItemsFromJson(String string) throws Exception {
|
76
|
ObjectMapper objectMapper = new ObjectMapper();
|
77
|
return objectMapper.readValue(string, objectMapper.getTypeFactory().constructCollectionType(List.class, ReportItem.class));
|
78
|
}
|
79
|
*/
|
80
|
public UsageStats executeUsageStats(String query, List<String> values, String type) {
|
81
|
|
82
|
UsageStats usageStats = new UsageStats();
|
83
|
int total_views = 0;
|
84
|
int total_downloads = 0;
|
85
|
int page_views = 0;
|
86
|
int openaire_downloads = 0;
|
87
|
int openaire_views = 0;
|
88
|
Connection connection = null;
|
89
|
PreparedStatement st = null;
|
90
|
ResultSet rs = null;
|
91
|
try {
|
92
|
connection = usageStatsDB.getConnection();
|
93
|
java.sql.Timestamp timestamp1 = new java.sql.Timestamp(System.currentTimeMillis());
|
94
|
//System.out.println("DB start "+timestamp1);
|
95
|
log.info("Query started..." + timestamp1);
|
96
|
st = connection.prepareStatement(query);
|
97
|
int i = 1;
|
98
|
for (String s : values) {
|
99
|
st.setString(i, s);
|
100
|
i++;
|
101
|
}
|
102
|
|
103
|
String redis_key = MD5(st.toString());
|
104
|
|
105
|
String redis_result = jedis.get(redis_key, "result");
|
106
|
if (redis_result != null) {
|
107
|
return fromJson(redis_result);
|
108
|
}
|
109
|
|
110
|
rs = st.executeQuery();
|
111
|
if (type.equals("result")) {
|
112
|
while (rs.next()) {
|
113
|
if (rs.getString(1).equals("views") && rs.getString(4) != null && !rs.getString(4).equals("") && !rs.getString(4).equals("null")) {
|
114
|
usageStats.addViews(new RepositoryStats(rs.getString(3), rs.getString(2), rs.getString(4), rs.getString(5)));
|
115
|
total_views += Integer.parseInt(rs.getString(4));
|
116
|
openaire_views += Integer.parseInt(rs.getString(5));
|
117
|
} else if (rs.getString(1).equals("downloads") && rs.getString(4) != null && !rs.getString(4).equals("") && !rs.getString(4).equals("null")) {
|
118
|
usageStats.addDownloads(new RepositoryStats(rs.getString(3), rs.getString(2), rs.getString(4), "0"));
|
119
|
total_downloads += Integer.parseInt(rs.getString(4));
|
120
|
openaire_downloads += Integer.parseInt(rs.getString(5));
|
121
|
} else if (rs.getString(1).equals("pageviews") && rs.getString(4) != null && !rs.getString(4).equals("") && !rs.getString(4).equals("null")) {
|
122
|
page_views = Integer.parseInt(rs.getString(4));
|
123
|
}
|
124
|
}
|
125
|
usageStats.setTotal_views(Integer.toString(total_views));
|
126
|
usageStats.setTotal_downloads(Integer.toString(total_downloads));
|
127
|
usageStats.setPageViews(Integer.toString(page_views));
|
128
|
usageStats.setTotal_openaire_views(Integer.toString(openaire_views));
|
129
|
usageStats.setTotal_openaire_downloads(Integer.toString(openaire_downloads));
|
130
|
} else if (type.equals("project") || type.equals("datasource")) {
|
131
|
while (rs.next()) {
|
132
|
if (rs.getString(1).equals("views") && rs.getString(2) != null && !rs.getString(2).equals("") && !rs.getString(2).equals("null")) {
|
133
|
total_views += Integer.parseInt(rs.getString(2));
|
134
|
openaire_views += Integer.parseInt(rs.getString(3));
|
135
|
} else if (rs.getString(1).equals("downloads") && rs.getString(2) != null && !rs.getString(2).equals("") && !rs.getString(2).equals("null")) {
|
136
|
total_downloads += Integer.parseInt(rs.getString(2));
|
137
|
openaire_downloads += Integer.parseInt(rs.getString(3));
|
138
|
} else if (rs.getString(1).equals("pageviews") && rs.getString(2) != null && !rs.getString(2).equals("") && !rs.getString(2).equals("null")) {
|
139
|
page_views = Integer.parseInt(rs.getString(2));
|
140
|
}
|
141
|
/*
|
142
|
else if (rs.getString(1).equals("openaire") && rs.getString(2) != null && !rs.getString(2).equals("") && !rs.getString(2).equals("null")) {
|
143
|
openaire = Integer.parseInt(rs.getString(2));
|
144
|
}
|
145
|
*/
|
146
|
|
147
|
}
|
148
|
usageStats.setTotal_views(Integer.toString(total_views));
|
149
|
usageStats.setTotal_downloads(Integer.toString(total_downloads));
|
150
|
usageStats.setPageViews(Integer.toString(page_views));
|
151
|
usageStats.setTotal_openaire_views(Integer.toString(openaire_views));
|
152
|
usageStats.setTotal_openaire_downloads(Integer.toString(openaire_downloads));
|
153
|
}
|
154
|
|
155
|
jedis.put(redis_key, "persistent", "false");
|
156
|
jedis.put(redis_key, "query", st.toString());
|
157
|
//jedis.put(redis_key, "result", toString(usageStats));
|
158
|
jedis.put(redis_key, "result", toJson(usageStats));
|
159
|
jedis.put(redis_key, "fetchMode", "3");
|
160
|
|
161
|
} catch (Exception e) {
|
162
|
log.error("Cannot execute query2 : ", e);
|
163
|
|
164
|
} finally {
|
165
|
DbUtils.closeQuietly(rs);
|
166
|
DbUtils.closeQuietly(st);
|
167
|
DbUtils.closeQuietly(connection);
|
168
|
java.sql.Timestamp timestamp = new java.sql.Timestamp(System.currentTimeMillis());
|
169
|
//System.out.println("DB end "+timestamp);
|
170
|
log.info("Query end..." + timestamp);
|
171
|
|
172
|
}
|
173
|
return usageStats;
|
174
|
}
|
175
|
|
176
|
public TotalStats executeTotalStats() {
|
177
|
TotalStats totalStats = null;
|
178
|
try {
|
179
|
String redis_result = jedis.get("total_stats", "result");
|
180
|
if (redis_result != null) {
|
181
|
totalStats = fromJsonTotalStats(redis_result);
|
182
|
} else {
|
183
|
return updateTotalStats();
|
184
|
}
|
185
|
} catch (Exception e) {
|
186
|
log.error("Cannot execute totalStats : ", e);
|
187
|
}
|
188
|
return totalStats;
|
189
|
}
|
190
|
|
191
|
public TotalStats updateTotalStats() {
|
192
|
TotalStats totalStats = new TotalStats();
|
193
|
Connection connection = null;
|
194
|
PreparedStatement st = null;
|
195
|
ResultSet rs = null;
|
196
|
HashMap<Integer, List<MonthlyStats>> monthlyStatsMap = new HashMap<>();
|
197
|
|
198
|
try {
|
199
|
connection = usageStatsDB.getConnection();
|
200
|
java.sql.Timestamp timestamp1 = new java.sql.Timestamp(System.currentTimeMillis());
|
201
|
//System.out.println("DB start "+timestamp1);
|
202
|
log.info("Query started..." + timestamp1);
|
203
|
|
204
|
//st = connection.prepareStatement("SELECT count(distinct d.repository_id) AS repository, count(distinct d.result_id) AS items, sum(d.count) AS downloads, sum(v.count) AS views from public.downloads_stats d FULL OUTER JOIN public.views_stats v ON d.source=v.source AND d.repository_id=v.repository_id AND d.result_id=v.result_id AND d.date=v.date;");
|
205
|
st = connection.prepareStatement("SELECT count(distinct repository_id) AS repository, count(distinct result_id) AS items, sum(downloads) AS downloads, sum(views) AS views from usage_stats");
|
206
|
rs = st.executeQuery();
|
207
|
rs.next();
|
208
|
totalStats.setRepositories(rs.getInt(1));
|
209
|
totalStats.setItems(rs.getInt(2));
|
210
|
totalStats.setDownloads(rs.getInt(3));
|
211
|
totalStats.setViews(rs.getInt(4));
|
212
|
rs.close();
|
213
|
st.close();
|
214
|
|
215
|
//st = connection.prepareStatement("select coalesce(d.date,v.date) as month, count(distinct d.repository_id) as repository, count(distinct d.result_id) as items, sum(d.count) as downloads, sum(v.count) as views from public.downloads_stats d FULL OUTER JOIN public.views_stats v ON d.source=v.source AND d.repository_id=v.repository_id AND d.result_id=v.result_id AND d.date=v.date group by month order by month;");
|
216
|
st = connection.prepareStatement("SELECT date, count(distinct repository_id) AS repository, count(distinct result_id) AS items, sum(downloads) AS downloads, sum(views) AS views FROM usage_stats GROUP BY date ORDER BY date;");
|
217
|
rs = st.executeQuery();
|
218
|
while (rs.next()) {
|
219
|
int year = Integer.parseInt(rs.getString(1).substring(0, 4));
|
220
|
int month = Integer.parseInt(rs.getString(1).substring(5));
|
221
|
MonthlyStats monthlyStats = new MonthlyStats();
|
222
|
monthlyStats.setMonth(month);
|
223
|
monthlyStats.setRepositories(rs.getInt(2));
|
224
|
monthlyStats.setItems(rs.getInt(3));
|
225
|
monthlyStats.setDownloads(rs.getInt(4));
|
226
|
monthlyStats.setViews(rs.getInt(5));
|
227
|
|
228
|
if (monthlyStatsMap.get(year) != null) {
|
229
|
monthlyStatsMap.get(year).add(monthlyStats);
|
230
|
} else {
|
231
|
List<MonthlyStats> newList = new ArrayList<>();
|
232
|
newList.add(monthlyStats);
|
233
|
monthlyStatsMap.put(year, newList);
|
234
|
|
235
|
}
|
236
|
}
|
237
|
rs.close();
|
238
|
st.close();
|
239
|
|
240
|
//st = connection.prepareStatement("SELECT COALESCE(SUBSTRING(d.date FROM 1 FOR 4), SUBSTRING(v.date FROM 1 FOR 4)) AS year, COUNT(DISTINCT d.repository_id) AS repository, COUNT(DISTINCT d.result_id) AS items, SUM(d.count) AS downloads, SUM(v.count) AS views FROM public.downloads_stats d FULL OUTER JOIN public.views_stats v ON d.source=v.source AND d.repository_id=v.repository_id AND d.result_id=v.result_id AND d.date=v.date GROUP BY year ORDER BY year;");
|
241
|
st = connection.prepareStatement("SELECT SUBSTRING(date FROM 1 FOR 4) AS year, COUNT(DISTINCT repository_id) AS repository, COUNT(DISTINCT result_id) AS items, SUM(downloads) AS downloads, SUM(views) AS views FROM usage_stats GROUP BY year ORDER BY year;");
|
242
|
rs = st.executeQuery();
|
243
|
List<YearlyStats> yearlyStatsList = new ArrayList<>();
|
244
|
while (rs.next()) {
|
245
|
YearlyStats yearlyStats = new YearlyStats();
|
246
|
yearlyStats.setYear(rs.getInt(1));
|
247
|
yearlyStats.setRepositories(rs.getInt(2));
|
248
|
yearlyStats.setItems(rs.getInt(3));
|
249
|
yearlyStats.setDownloads(rs.getInt(4));
|
250
|
yearlyStats.setViews(rs.getInt(5));
|
251
|
yearlyStats.setMonthlyStats(monthlyStatsMap.get(rs.getInt(1)));
|
252
|
yearlyStatsList.add(yearlyStats);
|
253
|
}
|
254
|
totalStats.setYearlyStats(yearlyStatsList);
|
255
|
jedis.put("total_stats", "result", toJson(totalStats));
|
256
|
jedis.put("total_stats", "persistent", "false");
|
257
|
|
258
|
} catch (Exception e) {
|
259
|
log.error("Cannot execute totalStats : ", e);
|
260
|
|
261
|
} finally {
|
262
|
DbUtils.closeQuietly(rs);
|
263
|
DbUtils.closeQuietly(st);
|
264
|
DbUtils.closeQuietly(connection);
|
265
|
java.sql.Timestamp timestamp = new java.sql.Timestamp(System.currentTimeMillis());
|
266
|
//System.out.println("DB end "+timestamp);
|
267
|
log.info("Query end..." + timestamp);
|
268
|
|
269
|
}
|
270
|
return totalStats;
|
271
|
}
|
272
|
|
273
|
private static TotalStats fromJsonTotalStats(String string) throws java.io.IOException {
|
274
|
ObjectMapper objectMapper = new ObjectMapper();
|
275
|
return objectMapper.readValue(string, TotalStats.class);
|
276
|
}
|
277
|
|
278
|
public String executeRepoId(String repositoryIdentifier, String report) {
|
279
|
PreparedStatement st = null;
|
280
|
Connection connection = null;
|
281
|
ResultSet rs = null;
|
282
|
try {
|
283
|
connection = usageStatsDB.getConnection();
|
284
|
java.sql.Timestamp timestamp1 = new java.sql.Timestamp(System.currentTimeMillis());
|
285
|
//System.out.println("DB start "+timestamp1);
|
286
|
log.info("Query started..." + timestamp1);
|
287
|
|
288
|
String[] split = repositoryIdentifier.split(":");
|
289
|
String openaire_id = "-1";
|
290
|
switch (split[0].toLowerCase()) {
|
291
|
case "openaire":
|
292
|
if (!report.equals("jr1")) {
|
293
|
st = connection.prepareStatement("select id from datasource where id=?");
|
294
|
st.setString(1, repositoryIdentifier.replaceFirst(split[0] + ":", ""));
|
295
|
} else {
|
296
|
st = connection.prepareStatement("select id from datasource where id=? AND (type='Journal' OR type='Journal Aggregator/Publisher')");
|
297
|
st.setString(1, repositoryIdentifier.replaceFirst(split[0] + ":", ""));
|
298
|
}
|
299
|
|
300
|
rs = st.executeQuery();
|
301
|
while (rs.next()) {
|
302
|
openaire_id = rs.getString(1);
|
303
|
}
|
304
|
return openaire_id;
|
305
|
|
306
|
case "opendoar":
|
307
|
if (!report.equals("jr1")) {
|
308
|
st = connection.prepareStatement("select id from datasource_oids where orid=?");
|
309
|
st.setString(1, "opendoar____::" + repositoryIdentifier.replaceFirst(split[0] + ":", ""));
|
310
|
} else {
|
311
|
st = connection.prepareStatement("select distinct d.id from datasource d, datasource_oids di where di.orid=? and d.id=di.id and (type='Journal' OR type='Journal Aggregator/Publisher')");
|
312
|
st.setString(1, "opendoar____::" + repositoryIdentifier.replaceFirst(split[0] + ":", ""));
|
313
|
}
|
314
|
|
315
|
rs = st.executeQuery();
|
316
|
while (rs.next()) {
|
317
|
openaire_id = rs.getString(1);
|
318
|
}
|
319
|
return openaire_id;
|
320
|
case "issn":
|
321
|
st = connection.prepareStatement("select distinct d.id from datasource d, datasource_oids di, datasource_results dr where d.id=dr.id and di.orid like ? and d.id=di.id and (type='Journal' OR type='Journal Aggregator/Publisher')");
|
322
|
st.setString(1, "%" + repositoryIdentifier.replaceFirst(split[0] + ":", "") + "%");
|
323
|
|
324
|
rs = st.executeQuery();
|
325
|
while (rs.next()) {
|
326
|
openaire_id = rs.getString(1);
|
327
|
}
|
328
|
return openaire_id;
|
329
|
default:
|
330
|
return "-1";
|
331
|
}
|
332
|
} catch (Exception e) {
|
333
|
log.error("Repository id failed: ", e);
|
334
|
} finally {
|
335
|
DbUtils.closeQuietly(rs);
|
336
|
DbUtils.closeQuietly(st);
|
337
|
DbUtils.closeQuietly(connection);
|
338
|
java.sql.Timestamp timestamp = new java.sql.Timestamp(System.currentTimeMillis());
|
339
|
//System.out.println("DB end "+timestamp);
|
340
|
log.info("Query end..." + timestamp);
|
341
|
|
342
|
}
|
343
|
return "-1";
|
344
|
}
|
345
|
|
346
|
public void executeItem(List<ReportItem> reportItems, String itemIdentifier, String repositoryIdentifier, String itemDataType, Date beginDate, Date endDate, String granularity) {
|
347
|
String[] split = itemIdentifier.split(":");
|
348
|
switch (split[0].toLowerCase()) {
|
349
|
case "oid":
|
350
|
executeOid(reportItems, itemIdentifier.replaceFirst(split[0] + ":", ""), repositoryIdentifier, itemDataType, beginDate, endDate, granularity);
|
351
|
break;
|
352
|
case "doi":
|
353
|
executeDoi(reportItems, itemIdentifier.replaceFirst(split[0] + ":", ""), repositoryIdentifier, itemDataType, beginDate, endDate, granularity);
|
354
|
break;
|
355
|
case "openaire":
|
356
|
executeOpenaire(reportItems, itemIdentifier.replaceFirst(split[0] + ":", ""), repositoryIdentifier, itemDataType, beginDate, endDate, granularity);
|
357
|
break;
|
358
|
default:
|
359
|
}
|
360
|
}
|
361
|
|
362
|
private void executeOid(List<ReportItem> reportItems, String oid, String repositoryIdentifier, String itemDataType, Date beginDate, Date endDate, String granularity) {
|
363
|
Connection connection = null;
|
364
|
PreparedStatement st = null;
|
365
|
ResultSet rs = null;
|
366
|
try {
|
367
|
connection = usageStatsDB.getConnection();
|
368
|
java.sql.Timestamp timestamp1 = new java.sql.Timestamp(System.currentTimeMillis());
|
369
|
//System.out.println("DB start "+timestamp1);
|
370
|
log.info("Query started..." + timestamp1);
|
371
|
|
372
|
//st = connection.prepareStatement("SELECT DISTINCT roid.id FROM public.result_oids roid, public.downloads_stats s WHERE s.result_id=roid.id AND roid.orid=? UNION SELECT DISTINCT roid.id FROM public.result_oids roid, public.views_stats s WHERE s.result_id=roid.id AND roid.orid=?");
|
373
|
//st = connection.prepareStatement("SELECT DISTINCT us.original_result_id FROM result_oids roid, usage_stats us WHERE us.result_id=roid.id AND roid.orid=?");
|
374
|
st = connection.prepareStatement("SELECT DISTINCT original_result_id FROM reports WHERE orid=?;");
|
375
|
st.setObject(1, connection.createArrayOf("text", new String[]{oid}));
|
376
|
//st.setString(1, oid);
|
377
|
|
378
|
rs = st.executeQuery();
|
379
|
|
380
|
while (rs.next()) {
|
381
|
executeOpenaire(reportItems, rs.getString(1), repositoryIdentifier, itemDataType, beginDate, endDate, granularity);
|
382
|
}
|
383
|
connection.close();
|
384
|
} catch (Exception e) {
|
385
|
log.error("Oid to OpenAIRE id failed: ", e);
|
386
|
} finally {
|
387
|
DbUtils.closeQuietly(rs);
|
388
|
DbUtils.closeQuietly(st);
|
389
|
DbUtils.closeQuietly(connection);
|
390
|
java.sql.Timestamp timestamp = new java.sql.Timestamp(System.currentTimeMillis());
|
391
|
//System.out.println("DB end "+timestamp);
|
392
|
log.info("Query end..." + timestamp);
|
393
|
|
394
|
}
|
395
|
}
|
396
|
|
397
|
private void executeDoi(List<ReportItem> reportItems, String doi, String repositoryIdentifier, String itemDataType, Date beginDate, Date endDate, String granularity) {
|
398
|
Connection connection = null;
|
399
|
PreparedStatement st = null;
|
400
|
ResultSet rs = null;
|
401
|
try {
|
402
|
connection = usageStatsDB.getConnection();
|
403
|
java.sql.Timestamp timestamp1 = new java.sql.Timestamp(System.currentTimeMillis());
|
404
|
//System.out.println("DB start "+timestamp1);
|
405
|
log.info("Query started..." + timestamp1);
|
406
|
|
407
|
//st = connection.prepareStatement("SELECT DISTINCT poid.id FROM public.result_pids poid, public.downloads_stats s WHERE s.result_id=poid.id AND poid.type='doi' AND poid.pid=? UNION SELECT DISTINCT poid.id FROM public.result_pids poid, public.views_stats s WHERE s.result_id=poid.id AND poid.type='doi' AND poid.pid=?");
|
408
|
//st = connection.prepareStatement("SELECT DISTINCT us.original_result_id FROM result_pids poid, usage_stats us WHERE us.result_id=poid.id AND poid.type='doi' AND poid.pid=?");
|
409
|
st = connection.prepareStatement("SELECT DISTINCT original_result_id FROM reports, result r, result_pids poid where original_result_id=r.original_id and r.id=poid.id and poid.type='doi' AND poid.pid=?;");
|
410
|
st.setString(1, doi);
|
411
|
//st.setString(2, doi);
|
412
|
|
413
|
rs = st.executeQuery();
|
414
|
|
415
|
while (rs.next()) {
|
416
|
executeOpenaire(reportItems, rs.getString(1), repositoryIdentifier, itemDataType, beginDate, endDate, granularity);
|
417
|
}
|
418
|
} catch (Exception e) {
|
419
|
log.error("Doi to OpenAIRE id failed: ", e);
|
420
|
} finally {
|
421
|
DbUtils.closeQuietly(rs);
|
422
|
DbUtils.closeQuietly(st);
|
423
|
DbUtils.closeQuietly(connection);
|
424
|
java.sql.Timestamp timestamp = new java.sql.Timestamp(System.currentTimeMillis());
|
425
|
//System.out.println("DB end "+timestamp);
|
426
|
log.info("Query end..." + timestamp);
|
427
|
|
428
|
}
|
429
|
}
|
430
|
|
431
|
private void executeOpenaire(List<ReportItem> reportItems, String openaire, String repositoryIdentifier, String itemDataType, Date beginDate, Date endDate, String granularity) {
|
432
|
SimpleDateFormat report_dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
433
|
SimpleDateFormat postgresFormat = new SimpleDateFormat("yyyy/MM");
|
434
|
String beginDateStr = postgresFormat.format(beginDate);
|
435
|
String endDateStr = postgresFormat.format(endDate);
|
436
|
|
437
|
Connection connection = null;
|
438
|
PreparedStatement st = null;
|
439
|
ResultSet rs = null;
|
440
|
|
441
|
/*
|
442
|
Calendar startCalendar = Calendar.getInstance();
|
443
|
startCalendar.setTime(beginDate);
|
444
|
Calendar endCalendar = Calendar.getInstance();
|
445
|
endCalendar.setTime(endDate);
|
446
|
int diffYear = endCalendar.get(Calendar.YEAR) - startCalendar.get(Calendar.YEAR);
|
447
|
int diffMonth = diffYear * 12 + endCalendar.get(Calendar.MONTH) - startCalendar.get(Calendar.MONTH);
|
448
|
*/
|
449
|
try {
|
450
|
connection = usageStatsDB.getConnection();
|
451
|
java.sql.Timestamp timestamp1 = new java.sql.Timestamp(System.currentTimeMillis());
|
452
|
//System.out.println("DB start "+timestamp1);
|
453
|
log.info("Query started..." + timestamp1);
|
454
|
|
455
|
if (repositoryIdentifier.equals("")) {
|
456
|
if (itemDataType.equals("")) {
|
457
|
//st = connection.prepareStatement("SELECT res.repository_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.ddate, oids.orid, res.downloads, res.views FROM (SELECT coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.result_id, vs.result_id) AS result_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.downloads_stats s WHERE s.date>=? AND s.date<=? AND s.result_id=? GROUP BY s.repository_id, s.result_id, s.date) AS ds FULL OUTER JOIN (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.views_stats s WHERE s.date>=? AND s.date<=? AND s.result_id=? GROUP BY s.repository_id, s.result_id, s.date) AS vs ON ds.result_id=vs.result_id AND ds.date=vs.date) AS res JOIN public.result r ON res.result_id=r.id JOIN public.datasource d ON d.id=res.repository_id JOIN public.result_classifications rc ON rc.id=r.id LEFT JOIN (SELECT pids.id, string_agg(pids.pid, '#!#') AS pid FROM public.result_pids pids WHERE pids.id=? AND type='doi' GROUP BY pids.id) AS pids ON pids.id=r.id LEFT JOIN (SELECT oids.id, string_agg(oids.orid, '#!#') AS orid FROM public.result_oids oids WHERE oids.id=? GROUP BY oids.id) AS oids ON oids.id=r.id ORDER BY res.repository_id, res.ddate;");
|
458
|
//st = connection.prepareStatement("SELECT res.repository_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.date, oids.orid, res.downloads, res.views FROM (SELECT us.repository_id, us.result_id, us.date, us.downloads, us.views FROM usage_stats us WHERE us.date>=? AND us.date<=? AND us.result_id=?) AS res JOIN result r ON res.result_id=r.id JOIN datasource d ON d.id=res.repository_id JOIN result_classifications rc ON rc.id=r.id LEFT JOIN (SELECT pids.id, string_agg(pids.pid, '#!#') AS pid FROM result_pids pids WHERE pids.id=? AND type='doi' GROUP BY pids.id) AS pids ON pids.id=r.id LEFT JOIN (SELECT oids.id, string_agg(oids.orid, '#!#') AS orid FROM result_oids oids WHERE oids.id=? GROUP BY oids.id) AS oids ON oids.id=r.id ORDER BY res.repository_id, res.date;");
|
459
|
//st = connection.prepareStatement("SELECT us.repository_id, r.title, r.publisher, r.source, rc.type, string_agg(distinct pids.pid, '#!#') AS pid, d.name, us.date, string_agg(distinct oids.orid, '#!#') AS orid, us.downloads, us.views FROM usage_stats us JOIN result r ON us.result_id=r.id JOIN datasource d ON d.id=us.repository_id JOIN result_classifications rc ON rc.id=r.id JOIN result_pids pids ON pids.id=r.id AND pids.type='doi' JOIN result_oids oids ON oids.id=r.id WHERE us.date>=? AND us.date<=? AND us.original_result_id=? GROUP BY us.repository_id, r.title, r.publisher, r.source, rc.type, d.name, us.date, us.downloads, us.views ORDER BY us.repository_id, us.date;");
|
460
|
st = connection.prepareStatement("select repository_id, r.title, r.publisher, r.source , rc.type, re.pid, name, date,orid,downloads,views from reports re, result_pids pids, result r, result_classifications rc where date>=? AND date<=? and original_result_id=r.original_id and r.id=pids.id and rc.id=r.id and original_result_id=? and pids.type='doi';");
|
461
|
st.setString(1, beginDateStr);
|
462
|
st.setString(2, endDateStr);
|
463
|
st.setString(3, openaire);
|
464
|
//st.setString(4, beginDateStr);
|
465
|
//st.setString(5, endDateStr);
|
466
|
//st.setString(6, openaire);
|
467
|
//st.setString(4, openaire);
|
468
|
//st.setString(5, openaire);
|
469
|
} else {
|
470
|
//st = connection.prepareStatement("SELECT res.repository_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.ddate, oids.orid, res.downloads, res.views FROM (SELECT coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.result_id, vs.result_id) AS result_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.downloads_stats s WHERE s.date>=? AND s.date<=? AND s.result_id=? GROUP BY s.repository_id, s.result_id, s.date) AS ds FULL OUTER JOIN (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.views_stats s WHERE s.date>=? AND s.date<=? AND s.result_id=? GROUP BY s.repository_id, s.result_id, s.date) AS vs ON ds.result_id=vs.result_id AND ds.date=vs.date) AS res JOIN public.result r ON res.result_id=r.id JOIN public.datasource d ON d.id=res.repository_id JOIN public.result_classifications rc ON rc.id=r.id AND rc.type=? LEFT JOIN (SELECT pids.id, string_agg(pids.pid, '#!#') AS pid FROM public.result_pids pids WHERE pids.id=? AND type='doi' GROUP BY pids.id) AS pids ON pids.id=r.id LEFT JOIN (SELECT oids.id, string_agg(oids.orid, '#!#') AS orid FROM public.result_oids oids WHERE oids.id=? GROUP BY oids.id) AS oids ON oids.id=r.id ORDER BY res.repository_id, res.ddate;");
|
471
|
//st = connection.prepareStatement("SELECT res.repository_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.date, oids.orid, res.downloads, res.views FROM (SELECT us.repository_id, us.result_id, us.date, us.downloads, us.views FROM usage_stats us WHERE us.date>=? AND us.date<=? AND us.result_id=?) AS res JOIN result r ON res.result_id=r.id JOIN datasource d ON d.id=res.repository_id JOIN result_classifications rc ON rc.id=r.id AND rc.type=? LEFT JOIN (SELECT pids.id, string_agg(pids.pid, '#!#') AS pid FROM result_pids pids WHERE pids.id=? AND type='doi' GROUP BY pids.id) AS pids ON pids.id=r.id LEFT JOIN (SELECT oids.id, string_agg(oids.orid, '#!#') AS orid FROM result_oids oids WHERE oids.id=? GROUP BY oids.id) AS oids ON oids.id=r.id ORDER BY res.repository_id, res.date;");
|
472
|
//st = connection.prepareStatement("SELECT us.repository_id, r.title, r.publisher, r.source, rc.type, string_agg(distinct pids.pid, '#!#') AS pid, d.name, us.date, string_agg(distinct oids.orid, '#!#') AS orid, us.downloads, us.views FROM usage_stats us JOIN result r ON us.result_id=r.id JOIN datasource d ON d.id=us.repository_id JOIN result_classifications rc ON rc.id=r.id JOIN result_pids pids ON pids.id=r.id AND pids.type='doi' JOIN result_oids oids ON oids.id=r.id WHERE us.date>=? AND us.date<=? AND us.original_result_id=? AND rc.type=? GROUP BY us.repository_id, r.title, r.publisher, r.source, rc.type, d.name, us.date, us.downloads, us.views ORDER BY us.repository_id, us.date;");
|
473
|
st = connection.prepareStatement("select repository_id, r.title, r.publisher, r.source , rc.type, re.pid, name, date,orid,downloads,views from reports re, result_pids pids, result r, result_classifications rc where date>=? AND date<=? and original_result_id=r.original_id and r.id=pids.id and rc.id=r.id and original_result_id=? and rc.type=? and pids.type='doi';");
|
474
|
st.setString(1, beginDateStr);
|
475
|
st.setString(2, endDateStr);
|
476
|
st.setString(3, openaire);
|
477
|
//st.setString(4, beginDateStr);
|
478
|
//st.setString(5, endDateStr);
|
479
|
//st.setString(6, openaire);
|
480
|
st.setString(4, itemDataType);
|
481
|
//st.setString(5, openaire);
|
482
|
//st.setString(6, openaire);
|
483
|
}
|
484
|
} else {
|
485
|
if (itemDataType.equals("")) {
|
486
|
//st = connection.prepareStatement("SELECT res.repository_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.ddate, oids.orid, res.downloads, res.views FROM (SELECT coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.result_id, vs.result_id) AS result_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.downloads_stats s WHERE s.date>=? AND s.date<=? AND s.result_id=? AND s.repository_id=? GROUP BY s.repository_id, s.result_id, s.date) AS ds FULL OUTER JOIN (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.views_stats s WHERE s.date>=? AND s.date<=? AND s.result_id=? AND s.repository_id=? GROUP BY s.repository_id, s.result_id, s.date) AS vs ON ds.result_id=vs.result_id AND ds.date=vs.date) AS res JOIN public.result r ON res.result_id=r.id JOIN public.datasource d ON d.id=res.repository_id JOIN public.result_classifications rc ON rc.id=r.id LEFT JOIN (SELECT pids.id, string_agg(pids.pid, '#!#') AS pid FROM public.result_pids pids WHERE pids.id=? AND type='doi' GROUP BY pids.id) AS pids ON pids.id=r.id LEFT JOIN (SELECT oids.id, string_agg(oids.orid, '#!#') AS orid FROM public.result_oids oids WHERE oids.id=? GROUP BY oids.id) AS oids ON oids.id=r.id ORDER BY res.repository_id, res.ddate;");
|
487
|
//st = connection.prepareStatement("SELECT us.repository_id, r.title, r.publisher, r.source, rc.type, string_agg(distinct pids.pid, '#!#') AS pid, d.name, us.date, string_agg(distinct oids.orid, '#!#') AS orid, us.downloads, us.views FROM usage_stats us JOIN result r ON us.result_id=r.id JOIN datasource d ON d.id=us.repository_id JOIN result_classifications rc ON rc.id=r.id JOIN result_pids pids ON pids.id=r.id AND pids.type='doi' JOIN result_oids oids ON oids.id=r.id WHERE us.date>=? AND us.date<=? AND us.original_result_id=? AND us.repository_id=? GROUP BY us.repository_id, r.title, r.publisher, r.source, rc.type, d.name, us.date, us.downloads, us.views ORDER BY us.repository_id, us.date;");
|
488
|
st = connection.prepareStatement("select repository_id, r.title, r.publisher, r.source , rc.type, re.pid, name, date,orid,downloads,views from reports re, result_pids pids, result r, result_classifications rc where date>=? AND date<=? and original_result_id=r.original_id and r.id=pids.id and rc.id=r.id and original_result_id=? and repository_id=? and pids.type='doi';");
|
489
|
st.setString(1, beginDateStr);
|
490
|
st.setString(2, endDateStr);
|
491
|
st.setString(3, openaire);
|
492
|
st.setString(4, repositoryIdentifier);
|
493
|
//st.setString(5, beginDateStr);
|
494
|
//st.setString(6, endDateStr);
|
495
|
//st.setString(7, openaire);
|
496
|
//st.setString(8, repositoryIdentifier);
|
497
|
//st.setString(5, openaire);
|
498
|
//st.setString(6, openaire);
|
499
|
} else {
|
500
|
//st = connection.prepareStatement("SELECT res.repository_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.ddate, oids.orid, res.downloads, res.views FROM (SELECT coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.result_id, vs.result_id) AS result_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.downloads_stats s WHERE s.date>=? AND s.date<=? AND s.result_id=? AND s.repository_id=? GROUP BY s.repository_id, s.result_id, s.date) AS ds FULL OUTER JOIN (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.views_stats s WHERE s.date>=? AND s.date<=? AND s.result_id=? AND s.repository_id=? GROUP BY s.repository_id, s.result_id, s.date) AS vs ON ds.result_id=vs.result_id AND ds.date=vs.date) AS res JOIN public.result r ON res.result_id=r.id JOIN public.datasource d ON d.id=res.repository_id JOIN public.result_classifications rc ON rc.id=r.id AND rc.type=? LEFT JOIN (SELECT pids.id, string_agg(pids.pid, '#!#') AS pid FROM public.result_pids pids WHERE pids.id=? AND type='doi' GROUP BY pids.id) AS pids ON pids.id=r.id LEFT JOIN (SELECT oids.id, string_agg(oids.orid, '#!#') AS orid FROM public.result_oids oids WHERE oids.id=? GROUP BY oids.id) AS oids ON oids.id=r.id ORDER BY res.repository_id, res.ddate;");
|
501
|
//st = connection.prepareStatement("SELECT us.repository_id, r.title, r.publisher, r.source, rc.type, string_agg(distinct pids.pid, '#!#') AS pid, d.name, us.date, string_agg(distinct oids.orid, '#!#') AS orid, us.downloads, us.views FROM usage_stats us JOIN result r ON us.result_id=r.id JOIN datasource d ON d.id=us.repository_id JOIN result_classifications rc ON rc.id=r.id JOIN result_pids pids ON pids.id=r.id AND pids.type='doi' JOIN result_oids oids ON oids.id=r.id WHERE us.date>=? AND us.date<=? AND us.original_result_id=? AND us.repository_id=? AND rc.type=? GROUP BY us.repository_id, r.title, r.publisher, r.source, rc.type, d.name, us.date, us.downloads, us.views ORDER BY us.repository_id, us.date;");
|
502
|
st = connection.prepareStatement("select repository_id, r.title, r.publisher, r.source , rc.type, re.pid, name, date,orid,downloads,views from reports re, result_pids pids, result r, result_classifications rc where date>=? AND date<=? and original_result_id=r.original_id and r.id=pids.id and rc.id=r.id and original_result_id=? and repository_id=? and rc.type=? and pids.type='doi';");
|
503
|
st.setString(1, beginDateStr);
|
504
|
st.setString(2, endDateStr);
|
505
|
st.setString(3, openaire);
|
506
|
st.setString(4, repositoryIdentifier);
|
507
|
//st.setString(5, beginDateStr);
|
508
|
//st.setString(6, endDateStr);
|
509
|
//st.setString(7, openaire);
|
510
|
//st.setString(8, repositoryIdentifier);
|
511
|
st.setString(5, itemDataType);
|
512
|
//st.setString(6, openaire);
|
513
|
//st.setString(7, openaire);
|
514
|
}
|
515
|
}
|
516
|
|
517
|
rs = st.executeQuery();
|
518
|
String repository = "";
|
519
|
String lastDate = "";
|
520
|
ReportItem reportItem = null;
|
521
|
int ft_total = 0;
|
522
|
int abstr = 0;
|
523
|
|
524
|
if (granularity.equalsIgnoreCase("totals")) {
|
525
|
while (rs.next()) {
|
526
|
if (!rs.getString(1).equals(repository)) {
|
527
|
if (reportItem != null) {
|
528
|
reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate), Integer.toString(ft_total), Integer.toString(abstr)));
|
529
|
reportItems.add(reportItem);
|
530
|
}
|
531
|
repository = rs.getString(1);
|
532
|
reportItem = new ReportItem(rs.getString(3), rs.getString(7), rs.getString(5), rs.getString(2));
|
533
|
reportItem.addIdentifier(new ItemIdentifier("OpenAIRE", openaire));
|
534
|
reportItem.addIdentifier(new ItemIdentifier("URLs", rs.getString(4)));
|
535
|
|
536
|
String[] oridsArr = (String[]) rs.getArray(9).getArray();
|
537
|
if (oridsArr[0] != null && !oridsArr[0].equals("")) {
|
538
|
reportItem.addIdentifier(new ItemIdentifier("OAI", oridsArr[0]));
|
539
|
}
|
540
|
String[] pidsArr = (String[]) rs.getArray(6).getArray();
|
541
|
if (pidsArr[0] != null && !pidsArr[0].equals("")) {
|
542
|
reportItem.addIdentifier(new ItemIdentifier("OAI", pidsArr[0]));
|
543
|
}
|
544
|
/*
|
545
|
if (rs.getString(9) != null && !rs.getString(9).equals("")) {
|
546
|
if (rs.getString(9).contains("#!#")) {
|
547
|
reportItem.addIdentifier(new ItemIdentifier("OAI", rs.getString(9).substring(0, rs.getString(9).indexOf("#!#"))));
|
548
|
} else {
|
549
|
reportItem.addIdentifier(new ItemIdentifier("OAI", rs.getString(9)));
|
550
|
}
|
551
|
}
|
552
|
if (rs.getString(6) != null && !rs.getString(6).equals("")) {
|
553
|
if (rs.getString(6).contains("#!#")) {
|
554
|
reportItem.addIdentifier(new ItemIdentifier("DOI", rs.getString(6).substring(0, rs.getString(6).indexOf("#!#"))));
|
555
|
} else {
|
556
|
reportItem.addIdentifier(new ItemIdentifier("DOI", rs.getString(6)));
|
557
|
}
|
558
|
}
|
559
|
*/
|
560
|
ft_total = 0;
|
561
|
abstr = 0;
|
562
|
}
|
563
|
ft_total += rs.getInt(10);
|
564
|
abstr += rs.getInt(11);
|
565
|
}
|
566
|
if (reportItem != null) {
|
567
|
reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate), Integer.toString(ft_total), Integer.toString(abstr)));
|
568
|
reportItems.add(reportItem);
|
569
|
}
|
570
|
} else if (granularity.equalsIgnoreCase("monthly")) {
|
571
|
Calendar endCal = Calendar.getInstance();
|
572
|
endCal.setTime(postgresFormat.parse(endDateStr));
|
573
|
endCal.add(Calendar.MONTH, 1);
|
574
|
Date endDateForZeros = endCal.getTime();
|
575
|
while (rs.next()) {
|
576
|
if (!rs.getString(1).equals(repository)) {
|
577
|
if (reportItem != null) {
|
578
|
fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
|
579
|
reportItems.add(reportItem);
|
580
|
}
|
581
|
repository = rs.getString(1);
|
582
|
lastDate = beginDateStr;
|
583
|
reportItem = new ReportItem(rs.getString(3), rs.getString(7), rs.getString(5), rs.getString(2));
|
584
|
reportItem.addIdentifier(new ItemIdentifier("OpenAIRE", openaire));
|
585
|
reportItem.addIdentifier(new ItemIdentifier("URLs", rs.getString(4)));
|
586
|
|
587
|
String[] oridsArr = (String[]) rs.getArray(9).getArray();
|
588
|
if (oridsArr[0] != null && !oridsArr[0].equals("")) {
|
589
|
reportItem.addIdentifier(new ItemIdentifier("OAI", oridsArr[0]));
|
590
|
}
|
591
|
String[] pidsArr = (String[]) rs.getArray(6).getArray();
|
592
|
if (pidsArr[0] != null && !pidsArr[0].equals("")) {
|
593
|
reportItem.addIdentifier(new ItemIdentifier("OAI", pidsArr[0]));
|
594
|
}
|
595
|
/*
|
596
|
if (rs.getString(9) != null && !rs.getString(9).equals("")) {
|
597
|
if (rs.getString(9).contains("#!#")) {
|
598
|
reportItem.addIdentifier(new ItemIdentifier("OAI", rs.getString(9).substring(0, rs.getString(9).indexOf("#!#"))));
|
599
|
} else {
|
600
|
reportItem.addIdentifier(new ItemIdentifier("OAI", rs.getString(9)));
|
601
|
}
|
602
|
}
|
603
|
if (rs.getString(6) != null && !rs.getString(6).equals("")) {
|
604
|
if (rs.getString(6).contains("#!#")) {
|
605
|
reportItem.addIdentifier(new ItemIdentifier("DOI", rs.getString(6).substring(0, rs.getString(6).indexOf("#!#"))));
|
606
|
} else {
|
607
|
reportItem.addIdentifier(new ItemIdentifier("DOI", rs.getString(6)));
|
608
|
}
|
609
|
}
|
610
|
*/
|
611
|
}
|
612
|
fillWithZeros(postgresFormat.parse(lastDate), postgresFormat.parse(rs.getString(8)), reportItem);
|
613
|
Calendar endC = Calendar.getInstance();
|
614
|
endC.setTime(postgresFormat.parse(rs.getString(8)));
|
615
|
endC.set(Calendar.DATE, endC.getActualMaximum(Calendar.DATE));
|
616
|
if (reportItem != null) {
|
617
|
reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(postgresFormat.parse(rs.getString(8))), report_dateFormat.format(endC.getTime()), rs.getString(10), rs.getString(11)));
|
618
|
}
|
619
|
endC.setTime(postgresFormat.parse(rs.getString(8)));
|
620
|
endC.add(Calendar.MONTH, 1);
|
621
|
lastDate = postgresFormat.format(endC.getTime());
|
622
|
}
|
623
|
if (reportItem != null) {
|
624
|
fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
|
625
|
reportItems.add(reportItem);
|
626
|
}
|
627
|
}
|
628
|
} catch (Exception e) {
|
629
|
log.error("Single Item Report failed: ", e);
|
630
|
} finally {
|
631
|
DbUtils.closeQuietly(rs);
|
632
|
DbUtils.closeQuietly(st);
|
633
|
DbUtils.closeQuietly(connection);
|
634
|
java.sql.Timestamp timestamp = new java.sql.Timestamp(System.currentTimeMillis());
|
635
|
//System.out.println("DB end "+timestamp);
|
636
|
log.info("Query end..." + timestamp);
|
637
|
|
638
|
}
|
639
|
}
|
640
|
|
641
|
public void executeRepo(List<ReportItem> reportItems, String repositoryIdentifier, String itemDataType, Date beginDate, Date endDate, String granularity) {
|
642
|
SimpleDateFormat report_dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
643
|
SimpleDateFormat postgresFormat = new SimpleDateFormat("yyyy/MM");
|
644
|
String beginDateStr = postgresFormat.format(beginDate);
|
645
|
String endDateStr = postgresFormat.format(endDate);
|
646
|
|
647
|
Connection connection = null;
|
648
|
PreparedStatement st = null;
|
649
|
ResultSet rs = null;
|
650
|
|
651
|
try {
|
652
|
connection = usageStatsDB.getConnection();
|
653
|
java.sql.Timestamp timestamp1 = new java.sql.Timestamp(System.currentTimeMillis());
|
654
|
//System.out.println("DB start "+timestamp1);
|
655
|
log.info("Query started..." + timestamp1);
|
656
|
|
657
|
if (repositoryIdentifier.equals("")) {
|
658
|
if (itemDataType.equals("")) {
|
659
|
//st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.ddate, res.downloads, res.views FROM (SELECT coalesce(ds.source, vs.source), coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.downloads_stats s WHERE s.date>=? AND s.date<=? GROUP BY s.source, s.repository_id, s.date) AS ds FULL OUTER JOIN (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.views_stats s WHERE s.date>=? AND s.date<=? GROUP BY s.source, s.repository_id, s.date) AS vs ON ds.source=vs.source AND ds.repository_id=vs.repository_id AND ds.date=vs.date) AS res JOIN public.datasource d ON d.id=res.repository_id JOIN public.datasource_oids dois ON d.id=dois.id WHERE dois.orid LIKE 'opendoar%' ORDER BY d.id, d.name, res.ddate ASC;");
|
660
|
st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.date, res.downloads, res.views FROM (SELECT us.source, us.repository_id, us.date, sum(us.downloads) AS downloads, sum(us.views) AS views FROM usage_stats us WHERE us.date>=? AND us.date<=? GROUP BY us.source, us.repository_id, us.date) AS res JOIN datasource d ON d.id=res.repository_id JOIN datasource_oids dois ON d.id=dois.id WHERE dois.orid LIKE 'opendoar%' ORDER BY d.id, d.name, res.date ASC;");
|
661
|
st.setString(1, beginDateStr);
|
662
|
st.setString(2, endDateStr);
|
663
|
//st.setString(3, beginDateStr);
|
664
|
//st.setString(4, endDateStr);
|
665
|
} else {
|
666
|
//st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.ddate, res.downloads, res.views FROM (SELECT coalesce(ds.source, vs.source), coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.downloads_stats s, result_classifications rc WHERE rc.id=s.result_id AND s.date>=? AND s.date<=? AND rc.type=? GROUP BY s.source, s.repository_id, s.date) AS ds FULL OUTER JOIN (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.views_stats s, public.result_classifications rc WHERE rc.id=s.result_id AND s.date>=? AND s.date<=? AND rc.type=? GROUP BY s.source, s.repository_id, s.date) AS vs ON ds.source=vs.source AND ds.repository_id=vs.repository_id AND ds.date=vs.date) AS res JOIN public.datasource d ON d.id=res.repository_id JOIN public.datasource_oids dois ON d.id=dois.id WHERE dois.orid LIKE 'opendoar%' ORDER BY d.id, d.name, res.ddate ASC;");
|
667
|
st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.date, res.downloads, res.views FROM (SELECT us.source, us.repository_id, us.date, sum(us.downloads) AS downloads, sum(us.views) AS views FROM usage_stats us, result_classifications rc WHERE rc.id=us.result_id AND us.date>=? AND us.date<=? AND rc.type=? GROUP BY us.source, us.repository_id, us.date) AS res JOIN datasource d ON d.id=res.repository_id JOIN datasource_oids dois ON d.id=dois.id WHERE dois.orid LIKE 'opendoar%' ORDER BY d.id, d.name, res.date ASC;");
|
668
|
st.setString(1, beginDateStr);
|
669
|
st.setString(2, endDateStr);
|
670
|
st.setString(3, itemDataType);
|
671
|
//st.setString(4, beginDateStr);
|
672
|
//st.setString(5, endDateStr);
|
673
|
//st.setString(6, itemDataType);
|
674
|
}
|
675
|
} else {
|
676
|
if (itemDataType.equals("")) {
|
677
|
//st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.ddate, res.downloads, res.views FROM (SELECT coalesce(ds.source, vs.source), coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.downloads_stats s WHERE s.date>=? AND s.date<=? AND s.repository_id=? GROUP BY s.source, s.repository_id, s.date) AS ds FULL OUTER JOIN (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.views_stats s WHERE s.date>=? AND s.date<=? AND s.repository_id=? GROUP BY s.source, s.repository_id, s.date) AS vs ON ds.source=vs.source AND ds.repository_id=vs.repository_id AND ds.date=vs.date) AS res JOIN public.datasource d ON d.id=res.repository_id JOIN public.datasource_oids dois ON d.id=dois.id WHERE dois.orid LIKE 'opendoar%' ORDER BY d.id, d.name, res.ddate ASC;");
|
678
|
st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.date, res.downloads, res.views FROM (SELECT us.source, us.repository_id, us.date, sum(us.downloads) AS downloads, sum(us.views) AS views FROM usage_stats us WHERE us.date>=? AND us.date<=? AND us.repository_id=? GROUP BY us.source, us.repository_id, us.date) AS res JOIN datasource d ON d.id=res.repository_id JOIN datasource_oids dois ON d.id=dois.id WHERE dois.orid LIKE 'opendoar%' ORDER BY d.id, d.name, res.date ASC;");
|
679
|
st.setString(1, beginDateStr);
|
680
|
st.setString(2, endDateStr);
|
681
|
st.setString(3, repositoryIdentifier);
|
682
|
//st.setString(4, beginDateStr);
|
683
|
//st.setString(5, endDateStr);
|
684
|
//st.setString(6, repositoryIdentifier);
|
685
|
} else {
|
686
|
//st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.ddate, res.downloads, res.views FROM (SELECT coalesce(ds.source, vs.source), coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.downloads_stats s, public.result_classifications rc WHERE rc.id=s.result_id AND s.date>=? AND s.date<=? AND rc.type=? AND s.repository_id=? GROUP BY s.source, s.repository_id, s.date) AS ds FULL OUTER JOIN (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.views_stats s, public.result_classifications rc WHERE rc.id=s.result_id AND s.date>=? AND s.date<=? AND rc.type=? AND s.repository_id=? GROUP BY s.source, s.repository_id, s.date) AS vs ON ds.source=vs.source AND ds.repository_id=vs.repository_id AND ds.date=vs.date) AS res JOIN public.datasource d ON d.id=res.repository_id JOIN public.datasource_oids dois ON d.id=dois.id WHERE dois.orid LIKE 'opendoar%' ORDER BY d.id, d.name, res.ddate ASC;");
|
687
|
st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.date, res.downloads, res.views FROM (SELECT us.source, us.repository_id, us.date, sum(us.downloads) AS downloads, sum(us.views) AS views FROM usage_stats us, result_classifications rc WHERE rc.id=us.result_id AND us.date>=? AND us.date<=? AND rc.type=? AND us.repository_id=? GROUP BY us.source, us.repository_id, us.date) AS res JOIN datasource d ON d.id=res.repository_id JOIN datasource_oids dois ON d.id=dois.id WHERE dois.orid LIKE 'opendoar%' ORDER BY d.id, d.name, res.date ASC;");
|
688
|
st.setString(1, beginDateStr);
|
689
|
st.setString(2, endDateStr);
|
690
|
st.setString(3, itemDataType);
|
691
|
st.setString(4, repositoryIdentifier);
|
692
|
//st.setString(5, beginDateStr);
|
693
|
//st.setString(6, endDateStr);
|
694
|
//st.setString(7, itemDataType);
|
695
|
//st.setString(8, repositoryIdentifier);
|
696
|
}
|
697
|
}
|
698
|
//log.error("RR STATEMENT: " + st);
|
699
|
|
700
|
/*
|
701
|
String redis_key = MD5(st.toString());
|
702
|
|
703
|
if (jedis.hasKey(redis_key, "result")) {
|
704
|
reportItems.addAll(reportItemsFromJson((String) jedis.get(redis_key, "result")));
|
705
|
st.close();
|
706
|
connection.close();
|
707
|
return;
|
708
|
}
|
709
|
*/
|
710
|
rs = st.executeQuery();
|
711
|
String repository = "";
|
712
|
String lastDate = "";
|
713
|
ReportItem reportItem = null;
|
714
|
|
715
|
/*
|
716
|
Calendar startCalendar = Calendar.getInstance();
|
717
|
startCalendar.setTime(beginDate);
|
718
|
Calendar endCalendar = Calendar.getInstance();
|
719
|
endCalendar.setTime(endDate);
|
720
|
*/
|
721
|
int ft_total = 0;
|
722
|
int abstr = 0;
|
723
|
if (granularity.equalsIgnoreCase("totals")) {
|
724
|
while (rs.next()) {
|
725
|
if (!rs.getString(1).equals(repository)) {
|
726
|
if (reportItem != null) {
|
727
|
reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate), Integer.toString(ft_total), Integer.toString(abstr)));
|
728
|
reportItems.add(reportItem);
|
729
|
}
|
730
|
repository = rs.getString(1);
|
731
|
reportItem = new ReportItem(null, rs.getString(2), "Platform", null);
|
732
|
reportItem.addIdentifier(new ItemIdentifier("OpenAIRE", rs.getString(1)));
|
733
|
reportItem.addIdentifier(new ItemIdentifier("OpenDOAR", rs.getString(4).substring(rs.getString(4).lastIndexOf(":") + 1)));
|
734
|
reportItem.addIdentifier(new ItemIdentifier("URL", rs.getString(3)));
|
735
|
ft_total = 0;
|
736
|
abstr = 0;
|
737
|
}
|
738
|
ft_total += rs.getInt(6);
|
739
|
abstr += rs.getInt(7);
|
740
|
}
|
741
|
if (reportItem != null) {
|
742
|
reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate), Integer.toString(ft_total), Integer.toString(abstr)));
|
743
|
reportItems.add(reportItem);
|
744
|
}
|
745
|
} else if (granularity.equalsIgnoreCase("monthly")) {
|
746
|
Calendar endCal = Calendar.getInstance();
|
747
|
endCal.setTime(postgresFormat.parse(endDateStr));
|
748
|
endCal.add(Calendar.MONTH, 1);
|
749
|
Date endDateForZeros = endCal.getTime();
|
750
|
while (rs.next()) {
|
751
|
if (!rs.getString(1).equals(repository)) {
|
752
|
if (reportItem != null) {
|
753
|
fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
|
754
|
reportItems.add(reportItem);
|
755
|
}
|
756
|
repository = rs.getString(1);
|
757
|
lastDate = beginDateStr;
|
758
|
reportItem = new ReportItem(null, rs.getString(2), "Platform", null);
|
759
|
reportItem.addIdentifier(new ItemIdentifier("OpenAIRE", rs.getString(1)));
|
760
|
reportItem.addIdentifier(new ItemIdentifier("OpenDOAR", rs.getString(4).substring(rs.getString(4).lastIndexOf(":") + 1)));
|
761
|
reportItem.addIdentifier(new ItemIdentifier("URL", rs.getString(3)));
|
762
|
}
|
763
|
fillWithZeros(postgresFormat.parse(lastDate), postgresFormat.parse(rs.getString(5)), reportItem);
|
764
|
Calendar endC = Calendar.getInstance();
|
765
|
endC.setTime(postgresFormat.parse(rs.getString(5)));
|
766
|
endC.set(Calendar.DATE, endC.getActualMaximum(Calendar.DATE));
|
767
|
if (reportItem != null) {
|
768
|
reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(postgresFormat.parse(rs.getString(5))), report_dateFormat.format(endC.getTime()), rs.getString(6), rs.getString(7)));
|
769
|
}
|
770
|
endC.setTime(postgresFormat.parse(rs.getString(5)));
|
771
|
endC.add(Calendar.MONTH, 1);
|
772
|
lastDate = postgresFormat.format(endC.getTime());
|
773
|
}
|
774
|
if (reportItem != null) {
|
775
|
fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
|
776
|
reportItems.add(reportItem);
|
777
|
}
|
778
|
}
|
779
|
|
780
|
/*
|
781
|
jedis.put(redis_key, "persistent", "false");
|
782
|
jedis.put(redis_key, "query", st.toString());
|
783
|
jedis.put(redis_key, "result", toJson(reportItems));
|
784
|
jedis.put(redis_key, "fetchMode", "3");
|
785
|
*/
|
786
|
rs.close();
|
787
|
st.close();
|
788
|
connection.close();
|
789
|
} catch (Exception e) {
|
790
|
log.error("Repository Report failed: ", e);
|
791
|
} finally {
|
792
|
DbUtils.closeQuietly(rs);
|
793
|
DbUtils.closeQuietly(st);
|
794
|
DbUtils.closeQuietly(connection);
|
795
|
java.sql.Timestamp timestamp = new java.sql.Timestamp(System.currentTimeMillis());
|
796
|
//System.out.println("DB end "+timestamp);
|
797
|
log.info("Query end..." + timestamp);
|
798
|
|
799
|
}
|
800
|
}
|
801
|
|
802
|
public void executeJournal(List<ReportItem> reportItems, String repositoryIdentifier, String itemDataType, Date beginDate, Date endDate, String granularity) {
|
803
|
SimpleDateFormat report_dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
804
|
SimpleDateFormat postgresFormat = new SimpleDateFormat("yyyy/MM");
|
805
|
String beginDateStr = postgresFormat.format(beginDate);
|
806
|
String endDateStr = postgresFormat.format(endDate);
|
807
|
|
808
|
Connection connection = null;
|
809
|
PreparedStatement st = null;
|
810
|
ResultSet rs = null;
|
811
|
|
812
|
try {
|
813
|
connection = usageStatsDB.getConnection();
|
814
|
java.sql.Timestamp timestamp1 = new java.sql.Timestamp(System.currentTimeMillis());
|
815
|
//System.out.println("DB start "+timestamp1);
|
816
|
log.info("Query started..." + timestamp1);
|
817
|
|
818
|
if (repositoryIdentifier.equals("")) {
|
819
|
if (itemDataType.equals("")) {
|
820
|
//st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.ddate, res.downloads, res.views FROM (SELECT coalesce(ds.source, vs.source), coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.downloads_stats s WHERE s.date>=? AND s.date<=? GROUP BY s.source, s.repository_id, s.date) AS ds FULL OUTER JOIN (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.views_stats s WHERE s.date>=? AND s.date<=? GROUP BY s.source, s.repository_id, s.date) AS vs ON ds.source=vs.source AND ds.repository_id=vs.repository_id AND ds.date=vs.date) AS res JOIN public.datasource d ON d.id=res.repository_id JOIN public.datasource_oids dois ON d.id=dois.id WHERE (d.type='Journal' OR d.type='Journal Aggregator/Publisher') ORDER BY d.id, d.name, res.ddate ASC;");
|
821
|
st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.date, res.downloads, res.views FROM (SELECT us.source, us.repository_id, us.date, sum(us.downloads) as downloads, sum(us.views) as views FROM usage_stats us WHERE us.date>=? AND us.date<=? GROUP BY us.source, us.repository_id, us.date) AS res JOIN datasource d ON d.id=res.repository_id JOIN datasource_oids dois ON d.id=dois.id WHERE (d.type='Journal' OR d.type='Journal Aggregator/Publisher') ORDER BY d.id, d.name, res.date ASC;");
|
822
|
st.setString(1, beginDateStr);
|
823
|
st.setString(2, endDateStr);
|
824
|
//st.setString(3, beginDateStr);
|
825
|
//st.setString(4, endDateStr);
|
826
|
} else {
|
827
|
//st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.ddate, res.downloads, res.views FROM (SELECT coalesce(ds.source, vs.source), coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.downloads_stats s, public.result_classifications rc WHERE rc.id=s.result_id AND s.date>=? AND s.date<=? AND rc.type=? GROUP BY s.source, s.repository_id, s.date) AS ds FULL OUTER JOIN (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.views_stats s, public.result_classifications rc WHERE rc.id=s.result_id AND s.date>=? AND s.date<=? AND rc.type=? GROUP BY s.source, s.repository_id, s.date) AS vs ON ds.source=vs.source AND ds.repository_id=vs.repository_id AND ds.date=vs.date) AS res JOIN public.datasource d ON d.id=res.repository_id JOIN public.datasource_oids dois ON d.id=dois.id WHERE (d.type='Journal' OR d.type='Journal Aggregator/Publisher') ORDER BY d.id, d.name, res.ddate ASC;");
|
828
|
st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.date, res.downloads, res.views FROM (SELECT us.source, us.repository_id, us.date, sum(us.downloads) as downloads, sum(us.views) as views FROM usage_stats us, result_classifications rc WHERE rc.id=us.result_id AND us.date>=? AND us.date<=? AND rc.type=? GROUP BY us.source, us.repository_id, us.date) AS res JOIN datasource d ON d.id=res.repository_id JOIN datasource_oids dois ON d.id=dois.id WHERE (d.type='Journal' OR d.type='Journal Aggregator/Publisher') ORDER BY d.id, d.name, res.date ASC;");
|
829
|
st.setString(1, beginDateStr);
|
830
|
st.setString(2, endDateStr);
|
831
|
st.setString(3, itemDataType);
|
832
|
//st.setString(4, beginDateStr);
|
833
|
//st.setString(5, endDateStr);
|
834
|
//st.setString(6, itemDataType);
|
835
|
}
|
836
|
} else {
|
837
|
if (itemDataType.equals("")) {
|
838
|
//st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.ddate, res.downloads, res.views FROM (SELECT coalesce(ds.source, vs.source), coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.downloads_stats s WHERE s.date>=? AND s.date<=? AND s.repository_id=? GROUP BY s.source, s.repository_id, s.date) AS ds FULL OUTER JOIN (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.views_stats s WHERE s.date>=? AND s.date<=? AND s.repository_id=? GROUP BY s.source, s.repository_id, s.date) AS vs ON ds.source=vs.source AND ds.repository_id=vs.repository_id AND ds.date=vs.date) AS res JOIN public.datasource d ON d.id=res.repository_id JOIN public.datasource_oids dois ON d.id=dois.id WHERE (d.type='Journal' OR d.type='Journal Aggregator/Publisher') ORDER BY d.id, d.name, res.ddate ASC;");
|
839
|
st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.date, res.downloads, res.views FROM (SELECT us.source, us.repository_id, us.date, sum(us.downloads) as downloads, sum(us.views) as views FROM usage_stats us WHERE us.date>=? AND us.date<=? AND us.repository_id=? GROUP BY us.source, us.repository_id, us.date) AS res JOIN datasource d ON d.id=res.repository_id JOIN datasource_oids dois ON d.id=dois.id WHERE (d.type='Journal' OR d.type='Journal Aggregator/Publisher') ORDER BY d.id, d.name, res.date ASC;");
|
840
|
st.setString(1, beginDateStr);
|
841
|
st.setString(2, endDateStr);
|
842
|
st.setString(3, repositoryIdentifier);
|
843
|
//st.setString(4, beginDateStr);
|
844
|
//st.setString(5, endDateStr);
|
845
|
//st.setString(6, repositoryIdentifier);
|
846
|
} else {
|
847
|
//st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.ddate, res.downloads, res.views FROM (SELECT coalesce(ds.source, vs.source), coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.downloads_stats s, public.result_classifications rc WHERE rc.id=s.result_id AND s.date>=? AND s.date<=? AND rc.type=? AND s.repository_id=? GROUP BY s.source, s.repository_id, s.date) AS ds FULL OUTER JOIN (SELECT s.source, s.repository_id, s.date, sum(s.count) FROM public.views_stats s, public.result_classifications rc WHERE rc.id=s.result_id AND s.date>=? AND s.date<=? AND rc.type=? AND s.repository_id=? GROUP BY s.source, s.repository_id, s.date) AS vs ON ds.source=vs.source AND ds.repository_id=vs.repository_id AND ds.date=vs.date) AS res JOIN public.datasource d ON d.id=res.repository_id JOIN public.datasource_oids dois ON d.id=dois.id WHERE (d.type='Journal' OR d.type='Journal Aggregator/Publisher') ORDER BY d.id, d.name, res.ddate ASC;");
|
848
|
st = connection.prepareStatement("SELECT d.id, d.name, d.websiteurl, dois.orid, res.date, res.downloads, res.views FROM (SELECT us.source, us.repository_id, us.date, sum(us.downloads) as downloads, sum(us.views) as views FROM usage_stats us, result_classifications rc WHERE rc.id=us.result_id AND us.date>=? AND us.date<=? AND rc.type=? AND us.repository_id=? GROUP BY us.source, us.repository_id, us.date) AS res JOIN datasource d ON d.id=res.repository_id JOIN datasource_oids dois ON d.id=dois.id WHERE (d.type='Journal' OR d.type='Journal Aggregator/Publisher') ORDER BY d.id, d.name, res.date ASC;");
|
849
|
st.setString(1, beginDateStr);
|
850
|
st.setString(2, endDateStr);
|
851
|
st.setString(3, itemDataType);
|
852
|
st.setString(4, repositoryIdentifier);
|
853
|
//st.setString(5, beginDateStr);
|
854
|
//st.setString(6, endDateStr);
|
855
|
//st.setString(7, itemDataType);
|
856
|
//st.setString(8, repositoryIdentifier);
|
857
|
}
|
858
|
}
|
859
|
//log.error("RR STATEMENT: " + st);
|
860
|
|
861
|
/*
|
862
|
String redis_key = MD5(st.toString());
|
863
|
|
864
|
if (jedis.hasKey(redis_key, "result")) {
|
865
|
reportItems.addAll(reportItemsFromJson((String) jedis.get(redis_key, "result")));
|
866
|
st.close();
|
867
|
connection.close();
|
868
|
return;
|
869
|
}
|
870
|
*/
|
871
|
rs = st.executeQuery();
|
872
|
String repository = "";
|
873
|
String lastDate = "";
|
874
|
ReportItem reportItem = null;
|
875
|
|
876
|
/*
|
877
|
Calendar startCalendar = Calendar.getInstance();
|
878
|
startCalendar.setTime(beginDate);
|
879
|
Calendar endCalendar = Calendar.getInstance();
|
880
|
endCalendar.setTime(endDate);
|
881
|
*/
|
882
|
int ft_total = 0;
|
883
|
int abstr = 0;
|
884
|
if (granularity.equalsIgnoreCase("totals")) {
|
885
|
while (rs.next()) {
|
886
|
if (!rs.getString(1).equals(repository)) {
|
887
|
if (reportItem != null) {
|
888
|
reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate), Integer.toString(ft_total), Integer.toString(abstr)));
|
889
|
reportItems.add(reportItem);
|
890
|
}
|
891
|
repository = rs.getString(1);
|
892
|
reportItem = new ReportItem(null, rs.getString(2), "Platform", null);
|
893
|
reportItem.addIdentifier(new ItemIdentifier("OpenAIRE", rs.getString(1)));
|
894
|
reportItem.addIdentifier(new ItemIdentifier("ISSN", rs.getString(4).substring(rs.getString(4).lastIndexOf(":") + 1)));
|
895
|
if (rs.getString(3) != null) {
|
896
|
reportItem.addIdentifier(new ItemIdentifier("URL", rs.getString(3)));
|
897
|
}
|
898
|
ft_total = 0;
|
899
|
abstr = 0;
|
900
|
}
|
901
|
ft_total += rs.getInt(6);
|
902
|
abstr += rs.getInt(7);
|
903
|
}
|
904
|
if (reportItem != null) {
|
905
|
reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate), Integer.toString(ft_total), Integer.toString(abstr)));
|
906
|
reportItems.add(reportItem);
|
907
|
}
|
908
|
} else if (granularity.equalsIgnoreCase("monthly")) {
|
909
|
Calendar endCal = Calendar.getInstance();
|
910
|
endCal.setTime(postgresFormat.parse(endDateStr));
|
911
|
endCal.add(Calendar.MONTH, 1);
|
912
|
Date endDateForZeros = endCal.getTime();
|
913
|
while (rs.next()) {
|
914
|
if (!rs.getString(1).equals(repository)) {
|
915
|
if (reportItem != null) {
|
916
|
fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
|
917
|
reportItems.add(reportItem);
|
918
|
}
|
919
|
repository = rs.getString(1);
|
920
|
lastDate = beginDateStr;
|
921
|
reportItem = new ReportItem(null, rs.getString(2), "Platform", null);
|
922
|
reportItem.addIdentifier(new ItemIdentifier("OpenAIRE", rs.getString(1)));
|
923
|
reportItem.addIdentifier(new ItemIdentifier("ISSN", rs.getString(4).substring(rs.getString(4).lastIndexOf(":") + 1)));
|
924
|
if (rs.getString(3) != null) {
|
925
|
reportItem.addIdentifier(new ItemIdentifier("URL", rs.getString(3)));
|
926
|
}
|
927
|
}
|
928
|
fillWithZeros(postgresFormat.parse(lastDate), postgresFormat.parse(rs.getString(5)), reportItem);
|
929
|
Calendar endC = Calendar.getInstance();
|
930
|
endC.setTime(postgresFormat.parse(rs.getString(5)));
|
931
|
endC.set(Calendar.DATE, endC.getActualMaximum(Calendar.DATE));
|
932
|
if (reportItem != null) {
|
933
|
reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(postgresFormat.parse(rs.getString(5))), report_dateFormat.format(endC.getTime()), rs.getString(6), rs.getString(7)));
|
934
|
}
|
935
|
endC.setTime(postgresFormat.parse(rs.getString(5)));
|
936
|
endC.add(Calendar.MONTH, 1);
|
937
|
lastDate = postgresFormat.format(endC.getTime());
|
938
|
}
|
939
|
if (reportItem != null) {
|
940
|
fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
|
941
|
reportItems.add(reportItem);
|
942
|
}
|
943
|
}
|
944
|
|
945
|
/*
|
946
|
jedis.put(redis_key, "persistent", "false");
|
947
|
jedis.put(redis_key, "query", st.toString());
|
948
|
jedis.put(redis_key, "result", toJson(reportItems));
|
949
|
jedis.put(redis_key, "fetchMode", "3");
|
950
|
*/
|
951
|
rs.close();
|
952
|
st.close();
|
953
|
connection.close();
|
954
|
} catch (Exception e) {
|
955
|
log.error("Repository Report failed: ", e);
|
956
|
} finally {
|
957
|
DbUtils.closeQuietly(rs);
|
958
|
DbUtils.closeQuietly(st);
|
959
|
DbUtils.closeQuietly(connection);
|
960
|
java.sql.Timestamp timestamp = new java.sql.Timestamp(System.currentTimeMillis());
|
961
|
//System.out.println("DB end "+timestamp);
|
962
|
log.info("Query end..." + timestamp);
|
963
|
|
964
|
}
|
965
|
}
|
966
|
|
967
|
public void executeBatchItems(List<ReportItem> reportItems, String repositoryIdentifier, String itemDataType, Date beginDate, Date endDate, String granularity) {
|
968
|
SimpleDateFormat report_dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
969
|
SimpleDateFormat postgresFormat = new SimpleDateFormat("yyyy/MM");
|
970
|
String beginDateStr = postgresFormat.format(beginDate);
|
971
|
String endDateStr = postgresFormat.format(endDate);
|
972
|
|
973
|
Connection connection = null;
|
974
|
PreparedStatement st = null;
|
975
|
ResultSet rs = null;
|
976
|
|
977
|
try {
|
978
|
connection = usageStatsDB.getConnection();
|
979
|
java.sql.Timestamp timestamp1 = new java.sql.Timestamp(System.currentTimeMillis());
|
980
|
//System.out.println("DB start "+timestamp1);
|
981
|
log.info("Query started..." + timestamp1);
|
982
|
if (itemDataType.equals("")) {
|
983
|
//st = connection.prepareStatement("SELECT res.result_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.ddate, oids.orid, res.downloads, res.views FROM (SELECT coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.result_id, vs.result_id) AS result_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.downloads_stats s WHERE s.date>=? AND s.date<=? AND s.repository_id=? GROUP BY s.repository_id, s.result_id, s.date) AS ds FULL OUTER JOIN (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.views_stats s WHERE s.date>=? AND s.date<=? AND s.repository_id=? GROUP BY s.repository_id, s.result_id, s.date) AS vs ON ds.result_id=vs.result_id AND ds.date=vs.date) AS res JOIN public.result r ON res.result_id=r.id JOIN public.datasource d ON d.id=res.repository_id JOIN public.result_classifications rc ON rc.id=r.id LEFT JOIN (SELECT pids.id, string_agg(pids.pid, '#!#') AS pid FROM public.result_pids pids, public.result_datasources rd WHERE rd.id=pids.id AND type='doi' AND rd.datasource=? GROUP BY pids.id) AS pids ON pids.id=r.id LEFT JOIN (SELECT oids.id, string_agg(oids.orid, '#!#') AS orid FROM public.result_oids oids, public.result_datasources rd WHERE rd.id=oids.id AND rd.datasource=? GROUP BY oids.id) AS oids ON oids.id=r.id ORDER BY res.result_id, res.ddate;");
|
984
|
//st = connection.prepareStatement("SELECT res.result_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.date, oids.orid, res.downloads, res.views FROM (SELECT us.repository_id, us.result_id, us.date, sum(us.downloads) as downloads, sum(us.views) as views FROM usage_stats us WHERE us.date>=? AND us.date<=? AND us.repository_id=? GROUP BY us.repository_id, us.result_id, us.date) AS res JOIN result r ON res.result_id=r.id JOIN datasource d ON d.id=res.repository_id JOIN result_classifications rc ON rc.id=r.id LEFT JOIN (SELECT pids.id, string_agg(pids.pid, '#!#') AS pid FROM result_pids pids, result_datasources rd WHERE rd.id=pids.id AND type='doi' AND rd.datasource=? GROUP BY pids.id) AS pids ON pids.id=r.id LEFT JOIN (SELECT oids.id, string_agg(oids.orid, '#!#') AS orid FROM result_oids oids, result_datasources rd WHERE rd.id=oids.id AND rd.datasource=? GROUP BY oids.id) AS oids ON oids.id=r.id ORDER BY res.result_id, res.date;");
|
985
|
//st = connection.prepareStatement("SELECT us.original_result_id, r.title, r.publisher, r.source, rc.type, string_agg(distinct pids.pid, '#!#') as pid, d.name, us.date, string_agg(distinct oids.orid, '#!#') AS orid , sum(us.downloads) as downloads, sum(us.views) as views FROM usage_stats us JOIN result r ON us.result_id=r.id JOIN datasource d ON d.id=us.repository_id LEFT OUTER JOIN result_classifications rc ON rc.id=r.id LEFT OUTER JOIN result_pids pids on pids.id=r.id LEFT OUTER JOIN result_oids oids on oids.id=r.id WHERE us.date>=? AND us.date<=? AND us.repository_id=? GROUP BY us.original_result_id, r.title, r.publisher, r.source, rc.type, d.name, us.date;");
|
986
|
st = connection.prepareStatement("SELECT original_result_id, re.title, re.publisher, re.source, rc.type, pid, name, date, orid, sum(downloads) as downloads, sum(views) as views FROM reports re, result r, result_classifications rc WHERE original_result_id=r.original_id and rc.id=r.id and date>=? AND date<=? AND repository_id=? GROUP BY original_result_id, re.title, re.publisher, pid, orid, re.source, rc.type, name, date;");
|
987
|
st.setString(1, beginDateStr);
|
988
|
st.setString(2, endDateStr);
|
989
|
st.setString(3, repositoryIdentifier);
|
990
|
//st.setString(4, beginDateStr);
|
991
|
//st.setString(5, endDateStr);
|
992
|
//st.setString(6, repositoryIdentifier);
|
993
|
//st.setString(4, repositoryIdentifier);
|
994
|
//st.setString(5, repositoryIdentifier);
|
995
|
} else {
|
996
|
//st = connection.prepareStatement("SELECT res.result_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.ddate, oids.orid, res.downloads, res.views FROM (SELECT coalesce(ds.repository_id, vs.repository_id) AS repository_id, coalesce(ds.result_id, vs.result_id) AS result_id, coalesce(ds.date, vs.date) AS ddate, coalesce(ds.sum, 0) AS downloads, coalesce(vs.sum,0) AS views FROM (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.downloads_stats s WHERE s.date>=? AND s.date<=? AND s.repository_id=? GROUP BY s.repository_id, s.result_id, s.date) AS ds FULL OUTER JOIN (SELECT s.repository_id, s.result_id, s.date, sum(s.count) FROM public.views_stats s WHERE s.date>=? AND s.date<=? AND s.repository_id=? GROUP BY s.repository_id, s.result_id, s.date) AS vs ON ds.result_id=vs.result_id AND ds.date=vs.date) AS res JOIN public.result r ON res.result_id=r.id JOIN public.datasource d ON d.id=res.repository_id JOIN public.result_classifications rc ON rc.id=r.id LEFT JOIN (SELECT pids.id, string_agg(pids.pid, '#!#') AS pid FROM public.result_pids pids, result_datasources rd WHERE rd.id=pids.id AND type='doi' AND rd.datasource=? GROUP BY pids.id) AS pids ON pids.id=r.id LEFT JOIN (SELECT oids.id, string_agg(oids.orid, '#!#') AS orid FROM public.result_oids oids, public.result_datasources rd WHERE rd.id=oids.id AND rd.datasource=? GROUP BY oids.id) AS oids ON oids.id=r.id WHERE rc.type=? ORDER BY res.result_id, res.ddate;");
|
997
|
//st = connection.prepareStatement("SELECT res.result_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.date, oids.orid, res.downloads, res.views FROM (SELECT us.repository_id, us.result_id, us.date, sum(us.downloads) as downloads, sum(us.views) as views FROM public.usage_stats us WHERE us.date>=? AND us.date<=? AND us.repository_id=? GROUP BY us.repository_id, us.result_id, us.date) AS res JOIN public.result r ON res.result_id=r.id JOIN public.datasource d ON d.id=res.repository_id JOIN public.result_classifications rc ON rc.id=r.id LEFT JOIN (SELECT pids.id, string_agg(pids.pid, '#!#') AS pid FROM public.result_pids pids, result_datasources rd WHERE rd.id=pids.id AND type='doi' AND rd.datasource=? GROUP BY pids.id) AS pids ON pids.id=r.id LEFT JOIN (SELECT oids.id, string_agg(oids.orid, '#!#') AS orid FROM public.result_oids oids, public.result_datasources rd WHERE rd.id=oids.id AND rd.datasource=? GROUP BY oids.id) AS oids ON oids.id=r.id WHERE rc.type=? ORDER BY res.result_id, res.date;");
|
998
|
//st = connection.prepareStatement("SELECT res.result_id, r.title, r.publisher, r.source, rc.type, pids.pid, d.name, res.date, oids.orid, res.downloads, res.views FROM (SELECT us.repository_id, us.result_id, us.date, sum(us.downloads) as downloads, sum(us.views) as views FROM usage_stats us WHERE us.date>=? AND us.date<=? AND us.repository_id=? GROUP BY us.repository_id, us.result_id, us.date) AS res JOIN result r ON res.result_id=r.id JOIN datasource d ON d.id=res.repository_id JOIN result_classifications rc ON rc.id=r.id LEFT JOIN (SELECT pids.id, string_agg(pids.pid, '#!#') AS pid FROM result_pids pids, result_datasources rd WHERE rd.id=pids.id AND type='doi' AND rd.datasource=? GROUP BY pids.id) AS pids ON pids.id=r.id LEFT JOIN (SELECT oids.id, string_agg(oids.orid, '#!#') AS orid FROM result_oids oids, result_datasources rd WHERE rd.id=oids.id AND rd.datasource=? GROUP BY oids.id) AS oids ON oids.id=r.id WHERE rc.type=? ORDER BY res.result_id, res.date;");
|
999
|
//st = connection.prepareStatement("SELECT us.original_result_id, r.title, r.publisher, r.source, rc.type, string_agg(distinct pids.pid, '#!#') as pid, d.name, us.date, string_agg(distinct oids.orid, '#!#') AS orid , sum(us.downloads) as downloads, sum(us.views) as views FROM usage_stats us JOIN result r ON us.result_id=r.id JOIN datasource d ON d.id=us.repository_id JOIN result_classifications rc ON rc.id=r.id LEFT OUTER JOIN result_pids pids on pids.id=r.id LEFT OUTER JOIN result_oids oids on oids.id=r.id WHERE us.date>=? AND us.date<=? AND us.repository_id=? AND rc.type=? GROUP BY us.original_result_id, r.title, r.publisher, r.source, rc.type, d.name, us.date;");
|
1000
|
st = connection.prepareStatement("SELECT original_result_id, re.title, re.publisher, re.source, rc.type, pid, name, date, orid, sum(downloads) as downloads, sum(views) as views FROM reports re, result r, result_classifications rc WHERE original_result_id=r.original_id and rc.id=r.id and date>=? AND date<=? AND repository_id=? and rc.type=? GROUP BY original_result_id, re.title, re.publisher, pid, orid, re.source, rc.type, name, date;");
|
1001
|
st.setString(1, beginDateStr);
|
1002
|
st.setString(2, endDateStr);
|
1003
|
st.setString(3, repositoryIdentifier);
|
1004
|
//st.setString(4, beginDateStr);
|
1005
|
//st.setString(5, endDateStr);
|
1006
|
//st.setString(6, repositoryIdentifier);
|
1007
|
st.setString(4, itemDataType);
|
1008
|
}
|
1009
|
//log.error("IR STATEMENT: " + st);
|
1010
|
|
1011
|
/*
|
1012
|
String redis_key = MD5(st.toString());
|
1013
|
|
1014
|
if (jedis.hasKey(redis_key, "result")) {
|
1015
|
reportItems.addAll(reportItemsFromJson((String) jedis.get(redis_key, "result")));
|
1016
|
st.close();
|
1017
|
connection.close();
|
1018
|
return;
|
1019
|
}
|
1020
|
*/
|
1021
|
//connection.setAutoCommit(false);
|
1022
|
//st.setFetchSize(5000);
|
1023
|
rs = st.executeQuery();
|
1024
|
String result = "";
|
1025
|
String lastDate = "";
|
1026
|
ReportItem reportItem = null;
|
1027
|
|
1028
|
int ft_total = 0;
|
1029
|
int abstr = 0;
|
1030
|
if (granularity.equalsIgnoreCase("totals")) {
|
1031
|
while (rs.next()) {
|
1032
|
if (!rs.getString(1).equals(result)) {
|
1033
|
if (reportItem != null) {
|
1034
|
reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate), Integer.toString(ft_total), Integer.toString(abstr)));
|
1035
|
reportItems.add(reportItem);
|
1036
|
}
|
1037
|
result = rs.getString(1);
|
1038
|
reportItem = new ReportItem(rs.getString(3), rs.getString(7), rs.getString(5), rs.getString(2));
|
1039
|
reportItem.addIdentifier(new ItemIdentifier("OpenAIRE", rs.getString(1)));
|
1040
|
reportItem.addIdentifier(new ItemIdentifier("URLs", rs.getString(4)));
|
1041
|
|
1042
|
String[] oridsArr = (String[]) rs.getArray(9).getArray();
|
1043
|
if (oridsArr[0] != null && !oridsArr[0].equals("")) {
|
1044
|
reportItem.addIdentifier(new ItemIdentifier("OAI", oridsArr[0]));
|
1045
|
}
|
1046
|
String[] pidsArr = (String[]) rs.getArray(6).getArray();
|
1047
|
if (pidsArr[0] != null && !pidsArr[0].equals("")) {
|
1048
|
reportItem.addIdentifier(new ItemIdentifier("OAI", pidsArr[0]));
|
1049
|
}
|
1050
|
/*
|
1051
|
if (rs.getString(9) != null && !rs.getString(9).equals("")) {
|
1052
|
if (rs.getString(9).contains("#!#")) {
|
1053
|
reportItem.addIdentifier(new ItemIdentifier("OAI", rs.getString(9).substring(0, rs.getString(9).indexOf("#!#"))));
|
1054
|
} else {
|
1055
|
reportItem.addIdentifier(new ItemIdentifier("OAI", rs.getString(9)));
|
1056
|
}
|
1057
|
}
|
1058
|
if (rs.getString(6) != null && !rs.getString(6).equals("")) {
|
1059
|
if (rs.getString(6).contains("#!#")) {
|
1060
|
reportItem.addIdentifier(new ItemIdentifier("DOI", rs.getString(6).substring(0, rs.getString(6).indexOf("#!#"))));
|
1061
|
} else {
|
1062
|
reportItem.addIdentifier(new ItemIdentifier("DOI", rs.getString(6)));
|
1063
|
}
|
1064
|
}
|
1065
|
*/
|
1066
|
ft_total = 0;
|
1067
|
abstr = 0;
|
1068
|
}
|
1069
|
ft_total += rs.getInt(10);
|
1070
|
abstr += rs.getInt(11);
|
1071
|
}
|
1072
|
if (reportItem != null) {
|
1073
|
reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate), Integer.toString(ft_total), Integer.toString(abstr)));
|
1074
|
reportItems.add(reportItem);
|
1075
|
}
|
1076
|
} else if (granularity.equalsIgnoreCase("monthly")) {
|
1077
|
Calendar endCal = Calendar.getInstance();
|
1078
|
endCal.setTime(postgresFormat.parse(endDateStr));
|
1079
|
endCal.add(Calendar.MONTH, 1);
|
1080
|
Date endDateForZeros = endCal.getTime();
|
1081
|
while (rs.next()) {
|
1082
|
if (!rs.getString(1).equals(result)) {
|
1083
|
if (reportItem != null) {
|
1084
|
fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
|
1085
|
reportItems.add(reportItem);
|
1086
|
}
|
1087
|
result = rs.getString(1);
|
1088
|
lastDate = beginDateStr;
|
1089
|
reportItem = new ReportItem(rs.getString(3), rs.getString(7), rs.getString(5), rs.getString(2));
|
1090
|
reportItem.addIdentifier(new ItemIdentifier("OpenAIRE", rs.getString(1)));
|
1091
|
reportItem.addIdentifier(new ItemIdentifier("URLs", rs.getString(4)));
|
1092
|
|
1093
|
String[] oridsArr = (String[]) rs.getArray(9).getArray();
|
1094
|
if (oridsArr[0] != null && !oridsArr[0].equals("")) {
|
1095
|
reportItem.addIdentifier(new ItemIdentifier("OAI", oridsArr[0]));
|
1096
|
}
|
1097
|
String[] pidsArr = (String[]) rs.getArray(6).getArray();
|
1098
|
if (pidsArr[0] != null && !pidsArr[0].equals("")) {
|
1099
|
reportItem.addIdentifier(new ItemIdentifier("OAI", pidsArr[0]));
|
1100
|
}
|
1101
|
/*
|
1102
|
if (rs.getString(9) != null && !rs.getString(9).equals("")) {
|
1103
|
if (rs.getString(9).contains("#!#")) {
|
1104
|
reportItem.addIdentifier(new ItemIdentifier("OAI", rs.getString(9).substring(0, rs.getString(9).indexOf("#!#"))));
|
1105
|
} else {
|
1106
|
reportItem.addIdentifier(new ItemIdentifier("OAI", rs.getString(9)));
|
1107
|
}
|
1108
|
}
|
1109
|
if (rs.getString(6) != null && !rs.getString(6).equals("")) {
|
1110
|
if (rs.getString(6).contains("#!#")) {
|
1111
|
reportItem.addIdentifier(new ItemIdentifier("DOI", rs.getString(6).substring(0, rs.getString(6).indexOf("#!#"))));
|
1112
|
} else {
|
1113
|
reportItem.addIdentifier(new ItemIdentifier("DOI", rs.getString(6)));
|
1114
|
}
|
1115
|
}
|
1116
|
*/
|
1117
|
}
|
1118
|
fillWithZeros(postgresFormat.parse(lastDate), postgresFormat.parse(rs.getString(8)), reportItem);
|
1119
|
Calendar endC = Calendar.getInstance();
|
1120
|
endC.setTime(postgresFormat.parse(rs.getString(8)));
|
1121
|
endC.set(Calendar.DATE, endC.getActualMaximum(Calendar.DATE));
|
1122
|
if (reportItem != null) {
|
1123
|
reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(postgresFormat.parse(rs.getString(8))), report_dateFormat.format(endC.getTime()), rs.getString(10), rs.getString(11)));
|
1124
|
}
|
1125
|
endC.setTime(postgresFormat.parse(rs.getString(8)));
|
1126
|
endC.add(Calendar.MONTH, 1);
|
1127
|
lastDate = postgresFormat.format(endC.getTime());
|
1128
|
}
|
1129
|
if (reportItem != null) {
|
1130
|
fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
|
1131
|
reportItems.add(reportItem);
|
1132
|
}
|
1133
|
|
1134
|
}
|
1135
|
|
1136
|
/*
|
1137
|
jedis.put(redis_key, "persistent", "false");
|
1138
|
jedis.put(redis_key, "query", st.toString());
|
1139
|
jedis.put(redis_key, "result", toJson(reportItems));
|
1140
|
jedis.put(redis_key, "fetchMode", "3");
|
1141
|
*/
|
1142
|
} catch (Exception e) {
|
1143
|
log.error("Batch Item Report failed: ", e);
|
1144
|
} finally {
|
1145
|
DbUtils.closeQuietly(rs);
|
1146
|
DbUtils.closeQuietly(st);
|
1147
|
DbUtils.closeQuietly(connection);
|
1148
|
java.sql.Timestamp timestamp = new java.sql.Timestamp(System.currentTimeMillis());
|
1149
|
//System.out.println("DB end "+timestamp);
|
1150
|
log.info("Query end..." + timestamp);
|
1151
|
|
1152
|
}
|
1153
|
}
|
1154
|
|
1155
|
private void fillWithZeros(Date from, Date to, ReportItem reportItem) {
|
1156
|
SimpleDateFormat report_dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
1157
|
|
1158
|
Calendar fromCalendar = Calendar.getInstance();
|
1159
|
fromCalendar.setTime(from);
|
1160
|
|
1161
|
Calendar toCalendar = Calendar.getInstance();
|
1162
|
toCalendar.setTime(to);
|
1163
|
while (from.before(to)) {
|
1164
|
Calendar temp_c = Calendar.getInstance();
|
1165
|
temp_c.setTime(from);
|
1166
|
temp_c.set(Calendar.DAY_OF_MONTH, temp_c.getActualMaximum(Calendar.DAY_OF_MONTH));
|
1167
|
Date temp_endDate = temp_c.getTime();
|
1168
|
|
1169
|
reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(from), report_dateFormat.format(temp_endDate), "0", "0"));
|
1170
|
fromCalendar.add(Calendar.MONTH, 1);
|
1171
|
from = fromCalendar.getTime();
|
1172
|
}
|
1173
|
}
|
1174
|
}
|