Commit ef25978f authored by Adam Retter's avatar Adam Retter

Added access Enum

parent f377b902
......@@ -145,7 +145,7 @@ public class GitlabAPI {
*
* @return The GitLab Group
*/
public GitlabGroup createGroup(String name, String path, String ldapCn, Integer ldapAccess) throws IOException {
public GitlabGroup createGroup(String name, String path, String ldapCn, GitlabAccessLevel ldapAccess) throws IOException {
Query query = new Query()
.append("name", name)
......
package org.gitlab.api.http;
import org.gitlab.api.models.GitlabAccessLevel;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
......@@ -87,6 +89,22 @@ public class Query {
return this;
}
/**
* Conditionally append a parameter to the query
* if the value of the parameter is not null
*
* @param name Parameter name
* @param value Parameter value
*
* @throws java.io.UnsupportedEncodingException If the provided value cannot be URL Encoded
*/
public Query appendIf(final String name, final GitlabAccessLevel value) throws UnsupportedEncodingException {
if(value != null) {
append(name, Integer.toString(value.accessValue));
}
return this;
}
/**
* Returns a Query suitable for appending
* to a URI
......
package org.gitlab.api.models;
public enum GitlabAccessLevel {
Guest(10),
Reporter(20),
Developer(30),
Master(40),
Owner(50);
public final int accessValue;
GitlabAccessLevel(int accessValue) {
this.accessValue = accessValue;
}
public static GitlabAccessLevel fromAccessValue(final int accessValue) throws IllegalArgumentException {
for(final GitlabAccessLevel gitlabAccessLevel : GitlabAccessLevel.values()) {
if(gitlabAccessLevel.accessValue == accessValue) {
return gitlabAccessLevel;
}
}
throw new IllegalArgumentException("No GitLab Access Level enum constant with access value: " + accessValue);
}
}
\ No newline at end of file
......@@ -48,11 +48,11 @@ public class GitlabGroup {
this._ldapCn = ldapCn;
}
public Integer getLdapAccess() {
return _ldapAccess;
public GitlabAccessLevel getLdapAccess() {
return GitlabAccessLevel.fromAccessValue(_ldapAccess);
}
public void setLdapAccess(Integer ldapAccess) {
this._ldapAccess = ldapAccess;
public void setLdapAccess(GitlabAccessLevel ldapGitlabAccessLevel) {
this._ldapAccess = ldapGitlabAccessLevel.accessValue;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment