LCOV - code coverage report
Current view: top level - server/extensions/events - ChangeDeleted.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 13 15 86.7 %
Date: 2022-11-19 15:00:39 Functions: 5 5 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2018 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.extensions.events;
      16             : 
      17             : import com.google.common.flogger.FluentLogger;
      18             : import com.google.gerrit.exceptions.StorageException;
      19             : import com.google.gerrit.extensions.api.changes.NotifyHandling;
      20             : import com.google.gerrit.extensions.common.AccountInfo;
      21             : import com.google.gerrit.extensions.common.ChangeInfo;
      22             : import com.google.gerrit.extensions.events.ChangeDeletedListener;
      23             : import com.google.gerrit.server.account.AccountState;
      24             : import com.google.gerrit.server.plugincontext.PluginSetContext;
      25             : import com.google.gerrit.server.query.change.ChangeData;
      26             : import com.google.inject.Inject;
      27             : import com.google.inject.Singleton;
      28             : import java.time.Instant;
      29             : 
      30             : /** Helper class to fire an event when a change has been deleted. */
      31             : @Singleton
      32             : public class ChangeDeleted {
      33         142 :   private static final FluentLogger logger = FluentLogger.forEnclosingClass();
      34             : 
      35             :   private final PluginSetContext<ChangeDeletedListener> listeners;
      36             :   private final EventUtil util;
      37             : 
      38             :   @Inject
      39         142 :   ChangeDeleted(PluginSetContext<ChangeDeletedListener> listeners, EventUtil util) {
      40         142 :     this.listeners = listeners;
      41         142 :     this.util = util;
      42         142 :   }
      43             : 
      44             :   public void fire(ChangeData changeData, AccountState deleter, Instant when) {
      45          11 :     if (listeners.isEmpty()) {
      46           4 :       return;
      47             :     }
      48             :     try {
      49           7 :       Event event = new Event(util.changeInfo(changeData), util.accountInfo(deleter), when);
      50           7 :       listeners.runEach(l -> l.onChangeDeleted(event));
      51           0 :     } catch (StorageException e) {
      52           0 :       logger.atSevere().withCause(e).log("Couldn't fire event");
      53           7 :     }
      54           7 :   }
      55             : 
      56             :   /** Event to be fired when a change has been deleted. */
      57             :   private static class Event extends AbstractChangeEvent implements ChangeDeletedListener.Event {
      58             :     Event(ChangeInfo change, AccountInfo deleter, Instant when) {
      59           7 :       super(change, deleter, when, NotifyHandling.ALL);
      60           7 :     }
      61             :   }
      62             : }

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