Newer
Older
/*
* This file is part of gms-client
* Copyright (C) 2021 Istituto Nazionale di Astrofisica
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package it.inaf.ia2.gms.client.call;
import it.inaf.ia2.client.BaseCall;
import it.inaf.ia2.gms.client.GmsClient;
import java.net.http.HttpRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class ListGroupsCall extends BaseCall<GmsClient> {
public ListGroupsCall(GmsClient client) {
super(client);
}
/**
* Returns the list of the groups in a given parent group (if the user has
* the privileges to see that information). The parent group name is removed
* by the service.
public List<String> listGroups(String parentGroup, boolean recursive) {
List<String> groups = new ArrayList<>();
String uri = "groups?parent="
+ URLEncoder.encode(parentGroup, StandardCharsets.UTF_8)
+ "&recursive=" + recursive;
.header("Accept", "text/plain")
.GET()
.build();
return client.call(groupsRequest, BodyHandlers.ofInputStream(), 200,
inputStream -> {
try ( Scanner scan = new Scanner(inputStream)) {
while (scan.hasNextLine()) {
String line = scan.nextLine();
if (!line.isEmpty()) {
groups.add(line);
}
}
}
return groups;