Files
gerrit/java/com/google/gerrit/server/audit/AuditService.java
David Ostrovsky 590071e7ff Isolate gerrit:server rule in gerrit/server package
Move c.g.g.rules and c.g.g.audit packages to c.g.g.server package to
reflect the real dependencies on server package for these clases.

This allows us to move server code related BUILD rules from general
package c.g.g to c.g.g.server package. With this small refactoring we
can achieve our goal having the BUILD files as close to the sources as
possible. Moreover, this non-intrusive change (no core plugins were
affected) significantly simplifies the whole build structure as this
allows us to eliminate BUILD rule in general c.g.g package.

Before this change a developer must study build files to actually
understand what parts of codes are controlled by c.g.g/BUILD build file.
With this change, it is obvious, because all BUILD files are located as
close as possible to the sources they control.

This changes also leaves place for improvement. At the moment, the
sources can be isolated from the giant java/com/google/gerrit/server
rules, the packages can be moved outside of c.g.g.server package and
de-coupled from java/com/google/gerrit/server rules, as it was already
done with receive, index, metrics and lifecycle packages. These future
and further decomposition of java/com/google/gerrit/server rule is
beyond of the scope of this change.

Change-Id: Iac35422bd9d6ad933c2dded2293c679cdd2aead5
2017-10-31 11:02:38 -04:00

90 lines
3.2 KiB
Java

// Copyright (C) 2012 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.audit;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroupById;
import com.google.gerrit.reviewdb.client.AccountGroupMember;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.Collection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
public class AuditService {
private static final Logger log = LoggerFactory.getLogger(AuditService.class);
private final DynamicSet<AuditListener> auditListeners;
private final DynamicSet<GroupMemberAuditListener> groupMemberAuditListeners;
@Inject
public AuditService(
DynamicSet<AuditListener> auditListeners,
DynamicSet<GroupMemberAuditListener> groupMemberAuditListeners) {
this.auditListeners = auditListeners;
this.groupMemberAuditListeners = groupMemberAuditListeners;
}
public void dispatch(AuditEvent action) {
for (AuditListener auditListener : auditListeners) {
auditListener.onAuditableAction(action);
}
}
public void dispatchAddAccountsToGroup(Account.Id actor, Collection<AccountGroupMember> added) {
for (GroupMemberAuditListener auditListener : groupMemberAuditListeners) {
try {
auditListener.onAddAccountsToGroup(actor, added);
} catch (RuntimeException e) {
log.error("failed to log add accounts to group event", e);
}
}
}
public void dispatchDeleteAccountsFromGroup(
Account.Id actor, Collection<AccountGroupMember> removed) {
for (GroupMemberAuditListener auditListener : groupMemberAuditListeners) {
try {
auditListener.onDeleteAccountsFromGroup(actor, removed);
} catch (RuntimeException e) {
log.error("failed to log delete accounts from group event", e);
}
}
}
public void dispatchAddGroupsToGroup(Account.Id actor, Collection<AccountGroupById> added) {
for (GroupMemberAuditListener auditListener : groupMemberAuditListeners) {
try {
auditListener.onAddGroupsToGroup(actor, added);
} catch (RuntimeException e) {
log.error("failed to log add groups to group event", e);
}
}
}
public void dispatchDeleteGroupsFromGroup(
Account.Id actor, Collection<AccountGroupById> removed) {
for (GroupMemberAuditListener auditListener : groupMemberAuditListeners) {
try {
auditListener.onDeleteGroupsFromGroup(actor, removed);
} catch (RuntimeException e) {
log.error("failed to log delete groups from group event", e);
}
}
}
}