Project

General

Profile

« Previous | Next » 

Revision 48235

Added by Tsampikos Livisianos over 7 years ago

add jr1 report

View differences:

modules/dnet-openaire-usage-stats-api/src/main/java/eu/dnetlib/usagestats/controllers/CustomWebMvcConfigurerAdapter.java
24 24
        registry.addViewController("/sushilite/RR1").setViewName("redirect:/sushilite/RR1/");
25 25
        registry.addViewController("/sushilite/RR1/").setViewName("forward:/sushilite/RR1/index.html");
26 26

  
27
        /*
28 27
        registry.addViewController("/sushilite/JR1").setViewName("redirect:/sushilite/JR1/");
29 28
        registry.addViewController("/sushilite/JR1/").setViewName("forward:/sushilite/JR1/index.html");
30
        */
31 29

  
32 30
        super.addViewControllers(registry);
33 31
    }
modules/dnet-openaire-usage-stats-api/src/main/java/eu/dnetlib/usagestats/repos/BaseRepository.java
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");
modules/dnet-openaire-usage-stats-api/src/main/java/eu/dnetlib/usagestats/sushilite/UsageReport.java
74 74

  
75 75
        String repoid = "";
76 76
        if (!repositoryIdentifier.equals("")) {
77
            repoid = executeRepoId(repositoryIdentifier);
77
            repoid = executeRepoId(repositoryIdentifier, reportName.toLowerCase());
78 78
            if (repoid.equals("-1")) {
79 79
                reportExceptions.add(new ReportException("3060", "Error", "Invalid Filter Value", "RepositoryIdentifier: " + repositoryIdentifier + " is not valid"));
80 80
            }
......
97 97
                    itemid = "-1";
98 98
            }
99 99
        }
100
        if (itemid.equals("") && repoid.equals("") && !reportName.equalsIgnoreCase("rr1")) {
100
        if (itemid.equals("") && repoid.equals("") && !reportName.equalsIgnoreCase("rr1") && !reportName.equalsIgnoreCase("jr1")) {
101 101
            reportExceptions.add(new ReportException("3070", "Error", "Required Filter Missing", "ItemIdentifier or RepositoryIdentifier must be supplied"));
102 102
        }
103 103
        if (reportName.equalsIgnoreCase("ar1")) {
......
133 133
            if (reportItems.isEmpty()) {
134 134
                reportExceptions.add(new ReportException("3030", "Error", "No Usage Available for Requested Dates", "Service did not find any data"));
135 135
            }
136
        } else if (reportName.equals("")) {
136
        } else if (reportName.equalsIgnoreCase("jr1")) {
137
            if (!repoid.equals("-1") && beginDateParsed != null && endDateParsed != null && beginDateParsed.before(endDateParsed)) {
138
                executeJournal(reportItems, repoid, itemDataType, beginDateParsed, endDateParsed, granularity);
139
            }
140
            if (reportItems.isEmpty()) {
141
                reportExceptions.add(new ReportException("3030", "Error", "No Usage Available for Requested Dates", "Service did not find any data"));
142
            }
143
        }else if (reportName.equals("")) {
137 144
            reportExceptions.add(new ReportException("3050", "Error", "Report argument is missing", "You must supply a Report argument"));
138 145
        } else {
139 146
            reportExceptions.add(new ReportException("3000", "Error", "Report " + reportName + " not supported", "Supported reports: AR1, IR1, RR1"));
modules/dnet-openaire-usage-stats-api/src/main/resources/static/sushilite/index.html
10 10
        <li><a href="./AR1/">AR1 Report</a></li>
11 11
        <li><a href="./IR1/">IR1 Report</a></li>
12 12
        <li><a href="./RR1/">RR1 Report</a></li>
13
        <!-- <li><a href="./JR1/">RR1 Report</a></li> -->
13
        <li><a href="./JR1/">JR1 Report</a></li>
14 14
    </ul>
15 15
</center>
16 16
</body>
modules/dnet-openaire-usage-stats-api/src/main/resources/static/sushilite/JR1/index.html
8 8
    <h3>Report Request</h3>
9 9
    Report Name:
10 10
    <select name='Report'>
11
        <option value='JR1'>RR1</option>
11
        <option value='JR1'>JR1</option>
12 12
    </select>
13 13
    <br />
14 14
    Release:
......
29 29
    <h4>Optional Filters</h4>
30 30
    <p>By default results are returned for all journals. Use this filter to get results for a single repository<br />
31 31
        Jounral Identifier format: <b>namespace:value</b><br />
32
        valid namespace: <b>openaire</b> or <b>ISSN</b>.<br />
32
        valid namespace: <b>openaire</b> or <b>issn</b>.<br />
33 33
    </p>
34 34
    JournalIdentifier:
35 35
    <input type="text" name="RepositoryIdentifier">
modules/dnet-openaire-usage-stats-api/pom.xml
15 15
        -->
16 16
        <groupId>org.springframework.boot</groupId>
17 17
        <artifactId>spring-boot-starter-parent</artifactId>
18
        <version>1.5.3.RELEASE</version>
18
        <version>1.5.4.RELEASE</version>
19 19
    </parent>
20 20

  
21 21
    <dependencies>

Also available in: Unified diff