LCOV - code coverage report
Current view: top level - server/audit - AuditService.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 22 22 100.0 %
Date: 2022-11-19 15:00:39 Functions: 6 11 54.5 %

          Line data    Source code
       1             : // Copyright (C) 2012 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.audit;
      16             : 
      17             : import com.google.common.collect.ImmutableSet;
      18             : import com.google.gerrit.entities.Account;
      19             : import com.google.gerrit.entities.AccountGroup;
      20             : import com.google.gerrit.server.AuditEvent;
      21             : import com.google.gerrit.server.audit.group.GroupAuditListener;
      22             : import com.google.gerrit.server.audit.group.GroupMemberAuditEvent;
      23             : import com.google.gerrit.server.audit.group.GroupSubgroupAuditEvent;
      24             : import com.google.gerrit.server.group.GroupAuditService;
      25             : import com.google.gerrit.server.plugincontext.PluginSetContext;
      26             : import com.google.inject.Inject;
      27             : import com.google.inject.Singleton;
      28             : import java.time.Instant;
      29             : 
      30             : @Singleton
      31             : public class AuditService implements GroupAuditService {
      32             :   private final PluginSetContext<AuditListener> auditListeners;
      33             :   private final PluginSetContext<GroupAuditListener> groupAuditListeners;
      34             : 
      35             :   @Inject
      36             :   public AuditService(
      37             :       PluginSetContext<AuditListener> auditListeners,
      38         151 :       PluginSetContext<GroupAuditListener> groupAuditListeners) {
      39         151 :     this.auditListeners = auditListeners;
      40         151 :     this.groupAuditListeners = groupAuditListeners;
      41         151 :   }
      42             : 
      43             :   @Override
      44             :   public void dispatch(AuditEvent action) {
      45          47 :     auditListeners.runEach(l -> l.onAuditableAction(action));
      46          47 :   }
      47             : 
      48             :   @Override
      49             :   public void dispatchAddMembers(
      50             :       Account.Id actor,
      51             :       AccountGroup.UUID updatedGroup,
      52             :       ImmutableSet<Account.Id> addedMembers,
      53             :       Instant addedOn) {
      54          34 :     GroupMemberAuditEvent event =
      55          34 :         GroupMemberAuditEvent.create(actor, updatedGroup, addedMembers, addedOn);
      56          34 :     groupAuditListeners.runEach(l -> l.onAddMembers(event));
      57          34 :   }
      58             : 
      59             :   @Override
      60             :   public void dispatchDeleteMembers(
      61             :       Account.Id actor,
      62             :       AccountGroup.UUID updatedGroup,
      63             :       ImmutableSet<Account.Id> deletedMembers,
      64             :       Instant deletedOn) {
      65           5 :     GroupMemberAuditEvent event =
      66           5 :         GroupMemberAuditEvent.create(actor, updatedGroup, deletedMembers, deletedOn);
      67           5 :     groupAuditListeners.runEach(l -> l.onDeleteMembers(event));
      68           5 :   }
      69             : 
      70             :   @Override
      71             :   public void dispatchAddSubgroups(
      72             :       Account.Id actor,
      73             :       AccountGroup.UUID updatedGroup,
      74             :       ImmutableSet<AccountGroup.UUID> addedSubgroups,
      75             :       Instant addedOn) {
      76           4 :     GroupSubgroupAuditEvent event =
      77           4 :         GroupSubgroupAuditEvent.create(actor, updatedGroup, addedSubgroups, addedOn);
      78           4 :     groupAuditListeners.runEach(l -> l.onAddSubgroups(event));
      79           4 :   }
      80             : 
      81             :   @Override
      82             :   public void dispatchDeleteSubgroups(
      83             :       Account.Id actor,
      84             :       AccountGroup.UUID updatedGroup,
      85             :       ImmutableSet<AccountGroup.UUID> deletedSubgroups,
      86             :       Instant deletedOn) {
      87           4 :     GroupSubgroupAuditEvent event =
      88           4 :         GroupSubgroupAuditEvent.create(actor, updatedGroup, deletedSubgroups, deletedOn);
      89           4 :     groupAuditListeners.runEach(l -> l.onDeleteSubgroups(event));
      90           4 :   }
      91             : }

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