Require REST endpoints to return Response<?>
At the moment REST endpoints can choose if they return a result object (that will be converted to JSON automatically unless it is a BinaryResult) or if they return a response object that specifies the response status code and other properties like caching behavior in addition to the result object. In addition REST endpoints can return special objects like Response.Redirect and Response.Accepted to trigger special behavior (Response.Redirect and Response.Accepted are neither a result object, nor a response object). If the first approach is chosen and a result object is returned, it is not clear from the implementation of the REST endpoint which status code is returned to the client. By default it is '200 OK', for RestCollectionCreateViews that are invoked via HTTP PUT/POST it is '201 Created' and for RestCollectionDeleteMissingViews that are invoked via HTTP DELETE it is '204 No Content'. By forcing REST endpoints to return a response object they must specify the status code. Hence implementors must explicitly think about this. Hopefully this leads to a more consistent use of status codes in our REST API. At the moment it happens frequently that status codes are wrong and need to be fixed, which is always a bit risky since callers may rely on an expected status code. Having all REST endpoints return response objects also has the advantage that wrappers around REST endpoints, such as RetryingRestModifyView, can set additional properties on the response. E.g. change I2b78cbef5 implements automatic request tracing in RetryingRestModifyView, but currently has no possibility to return the trace ID to the client. If that was possible, error popups in the frontend could display the trace ID. If the trace ID is included into bug reports, investigation of issues gets easier and faster. Response.Redirect and Response.Accepted are made subclasses of Response so that REST endpoints can still return them. Change-Id: I1dd37821a8a859ade43336eb5f6cce6bcc71fc02 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -240,7 +240,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public AccountDetailInfo detail() throws RestApiException {
|
||||
try {
|
||||
return getDetail.apply(account);
|
||||
return getDetail.apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get detail", e);
|
||||
}
|
||||
@@ -274,7 +274,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public GeneralPreferencesInfo getPreferences() throws RestApiException {
|
||||
try {
|
||||
return getPreferences.apply(account);
|
||||
return getPreferences.apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get preferences", e);
|
||||
}
|
||||
@@ -283,7 +283,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public GeneralPreferencesInfo setPreferences(GeneralPreferencesInfo in) throws RestApiException {
|
||||
try {
|
||||
return setPreferences.apply(account, in);
|
||||
return setPreferences.apply(account, in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set preferences", e);
|
||||
}
|
||||
@@ -292,7 +292,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public DiffPreferencesInfo getDiffPreferences() throws RestApiException {
|
||||
try {
|
||||
return getDiffPreferences.apply(account);
|
||||
return getDiffPreferences.apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot query diff preferences", e);
|
||||
}
|
||||
@@ -301,7 +301,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public DiffPreferencesInfo setDiffPreferences(DiffPreferencesInfo in) throws RestApiException {
|
||||
try {
|
||||
return setDiffPreferences.apply(account, in);
|
||||
return setDiffPreferences.apply(account, in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set diff preferences", e);
|
||||
}
|
||||
@@ -310,7 +310,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public EditPreferencesInfo getEditPreferences() throws RestApiException {
|
||||
try {
|
||||
return getEditPreferences.apply(account);
|
||||
return getEditPreferences.apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot query edit preferences", e);
|
||||
}
|
||||
@@ -319,7 +319,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public EditPreferencesInfo setEditPreferences(EditPreferencesInfo in) throws RestApiException {
|
||||
try {
|
||||
return setEditPreferences.apply(account, in);
|
||||
return setEditPreferences.apply(account, in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set edit preferences", e);
|
||||
}
|
||||
@@ -328,7 +328,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public List<ProjectWatchInfo> getWatchedProjects() throws RestApiException {
|
||||
try {
|
||||
return getWatchedProjects.apply(account);
|
||||
return getWatchedProjects.apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get watched projects", e);
|
||||
}
|
||||
@@ -338,7 +338,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
public List<ProjectWatchInfo> setWatchedProjects(List<ProjectWatchInfo> in)
|
||||
throws RestApiException {
|
||||
try {
|
||||
return postWatchedProjects.apply(account, in);
|
||||
return postWatchedProjects.apply(account, in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot update watched projects", e);
|
||||
}
|
||||
@@ -389,7 +389,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
public SortedSet<String> getStars(String changeId) throws RestApiException {
|
||||
try {
|
||||
AccountResource.Star rsrc = stars.parse(account, IdString.fromUrl(changeId));
|
||||
return starsGet.apply(rsrc);
|
||||
return starsGet.apply(rsrc).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get stars", e);
|
||||
}
|
||||
@@ -398,7 +398,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public List<ChangeInfo> getStarredChanges() throws RestApiException {
|
||||
try {
|
||||
return stars.list().apply(account);
|
||||
return stars.list().apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get starred changes", e);
|
||||
}
|
||||
@@ -407,7 +407,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public List<GroupInfo> getGroups() throws RestApiException {
|
||||
try {
|
||||
return getGroups.apply(account);
|
||||
return getGroups.apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get groups", e);
|
||||
}
|
||||
@@ -416,7 +416,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public List<EmailInfo> getEmails() throws RestApiException {
|
||||
try {
|
||||
return getEmails.apply(account);
|
||||
return getEmails.apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get emails", e);
|
||||
}
|
||||
@@ -475,7 +475,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public List<SshKeyInfo> listSshKeys() throws RestApiException {
|
||||
try {
|
||||
return getSshKeys.apply(account);
|
||||
return getSshKeys.apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list SSH keys", e);
|
||||
}
|
||||
@@ -534,7 +534,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public List<AgreementInfo> listAgreements() throws RestApiException {
|
||||
try {
|
||||
return getAgreements.apply(account);
|
||||
return getAgreements.apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get agreements", e);
|
||||
}
|
||||
@@ -563,7 +563,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
@Override
|
||||
public List<AccountExternalIdInfo> getExternalIds() throws RestApiException {
|
||||
try {
|
||||
return getExternalIds.apply(account);
|
||||
return getExternalIds.apply(account).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get external IDs", e);
|
||||
}
|
||||
@@ -582,7 +582,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
public List<DeletedDraftCommentInfo> deleteDraftComments(DeleteDraftCommentsInput input)
|
||||
throws RestApiException {
|
||||
try {
|
||||
return deleteDraftComments.apply(account, input);
|
||||
return deleteDraftComments.apply(account, input).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete draft comments", e);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ public class AccountsImpl implements Accounts {
|
||||
myQueryAccounts.setSuggest(true);
|
||||
myQueryAccounts.setQuery(r.getQuery());
|
||||
myQueryAccounts.setLimit(r.getLimit());
|
||||
return myQueryAccounts.apply(TopLevelResource.INSTANCE);
|
||||
return myQueryAccounts.apply(TopLevelResource.INSTANCE).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve suggested accounts", e);
|
||||
}
|
||||
@@ -164,7 +164,7 @@ public class AccountsImpl implements Accounts {
|
||||
for (ListAccountsOption option : r.getOptions()) {
|
||||
myQueryAccounts.addOption(option);
|
||||
}
|
||||
return myQueryAccounts.apply(TopLevelResource.INSTANCE);
|
||||
return myQueryAccounts.apply(TopLevelResource.INSTANCE).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve suggested accounts", e);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class EmailApiImpl implements EmailApi {
|
||||
@Override
|
||||
public EmailInfo get() throws RestApiException {
|
||||
try {
|
||||
return get.apply(resource());
|
||||
return get.apply(resource()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot read email", e);
|
||||
}
|
||||
|
||||
@@ -351,7 +351,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
@Override
|
||||
public ChangeApi revert(RevertInput in) throws RestApiException {
|
||||
try {
|
||||
return changeApi.id(revert.apply(change, in)._number);
|
||||
return changeApi.id(revert.apply(change, in).value()._number);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot revert change", e);
|
||||
}
|
||||
@@ -401,7 +401,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
|
||||
@Override
|
||||
public String topic() throws RestApiException {
|
||||
return getTopic.apply(change);
|
||||
return getTopic.apply(change).value();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -418,7 +418,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
@Override
|
||||
public IncludedInInfo includedIn() throws RestApiException {
|
||||
try {
|
||||
return includedIn.apply(change);
|
||||
return includedIn.apply(change).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Could not extract IncludedIn data", e);
|
||||
}
|
||||
@@ -427,7 +427,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
@Override
|
||||
public AddReviewerResult addReviewer(AddReviewerInput in) throws RestApiException {
|
||||
try {
|
||||
return postReviewers.apply(change, in);
|
||||
return postReviewers.apply(change, in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot add change reviewer", e);
|
||||
}
|
||||
@@ -448,7 +448,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
try {
|
||||
suggestReviewers.setQuery(r.getQuery());
|
||||
suggestReviewers.setLimit(r.getLimit());
|
||||
return suggestReviewers.apply(change);
|
||||
return suggestReviewers.apply(change).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve suggested reviewers", e);
|
||||
}
|
||||
@@ -457,7 +457,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
@Override
|
||||
public List<ReviewerInfo> reviewers() throws RestApiException {
|
||||
try {
|
||||
return listReviewers.apply(change);
|
||||
return listReviewers.apply(change).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve reviewers", e);
|
||||
}
|
||||
@@ -512,7 +512,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
@Override
|
||||
public AccountInfo setAssignee(AssigneeInput input) throws RestApiException {
|
||||
try {
|
||||
return putAssignee.apply(change, input);
|
||||
return putAssignee.apply(change, input).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set assignee", e);
|
||||
}
|
||||
@@ -550,7 +550,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
@Override
|
||||
public Map<String, List<CommentInfo>> comments() throws RestApiException {
|
||||
try {
|
||||
return listComments.apply(change);
|
||||
return listComments.apply(change).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get comments", e);
|
||||
}
|
||||
@@ -559,7 +559,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
@Override
|
||||
public Map<String, List<RobotCommentInfo>> robotComments() throws RestApiException {
|
||||
try {
|
||||
return listChangeRobotComments.apply(change);
|
||||
return listChangeRobotComments.apply(change).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get robot comments", e);
|
||||
}
|
||||
@@ -568,7 +568,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
@Override
|
||||
public Map<String, List<CommentInfo>> drafts() throws RestApiException {
|
||||
try {
|
||||
return listDrafts.apply(change);
|
||||
return listDrafts.apply(change).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get drafts", e);
|
||||
}
|
||||
@@ -653,7 +653,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
try {
|
||||
GetPureRevert getPureRevert = getPureRevertProvider.get();
|
||||
getPureRevert.setClaimedOriginal(claimedOriginal);
|
||||
return getPureRevert.apply(change);
|
||||
return getPureRevert.apply(change).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot compute pure revert", e);
|
||||
}
|
||||
@@ -662,7 +662,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
@Override
|
||||
public List<ChangeMessageInfo> messages() throws RestApiException {
|
||||
try {
|
||||
return changeMessages.list().apply(change);
|
||||
return changeMessages.list().apply(change).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list change messages", e);
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ public class ChangeEditApiImpl implements ChangeEditApi {
|
||||
public String getCommitMessage() throws RestApiException {
|
||||
try {
|
||||
try (BinaryResult binaryResult =
|
||||
getChangeEditCommitMessageProvider.get().apply(changeResource)) {
|
||||
getChangeEditCommitMessageProvider.get().apply(changeResource).value()) {
|
||||
return binaryResult.asString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -48,7 +48,7 @@ class ChangeMessageApiImpl implements ChangeMessageApi {
|
||||
@Override
|
||||
public ChangeMessageInfo get() throws RestApiException {
|
||||
try {
|
||||
return getChangeMessage.apply(changeMessageResource);
|
||||
return getChangeMessage.apply(changeMessageResource).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve change message", e);
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ class ChangesImpl implements Changes {
|
||||
dynamicOptionParser.parseDynamicOptions(qc, q.getPluginOptions());
|
||||
|
||||
try {
|
||||
List<?> result = qc.apply(TopLevelResource.INSTANCE);
|
||||
List<?> result = qc.apply(TopLevelResource.INSTANCE).value();
|
||||
if (result.isEmpty()) {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class CommentApiImpl implements CommentApi {
|
||||
@Override
|
||||
public CommentInfo get() throws RestApiException {
|
||||
try {
|
||||
return getComment.apply(comment);
|
||||
return getComment.apply(comment).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve comment", e);
|
||||
}
|
||||
@@ -55,7 +55,7 @@ class CommentApiImpl implements CommentApi {
|
||||
@Override
|
||||
public CommentInfo delete(DeleteCommentInput input) throws RestApiException {
|
||||
try {
|
||||
return deleteComment.apply(comment, input);
|
||||
return deleteComment.apply(comment, input).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot delete comment", e);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class DraftApiImpl implements DraftApi {
|
||||
@Override
|
||||
public CommentInfo get() throws RestApiException {
|
||||
try {
|
||||
return getDraft.apply(draft);
|
||||
return getDraft.apply(draft).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve draft", e);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class FileApiImpl implements FileApi {
|
||||
@Override
|
||||
public BinaryResult content() throws RestApiException {
|
||||
try {
|
||||
return getContent.apply(file);
|
||||
return getContent.apply(file).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve file content", e);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class ReviewerApiImpl implements ReviewerApi {
|
||||
@Override
|
||||
public Map<String, Short> votes() throws RestApiException {
|
||||
try {
|
||||
return listVotes.apply(reviewer);
|
||||
return listVotes.apply(reviewer).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list votes", e);
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
public BinaryResult submitPreview(String format) throws RestApiException {
|
||||
try {
|
||||
submitPreview.setFormat(format);
|
||||
return submitPreview.apply(revision);
|
||||
return submitPreview.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get submit preview", e);
|
||||
}
|
||||
@@ -263,7 +263,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public ChangeApi rebase(RebaseInput in) throws RestApiException {
|
||||
try {
|
||||
return changes.id(rebase.apply(revision, in)._number);
|
||||
return changes.id(rebase.apply(revision, in).value()._number);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot rebase ps", e);
|
||||
}
|
||||
@@ -282,7 +282,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public ChangeApi cherryPick(CherryPickInput in) throws RestApiException {
|
||||
try {
|
||||
return changes.id(cherryPick.apply(revision, in)._number);
|
||||
return changes.id(cherryPick.apply(revision, in).value()._number);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot cherry pick", e);
|
||||
}
|
||||
@@ -291,7 +291,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public CherryPickChangeInfo cherryPickAsInfo(CherryPickInput in) throws RestApiException {
|
||||
try {
|
||||
return cherryPick.apply(revision, in);
|
||||
return cherryPick.apply(revision, in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot cherry pick", e);
|
||||
}
|
||||
@@ -336,7 +336,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public MergeableInfo mergeable() throws RestApiException {
|
||||
try {
|
||||
return mergeable.apply(revision);
|
||||
return mergeable.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot check mergeability", e);
|
||||
}
|
||||
@@ -346,7 +346,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
public MergeableInfo mergeableOtherBranches() throws RestApiException {
|
||||
try {
|
||||
mergeable.setOtherBranches(true);
|
||||
return mergeable.apply(revision);
|
||||
return mergeable.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot check mergeability", e);
|
||||
}
|
||||
@@ -400,7 +400,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public Map<String, List<CommentInfo>> comments() throws RestApiException {
|
||||
try {
|
||||
return listComments.apply(revision);
|
||||
return listComments.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve comments", e);
|
||||
}
|
||||
@@ -409,7 +409,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public Map<String, List<RobotCommentInfo>> robotComments() throws RestApiException {
|
||||
try {
|
||||
return listRobotComments.apply(revision);
|
||||
return listRobotComments.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve robot comments", e);
|
||||
}
|
||||
@@ -427,7 +427,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public Map<String, List<CommentInfo>> drafts() throws RestApiException {
|
||||
try {
|
||||
return listDrafts.apply(revision);
|
||||
return listDrafts.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve drafts", e);
|
||||
}
|
||||
@@ -504,7 +504,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public BinaryResult patch() throws RestApiException {
|
||||
try {
|
||||
return getPatch.apply(revision);
|
||||
return getPatch.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get patch", e);
|
||||
}
|
||||
@@ -513,7 +513,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public BinaryResult patch(String path) throws RestApiException {
|
||||
try {
|
||||
return getPatch.setPath(path).apply(revision);
|
||||
return getPatch.setPath(path).apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get patch", e);
|
||||
}
|
||||
@@ -531,7 +531,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public SubmitType submitType() throws RestApiException {
|
||||
try {
|
||||
return getSubmitType.apply(revision);
|
||||
return getSubmitType.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get submit type", e);
|
||||
}
|
||||
@@ -540,7 +540,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public SubmitType testSubmitType(TestSubmitRuleInput in) throws RestApiException {
|
||||
try {
|
||||
return testSubmitType.apply(revision, in);
|
||||
return testSubmitType.apply(revision, in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot test submit type", e);
|
||||
}
|
||||
@@ -549,7 +549,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public List<TestSubmitRuleInfo> testSubmitRule(TestSubmitRuleInput in) throws RestApiException {
|
||||
try {
|
||||
return testSubmitRule.get().apply(revision, in);
|
||||
return testSubmitRule.get().apply(revision, in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot test submit rule", e);
|
||||
}
|
||||
@@ -575,7 +575,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
@Override
|
||||
public RelatedChangesInfo related() throws RestApiException {
|
||||
try {
|
||||
return getRelated.apply(revision);
|
||||
return getRelated.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get related changes", e);
|
||||
}
|
||||
@@ -624,7 +624,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
|
||||
@Override
|
||||
public String description() throws RestApiException {
|
||||
return getDescription.apply(revision);
|
||||
return getDescription.apply(revision).value();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,7 +47,7 @@ public class RevisionReviewerApiImpl implements RevisionReviewerApi {
|
||||
@Override
|
||||
public Map<String, Short> votes() throws RestApiException {
|
||||
try {
|
||||
return listVotes.apply(reviewer);
|
||||
return listVotes.apply(reviewer).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list votes", e);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class RobotCommentApiImpl implements RobotCommentApi {
|
||||
@Override
|
||||
public RobotCommentInfo get() throws RestApiException {
|
||||
try {
|
||||
return getComment.apply(comment);
|
||||
return getComment.apply(comment).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve robot comment", e);
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ public class ServerImpl implements Server {
|
||||
@Override
|
||||
public ServerInfo getInfo() throws RestApiException {
|
||||
try {
|
||||
return getServerInfo.apply(new ConfigResource());
|
||||
return getServerInfo.apply(new ConfigResource()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get server info", e);
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public class ServerImpl implements Server {
|
||||
@Override
|
||||
public GeneralPreferencesInfo getDefaultPreferences() throws RestApiException {
|
||||
try {
|
||||
return getPreferences.apply(new ConfigResource());
|
||||
return getPreferences.apply(new ConfigResource()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get default general preferences", e);
|
||||
}
|
||||
@@ -102,7 +102,7 @@ public class ServerImpl implements Server {
|
||||
public GeneralPreferencesInfo setDefaultPreferences(GeneralPreferencesInfo in)
|
||||
throws RestApiException {
|
||||
try {
|
||||
return setPreferences.apply(new ConfigResource(), in);
|
||||
return setPreferences.apply(new ConfigResource(), in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set default general preferences", e);
|
||||
}
|
||||
@@ -111,7 +111,7 @@ public class ServerImpl implements Server {
|
||||
@Override
|
||||
public DiffPreferencesInfo getDefaultDiffPreferences() throws RestApiException {
|
||||
try {
|
||||
return getDiffPreferences.apply(new ConfigResource());
|
||||
return getDiffPreferences.apply(new ConfigResource()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get default diff preferences", e);
|
||||
}
|
||||
@@ -121,7 +121,7 @@ public class ServerImpl implements Server {
|
||||
public DiffPreferencesInfo setDefaultDiffPreferences(DiffPreferencesInfo in)
|
||||
throws RestApiException {
|
||||
try {
|
||||
return setDiffPreferences.apply(new ConfigResource(), in);
|
||||
return setDiffPreferences.apply(new ConfigResource(), in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set default diff preferences", e);
|
||||
}
|
||||
@@ -130,7 +130,7 @@ public class ServerImpl implements Server {
|
||||
@Override
|
||||
public EditPreferencesInfo getDefaultEditPreferences() throws RestApiException {
|
||||
try {
|
||||
return getEditPreferences.apply(new ConfigResource());
|
||||
return getEditPreferences.apply(new ConfigResource()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get default edit preferences", e);
|
||||
}
|
||||
@@ -140,7 +140,7 @@ public class ServerImpl implements Server {
|
||||
public EditPreferencesInfo setDefaultEditPreferences(EditPreferencesInfo in)
|
||||
throws RestApiException {
|
||||
try {
|
||||
return setEditPreferences.apply(new ConfigResource(), in);
|
||||
return setEditPreferences.apply(new ConfigResource(), in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot set default edit preferences", e);
|
||||
}
|
||||
@@ -149,7 +149,7 @@ public class ServerImpl implements Server {
|
||||
@Override
|
||||
public ConsistencyCheckInfo checkConsistency(ConsistencyCheckInput in) throws RestApiException {
|
||||
try {
|
||||
return checkConsistency.get().apply(new ConfigResource(), in);
|
||||
return checkConsistency.get().apply(new ConfigResource(), in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot check consistency", e);
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ class GroupApiImpl implements GroupApi {
|
||||
@Override
|
||||
public GroupInfo get() throws RestApiException {
|
||||
try {
|
||||
return getGroup.apply(rsrc);
|
||||
return getGroup.apply(rsrc).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve group", e);
|
||||
}
|
||||
@@ -128,7 +128,7 @@ class GroupApiImpl implements GroupApi {
|
||||
@Override
|
||||
public GroupInfo detail() throws RestApiException {
|
||||
try {
|
||||
return getDetail.apply(rsrc);
|
||||
return getDetail.apply(rsrc).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve group", e);
|
||||
}
|
||||
@@ -136,7 +136,7 @@ class GroupApiImpl implements GroupApi {
|
||||
|
||||
@Override
|
||||
public String name() throws RestApiException {
|
||||
return getName.apply(rsrc);
|
||||
return getName.apply(rsrc).value();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -153,7 +153,7 @@ class GroupApiImpl implements GroupApi {
|
||||
@Override
|
||||
public GroupInfo owner() throws RestApiException {
|
||||
try {
|
||||
return getOwner.apply(rsrc);
|
||||
return getOwner.apply(rsrc).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get group owner", e);
|
||||
}
|
||||
@@ -172,7 +172,7 @@ class GroupApiImpl implements GroupApi {
|
||||
|
||||
@Override
|
||||
public String description() throws RestApiException {
|
||||
return getDescription.apply(rsrc);
|
||||
return getDescription.apply(rsrc).value();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -188,7 +188,7 @@ class GroupApiImpl implements GroupApi {
|
||||
|
||||
@Override
|
||||
public GroupOptionsInfo options() throws RestApiException {
|
||||
return getOptions.apply(rsrc);
|
||||
return getOptions.apply(rsrc).value();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -209,7 +209,7 @@ class GroupApiImpl implements GroupApi {
|
||||
public List<AccountInfo> members(boolean recursive) throws RestApiException {
|
||||
listMembers.setRecursive(recursive);
|
||||
try {
|
||||
return listMembers.apply(rsrc);
|
||||
return listMembers.apply(rsrc).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list group members", e);
|
||||
}
|
||||
@@ -236,7 +236,7 @@ class GroupApiImpl implements GroupApi {
|
||||
@Override
|
||||
public List<GroupInfo> includedGroups() throws RestApiException {
|
||||
try {
|
||||
return listSubgroups.apply(rsrc);
|
||||
return listSubgroups.apply(rsrc).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list subgroups", e);
|
||||
}
|
||||
@@ -263,7 +263,7 @@ class GroupApiImpl implements GroupApi {
|
||||
@Override
|
||||
public List<? extends GroupAuditEventInfo> auditLog() throws RestApiException {
|
||||
try {
|
||||
return getAuditLog.apply(rsrc);
|
||||
return getAuditLog.apply(rsrc).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get audit log", e);
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ class GroupsImpl implements Groups {
|
||||
.currentUser()
|
||||
.checkAny(GlobalPermission.fromAnnotation(createGroup.getClass()));
|
||||
GroupInfo info =
|
||||
createGroup.apply(TopLevelResource.INSTANCE, IdString.fromDecoded(in.name), in);
|
||||
createGroup.apply(TopLevelResource.INSTANCE, IdString.fromDecoded(in.name), in).value();
|
||||
return id(info.id);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot create group " + in.name, e);
|
||||
@@ -154,7 +154,7 @@ class GroupsImpl implements Groups {
|
||||
list.setMatchRegex(req.getRegex());
|
||||
list.setSuggest(req.getSuggest());
|
||||
try {
|
||||
return list.apply(tlr);
|
||||
return list.apply(tlr).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list groups", e);
|
||||
}
|
||||
@@ -184,7 +184,7 @@ class GroupsImpl implements Groups {
|
||||
for (ListGroupsOption option : r.getOptions()) {
|
||||
myQueryGroups.addOption(option);
|
||||
}
|
||||
return myQueryGroups.apply(TopLevelResource.INSTANCE);
|
||||
return myQueryGroups.apply(TopLevelResource.INSTANCE).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot query groups", e);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class PluginApiImpl implements PluginApi {
|
||||
|
||||
@Override
|
||||
public PluginInfo get() throws RestApiException {
|
||||
return getStatus.apply(resource);
|
||||
return getStatus.apply(resource).value();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -59,7 +59,7 @@ public class PluginsImpl implements Plugins {
|
||||
return new ListRequest() {
|
||||
@Override
|
||||
public SortedMap<String, PluginInfo> getAsMap() throws RestApiException {
|
||||
return listProvider.get().request(this).apply(TopLevelResource.INSTANCE);
|
||||
return listProvider.get().request(this).apply(TopLevelResource.INSTANCE).value();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class BranchApiImpl implements BranchApi {
|
||||
@Override
|
||||
public BranchInfo get() throws RestApiException {
|
||||
try {
|
||||
return getBranch.apply(resource());
|
||||
return getBranch.apply(resource()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot read branch", e);
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public class BranchApiImpl implements BranchApi {
|
||||
public BinaryResult file(String path) throws RestApiException {
|
||||
try {
|
||||
FileResource resource = filesCollection.parse(resource(), IdString.fromDecoded(path));
|
||||
return getContent.apply(resource);
|
||||
return getContent.apply(resource).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve file", e);
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public class BranchApiImpl implements BranchApi {
|
||||
@Override
|
||||
public List<ReflogEntryInfo> reflog() throws RestApiException {
|
||||
try {
|
||||
return getReflog.apply(resource());
|
||||
return getReflog.apply(resource()).value();
|
||||
} catch (IOException | PermissionBackendException e) {
|
||||
throw new RestApiException("Cannot retrieve reflog", e);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,6 @@ public class ChildProjectApiImpl implements ChildProjectApi {
|
||||
@Override
|
||||
public ProjectInfo get(boolean recursive) throws RestApiException {
|
||||
getChildProject.setRecursive(recursive);
|
||||
return getChildProject.apply(rsrc);
|
||||
return getChildProject.apply(rsrc).value();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class CommitApiImpl implements CommitApi {
|
||||
@Override
|
||||
public ChangeApi cherryPick(CherryPickInput input) throws RestApiException {
|
||||
try {
|
||||
return changes.id(cherryPickCommit.apply(commitResource, input)._number);
|
||||
return changes.id(cherryPickCommit.apply(commitResource, input).value()._number);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot cherry pick", e);
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class CommitApiImpl implements CommitApi {
|
||||
@Override
|
||||
public IncludedInInfo includedIn() throws RestApiException {
|
||||
try {
|
||||
return includedIn.apply(commitResource);
|
||||
return includedIn.apply(commitResource).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Could not extract IncludedIn data", e);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class DashboardApiImpl implements DashboardApi {
|
||||
@Override
|
||||
public DashboardInfo get(boolean inherited) throws RestApiException {
|
||||
try {
|
||||
return get.get().setInherited(inherited).apply(resource());
|
||||
return get.get().setInherited(inherited).apply(resource()).value();
|
||||
} catch (IOException | PermissionBackendException | ConfigInvalidException e) {
|
||||
throw asRestApiException("Cannot read dashboard", e);
|
||||
}
|
||||
|
||||
@@ -368,13 +368,13 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
|
||||
@Override
|
||||
public String description() throws RestApiException {
|
||||
return getDescription.apply(checkExists());
|
||||
return getDescription.apply(checkExists()).value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectAccessInfo access() throws RestApiException {
|
||||
try {
|
||||
return getAccess.apply(checkExists());
|
||||
return getAccess.apply(checkExists()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get access rights", e);
|
||||
}
|
||||
@@ -383,7 +383,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
@Override
|
||||
public ProjectAccessInfo access(ProjectAccessInput p) throws RestApiException {
|
||||
try {
|
||||
return setAccess.apply(checkExists(), p);
|
||||
return setAccess.apply(checkExists(), p).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot put access rights", e);
|
||||
}
|
||||
@@ -401,7 +401,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
@Override
|
||||
public AccessCheckInfo checkAccess(AccessCheckInput in) throws RestApiException {
|
||||
try {
|
||||
return checkAccess.apply(checkExists(), in);
|
||||
return checkAccess.apply(checkExists(), in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot check access rights", e);
|
||||
}
|
||||
@@ -410,7 +410,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
@Override
|
||||
public CheckProjectResultInfo check(CheckProjectInput in) throws RestApiException {
|
||||
try {
|
||||
return check.apply(checkExists(), in);
|
||||
return check.apply(checkExists(), in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot check project", e);
|
||||
}
|
||||
@@ -427,13 +427,13 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
|
||||
@Override
|
||||
public ConfigInfo config() throws RestApiException {
|
||||
return getConfig.apply(checkExists());
|
||||
return getConfig.apply(checkExists()).value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigInfo config(ConfigInput in) throws RestApiException {
|
||||
try {
|
||||
return putConfig.apply(checkExists(), in);
|
||||
return putConfig.apply(checkExists(), in).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list tags", e);
|
||||
}
|
||||
@@ -445,7 +445,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
@Override
|
||||
public List<BranchInfo> get() throws RestApiException {
|
||||
try {
|
||||
return listBranches.get().request(this).apply(checkExists());
|
||||
return listBranches.get().request(this).apply(checkExists()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list branches", e);
|
||||
}
|
||||
@@ -459,7 +459,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
@Override
|
||||
public List<TagInfo> get() throws RestApiException {
|
||||
try {
|
||||
return listTags.get().request(this).apply(checkExists());
|
||||
return listTags.get().request(this).apply(checkExists()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list tags", e);
|
||||
}
|
||||
@@ -475,7 +475,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
@Override
|
||||
public List<ProjectInfo> children(boolean recursive) throws RestApiException {
|
||||
try {
|
||||
return children.list().withRecursive(recursive).apply(checkExists());
|
||||
return children.list().withRecursive(recursive).apply(checkExists()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list children", e);
|
||||
}
|
||||
@@ -484,7 +484,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
@Override
|
||||
public List<ProjectInfo> children(int limit) throws RestApiException {
|
||||
try {
|
||||
return children.list().withLimit(limit).apply(checkExists());
|
||||
return children.list().withLimit(limit).apply(checkExists()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot list children", e);
|
||||
}
|
||||
@@ -574,7 +574,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
@Override
|
||||
public List<DashboardInfo> get() throws RestApiException {
|
||||
try {
|
||||
List<?> r = listDashboards.get().apply(checkExists());
|
||||
List<?> r = listDashboards.get().apply(checkExists()).value();
|
||||
if (r.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -592,7 +592,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
@Override
|
||||
public String head() throws RestApiException {
|
||||
try {
|
||||
return getHead.apply(checkExists());
|
||||
return getHead.apply(checkExists()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get HEAD", e);
|
||||
}
|
||||
@@ -612,7 +612,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
@Override
|
||||
public String parent() throws RestApiException {
|
||||
try {
|
||||
return getParent.apply(checkExists());
|
||||
return getParent.apply(checkExists()).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get parent", e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user