| // Copyright (C) 2023 The Android Open Source Project | |
| // | |
| // Licensed under the Apache License, Version 2.0 (the "License"); | |
| // you may not use this file except in compliance with the License. | |
| // You may obtain a copy of the License at | |
| // | |
| // http://www.apache.org/licenses/LICENSE-2.0 | |
| // | |
| // Unless required by applicable law or agreed to in writing, software | |
| // distributed under the License is distributed on an "AS IS" BASIS, | |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| // See the License for the specific language governing permissions and | |
| // limitations under the License. | |
| package com.google.gerrit.server.rules.prolog; | |
| import com.google.gerrit.entities.SubmitRecord; | |
| import com.google.gerrit.entities.SubmitTypeRecord; | |
| import com.google.gerrit.server.query.change.ChangeData; | |
| import com.google.gerrit.server.rules.PrologSubmitRuleUtil; | |
| import com.google.inject.Singleton; | |
| import javax.inject.Inject; | |
| /** Implementation of {@link PrologSubmitRuleUtil}. */ | |
| @Singleton | |
| public class PrologSubmitRuleUtilImpl implements PrologSubmitRuleUtil { | |
| private final PrologRule prologRule; | |
| private final RulesCache rulesCache; | |
| @Inject | |
| public PrologSubmitRuleUtilImpl(PrologRule prologRule, RulesCache rulesCache) { | |
| this.prologRule = prologRule; | |
| this.rulesCache = rulesCache; | |
| } | |
| @Override | |
| public SubmitTypeRecord getSubmitType(ChangeData cd) { | |
| return prologRule.getSubmitType(cd); | |
| } | |
| @Override | |
| public SubmitTypeRecord getSubmitType(ChangeData cd, String ruleToTest, boolean skipFilters) { | |
| return prologRule.getSubmitType(cd, PrologOptions.dryRunOptions(ruleToTest, skipFilters)); | |
| } | |
| @Override | |
| public SubmitRecord evaluate(ChangeData cd, String ruleToTest, boolean skipFilters) { | |
| return prologRule.evaluate(cd, PrologOptions.dryRunOptions(ruleToTest, skipFilters)); | |
| } | |
| @Override | |
| public boolean isProjectRulesEnabled() { | |
| return rulesCache.isProjectRulesEnabled(); | |
| } | |
| } |