Line data Source code
1 : // Copyright (C) 2013 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.restapi.account; 16 : 17 : import com.google.gerrit.extensions.api.accounts.EmailInput; 18 : import com.google.gerrit.extensions.restapi.ResourceConflictException; 19 : import com.google.gerrit.extensions.restapi.Response; 20 : import com.google.gerrit.extensions.restapi.RestModifyView; 21 : import com.google.gerrit.server.account.AccountResource; 22 : import com.google.inject.Singleton; 23 : 24 : /** 25 : * REST endpoint for updating an existing email address of an account. 26 : * 27 : * <p>This REST endpoint handles {@code PUT 28 : * /accounts/<account-identifier>/emails/<email-identifier>} requests if the specified email address 29 : * already exists for the account. If it doesn't exist yet, the request is handled by {@link 30 : * CreateEmail}. 31 : * 32 : * <p>We do not support email address updates via this path, hence this REST endpoint always throws 33 : * a {@link ResourceConflictException} which results in a {@code 409 Conflict} response. 34 : * 35 : * <p>This REST endpoint solely exists to avoid user confusion if they create a new email address 36 : * with {@code PUT /accounts/<account-identifier>/emails/<email-identifier>} and then repeat the 37 : * same request. Without this REST endpoint the second request would fail with {@code 404 Not 38 : * Found}, which would be surprising to the user. 39 : */ 40 : @Singleton 41 138 : public class PutEmail implements RestModifyView<AccountResource.Email, EmailInput> { 42 : @Override 43 : public Response<?> apply(AccountResource.Email rsrc, EmailInput input) 44 : throws ResourceConflictException { 45 1 : throw new ResourceConflictException("email exists"); 46 : } 47 : }