196 |
196 |
return usageStats;
|
197 |
197 |
}
|
198 |
198 |
|
199 |
|
protected String executeRepoId(String repositoryIdentifier) {
|
|
199 |
protected String executeRepoId(String repositoryIdentifier, String report) {
|
200 |
200 |
PreparedStatement st = null;
|
201 |
201 |
Connection connection = null;
|
202 |
202 |
ResultSet rs = null;
|
... | ... | |
206 |
206 |
String openaire_id = "-1";
|
207 |
207 |
switch (split[0].toLowerCase()) {
|
208 |
208 |
case "openaire":
|
209 |
|
st = connection.prepareStatement("select id from datasource where id=?");
|
210 |
|
st.setString(1, repositoryIdentifier.replaceFirst(split[0] + ":", ""));
|
|
209 |
if(!report.equals("jr1")) {
|
|
210 |
st = connection.prepareStatement("select id from datasource where id=?");
|
|
211 |
st.setString(1, repositoryIdentifier.replaceFirst(split[0] + ":", ""));
|
|
212 |
} else {
|
|
213 |
st = connection.prepareStatement("select id from datasource where id=? AND (type='Journal' OR type='Journal Aggregator/Publisher')");
|
|
214 |
st.setString(1, repositoryIdentifier.replaceFirst(split[0] + ":", ""));
|
|
215 |
}
|
211 |
216 |
|
212 |
217 |
rs = st.executeQuery();
|
213 |
218 |
while (rs.next()) {
|
... | ... | |
216 |
221 |
return openaire_id;
|
217 |
222 |
|
218 |
223 |
case "opendoar":
|
219 |
|
st = connection.prepareStatement("select id from datasource_oids where orid=?");
|
220 |
|
st.setString(1, "opendoar____::" + repositoryIdentifier.replaceFirst(split[0] + ":", ""));
|
|
224 |
if(!report.equals("jr1")) {
|
|
225 |
st = connection.prepareStatement("select id from datasource_oids where orid=?");
|
|
226 |
st.setString(1, "opendoar____::" + repositoryIdentifier.replaceFirst(split[0] + ":", ""));
|
|
227 |
} else {
|
|
228 |
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')");
|
|
229 |
st.setString(1, "opendoar____::" + repositoryIdentifier.replaceFirst(split[0] + ":", ""));
|
|
230 |
}
|
221 |
231 |
|
222 |
232 |
rs = st.executeQuery();
|
223 |
233 |
while (rs.next()) {
|
224 |
234 |
openaire_id = rs.getString(1);
|
225 |
235 |
}
|
226 |
236 |
return openaire_id;
|
|
237 |
case "issn":
|
|
238 |
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')");
|
|
239 |
st.setString(1, "%" + repositoryIdentifier.replaceFirst(split[0] + ":", "") + "%");
|
|
240 |
|
|
241 |
rs = st.executeQuery();
|
|
242 |
while (rs.next()) {
|
|
243 |
openaire_id = rs.getString(1);
|
|
244 |
}
|
|
245 |
return openaire_id;
|
227 |
246 |
default:
|
228 |
247 |
return "-1";
|
229 |
248 |
}
|
... | ... | |
472 |
491 |
DbUtils.closeQuietly(connection);
|
473 |
492 |
}
|
474 |
493 |
}
|
475 |
|
|
476 |
494 |
protected void executeRepo(List<ReportItem> reportItems, String repositoryIdentifier, String itemDataType, Date beginDate, Date endDate, String granularity) {
|
477 |
495 |
SimpleDateFormat report_dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
478 |
496 |
SimpleDateFormat postgresFormat = new SimpleDateFormat("yyyy/MM");
|
... | ... | |
625 |
643 |
DbUtils.closeQuietly(connection);
|
626 |
644 |
}
|
627 |
645 |
}
|
|
646 |
protected void executeJournal(List<ReportItem> reportItems, String repositoryIdentifier, String itemDataType, Date beginDate, Date endDate, String granularity) {
|
|
647 |
SimpleDateFormat report_dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
648 |
SimpleDateFormat postgresFormat = new SimpleDateFormat("yyyy/MM");
|
|
649 |
String beginDateStr = postgresFormat.format(beginDate);
|
|
650 |
String endDateStr = postgresFormat.format(endDate);
|
628 |
651 |
|
|
652 |
Connection connection = null;
|
|
653 |
PreparedStatement st = null;
|
|
654 |
ResultSet rs = null;
|
|
655 |
|
|
656 |
try {
|
|
657 |
connection = usageStatsDB.getConnection();
|
|
658 |
|
|
659 |
if (repositoryIdentifier.equals("")) {
|
|
660 |
if (itemDataType.equals("")) {
|
|
661 |
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 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 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 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.ddate ASC;");
|
|
662 |
st.setString(1, beginDateStr);
|
|
663 |
st.setString(2, endDateStr);
|
|
664 |
st.setString(3, beginDateStr);
|
|
665 |
st.setString(4, endDateStr);
|
|
666 |
} else {
|
|
667 |
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 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 views_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 vs ON ds.source=vs.source AND ds.repository_id=vs.repository_id AND ds.date=vs.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.ddate 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 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 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 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.ddate ASC;");
|
|
678 |
st.setString(1, beginDateStr);
|
|
679 |
st.setString(2, endDateStr);
|
|
680 |
st.setString(3, repositoryIdentifier);
|
|
681 |
st.setString(4, beginDateStr);
|
|
682 |
st.setString(5, endDateStr);
|
|
683 |
st.setString(6, repositoryIdentifier);
|
|
684 |
} else {
|
|
685 |
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 downloads_stats s, 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 views_stats s, 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 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.ddate ASC;");
|
|
686 |
st.setString(1, beginDateStr);
|
|
687 |
st.setString(2, endDateStr);
|
|
688 |
st.setString(3, itemDataType);
|
|
689 |
st.setString(4, repositoryIdentifier);
|
|
690 |
st.setString(5, beginDateStr);
|
|
691 |
st.setString(6, endDateStr);
|
|
692 |
st.setString(7, itemDataType);
|
|
693 |
st.setString(8, repositoryIdentifier);
|
|
694 |
}
|
|
695 |
}
|
|
696 |
//log.error("RR STATEMENT: " + st);
|
|
697 |
|
|
698 |
/*
|
|
699 |
String redis_key = MD5(st.toString());
|
|
700 |
|
|
701 |
if (jedis.hasKey(redis_key, "result")) {
|
|
702 |
reportItems.addAll(reportItemsFromJson((String) jedis.get(redis_key, "result")));
|
|
703 |
st.close();
|
|
704 |
connection.close();
|
|
705 |
return;
|
|
706 |
}
|
|
707 |
*/
|
|
708 |
|
|
709 |
rs = st.executeQuery();
|
|
710 |
String repository = "";
|
|
711 |
String lastDate = "";
|
|
712 |
ReportItem reportItem = null;
|
|
713 |
|
|
714 |
/*
|
|
715 |
Calendar startCalendar = Calendar.getInstance();
|
|
716 |
startCalendar.setTime(beginDate);
|
|
717 |
Calendar endCalendar = Calendar.getInstance();
|
|
718 |
endCalendar.setTime(endDate);
|
|
719 |
*/
|
|
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("ISSN", rs.getString(4).substring(rs.getString(4).lastIndexOf(":") + 1)));
|
|
734 |
if(rs.getString(3) != null) {
|
|
735 |
reportItem.addIdentifier(new ItemIdentifier("URL", rs.getString(3)));
|
|
736 |
}
|
|
737 |
ft_total = 0;
|
|
738 |
abstr = 0;
|
|
739 |
}
|
|
740 |
ft_total += rs.getInt(6);
|
|
741 |
abstr += rs.getInt(7);
|
|
742 |
}
|
|
743 |
if (reportItem != null) {
|
|
744 |
reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(beginDate), report_dateFormat.format(endDate), Integer.toString(ft_total), Integer.toString(abstr)));
|
|
745 |
reportItems.add(reportItem);
|
|
746 |
}
|
|
747 |
} else if (granularity.equalsIgnoreCase("monthly")) {
|
|
748 |
Calendar endCal = Calendar.getInstance();
|
|
749 |
endCal.setTime(postgresFormat.parse(endDateStr));
|
|
750 |
endCal.add(Calendar.MONTH, 1);
|
|
751 |
Date endDateForZeros = endCal.getTime();
|
|
752 |
while (rs.next()) {
|
|
753 |
if (!rs.getString(1).equals(repository)) {
|
|
754 |
if (reportItem != null) {
|
|
755 |
fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
|
|
756 |
reportItems.add(reportItem);
|
|
757 |
}
|
|
758 |
repository = rs.getString(1);
|
|
759 |
lastDate = beginDateStr;
|
|
760 |
reportItem = new ReportItem(null, rs.getString(2), "Platform", null);
|
|
761 |
reportItem.addIdentifier(new ItemIdentifier("OpenAIRE", rs.getString(1)));
|
|
762 |
reportItem.addIdentifier(new ItemIdentifier("ISSN", rs.getString(4).substring(rs.getString(4).lastIndexOf(":") + 1)));
|
|
763 |
if(rs.getString(3) != null) {
|
|
764 |
reportItem.addIdentifier(new ItemIdentifier("URL", rs.getString(3)));
|
|
765 |
}
|
|
766 |
}
|
|
767 |
fillWithZeros(postgresFormat.parse(lastDate), postgresFormat.parse(rs.getString(5)), reportItem);
|
|
768 |
Calendar endC = Calendar.getInstance();
|
|
769 |
endC.setTime(postgresFormat.parse(rs.getString(5)));
|
|
770 |
endC.set(Calendar.DATE, endC.getActualMaximum(Calendar.DATE));
|
|
771 |
if (reportItem != null) {
|
|
772 |
reportItem.addPerformance(new ItemPerformance(report_dateFormat.format(postgresFormat.parse(rs.getString(5))), report_dateFormat.format(endC.getTime()), rs.getString(6), rs.getString(7)));
|
|
773 |
}
|
|
774 |
endC.setTime(postgresFormat.parse(rs.getString(5)));
|
|
775 |
endC.add(Calendar.MONTH, 1);
|
|
776 |
lastDate = postgresFormat.format(endC.getTime());
|
|
777 |
}
|
|
778 |
if (reportItem != null) {
|
|
779 |
fillWithZeros(postgresFormat.parse(lastDate), endDateForZeros, reportItem);
|
|
780 |
reportItems.add(reportItem);
|
|
781 |
}
|
|
782 |
}
|
|
783 |
|
|
784 |
/*
|
|
785 |
jedis.put(redis_key, "persistent", "false");
|
|
786 |
jedis.put(redis_key, "query", st.toString());
|
|
787 |
jedis.put(redis_key, "result", toJson(reportItems));
|
|
788 |
jedis.put(redis_key, "fetchMode", "3");
|
|
789 |
*/
|
|
790 |
|
|
791 |
rs.close();
|
|
792 |
st.close();
|
|
793 |
connection.close();
|
|
794 |
} catch (Exception e) {
|
|
795 |
log.error("Repository Report failed: ", e);
|
|
796 |
} finally {
|
|
797 |
DbUtils.closeQuietly(rs);
|
|
798 |
DbUtils.closeQuietly(st);
|
|
799 |
DbUtils.closeQuietly(connection);
|
|
800 |
}
|
|
801 |
}
|
|
802 |
|
629 |
803 |
protected void executeBatchItems(List<ReportItem> reportItems, String repositoryIdentifier, String itemDataType, Date beginDate, Date endDate, String granularity) {
|
630 |
804 |
SimpleDateFormat report_dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
631 |
805 |
SimpleDateFormat postgresFormat = new SimpleDateFormat("yyyy/MM");
|
add jr1 report