Project

General

Profile

« Previous | Next » 

Revision 56683

Adding totals to final array

View differences:

modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/PiWikService.java
18 18

  
19 19
    List<PiwikInfo> getPiwikSitesForRepos(OrderByField orderByField, OrderByType orderByType, int from, int quantity, String searchField);
20 20

  
21
    int getPiwikSitesTotals();
22

  
21 23
    ResponseEntity<Object> approvePiwikSite(String repositoryId);
22 24

  
23 25
    String getOpenaireId(String repositoryid);
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/service/PiWikServiceImpl.java
64 64

  
65 65
    private final static String INSERT_PIWIK_INFO = "insert into piwik_site (repositoryid, siteid, creationdate, requestorname, requestoremail, validated, repositoryname, country, authenticationtoken) values (?, ?, now(), ?, ?, ?, ?, ?, ?)";
66 66

  
67
    private final static String GET_PIWIK_SITES = "select count(*) OVER() as totals, repositoryid, siteid, authenticationtoken, creationdate, requestorname, requestoremail, validated, validationdate, comment, repositoryname, country from piwik_site ";
67
    private final static String GET_PIWIK_SITES = "select  repositoryid, siteid, authenticationtoken, creationdate, requestorname, requestoremail, validated, validationdate, comment, repositoryname, country from piwik_site ";
68 68

  
69
    private final static String GET_PIWIK_SITES_TOTAL = "select count(*) as totals from piwik_site ";
70

  
69 71
    private final static String APPROVE_PIWIK_SITE = "update piwik_site set validated=true, validationdate=now() where repositoryid = ?;";
70 72

  
71 73
    private RowMapper<PiwikInfo> piwikRowMapper = (rs, i) -> new PiwikInfo(rs.getString("repositoryid"), getOpenaireId(rs.getString("repositoryid")), rs.getString("repositoryname"), rs.getString("country"),
......
124 126
    }
125 127

  
126 128
    @Override
129
    public int getPiwikSitesTotals(){
130
        try{
131
            return new JdbcTemplate(dataSource).queryForObject(GET_PIWIK_SITES_TOTAL,Integer.class);
132
        }catch (EmptyResultDataAccessException e){
133
            return 0;
134
        }
135
    }
136

  
137
    @Override
127 138
    @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_ADMIN')")
128 139
    public ResponseEntity<Object> approvePiwikSite(String repositoryId) {
129 140
        new JdbcTemplate(dataSource).update(APPROVE_PIWIK_SITE, new Object[] {repositoryId}, new int[] {Types.VARCHAR});
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/controllers/PiWikController.java
3 3
import eu.dnetlib.domain.data.PiwikInfo;
4 4
import eu.dnetlib.repo.manager.domain.OrderByField;
5 5
import eu.dnetlib.repo.manager.domain.OrderByType;
6
import eu.dnetlib.repo.manager.domain.Paging;
6 7
import eu.dnetlib.repo.manager.service.PiWikServiceImpl;
7 8
import eu.dnetlib.repo.manager.shared.RepositoryServiceException;
8 9
import io.swagger.annotations.Api;
......
46 47
            @ApiImplicitParam(name = "searchField", dataType = "eu.dnetlib.repo.manager.domain.OrderByField", paramType = "query"),
47 48
            @ApiImplicitParam(name = "orderField", dataType = "string", paramType = "query"),
48 49
    })
49
    public List<PiwikInfo> getPiwikSitesForRepos(
50
    public Paging<PiwikInfo> getPiwikSitesForRepos(
50 51
            @RequestParam(value = "from",required=false,defaultValue = "0") int from,
51 52
            @RequestParam(value = "quantity",required=false,defaultValue = "100") int quantity,
52 53
            @RequestParam(value = "order",required=false,defaultValue = "ASC") OrderByType orderType,
......
54 55
            @RequestParam(value = "searchField", required = false, defaultValue = "") String searchField
55 56

  
56 57
    ){
57
        return piWikService.getPiwikSitesForRepos(orderField,orderType,from,quantity,searchField);
58
        Paging<PiwikInfo> results = new Paging<>();
59
        List<PiwikInfo> returning = piWikService.getPiwikSitesForRepos(orderField,orderType,from,quantity,searchField);
60
        results.setFrom(from);
61
        results.setTo(from + returning.size());
62
        results.setTotal(piWikService.getPiwikSitesTotals());
63
        results.setResults(returning);
64
        return results;
58 65
    }
59 66

  
60 67
    @RequestMapping(value = "/approvePiwikSite/{repositoryId}" , method = RequestMethod.GET)
modules/uoa-repository-manager-service/trunk/src/main/java/eu/dnetlib/repo/manager/domain/Paging.java
1
package eu.dnetlib.repo.manager.domain;
2

  
3

  
4
import javax.validation.constraints.NotNull;
5
import java.util.ArrayList;
6
import java.util.List;
7

  
8
public class Paging<T> {
9

  
10
    private int total;
11

  
12
    private int from;
13

  
14
    private int to;
15

  
16
    private List<T> results;
17

  
18
    public Paging(int total, int from, int to, List<T> results) {
19
        this.total = total;
20
        this.from = from;
21
        this.to = to;
22
        this.results = results;
23
    }
24

  
25
    public Paging(@NotNull Paging<T> page) {
26
        this.total = page.getTotal();
27
        this.from = page.getFrom();
28
        this.to = page.getTo();
29
        this.results = page.getResults();
30
    }
31

  
32
    public <K> Paging(@NotNull Paging<K> page, List<T> results) {
33
        this.total = page.getTotal();
34
        this.from = page.getFrom();
35
        this.to = page.getTo();
36
        this.results = results;
37
    }
38

  
39
    public Paging() {
40
        this.total = 0;
41
        this.from = 0;
42
        this.to = 0;
43
        this.results = new ArrayList<>();
44
    }
45

  
46
    public int getTotal() {
47
        return total;
48
    }
49

  
50
    public void setTotal(int total) {
51
        this.total = total;
52
    }
53

  
54
    public int getFrom() {
55
        return from;
56
    }
57

  
58
    public void setFrom(int from) {
59
        this.from = from;
60
    }
61

  
62
    public int getTo() {
63
        return to;
64
    }
65

  
66
    public void setTo(int to) {
67
        this.to = to;
68
    }
69

  
70
    public List<T> getResults() {
71
        return results;
72
    }
73

  
74
    public void setResults(List<T> results) {
75
        this.results = results;
76
    }
77
}

Also available in: Unified diff