Move CreateEmail.Input to EmailInput in extension API

So it can be used by following change(s) in the account API.

Change-Id: I5c216a0f8f630f0882a2277ab6fb412082113127
This commit is contained in:
David Pursehouse 2015-05-27 15:30:26 +09:00
parent 0fe430cc4e
commit 6544510802
4 changed files with 44 additions and 17 deletions

View File

@ -0,0 +1,34 @@
// Copyright (C) 2015 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.extensions.api.accounts;
import com.google.gerrit.extensions.restapi.DefaultInput;
/** This entity contains information for registering a new email address. */
public class EmailInput {
/* The email address. If provided, must match the email address from the URL. */
@DefaultInput
public String email;
/* Whether the new email address should become the preferred email address of
* the user. Only supported if {@link #noConfirmation} is set or if the
* authentication type is DEVELOPMENT_BECOME_ANY_ACCOUNT.*/
public boolean preferred;
/* Whether the email address should be added without confirmation. In this
* case no verification email is sent to the user. Only Gerrit administrators
* are allowed to add email addresses without confirmation. */
public boolean noConfirmation;
}

View File

@ -15,9 +15,9 @@
package com.google.gerrit.server.account;
import com.google.gerrit.common.errors.EmailException;
import com.google.gerrit.extensions.api.accounts.EmailInput;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.DefaultInput;
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
@ -27,7 +27,6 @@ import com.google.gerrit.reviewdb.client.Account.FieldName;
import com.google.gerrit.reviewdb.client.AuthType;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.CreateEmail.Input;
import com.google.gerrit.server.account.GetEmails.EmailInfo;
import com.google.gerrit.server.config.AuthConfig;
import com.google.gerrit.server.mail.RegisterNewEmailSender;
@ -40,16 +39,9 @@ import org.apache.commons.validator.routines.EmailValidator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CreateEmail implements RestModifyView<AccountResource, Input> {
public class CreateEmail implements RestModifyView<AccountResource, EmailInput> {
private final Logger log = LoggerFactory.getLogger(getClass());
public static class Input {
@DefaultInput
public String email;
public boolean preferred;
public boolean noConfirmation;
}
public static interface Factory {
CreateEmail create(String email);
}
@ -80,7 +72,7 @@ public class CreateEmail implements RestModifyView<AccountResource, Input> {
}
@Override
public Response<EmailInfo> apply(AccountResource rsrc, Input input)
public Response<EmailInfo> apply(AccountResource rsrc, EmailInput input)
throws AuthException, BadRequestException, ResourceConflictException,
ResourceNotFoundException, OrmException, EmailException,
MethodNotAllowedException {
@ -90,7 +82,7 @@ public class CreateEmail implements RestModifyView<AccountResource, Input> {
}
if (input == null) {
input = new Input();
input = new EmailInput();
}
if (!EmailValidator.getInstance().isValid(email)) {
@ -105,7 +97,7 @@ public class CreateEmail implements RestModifyView<AccountResource, Input> {
return apply(rsrc.getUser(), input);
}
public Response<EmailInfo> apply(IdentifiedUser user, Input input)
public Response<EmailInfo> apply(IdentifiedUser user, EmailInput input)
throws AuthException, BadRequestException, ResourceConflictException,
ResourceNotFoundException, OrmException, EmailException,
MethodNotAllowedException {

View File

@ -14,16 +14,16 @@
package com.google.gerrit.server.account;
import com.google.gerrit.extensions.api.accounts.EmailInput;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.server.account.CreateEmail.Input;
import com.google.inject.Singleton;
@Singleton
public class PutEmail implements RestModifyView<AccountResource.Email, Input> {
public class PutEmail implements RestModifyView<AccountResource.Email, EmailInput> {
@Override
public Response<?> apply(AccountResource.Email rsrc, Input input)
public Response<?> apply(AccountResource.Email rsrc, EmailInput input)
throws ResourceConflictException {
throw new ResourceConflictException("email exists");
}

View File

@ -18,6 +18,7 @@ import com.google.common.base.Strings;
import com.google.gerrit.common.data.GlobalCapability;
import com.google.gerrit.common.errors.EmailException;
import com.google.gerrit.extensions.annotations.RequiresCapability;
import com.google.gerrit.extensions.api.accounts.EmailInput;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.RawInput;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
@ -270,7 +271,7 @@ final class SetAccountCommand extends SshCommand {
private void addEmail(String email) throws UnloggedFailure, RestApiException,
OrmException {
CreateEmail.Input in = new CreateEmail.Input();
EmailInput in = new EmailInput();
in.email = email;
in.noConfirmation = true;
try {