Line data Source code
1 : // Copyright (C) 2015 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.entities.Account; 18 : import com.google.gerrit.extensions.common.AccountDetailInfo; 19 : import com.google.gerrit.extensions.restapi.Response; 20 : import com.google.gerrit.extensions.restapi.RestReadView; 21 : import com.google.gerrit.server.account.AccountDirectory.FillOptions; 22 : import com.google.gerrit.server.account.AccountResource; 23 : import com.google.gerrit.server.account.InternalAccountDirectory; 24 : import com.google.gerrit.server.permissions.PermissionBackendException; 25 : import com.google.inject.Inject; 26 : import com.google.inject.Singleton; 27 : import java.util.Collections; 28 : import java.util.EnumSet; 29 : 30 : /** 31 : * REST endpoint to get details of an account. 32 : * 33 : * <p>This REST endpoint handles {@code GET /accounts/<account-identifier>/detail} requests. 34 : * 35 : * <p>In the response all fields are populated. In contrast to this {@link GetAccount} populates 36 : * only a subset of the fields in the response. 37 : */ 38 : @Singleton 39 : public class GetDetail implements RestReadView<AccountResource> { 40 : private final InternalAccountDirectory directory; 41 : 42 : @Inject 43 148 : public GetDetail(InternalAccountDirectory directory) { 44 148 : this.directory = directory; 45 148 : } 46 : 47 : @Override 48 : public Response<AccountDetailInfo> apply(AccountResource rsrc) throws PermissionBackendException { 49 5 : Account a = rsrc.getUser().getAccount(); 50 5 : AccountDetailInfo info = new AccountDetailInfo(a.id().get()); 51 5 : info.setRegisteredOn(a.registeredOn()); 52 5 : info.inactive = !a.isActive() ? true : null; 53 5 : directory.fillAccountInfo(Collections.singleton(info), EnumSet.allOf(FillOptions.class)); 54 5 : return Response.ok(info); 55 : } 56 : }