Line data Source code
1 : // Copyright (C) 2022 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.project; 16 : 17 : import com.google.gerrit.entities.SubmitRequirement; 18 : import com.google.gerrit.extensions.common.SubmitRequirementInfo; 19 : import com.google.inject.Singleton; 20 : 21 : /** Converts a {@link SubmitRequirement} to a {@link SubmitRequirementInfo}. */ 22 : @Singleton 23 0 : public class SubmitRequirementJson { 24 : public static SubmitRequirementInfo format(SubmitRequirement sr) { 25 3 : SubmitRequirementInfo info = new SubmitRequirementInfo(); 26 3 : info.name = sr.name(); 27 3 : info.description = sr.description().orElse(null); 28 3 : if (sr.applicabilityExpression().isPresent()) { 29 2 : info.applicabilityExpression = sr.applicabilityExpression().get().expressionString(); 30 : } 31 3 : if (sr.overrideExpression().isPresent()) { 32 1 : info.overrideExpression = sr.overrideExpression().get().expressionString(); 33 : } 34 3 : info.submittabilityExpression = sr.submittabilityExpression().expressionString(); 35 3 : info.allowOverrideInChildProjects = sr.allowOverrideInChildProjects(); 36 3 : return info; 37 : } 38 : }