1
|
/**
|
2
|
* Created by Glykeria Katsari on 2/20/2016.
|
3
|
*/
|
4
|
package eu.dnetlib.usagestats.repos;
|
5
|
|
6
|
|
7
|
import eu.dnetlib.usagestats.domain.UsageStats;
|
8
|
import org.apache.log4j.Logger;
|
9
|
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
10
|
import org.springframework.stereotype.Repository;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.List;
|
14
|
|
15
|
|
16
|
@Repository
|
17
|
public class OrganizationRepo extends BaseRepository {
|
18
|
|
19
|
private Logger log = Logger.getLogger(this.getClass());
|
20
|
|
21
|
public UsageStats getClicks(String organizationId) {
|
22
|
|
23
|
String query = "select o.id, o.name , sum (os.numberofviews) from organization o, usagestats.organizationsstats os " +
|
24
|
"where os.organizationid=o.id and o.id=? group by o.id, o.name;";
|
25
|
|
26
|
List<String> values = new ArrayList<String>();
|
27
|
values.add(organizationId);
|
28
|
|
29
|
List<UsageStats> results = executePreparedQuery(query, values);
|
30
|
if (!results.isEmpty()) return results.get(0);
|
31
|
|
32
|
return new UsageStats();
|
33
|
}
|
34
|
|
35
|
|
36
|
public List<UsageStats> getMostPopular(String limit) {
|
37
|
String query = "select o.id, o.name , sum (os.numberofviews) from organization o, usagestats.organizationsstats os where " +
|
38
|
"os.organizationid=o.id group by o.id, o.name order by sum(os.numberofviews) desc limit " + limit + " ;";
|
39
|
|
40
|
return executeQuery(query);
|
41
|
}
|
42
|
|
43
|
|
44
|
public List<UsageStats> getMostPopularProjects(String organizationId) {
|
45
|
|
46
|
String query = "select p.id, p.title, sum(ps.numberofviews) from project p, project_organizations por, usagestats.projectsstats ps " +
|
47
|
" where por.organization=? and p.id=por.id and ps.projectid=p.id " +
|
48
|
" group by p.id, p.title order by sum (ps.numberofviews) desc limit 10;";
|
49
|
List<String> values = new ArrayList<String>();
|
50
|
|
51
|
values.add(organizationId);
|
52
|
return executePreparedQuery(query, values);
|
53
|
}
|
54
|
|
55
|
public List<UsageStats> getPopularityOverTime(String organizationId) {
|
56
|
|
57
|
String query = "select os.organizationid, os.timestamp_month , os.numberofviews from usagestats.organizationsstats os " +
|
58
|
" where os.organizationid=? order by to_date(os.timestamp_month,'MM/YYYY') ;";
|
59
|
List<String> values = new ArrayList<String>();
|
60
|
values.add(organizationId);
|
61
|
return executePreparedQuery(query, values);
|
62
|
|
63
|
}
|
64
|
|
65
|
|
66
|
}
|
67
|
|
68
|
|