• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OpenRefine / OpenRefine / 23267931748

18 Mar 2026 09:27PM UTC coverage: 71.233% (+20.5%) from 50.749%
23267931748

Pull #7718

github

web-flow
Merge 09205aa42 into 7ffb1b339
Pull Request #7718: API: Add `get-projects` endpoint with array response format and pagination

3470 of 5583 branches covered (62.15%)

Branch coverage included in aggregate %.

26 of 28 new or added lines in 1 file covered. (92.86%)

10050 of 13397 relevant lines covered (75.02%)

3.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/main/src/com/google/refine/commands/workspace/GetProjectsCommand.java
1
/*
2

3
Copyright 2010, 2025 Google Inc. & OpenRefine contributors
4
All rights reserved.
5

6
Redistribution and use in source and binary forms, with or without
7
modification, are permitted provided that the following conditions are
8
met:
9

10
    * Redistributions of source code must retain the above copyright
11
notice, this list of conditions and the following disclaimer.
12
    * Redistributions in binary form must reproduce the above
13
copyright notice, this list of conditions and the following disclaimer
14
in the documentation and/or other materials provided with the
15
distribution.
16
    * Neither the name of Google Inc. nor the names of its
17
contributors may be used to endorse or promote products derived from
18
this software without specific prior written permission.
19

20
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31

32
*/
33

34
package com.google.refine.commands.workspace;
35

36
import java.io.IOException;
37
import java.util.List;
38
import java.util.Map;
39
import java.util.stream.Collectors;
40

41
import javax.servlet.ServletException;
42
import javax.servlet.http.HttpServletRequest;
43
import javax.servlet.http.HttpServletResponse;
44

45
import com.fasterxml.jackson.annotation.JsonInclude;
46
import com.fasterxml.jackson.annotation.JsonInclude.Include;
47
import com.fasterxml.jackson.annotation.JsonProperty;
48
import com.fasterxml.jackson.annotation.JsonRawValue;
49
import com.fasterxml.jackson.annotation.JsonUnwrapped;
50

51
import com.google.refine.ProjectManager;
52
import com.google.refine.ProjectMetadata;
53
import com.google.refine.commands.Command;
54

55
public class GetProjectsCommand extends Command {
3✔
56

57
    static final int DEFAULT_LIMIT = 50;
58

59
    public static class ProjectMetadataWithId {
60

61
        @JsonProperty("id")
62
        protected long id;
63

64
        @JsonUnwrapped
65
        protected ProjectMetadata metadata;
66

67
        protected ProjectMetadataWithId(long id, ProjectMetadata metadata) {
2✔
68
            this.id = id;
3✔
69
            this.metadata = metadata;
3✔
70
        }
1✔
71
    }
72

73
    public static class ProjectsResponse {
74

75
        @JsonProperty("projects")
76
        protected List<ProjectMetadataWithId> projects;
77
        @JsonProperty("total")
78
        protected int total;
79
        @JsonProperty("start")
80
        protected int start;
81
        @JsonProperty("limit")
82
        protected int limit;
83
        @JsonProperty("customMetadataColumns")
84
        @JsonInclude(Include.NON_NULL)
85
        @JsonRawValue
86
        protected String customMetadataColumns;
87

88
        protected ProjectsResponse(List<ProjectMetadataWithId> projects, int total, int start, int limit, String customMetadataColumns) {
2✔
89
            this.projects = projects;
3✔
90
            this.total = total;
3✔
91
            this.start = start;
3✔
92
            this.limit = limit;
3✔
93
            this.customMetadataColumns = customMetadataColumns;
3✔
94
        }
1✔
95
    }
96

97
    @Override
98
    public void doGet(HttpServletRequest request, HttpServletResponse response)
99
            throws ServletException, IOException {
100

101
        int start = getIntegerParameter(request, "start", 0);
5✔
102
        int limit = getIntegerParameter(request, "limit", DEFAULT_LIMIT);
5✔
103

104
        if (start < 0) {
2!
NEW
105
            start = 0;
×
106
        }
107
        if (limit < 0) {
2!
NEW
108
            limit = DEFAULT_LIMIT;
×
109
        }
110

111
        Map<Long, ProjectMetadata> allProjects = ProjectManager.singleton.getAllProjectMetadata();
3✔
112
        String userMeta = (String) ProjectManager.singleton.getPreferenceStore().get("userMetadata");
6✔
113

114
        int total = allProjects.size();
3✔
115
        List<ProjectMetadataWithId> page = allProjects.entrySet().stream()
5✔
116
                .skip(start)
3✔
117
                .limit(limit)
2✔
118
                .map(entry -> new ProjectMetadataWithId(entry.getKey(), entry.getValue()))
12✔
119
                .collect(Collectors.toList());
4✔
120

121
        respondJSON(response, new ProjectsResponse(page, total, start, limit, userMeta));
10✔
122
    }
1✔
123
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc