|
1 | 1 | package org.gitlab4j.api;
|
2 | 2 |
|
3 | 3 | import java.util.List;
|
| 4 | +import java.util.Optional; |
4 | 5 | import java.util.stream.Stream;
|
5 | 6 |
|
6 | 7 | import jakarta.ws.rs.core.GenericType;
|
@@ -130,4 +131,35 @@ public Pager<Namespace> findNamespaces(String query, int itemsPerPage) throws Gi
|
130 | 131 | public Stream<Namespace> findNamespacesStream(String query) throws GitLabApiException {
|
131 | 132 | return (findNamespaces(query, getDefaultPerPage()).stream());
|
132 | 133 | }
|
| 134 | + |
| 135 | + /** |
| 136 | + * Get all details of a namespace. |
| 137 | + * |
| 138 | + * <pre><code>GitLab Endpoint: GET /namespaces/:id</code></pre> |
| 139 | + * |
| 140 | + * @param namespaceIdOrPath the namespace ID, path of the namespace, or a Namespace instance holding the namespace ID or path |
| 141 | + * @return the Namespace instance for the specified path |
| 142 | + * @throws GitLabApiException if any exception occurs |
| 143 | + */ |
| 144 | + |
| 145 | + public Namespace getNamespace(Object namespaceIdOrPath) throws GitLabApiException { |
| 146 | + Response response = get(Response.Status.OK, null, "namespaces", getNamespaceIdOrPath(namespaceIdOrPath)); |
| 147 | + return (response.readEntity(Namespace .class)); |
| 148 | + } |
| 149 | + |
| 150 | + /** |
| 151 | + * Get all details of a namespace as an Optional instance. |
| 152 | + * |
| 153 | + * <pre><code>GitLab Endpoint: GET /namespaces/:id</code></pre> |
| 154 | + * |
| 155 | + * @param namespaceIdOrPath the namespace ID, path of the namespace, or a Namespace instance holding the namespace ID or path |
| 156 | + * @return the Group for the specified group path as an Optional instance |
| 157 | + */ |
| 158 | + public Optional<Namespace> getOptionalNamespace(Object namespaceIdOrPath) { |
| 159 | + try { |
| 160 | + return (Optional.ofNullable(getNamespace(namespaceIdOrPath))); |
| 161 | + } catch (GitLabApiException glae) { |
| 162 | + return (GitLabApi.createOptionalFromException(glae)); |
| 163 | + } |
| 164 | + } |
133 | 165 | }
|
0 commit comments