An error occurred while loading the file. Please try again.
An error occurred while loading the file. Please try again.
An error occurred while loading the file. Please try again.
-
Mike Cook authoredUnverifiedf9fbd882
package org.gitlab4j.api;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import javax.ws.rs.NotAuthorizedException;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Group;
import org.gitlab4j.api.models.Label;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.User;
import org.gitlab4j.api.utils.UrlEncoder;
/**
* This class is the base class for all the sub API classes. It provides implementations of
* delete(), get(), post() and put() that are re-used by all the sub-classes.
*/
public abstract class AbstractApi implements Constants {
protected final GitLabApi gitLabApi;
public AbstractApi(GitLabApi gitLabApi) {
this.gitLabApi = gitLabApi;
}
/**
* Returns the project ID or path from the provided Integer, String, or Project instance.
*
* @param obj the object to determine the ID or path from
* @return the project ID or path from the provided Long, String, or Project instance
* @throws GitLabApiException if any exception occurs during execution
*/
public Object getProjectIdOrPath(Object obj) throws GitLabApiException {
if (obj == null) {
throw (new RuntimeException("Cannot determine ID or path from null object"));
} else if (obj instanceof Long) {
return (obj);
} else if (obj instanceof String) {
return (urlEncode(((String) obj).trim()));
} else if (obj instanceof Project) {
Long id = ((Project) obj).getId();
if (id != null && id.longValue() > 0) {
return (id);
}
String path = ((Project) obj).getPathWithNamespace();
if (path != null && path.trim().length() > 0) {
return (urlEncode(path.trim()));
}
throw (new RuntimeException("Cannot determine ID or path from provided Project instance"));
} else {
throw (new RuntimeException("Cannot determine ID or path from provided " + obj.getClass().getSimpleName() +
" instance, must be Long, String, or a Project instance"));
}
}
/**
* Returns the group ID or path from the provided Integer, String, or Group instance.
*
* @param obj the object to determine the ID or path from
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
* @return the group ID or path from the provided Long, String, or Group instance
* @throws GitLabApiException if any exception occurs during execution
*/
public Object getGroupIdOrPath(Object obj) throws GitLabApiException {
if (obj == null) {
throw (new RuntimeException("Cannot determine ID or path from null object"));
} else if (obj instanceof Long) {
return (obj);
} else if (obj instanceof String) {
return (urlEncode(((String) obj).trim()));
} else if (obj instanceof Group) {
Long id = ((Group) obj).getId();
if (id != null && id.longValue() > 0) {
return (id);
}
String path = ((Group) obj).getFullPath();
if (path != null && path.trim().length() > 0) {
return (urlEncode(path.trim()));
}
throw (new RuntimeException("Cannot determine ID or path from provided Group instance"));
} else {
throw (new RuntimeException("Cannot determine ID or path from provided " + obj.getClass().getSimpleName() +
" instance, must be Long, String, or a Group instance"));
}
}
/**
* Returns the user ID or path from the provided Integer, String, or User instance.
*
* @param obj the object to determine the ID or username from
* @return the user ID or username from the provided Integer, String, or User instance
* @throws GitLabApiException if any exception occurs during execution
*/
public Object getUserIdOrUsername(Object obj) throws GitLabApiException {
if (obj == null) {
throw (new RuntimeException("Cannot determine ID or username from null object"));
} else if (obj instanceof Long) {
return (obj);
} else if (obj instanceof String) {
return (urlEncode(((String) obj).trim()));
} else if (obj instanceof User) {
Long id = ((User) obj).getId();
if (id != null && id.longValue() > 0) {
return (id);
}
String username = ((User) obj).getUsername();
if (username != null && username.trim().length() > 0) {
return (urlEncode(username.trim()));
}
throw (new RuntimeException("Cannot determine ID or username from provided User instance"));
} else {
throw (new RuntimeException("Cannot determine ID or username from provided " + obj.getClass().getSimpleName() +
" instance, must be Integer, String, or a User instance"));
}
}
/**
* Returns the label ID or name from the provided Integer, String, or Label instance.
*
* @param obj the object to determine the ID or name from