Line data Source code
1 : // Copyright (C) 2011 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.change; 16 : 17 : import com.google.gerrit.entities.Account; 18 : import com.google.gerrit.entities.AccountGroup; 19 : import com.google.gerrit.index.query.PostFilterPredicate; 20 : import com.google.gerrit.server.IdentifiedUser; 21 : import com.google.gerrit.server.notedb.ReviewerStateInternal; 22 : 23 : public class ReviewerinPredicate extends PostFilterPredicate<ChangeData> { 24 : protected final IdentifiedUser.GenericFactory userFactory; 25 : protected final AccountGroup.UUID uuid; 26 : 27 : public ReviewerinPredicate(IdentifiedUser.GenericFactory userFactory, AccountGroup.UUID uuid) { 28 4 : super(ChangeQueryBuilder.FIELD_REVIEWERIN, uuid.get()); 29 4 : this.userFactory = userFactory; 30 4 : this.uuid = uuid; 31 4 : } 32 : 33 : protected AccountGroup.UUID getAccountGroupUUID() { 34 0 : return uuid; 35 : } 36 : 37 : @Override 38 : public boolean match(ChangeData object) { 39 4 : for (Account.Id accountId : object.reviewers().byState(ReviewerStateInternal.REVIEWER)) { 40 4 : IdentifiedUser reviewer = userFactory.create(accountId); 41 4 : if (reviewer.getEffectiveGroups().contains(uuid)) { 42 4 : return true; 43 : } 44 4 : } 45 4 : return false; 46 : } 47 : 48 : @Override 49 : public int getCost() { 50 4 : return 3; 51 : } 52 : }