Line data Source code
1 : // Copyright (C) 2017 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.group; 16 : 17 : import com.google.gerrit.entities.GroupDescription; 18 : import com.google.gerrit.extensions.restapi.RestResource; 19 : import com.google.gerrit.extensions.restapi.RestView; 20 : import com.google.gerrit.server.account.GroupControl; 21 : import com.google.inject.TypeLiteral; 22 : import java.util.Optional; 23 : 24 : public class GroupResource implements RestResource { 25 152 : public static final TypeLiteral<RestView<GroupResource>> GROUP_KIND = new TypeLiteral<>() {}; 26 : 27 : private final GroupControl control; 28 : 29 30 : public GroupResource(GroupControl control) { 30 30 : this.control = control; 31 30 : } 32 : 33 1 : GroupResource(GroupResource rsrc) { 34 1 : this.control = rsrc.getControl(); 35 1 : } 36 : 37 : public GroupDescription.Basic getGroup() { 38 19 : return control.getGroup(); 39 : } 40 : 41 : public String getName() { 42 3 : return getGroup().getName(); 43 : } 44 : 45 : public boolean isInternalGroup() { 46 4 : GroupDescription.Basic group = getGroup(); 47 4 : return group instanceof GroupDescription.Internal; 48 : } 49 : 50 : public Optional<GroupDescription.Internal> asInternalGroup() { 51 13 : GroupDescription.Basic group = getGroup(); 52 13 : if (group instanceof GroupDescription.Internal) { 53 13 : return Optional.of((GroupDescription.Internal) group); 54 : } 55 0 : return Optional.empty(); 56 : } 57 : 58 : public GroupControl getControl() { 59 14 : return control; 60 : } 61 : }