LCOV - code coverage report
Current view: top level - server/cache/serialize/entities - ContributorAgreementSerializer.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 26 26 100.0 %
Date: 2022-11-19 15:00:39 Functions: 2 2 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2020 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.cache.serialize.entities;
      16             : 
      17             : import static com.google.common.base.Strings.emptyToNull;
      18             : import static com.google.common.base.Strings.nullToEmpty;
      19             : import static com.google.common.collect.ImmutableList.toImmutableList;
      20             : 
      21             : import com.google.gerrit.entities.ContributorAgreement;
      22             : import com.google.gerrit.server.cache.proto.Cache;
      23             : 
      24             : /** Helper to (de)serialize values for caches. */
      25             : public class ContributorAgreementSerializer {
      26             :   public static ContributorAgreement deserialize(Cache.ContributorAgreementProto proto) {
      27           1 :     ContributorAgreement.Builder builder =
      28           1 :         ContributorAgreement.builder(proto.getName())
      29           1 :             .setDescription(emptyToNull(proto.getDescription()))
      30           1 :             .setAccepted(
      31           1 :                 proto.getAcceptedList().stream()
      32           1 :                     .map(PermissionRuleSerializer::deserialize)
      33           1 :                     .collect(toImmutableList()))
      34           1 :             .setAgreementUrl(emptyToNull(proto.getUrl()))
      35           1 :             .setExcludeProjectsRegexes(proto.getExcludeRegularExpressionsList())
      36           1 :             .setMatchProjectsRegexes(proto.getMatchRegularExpressionsList());
      37           1 :     if (proto.hasAutoVerify()) {
      38           1 :       builder.setAutoVerify(GroupReferenceSerializer.deserialize(proto.getAutoVerify()));
      39             :     }
      40           1 :     return builder.build();
      41             :   }
      42             : 
      43             :   public static Cache.ContributorAgreementProto serialize(ContributorAgreement autoValue) {
      44             :     Cache.ContributorAgreementProto.Builder builder =
      45           1 :         Cache.ContributorAgreementProto.newBuilder()
      46           1 :             .setName(autoValue.getName())
      47           1 :             .setDescription(nullToEmpty(autoValue.getDescription()))
      48           1 :             .addAllAccepted(
      49           1 :                 autoValue.getAccepted().stream()
      50           1 :                     .map(PermissionRuleSerializer::serialize)
      51           1 :                     .collect(toImmutableList()))
      52           1 :             .setUrl(nullToEmpty(autoValue.getAgreementUrl()))
      53           1 :             .addAllExcludeRegularExpressions(autoValue.getExcludeProjectsRegexes())
      54           1 :             .addAllMatchRegularExpressions(autoValue.getMatchProjectsRegexes());
      55           1 :     if (autoValue.getAutoVerify() != null) {
      56           1 :       builder.setAutoVerify(GroupReferenceSerializer.serialize(autoValue.getAutoVerify()));
      57             :     }
      58           1 :     return builder.build();
      59             :   }
      60             : 
      61             :   private ContributorAgreementSerializer() {}
      62             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750