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.query.group; 16 : 17 : import com.google.gerrit.entities.Account; 18 : import com.google.gerrit.entities.AccountGroup; 19 : import com.google.gerrit.entities.InternalGroup; 20 : import com.google.gerrit.index.SchemaFieldDefs.SchemaField; 21 : import com.google.gerrit.index.query.IndexPredicate; 22 : import com.google.gerrit.index.query.Predicate; 23 : import com.google.gerrit.server.index.group.GroupField; 24 : import java.util.Locale; 25 : 26 : /** Utility class to create predicates for group index queries. */ 27 : public class GroupPredicates { 28 : public static Predicate<InternalGroup> id(AccountGroup.Id groupId) { 29 7 : return new GroupPredicate(GroupField.ID_FIELD_SPEC, groupId.toString()); 30 : } 31 : 32 : public static Predicate<InternalGroup> uuid(AccountGroup.UUID uuid) { 33 11 : return new GroupPredicate(GroupField.UUID_FIELD_SPEC, GroupQueryBuilder.FIELD_UUID, uuid.get()); 34 : } 35 : 36 : public static Predicate<InternalGroup> description(String description) { 37 7 : return new GroupPredicate( 38 : GroupField.DESCRIPTION_SPEC, GroupQueryBuilder.FIELD_DESCRIPTION, description); 39 : } 40 : 41 : public static Predicate<InternalGroup> inname(String name) { 42 7 : return new GroupPredicate( 43 7 : GroupField.NAME_PART_SPEC, GroupQueryBuilder.FIELD_INNAME, name.toLowerCase(Locale.US)); 44 : } 45 : 46 : public static Predicate<InternalGroup> name(String name) { 47 150 : return new GroupPredicate(GroupField.NAME_SPEC, name); 48 : } 49 : 50 : public static Predicate<InternalGroup> owner(AccountGroup.UUID ownerUuid) { 51 7 : return new GroupPredicate( 52 7 : GroupField.OWNER_UUID_SPEC, GroupQueryBuilder.FIELD_OWNER, ownerUuid.get()); 53 : } 54 : 55 : public static Predicate<InternalGroup> isVisibleToAll() { 56 2 : return new GroupPredicate(GroupField.IS_VISIBLE_TO_ALL_SPEC, "1"); 57 : } 58 : 59 : public static Predicate<InternalGroup> member(Account.Id memberId) { 60 22 : return new GroupPredicate(GroupField.MEMBER_SPEC, memberId.toString()); 61 : } 62 : 63 : public static Predicate<InternalGroup> subgroup(AccountGroup.UUID subgroupUuid) { 64 20 : return new GroupPredicate(GroupField.SUBGROUP_SPEC, subgroupUuid.get()); 65 : } 66 : 67 : /** Predicate that is mapped to a field in the group index. */ 68 : static class GroupPredicate extends IndexPredicate<InternalGroup> { 69 : GroupPredicate(SchemaField<InternalGroup, ?> def, String value) { 70 150 : super(def, value); 71 150 : } 72 : 73 : GroupPredicate(SchemaField<InternalGroup, ?> def, String name, String value) { 74 11 : super(def, name, value); 75 11 : } 76 : } 77 : 78 : private GroupPredicates() {} 79 : }