|
11 | 11 | import javax.ws.rs.core.StreamingOutput;
|
12 | 12 |
|
13 | 13 | import org.gitlab4j.api.GitLabApi.ApiVersion;
|
| 14 | +import org.gitlab4j.api.models.Group; |
14 | 15 | import org.gitlab4j.api.models.Project;
|
15 | 16 |
|
16 | 17 | /**
|
@@ -56,8 +57,44 @@ public Object getProjectIdOrPath(Object obj) throws GitLabApiException {
|
56 | 57 |
|
57 | 58 | } else {
|
58 | 59 |
|
59 |
| - throw (new RuntimeException("Cannot determine ID or path from provided " + obj.getClass().getSimpleName() + |
60 |
| - " instance, must be Integer, String, or Project instance")); |
| 60 | + throw (new RuntimeException("Cannot determine ID or path from provided " + obj.getClass().getSimpleName() + |
| 61 | + " instance, must be Integer, String, or a Project instance")); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Returns the group ID or path from the provided Integer, String, or Group instance. |
| 67 | + * |
| 68 | + * @param obj the object to determine the ID or path from |
| 69 | + * @return the group ID or path from the provided Integer, String, or Group instance |
| 70 | + * @throws GitLabApiException if any exception occurs during execution |
| 71 | + */ |
| 72 | + public Object getGroupIdOrPath(Object obj) throws GitLabApiException { |
| 73 | + |
| 74 | + if (obj == null) { |
| 75 | + throw (new RuntimeException("Cannot determine ID or path from null object")); |
| 76 | + } else if (obj instanceof Integer) { |
| 77 | + return (obj); |
| 78 | + } else if (obj instanceof String) { |
| 79 | + return (urlEncode(((String) obj).trim())); |
| 80 | + } else if (obj instanceof Group) { |
| 81 | + |
| 82 | + Integer id = ((Group) obj).getId(); |
| 83 | + if (id != null && id.intValue() > 0) { |
| 84 | + return (id); |
| 85 | + } |
| 86 | + |
| 87 | + String path = ((Group) obj).getFullPath(); |
| 88 | + if (path != null && path.trim().length() > 0) { |
| 89 | + return (urlEncode(path.trim())); |
| 90 | + } |
| 91 | + |
| 92 | + throw (new RuntimeException("Cannot determine ID or path from provided Group instance")); |
| 93 | + |
| 94 | + } else { |
| 95 | + |
| 96 | + throw (new RuntimeException("Cannot determine ID or path from provided " + obj.getClass().getSimpleName() + |
| 97 | + " instance, must be Integer, String, or a Group instance")); |
61 | 98 | }
|
62 | 99 | }
|
63 | 100 |
|
|
0 commit comments