Commit ebc2eb04 authored by Greg Messner's avatar Greg Messner
Browse files

Added Optional<> support (#127).

parent bcd278bb
...@@ -25,6 +25,7 @@ package org.gitlab4j.api; ...@@ -25,6 +25,7 @@ package org.gitlab4j.api;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Optional;
import javax.ws.rs.core.GenericType; import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
...@@ -147,6 +148,23 @@ public class IssuesApi extends AbstractApi implements Constants { ...@@ -147,6 +148,23 @@ public class IssuesApi extends AbstractApi implements Constants {
return (response.readEntity(Issue.class)); return (response.readEntity(Issue.class));
} }
/**
* Get a single project issue as an Optional instance.
*
* GET /projects/:id/issues/:issue_iid
*
* @param projectId the project ID to get the issue for
* @param issueId the internal ID of a project's issue
* @return the specified Issue as an Optional instance
*/
public Optional<Issue> getOptionalIssue(Integer projectId, Integer issueId) {
try {
return (Optional.ofNullable(getIssue(projectId, issueId)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
/** /**
* Create an issue for the project. * Create an issue for the project.
* *
...@@ -462,13 +480,13 @@ public class IssuesApi extends AbstractApi implements Constants { ...@@ -462,13 +480,13 @@ public class IssuesApi extends AbstractApi implements Constants {
} }
/** /**
* Get time tracking stats * Get time tracking stats.
* *
* GET /projects/:id/issues/:issue_iid/time_stats * GET /projects/:id/issues/:issue_iid/time_stats
* *
* @param projectId the project ID that owns the issue * @param projectId the project ID that owns the issue
* @param issueIid the internal ID of a project's issue * @param issueIid the internal ID of a project's issue
* @return a TimeSTats instance * @return a TimeStats instance
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public TimeStats getTimeTrackingStats(Integer projectId, Integer issueIid) throws GitLabApiException { public TimeStats getTimeTrackingStats(Integer projectId, Integer issueIid) throws GitLabApiException {
...@@ -484,4 +502,21 @@ public class IssuesApi extends AbstractApi implements Constants { ...@@ -484,4 +502,21 @@ public class IssuesApi extends AbstractApi implements Constants {
Response response = get(Response.Status.OK, new GitLabApiForm().asMap(), "projects", projectId, "issues", issueIid, "time_stats"); Response response = get(Response.Status.OK, new GitLabApiForm().asMap(), "projects", projectId, "issues", issueIid, "time_stats");
return (response.readEntity(TimeStats.class)); return (response.readEntity(TimeStats.class));
} }
/**
* Get time tracking stats as an Optional instance
*
* GET /projects/:id/issues/:issue_iid/time_stats
*
* @param projectId the project ID that owns the issue
* @param issueIid the internal ID of a project's issue
* @return a TimeStats as an Optional instance
*/
public Optional<TimeStats> getOptionalTimeTrackingStats(Integer projectId, Integer issueIid) {
try {
return (Optional.ofNullable(getTimeTrackingStats(projectId, issueIid)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
} }
...@@ -6,6 +6,7 @@ import java.io.InputStream; ...@@ -6,6 +6,7 @@ import java.io.InputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.util.List; import java.util.List;
import java.util.Optional;
import javax.ws.rs.core.Form; import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType; import javax.ws.rs.core.GenericType;
...@@ -134,6 +135,23 @@ public class JobApi extends AbstractApi implements Constants { ...@@ -134,6 +135,23 @@ public class JobApi extends AbstractApi implements Constants {
return (response.readEntity(Job.class)); return (response.readEntity(Job.class));
} }
/**
* Get single job in a project as an Optional instance.
*
* GET /projects/:id/jobs/:job_id
*
* @param projectId the project ID to get the specified job for
* @param jobId the job ID to get
* @return a single job for the specified project ID as an Optional intance
*/
public Optional<Job> getOptionalJob(int projectId, int jobId) {
try {
return (Optional.ofNullable(getJob(projectId, jobId)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
/** /**
* Download the artifacts file from the given reference name and job provided the job finished successfully. * Download the artifacts file from the given reference name and job provided the job finished successfully.
* The file will be saved to the specified directory. If the file already exists in the directory it will * The file will be saved to the specified directory. If the file already exists in the directory it will
......
Supports Markdown
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