Skip to content

Commit 216d94f

Browse files
committed
add endpoint to retrieve group pattern
1 parent 0f39711 commit 216d94f

File tree

3 files changed

+52
-11
lines changed

3 files changed

+52
-11
lines changed

apiary.apib

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,15 @@ This includes also projects of any sub-groups.
316316

317317
["foo","bar"]
318318

319+
## Group pattern [/groups/{group}/pattern]
320+
321+
### returns pattern for given group [GET]
322+
323+
+ Response 200 (text/plain)
324+
+ Body
325+
326+
^foo-.*
327+
319328
## Projects [/projects]
320329

321330
### returns a list of all projects [GET]

opengrok-web/src/main/java/org/opengrok/web/api/v1/controller/GroupsController.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,18 @@ public Response getAllProjectsForGroup(@PathParam("group") String groupName) {
7373
return Response.ok().entity(projectNameList).build();
7474
}
7575
}
76+
77+
@GET
78+
@Path("/{group}/pattern")
79+
@Produces(MediaType.TEXT_PLAIN)
80+
public Response getPattern(@PathParam("group") String groupName) {
81+
groupName = Laundromat.launderInput(groupName);
82+
Group group;
83+
group = Group.getByName(groupName);
84+
if (group == null) {
85+
return Response.status(Response.Status.NOT_FOUND).build();
86+
}
87+
88+
return Response.ok().entity(group.getPattern()).build();
89+
}
7690
}

opengrok-web/src/test/java/org/opengrok/web/api/v1/controller/GroupsControllerTest.java

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,20 @@ private List<String> listAllProjects(String groupName) {
9898
.get(type);
9999
}
100100

101-
@Test
102-
void testGetAllProjectsEmpty() {
101+
private Group setGroup(String groupName, String pattern) {
103102
Set<Group> groups = new TreeSet<>();
104103
Group group;
105-
String groupName = "group-foo";
106-
group = new Group(groupName, "project-(1|2|3)");
104+
group = new Group(groupName, pattern);
107105
groups.add(group);
108106
env.setGroups(groups);
109107
assertTrue(env.hasGroups());
108+
return group;
109+
}
110+
111+
@Test
112+
void testGetAllProjectsEmpty() {
113+
String groupName = "group-empty";
114+
setGroup(groupName, "project-(1|2|3)");
110115

111116
List<String> groupsResult = listAllProjects(groupName);
112117
assertNotNull(groupsResult);
@@ -136,13 +141,8 @@ void testGetAllProjects() {
136141
env.setProjects(projects);
137142

138143
// Set group.
139-
Set<Group> groups = new TreeSet<>();
140-
Group group;
141-
String groupName = "group-foo";
142-
group = new Group(groupName, "project-(1|2|3)");
143-
groups.add(group);
144-
env.setGroups(groups);
145-
assertTrue(env.hasGroups());
144+
String groupName = "group-all";
145+
Group group = setGroup(groupName, "project-(1|2|3)");
146146

147147
// Verify that the group has the projects.
148148
Set<Project> expectedProjects = group.getAllProjects();
@@ -153,4 +153,22 @@ void testGetAllProjects() {
153153
assertEquals(expectedProjects.stream().map(Project::getName).collect(Collectors.toList()),
154154
groupsResult);
155155
}
156+
157+
@Test
158+
void testGetPattern() {
159+
String groupName = "group-pattern";
160+
final String groupPattern = "^project-.*";
161+
setGroup(groupName, groupPattern);
162+
163+
GenericType<String> type = new GenericType<>() {
164+
};
165+
166+
String pattern = target("groups")
167+
.path(groupName)
168+
.path("pattern")
169+
.request()
170+
.get(type);
171+
assertNotNull(pattern);
172+
assertEquals(groupPattern, pattern);
173+
}
156174
}

0 commit comments

Comments
 (0)