Skip to content

Commit 444f71d

Browse files
committed
Move param decoding to a static method
1 parent d4eb318 commit 444f71d

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

core/trino-main/src/main/java/io/trino/server/ResourceGroupStateInfoResource.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,7 @@
2525
import jakarta.ws.rs.Produces;
2626
import jakarta.ws.rs.core.MediaType;
2727

28-
import java.net.URLDecoder;
29-
import java.util.Arrays;
30-
31-
import static com.google.common.base.Strings.isNullOrEmpty;
32-
import static com.google.common.collect.ImmutableList.toImmutableList;
3328
import static io.trino.server.security.ResourceSecurity.AccessType.MANAGEMENT_READ;
34-
import static java.nio.charset.StandardCharsets.UTF_8;
3529
import static java.util.Objects.requireNonNull;
3630

3731
@Path("/v1/resourceGroupState")
@@ -50,21 +44,13 @@ public ResourceGroupStateInfoResource(ResourceGroupInfoProvider resourceGroupInf
5044
@Produces(MediaType.APPLICATION_JSON)
5145
@Encoded
5246
@Path("{resourceGroupId: .+}")
53-
public ResourceGroupInfo getQueryStateInfos(@PathParam("resourceGroupId") String resourceGroupIdString)
47+
public ResourceGroupInfo getQueryStateInfos(@PathParam("resourceGroupId") ResourceGroupId resourceGroupId)
5448
{
55-
if (!isNullOrEmpty(resourceGroupIdString)) {
56-
return resourceGroupInfoProvider.tryGetResourceGroupInfo(
57-
new ResourceGroupId(
58-
Arrays.stream(resourceGroupIdString.split("/"))
59-
.map(ResourceGroupStateInfoResource::urlDecode)
60-
.collect(toImmutableList())))
61-
.orElseThrow(NotFoundException::new);
49+
if (resourceGroupId == null) {
50+
throw new NotFoundException();
6251
}
63-
throw new NotFoundException();
64-
}
6552

66-
private static String urlDecode(String value)
67-
{
68-
return URLDecoder.decode(value, UTF_8);
53+
return resourceGroupInfoProvider.tryGetResourceGroupInfo(resourceGroupId)
54+
.orElseThrow(NotFoundException::new);
6955
}
7056
}

core/trino-spi/src/main/java/io/trino/spi/resourcegroups/ResourceGroupId.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@
1616
import com.fasterxml.jackson.annotation.JsonCreator;
1717
import com.fasterxml.jackson.annotation.JsonValue;
1818

19+
import java.net.URLDecoder;
1920
import java.util.ArrayList;
21+
import java.util.Arrays;
2022
import java.util.List;
2123
import java.util.Objects;
2224
import java.util.Optional;
2325

26+
import static java.nio.charset.StandardCharsets.UTF_8;
2427
import static java.util.Collections.singletonList;
2528
import static java.util.Objects.requireNonNull;
2629
import static java.util.stream.Collectors.joining;
30+
import static java.util.stream.Collectors.toUnmodifiableList;
2731

2832
public final class ResourceGroupId
2933
{
@@ -60,6 +64,15 @@ public ResourceGroupId(List<String> segments)
6064
this.segments = segments;
6165
}
6266

67+
// this is needed by JAX-RS, see: org.glassfish.jersey.internal.util.ReflectionHelper
68+
public static ResourceGroupId valueOf(String value)
69+
{
70+
return new ResourceGroupId(
71+
Arrays.stream(value.split("/"))
72+
.map(part -> URLDecoder.decode(part, UTF_8))
73+
.collect(toUnmodifiableList()));
74+
}
75+
6376
public String getLastSegment()
6477
{
6578
return segments.getLast();

0 commit comments

Comments
 (0)