use of com.google.gerrit.extensions.restapi.UnprocessableEntityException in project gerrit by GerritCodeReview.
the class ConfirmEmail method apply.
@Override
public Response<?> apply(ConfigResource rsrc, Input input) throws AuthException, UnprocessableEntityException, IOException, ConfigInvalidException {
CurrentUser user = self.get();
if (!user.isIdentifiedUser()) {
throw new AuthException("Authentication required");
}
if (input == null) {
input = new Input();
}
if (input.token == null) {
throw new UnprocessableEntityException("missing token");
}
try {
EmailTokenVerifier.ParsedToken token = emailTokenVerifier.decode(input.token);
Account.Id accId = user.getAccountId();
if (accId.equals(token.getAccountId())) {
accountManager.link(accId, token.toAuthRequest());
return Response.none();
}
throw new UnprocessableEntityException("invalid token");
} catch (EmailTokenVerifier.InvalidTokenException e) {
throw new UnprocessableEntityException("invalid token", e);
} catch (AccountException e) {
throw new UnprocessableEntityException(e.getMessage());
}
}
use of com.google.gerrit.extensions.restapi.UnprocessableEntityException in project gerrit by GerritCodeReview.
the class PostLabelsIT method cannotDeleteAndUpdateLabel.
@Test
public void cannotDeleteAndUpdateLabel() throws Exception {
configLabel("Foo", LabelFunction.NO_OP);
LabelDefinitionInput fooInput = new LabelDefinitionInput();
fooInput.function = LabelFunction.MAX_NO_BLOCK.getFunctionName();
BatchLabelInput input = new BatchLabelInput();
input.delete = ImmutableList.of("Foo");
input.update = ImmutableMap.of("Foo", fooInput);
UnprocessableEntityException thrown = assertThrows(UnprocessableEntityException.class, () -> gApi.projects().name(project.get()).labels(input));
assertThat(thrown).hasMessageThat().contains("label Foo not found");
}
use of com.google.gerrit.extensions.restapi.UnprocessableEntityException in project gerrit by GerritCodeReview.
the class PostLabelsIT method updateNonExistingLabel.
@Test
public void updateNonExistingLabel() throws Exception {
BatchLabelInput input = new BatchLabelInput();
input.update = ImmutableMap.of("Foo", new LabelDefinitionInput());
UnprocessableEntityException thrown = assertThrows(UnprocessableEntityException.class, () -> gApi.projects().name(allProjects.get()).labels(input));
assertThat(thrown).hasMessageThat().contains("label Foo not found");
}
use of com.google.gerrit.extensions.restapi.UnprocessableEntityException in project gerrit by GerritCodeReview.
the class PostLabelsIT method deleteNonExistingLabel.
@Test
public void deleteNonExistingLabel() throws Exception {
BatchLabelInput input = new BatchLabelInput();
input.delete = ImmutableList.of("Foo");
UnprocessableEntityException thrown = assertThrows(UnprocessableEntityException.class, () -> gApi.projects().name(allProjects.get()).labels(input));
assertThat(thrown).hasMessageThat().contains("label Foo not found");
}
use of com.google.gerrit.extensions.restapi.UnprocessableEntityException in project gerrit by GerritCodeReview.
the class ChangeInserter method updateChange.
@Override
public boolean updateChange(ChangeContext ctx) throws RestApiException, IOException, PermissionBackendException, ConfigInvalidException {
// Use defensive copy created by ChangeControl.
change = ctx.getChange();
patchSetInfo = patchSetInfoFactory.get(ctx.getRevWalk(), ctx.getRevWalk().parseCommit(commitId), psId);
ctx.getChange().setCurrentPatchSet(patchSetInfo);
ChangeUpdate update = ctx.getUpdate(psId);
update.setChangeId(change.getKey().get());
update.setSubjectForCommit("Create change");
update.setBranch(change.getDest().branch());
try {
update.setTopic(change.getTopic());
} catch (ValidationException ex) {
throw new BadRequestException(ex.getMessage());
}
update.setPsDescription(patchSetDescription);
update.setPrivate(isPrivate);
update.setWorkInProgress(workInProgress);
if (revertOf != null) {
update.setRevertOf(revertOf.get());
}
if (cherryPickOf != null) {
update.setCherryPickOf(cherryPickOf.getCommaSeparatedChangeAndPatchSetId());
}
List<String> newGroups = groups;
if (newGroups.isEmpty()) {
newGroups = GroupCollector.getDefaultGroups(commitId);
}
patchSet = psUtil.insert(ctx.getRevWalk(), update, psId, commitId, newGroups, pushCert, patchSetDescription);
/* TODO: fixStatusToMerged is used here because the tests
* (byStatusClosed() in AbstractQueryChangesTest)
* insert changes that are already merged,
* and setStatus may not be used to set the Status to merged
*
* is it possible to make the tests use the merge code path,
* instead of setting the status directly?
*/
if (change.getStatus() == Change.Status.MERGED) {
update.fixStatusToMerged(new SubmissionId(change));
} else {
update.setStatus(change.getStatus());
}
reviewerAdditions = reviewerModifier.prepare(ctx.getNotes(), ctx.getUser(), getReviewerInputs(), true);
Optional<ReviewerModification> reviewerError = reviewerAdditions.getFailures().stream().findFirst();
if (reviewerError.isPresent()) {
throw new UnprocessableEntityException(reviewerError.get().result.error);
}
reviewerAdditions.updateChange(ctx, patchSet);
LabelTypes labelTypes = projectState.getLabelTypes();
approvalsUtil.addApprovalsForNewPatchSet(update, labelTypes, patchSet, ctx.getUser(), approvals);
// reviewer which is needed in several other code paths.
if (!approvals.isEmpty()) {
update.putReviewer(ctx.getAccountId(), REVIEWER);
}
if (message != null) {
changeMessage = cmUtil.setChangeMessage(update, message, ChangeMessagesUtil.uploadedPatchSetTag(workInProgress));
}
return true;
}
Aggregations