package org.sonar.ce.task.projectanalysis.component;
import org.apache.commons.lang.StringUtils;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
projectDto.setName(root.getName());
projectDto.setDescription(root.getDescription());
projectDto.setUpdatedAt(system2.now());
+ projectDto.setKey(root.getKey());
+ projectDto.setQualifier(root.getType().equals(Component.Type.PROJECT) ? Qualifiers.PROJECT : Qualifiers.APP);
return projectDto;
}
}
import static java.util.Optional.ofNullable;
import static org.sonar.api.resources.Qualifiers.PROJECT;
-import static org.sonar.api.resources.Qualifiers.VIEW;
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER;
import static org.sonar.db.component.ComponentDto.UUID_PATH_OF_ROOT;
import static org.sonar.db.component.ComponentDto.UUID_PATH_SEPARATOR;
.visit(treeRootHolder.getRoot());
disableRemainingComponents(dbSession, existingDtosByUuids.values());
- ensureConsistentVisibility(dbSession, projectUuid, isRootPrivate, treeRootHolder.getRoot().getType(), treeRootHolder.getRoot().getName());
-
+ dbClient.componentDao().setPrivateForRootComponentUuidWithoutAudit(dbSession, projectUuid, isRootPrivate);
dbSession.commit();
}
}
disabledComponentsHolder.setUuids(uuids);
}
- private void ensureConsistentVisibility(DbSession dbSession, String projectUuid, boolean isRootPrivate,
- Component.Type type, String componentName) {
- String qualifier = null;
- if (type == Component.Type.PROJECT) {
- qualifier = PROJECT;
- } else if (type == Component.Type.VIEW) {
- qualifier = VIEW;
- }
- dbClient.componentDao().setPrivateForRootComponentUuid(dbSession, projectUuid, isRootPrivate,
- "", qualifier, componentName, false);
- }
-
private static boolean isRootPrivate(Component root, Map<String, ComponentDto> existingDtosByUuids) {
ComponentDto rootDto = existingDtosByUuids.get(root.getUuid());
if (rootDto == null) {
import org.sonar.db.DbClient;
import org.sonar.db.DefaultDatabase;
import org.sonar.db.MyBatis;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.db.purge.PurgeProfiler;
import org.sonar.process.NetworkUtilsImpl;
import org.sonar.process.Props;
level1.getComponentByType(CECoreExtensionsInstaller.class)
.install(level1, hasPlatformLevel(1), noAdditionalSideFilter());
+ if (level1.getComponentByType(AuditPersister.class) == null) {
+ level1.add(NoOpAuditPersister.class);
+ }
level1.startComponents();
}
import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
+import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.db.property.PropertiesDao;
import org.sonar.db.property.PropertyDto;
*/
public class ReadOnlyPropertiesDao extends PropertiesDao {
public ReadOnlyPropertiesDao(MyBatis mybatis, System2 system2, UuidFactory uuidFactory) {
- super(mybatis, system2, uuidFactory);
+ super(mybatis, system2, uuidFactory, new NoOpAuditPersister());
}
@Override
private final System2 system2;
private final UuidFactory uuidFactory;
- private AuditPersister auditPersister;
-
- public AlmPatDao(System2 system2, UuidFactory uuidFactory) {
- this.system2 = system2;
- this.uuidFactory = uuidFactory;
- }
+ private final AuditPersister auditPersister;
public AlmPatDao(System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) {
this.system2 = system2;
almPatDto.setUpdatedAt(now);
getMapper(dbSession).insert(almPatDto);
- if (auditPersister != null) {
- auditPersister.addPersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almPatDto, userLogin, almSettingKey));
- }
+ auditPersister.addPersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almPatDto, userLogin, almSettingKey));
}
public void update(DbSession dbSession, AlmPatDto almPatDto, @Nullable String userLogin, @Nullable String almSettingKey) {
long now = system2.now();
almPatDto.setUpdatedAt(now);
getMapper(dbSession).update(almPatDto);
- if (auditPersister != null) {
- auditPersister.updatePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almPatDto, userLogin, almSettingKey));
- }
+ auditPersister.updatePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almPatDto, userLogin, almSettingKey));
}
public void delete(DbSession dbSession, AlmPatDto almPatDto, @Nullable String userLogin, @Nullable String almSettingKey) {
int deletedRows = getMapper(dbSession).deleteByUuid(almPatDto.getUuid());
- if (deletedRows > 0 && auditPersister != null) {
+ if (deletedRows > 0) {
auditPersister.deletePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almPatDto, userLogin, almSettingKey));
}
}
public void deleteByUser(DbSession dbSession, UserDto user) {
int deletedRows = getMapper(dbSession).deleteByUser(user.getUuid());
- if (deletedRows > 0 && auditPersister != null) {
+ if (deletedRows > 0) {
auditPersister.deletePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(user));
}
}
public void deleteByAlmSetting(DbSession dbSession, AlmSettingDto almSetting) {
int deletedRows = getMapper(dbSession).deleteByAlmSetting(almSetting.getUuid());
- if (deletedRows > 0 && auditPersister != null) {
+ if (deletedRows > 0) {
auditPersister.deletePersonalAccessToken(dbSession, new PersonalAccessTokenNewValue(almSetting));
}
}
private final System2 system2;
private final UuidFactory uuidFactory;
+ private final AuditPersister auditPersister;
- private AuditPersister auditPersister;
-
- public AlmSettingDao(System2 system2, UuidFactory uuidFactory) {
+ public AlmSettingDao(System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) {
this.system2 = system2;
this.uuidFactory = uuidFactory;
- }
-
- public AlmSettingDao(System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) {
- this(system2, uuidFactory);
this.auditPersister = auditPersister;
}
almSettingDto.setUpdatedAt(now);
getMapper(dbSession).insert(almSettingDto);
- if (auditPersister != null) {
- auditPersister.addDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSettingDto));
- }
+ auditPersister.addDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSettingDto));
}
public Optional<AlmSettingDto> selectByUuid(DbSession dbSession, String uuid) {
public void delete(DbSession dbSession, AlmSettingDto almSettingDto) {
int deletedRows = getMapper(dbSession).deleteByKey(almSettingDto.getKey());
- if (deletedRows > 0 && auditPersister != null) {
+ if (deletedRows > 0) {
auditPersister.deleteDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSettingDto.getUuid(), almSettingDto.getKey()));
}
}
long now = system2.now();
almSettingDto.setUpdatedAt(now);
getMapper(dbSession).update(almSettingDto);
-
- if (auditPersister != null) {
- if (updateSecret) {
- auditPersister.updateDevOpsPlatformSecret(dbSession, new SecretNewValue("DevOpsPlatform", almSettingDto.getRawAlm()));
- }
- auditPersister.updateDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSettingDto));
+ if (updateSecret) {
+ auditPersister.updateDevOpsPlatformSecret(dbSession, new SecretNewValue("DevOpsPlatform", almSettingDto.getRawAlm()));
}
+ auditPersister.updateDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSettingDto));
}
}
private final System2 system2;
private final UuidFactory uuidFactory;
- private AuditPersister auditPersister;
+ private final AuditPersister auditPersister;
- public ProjectAlmSettingDao(System2 system2, UuidFactory uuidFactory) {
+ public ProjectAlmSettingDao(System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) {
this.system2 = system2;
this.uuidFactory = uuidFactory;
- }
-
- public ProjectAlmSettingDao(System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) {
- this(system2, uuidFactory);
this.auditPersister = auditPersister;
}
- public void insertOrUpdate(DbSession dbSession, ProjectAlmSettingDto projectAlmSettingDto, String key,
- String projectName, String projectKey) {
+ public void insertOrUpdate(DbSession dbSession, ProjectAlmSettingDto projectAlmSettingDto, String key, String projectName, String projectKey) {
String uuid = uuidFactory.create();
long now = system2.now();
ProjectAlmSettingMapper mapper = getMapper(dbSession);
}
projectAlmSettingDto.setUpdatedAt(now);
- if (auditPersister != null) {
- DevOpsPlatformSettingNewValue value = new DevOpsPlatformSettingNewValue(projectAlmSettingDto, key,
- projectName, projectKey);
- if (isUpdate) {
- auditPersister.updateDevOpsPlatformSetting(dbSession, value);
- } else {
- auditPersister.addDevOpsPlatformSetting(dbSession, value);
- }
+ DevOpsPlatformSettingNewValue value = new DevOpsPlatformSettingNewValue(projectAlmSettingDto, key, projectName, projectKey);
+ if (isUpdate) {
+ auditPersister.updateDevOpsPlatformSetting(dbSession, value);
+ } else {
+ auditPersister.addDevOpsPlatformSetting(dbSession, value);
}
}
public void deleteByProject(DbSession dbSession, ProjectDto project) {
int deletedRows = getMapper(dbSession).deleteByProjectUuid(project.getUuid());
- if (deletedRows > 0 && auditPersister != null) {
+ if (deletedRows > 0) {
auditPersister.deleteDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(project));
}
}
import org.sonar.core.extension.PlatformLevel;
import org.sonar.db.DbSession;
-import org.sonar.db.audit.model.NewValue;
-
-import javax.annotation.Nullable;
+import org.sonar.db.audit.model.ComponentKeyNewValue;
+import org.sonar.db.audit.model.ComponentNewValue;
+import org.sonar.db.audit.model.DevOpsPlatformSettingNewValue;
+import org.sonar.db.audit.model.GroupPermissionNewValue;
+import org.sonar.db.audit.model.LicenseNewValue;
+import org.sonar.db.audit.model.PermissionTemplateNewValue;
+import org.sonar.db.audit.model.PersonalAccessTokenNewValue;
+import org.sonar.db.audit.model.PluginNewValue;
+import org.sonar.db.audit.model.PropertyNewValue;
+import org.sonar.db.audit.model.SecretNewValue;
+import org.sonar.db.audit.model.UserGroupNewValue;
+import org.sonar.db.audit.model.UserNewValue;
+import org.sonar.db.audit.model.UserPermissionNewValue;
+import org.sonar.db.audit.model.UserTokenNewValue;
+import org.sonar.db.audit.model.WebhookNewValue;
@PlatformLevel(1)
public interface AuditPersister {
- void addUserGroup(DbSession dbSession, NewValue newValue);
+ void addUserGroup(DbSession dbSession, UserGroupNewValue newValue);
- void updateUserGroup(DbSession dbSession, NewValue newValue);
+ void updateUserGroup(DbSession dbSession, UserGroupNewValue newValue);
- void deleteUserGroup(DbSession dbSession, NewValue newValue);
+ void deleteUserGroup(DbSession dbSession, UserGroupNewValue newValue);
- void addUser(DbSession dbSession, NewValue newValue);
+ void addUser(DbSession dbSession, UserNewValue newValue);
- void updateUser(DbSession dbSession, NewValue newValue);
+ void updateUser(DbSession dbSession, UserNewValue newValue);
- void updateUserPassword(DbSession dbSession, NewValue newValue);
+ void updateUserPassword(DbSession dbSession, SecretNewValue newValue);
- void updateWebhookSecret(DbSession dbSession, NewValue newValue);
+ void updateWebhookSecret(DbSession dbSession, SecretNewValue newValue);
- void updateDevOpsPlatformSecret(DbSession dbSession, NewValue newValue);
+ void updateDevOpsPlatformSecret(DbSession dbSession, SecretNewValue newValue);
- void deactivateUser(DbSession dbSession, NewValue newValue);
+ void deactivateUser(DbSession dbSession, UserNewValue newValue);
- void addUserToGroup(DbSession dbSession, NewValue newValue);
+ void addUserToGroup(DbSession dbSession, UserGroupNewValue newValue);
- void deleteUserFromGroup(DbSession dbSession, NewValue newValue);
+ void deleteUserFromGroup(DbSession dbSession, UserGroupNewValue newValue);
- void addProperty(DbSession dbSession, NewValue newValue, boolean isUserProperty);
+ void addProperty(DbSession dbSession, PropertyNewValue newValue, boolean isUserProperty);
- void updateProperty(DbSession dbSession, NewValue newValue, boolean isUserProperty);
+ void updateProperty(DbSession dbSession, PropertyNewValue newValue, boolean isUserProperty);
- void deleteProperty(DbSession dbSession, NewValue newValue, boolean isUserProperty);
+ void deleteProperty(DbSession dbSession, PropertyNewValue newValue, boolean isUserProperty);
- void addUserToken(DbSession dbSession, NewValue newValue);
+ void addUserToken(DbSession dbSession, UserTokenNewValue newValue);
- void updateUserToken(DbSession dbSession, NewValue newValue);
+ void updateUserToken(DbSession dbSession, UserTokenNewValue newValue);
- void deleteUserToken(DbSession dbSession, NewValue newValue);
+ void deleteUserToken(DbSession dbSession, UserTokenNewValue newValue);
- void addGroupPermission(DbSession dbSession, NewValue newValue);
+ void addGroupPermission(DbSession dbSession, GroupPermissionNewValue newValue);
- void deleteGroupPermission(DbSession dbSession, NewValue newValue);
+ void deleteGroupPermission(DbSession dbSession, GroupPermissionNewValue newValue);
- void addUserPermission(DbSession dbSession, NewValue newValue);
+ void addUserPermission(DbSession dbSession, UserPermissionNewValue newValue);
- void deleteUserPermission(DbSession dbSession, NewValue newValue);
+ void deleteUserPermission(DbSession dbSession, UserPermissionNewValue newValue);
- void addPermissionTemplate(DbSession dbSession, NewValue newValue);
+ void addPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue);
- void updatePermissionTemplate(DbSession dbSession, NewValue newValue);
+ void updatePermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue);
- void deletePermissionTemplate(DbSession dbSession, NewValue newValue);
+ void deletePermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue);
- void addUserToPermissionTemplate(DbSession dbSession, NewValue newValue);
+ void addUserToPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue);
- void deleteUserFromPermissionTemplate(DbSession dbSession, NewValue newValue);
+ void deleteUserFromPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue);
- void addGroupToPermissionTemplate(DbSession dbSession, NewValue newValue);
+ void addGroupToPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue);
- void deleteGroupFromPermissionTemplate(DbSession dbSession, NewValue newValue);
+ void deleteGroupFromPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue);
- void addCharacteristicToPermissionTemplate(DbSession dbSession, NewValue newValue);
+ void addCharacteristicToPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue);
- void updateCharacteristicInPermissionTemplate(DbSession dbSession, NewValue newValue);
+ void updateCharacteristicInPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue);
- void addPlugin(DbSession dbSession, NewValue newValue);
+ void addPlugin(DbSession dbSession, PluginNewValue newValue);
- void updatePlugin(DbSession dbSession, NewValue newValue);
+ void updatePlugin(DbSession dbSession, PluginNewValue newValue);
void generateSecretKey(DbSession dbSession);
- void setLicense(DbSession dbSession, boolean isSet, NewValue newValue);
+ void setLicense(DbSession dbSession, boolean isSet, LicenseNewValue newValue);
- void addWebhook(DbSession dbSession, NewValue newValue);
+ void addWebhook(DbSession dbSession, WebhookNewValue newValue);
- void updateWebhook(DbSession dbSession, NewValue newValue);
+ void updateWebhook(DbSession dbSession, WebhookNewValue newValue);
- void deleteWebhook(DbSession dbSession, NewValue newValue);
+ void deleteWebhook(DbSession dbSession, WebhookNewValue newValue);
- void addDevOpsPlatformSetting(DbSession dbSession, NewValue newValue);
+ void addDevOpsPlatformSetting(DbSession dbSession, DevOpsPlatformSettingNewValue newValue);
- void updateDevOpsPlatformSetting(DbSession dbSession, NewValue newValue);
+ void updateDevOpsPlatformSetting(DbSession dbSession, DevOpsPlatformSettingNewValue newValue);
- void deleteDevOpsPlatformSetting(DbSession dbSession, NewValue newValue);
+ void deleteDevOpsPlatformSetting(DbSession dbSession, DevOpsPlatformSettingNewValue newValue);
- void addPersonalAccessToken(DbSession dbSession, NewValue newValue);
+ void addPersonalAccessToken(DbSession dbSession, PersonalAccessTokenNewValue newValue);
- void updatePersonalAccessToken(DbSession dbSession, NewValue newValue);
+ void updatePersonalAccessToken(DbSession dbSession, PersonalAccessTokenNewValue newValue);
- void deletePersonalAccessToken(DbSession dbSession, NewValue newValue);
+ void deletePersonalAccessToken(DbSession dbSession, PersonalAccessTokenNewValue newValue);
boolean isTrackedProperty(String propertyKey);
- void addComponent(DbSession dbSession, NewValue newValue, String qualifier);
+ void addComponent(DbSession dbSession, ComponentNewValue newValue);
- void deleteComponent(DbSession dbSession, NewValue newValue, @Nullable String qualifier);
+ void deleteComponent(DbSession dbSession, ComponentNewValue newValue);
- void updateComponent(DbSession dbSession, NewValue newValue, String qualifier);
+ void updateComponent(DbSession dbSession, ComponentNewValue newValue);
- void updateComponentVisibility(DbSession session, NewValue componentNewValue, @Nullable String qualifier);
+ void updateComponentVisibility(DbSession session, ComponentNewValue componentNewValue);
- void componentKeyUpdate(DbSession session, NewValue componentKeyNewValue, String qualifier);
+ void componentKeyUpdate(DbSession session, ComponentKeyNewValue componentKeyNewValue, String qualifier);
- void componentKeyBranchUpdate(DbSession session, NewValue componentKeyNewValue, String qualifier);
+ void componentKeyBranchUpdate(DbSession session, ComponentKeyNewValue componentKeyNewValue, String qualifier);
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.audit;
+
+import org.sonar.db.DbSession;
+import org.sonar.db.audit.model.ComponentKeyNewValue;
+import org.sonar.db.audit.model.ComponentNewValue;
+import org.sonar.db.audit.model.DevOpsPlatformSettingNewValue;
+import org.sonar.db.audit.model.GroupPermissionNewValue;
+import org.sonar.db.audit.model.LicenseNewValue;
+import org.sonar.db.audit.model.PermissionTemplateNewValue;
+import org.sonar.db.audit.model.PersonalAccessTokenNewValue;
+import org.sonar.db.audit.model.PluginNewValue;
+import org.sonar.db.audit.model.PropertyNewValue;
+import org.sonar.db.audit.model.SecretNewValue;
+import org.sonar.db.audit.model.UserGroupNewValue;
+import org.sonar.db.audit.model.UserNewValue;
+import org.sonar.db.audit.model.UserPermissionNewValue;
+import org.sonar.db.audit.model.UserTokenNewValue;
+import org.sonar.db.audit.model.WebhookNewValue;
+
+public class NoOpAuditPersister implements AuditPersister {
+ @Override
+ public void addUserGroup(DbSession dbSession, UserGroupNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void updateUserGroup(DbSession dbSession, UserGroupNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void deleteUserGroup(DbSession dbSession, UserGroupNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void addUser(DbSession dbSession, UserNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void updateUser(DbSession dbSession, UserNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void updateUserPassword(DbSession dbSession, SecretNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void updateWebhookSecret(DbSession dbSession, SecretNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void updateDevOpsPlatformSecret(DbSession dbSession, SecretNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void deactivateUser(DbSession dbSession, UserNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void addUserToGroup(DbSession dbSession, UserGroupNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void deleteUserFromGroup(DbSession dbSession, UserGroupNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void addProperty(DbSession dbSession, PropertyNewValue newValue, boolean isUserProperty) {
+ // no op
+ }
+
+ @Override
+ public void updateProperty(DbSession dbSession, PropertyNewValue newValue, boolean isUserProperty) {
+ // no op
+ }
+
+ @Override
+ public void deleteProperty(DbSession dbSession, PropertyNewValue newValue, boolean isUserProperty) {
+ // no op
+ }
+
+ @Override
+ public void addUserToken(DbSession dbSession, UserTokenNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void updateUserToken(DbSession dbSession, UserTokenNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void deleteUserToken(DbSession dbSession, UserTokenNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void addGroupPermission(DbSession dbSession, GroupPermissionNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void deleteGroupPermission(DbSession dbSession, GroupPermissionNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void addUserPermission(DbSession dbSession, UserPermissionNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void deleteUserPermission(DbSession dbSession, UserPermissionNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void addPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void updatePermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void deletePermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void addUserToPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void deleteUserFromPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void addGroupToPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void deleteGroupFromPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void addCharacteristicToPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void updateCharacteristicInPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void addPlugin(DbSession dbSession, PluginNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void updatePlugin(DbSession dbSession, PluginNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void generateSecretKey(DbSession dbSession) {
+ // no op
+ }
+
+ @Override
+ public void setLicense(DbSession dbSession, boolean isSet, LicenseNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void addWebhook(DbSession dbSession, WebhookNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void updateWebhook(DbSession dbSession, WebhookNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void deleteWebhook(DbSession dbSession, WebhookNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void addDevOpsPlatformSetting(DbSession dbSession, DevOpsPlatformSettingNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void updateDevOpsPlatformSetting(DbSession dbSession, DevOpsPlatformSettingNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void deleteDevOpsPlatformSetting(DbSession dbSession, DevOpsPlatformSettingNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void addPersonalAccessToken(DbSession dbSession, PersonalAccessTokenNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void updatePersonalAccessToken(DbSession dbSession, PersonalAccessTokenNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void deletePersonalAccessToken(DbSession dbSession, PersonalAccessTokenNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public boolean isTrackedProperty(String propertyKey) {
+ return false;
+ }
+
+ @Override
+ public void addComponent(DbSession dbSession, ComponentNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void deleteComponent(DbSession dbSession, ComponentNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void updateComponent(DbSession dbSession, ComponentNewValue newValue) {
+ // no op
+ }
+
+ @Override
+ public void updateComponentVisibility(DbSession session, ComponentNewValue componentNewValue) {
+ // no op
+ }
+
+ @Override
+ public void componentKeyUpdate(DbSession session, ComponentKeyNewValue componentKeyNewValue, String qualifier) {
+ // no op
+ }
+
+ @Override
+ public void componentKeyBranchUpdate(DbSession session, ComponentKeyNewValue componentKeyNewValue, String qualifier) {
+ // no op
+ }
+}
*/
package org.sonar.db.audit.model;
-public class ComponentKeyNewValue extends NewValue{
+import static com.google.common.base.Preconditions.checkNotNull;
+
+public class ComponentKeyNewValue extends NewValue {
private final String componentUuid;
private final String oldKey;
private final String newKey;
public ComponentKeyNewValue(String componentUuid, String oldKey, String newKey) {
+ checkNotNull(componentUuid, oldKey, newKey);
this.componentUuid = componentUuid;
this.oldKey = oldKey;
this.newKey = newKey;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.ObjectUtils;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.project.ProjectDto;
-public class ComponentNewValue extends NewValue {
+import static java.util.Objects.requireNonNull;
- private String componentUuid;
- private String componentName;
- @Nullable
- private String description;
- private String rootComponentUuid;
- private String path;
- private String componentKey;
- private Boolean isPrivate;
+public class ComponentNewValue extends NewValue {
+ private final String componentUuid;
+ private final String componentKey;
+ private final String componentName;
+ private final String description;
+ private final Boolean isPrivate;
+ private final String qualifier;
private Boolean isEnabled;
- private String qualifier;
+ private String path;
- public ComponentNewValue(String componentUuid, String name, String componentKey, @Nullable String qualifier) {
- this.componentUuid = componentUuid;
- this.componentName = name;
- this.componentKey = componentKey;
- this.qualifier = getQualifier(qualifier);
+ public ComponentNewValue(ProjectDto project) {
+ this(project.getUuid(), project.getName(), project.getKey(), project.isPrivate(), project.getDescription(), project.getQualifier());
}
- public ComponentNewValue(String componentUuid, String name, String componentKey, boolean isPrivate, String qualifier) {
- this.componentUuid = componentUuid;
- this.componentName = name;
- this.componentKey = componentKey;
- this.isPrivate = isPrivate;
- this.qualifier = getQualifier(qualifier);
+ public ComponentNewValue(ComponentDto component) {
+ this(component.uuid(), component.name(), component.getKey(), component.isPrivate(), component.description(), component.qualifier());
}
- public ComponentNewValue(String uuid, String name, String componentKey, boolean enabled, String path, @Nullable String qualifier) {
- this.componentUuid = uuid;
- this.componentName = name;
+ public ComponentNewValue(String componentUuid, String componentName, String componentKey, String qualifier) {
+ this(componentUuid, componentName, componentKey, null, null, qualifier);
+ }
+
+ public ComponentNewValue(String componentUuid, String componentName, String componentKey, boolean isPrivate, String qualifier) {
+ this(componentUuid, isPrivate, componentName, componentKey, null, qualifier);
+ }
+
+ public ComponentNewValue(String uuid, String name, String key, boolean enabled, String path, String qualifier) {
+ this(uuid, name, key, null, null, qualifier);
this.isEnabled = enabled;
this.path = path;
- this.componentKey = componentKey;
- this.qualifier = getQualifier(qualifier);
}
- public ComponentNewValue(String uuid, boolean isPrivate, String name, String componentKey, @Nullable String description, @Nullable String qualifier) {
- this.componentUuid = uuid;
- this.isPrivate = isPrivate;
+ public ComponentNewValue(String uuid, @Nullable Boolean isPrivate, String name, String key, @Nullable String description, String qualifier) {
+ this(uuid, name, key, isPrivate, description, qualifier);
+ }
+
+ private ComponentNewValue(String uuid, String name, String key, @Nullable Boolean isPrivate, @Nullable String description, String qualifier) {
+ this.componentUuid = requireNonNull(uuid);
this.componentName = name;
- this.componentKey = componentKey;
+ this.componentKey = key;
+ this.isPrivate = isPrivate;
this.description = description;
- this.qualifier = getQualifier(qualifier);
+ this.qualifier = qualifier;
}
public String getComponentUuid() {
return componentKey;
}
+ @CheckForNull
public boolean isPrivate() {
return isPrivate;
}
public String toString() {
StringBuilder sb = new StringBuilder("{");
addField(sb, "\"componentUuid\": ", this.componentUuid, true);
- addField(sb, "\"rootComponentUuid\": ", this.rootComponentUuid, true);
addField(sb, "\"componentKey\": ", this.componentKey, true);
addField(sb, "\"componentName\": ", this.componentName, true);
- addField(sb, "\"qualifier\": ", this.qualifier, true);
+ addField(sb, "\"qualifier\": ", getQualifier(qualifier), true);
addField(sb, "\"description\": ", this.description, true);
addField(sb, "\"path\": ", this.path, true);
addField(sb, "\"isPrivate\": ", ObjectUtils.toString(this.isPrivate), false);
@Nullable
private String groupName;
- public GroupPermissionNewValue(String uuid, String rootComponentUuid, String componentKey, String componentName,
- String role, String groupUuid, String groupName, String qualifier,
- @Nullable PermissionTemplateDto permissionTemplateDto) {
- super(uuid, rootComponentUuid, componentKey, componentName, role, qualifier, permissionTemplateDto);
+ public GroupPermissionNewValue(String uuid, String componentUuid, String componentKey, String componentName, String role, String groupUuid, String groupName,
+ String qualifier, @Nullable PermissionTemplateDto permissionTemplate) {
+ super(uuid, componentUuid, componentKey, componentName, role, qualifier, permissionTemplate);
this.groupUuid = groupUuid;
this.groupName = groupName;
}
-
- public GroupPermissionNewValue(String rootComponentUuid, String componentKey, String componentName, String role,
- String groupUuid, String groupName, String qualifier) {
- this(null, rootComponentUuid, componentKey, componentName, role, groupUuid, groupName, qualifier, null);
+ public GroupPermissionNewValue(String componentUuid, String componentKey, String componentName, String role, String groupUuid, String groupName, String qualifier) {
+ this(null, componentUuid, componentKey, componentName, role, groupUuid, groupName, qualifier, null);
}
- public GroupPermissionNewValue(GroupPermissionDto dto, @Nullable String componentKey, @Nullable String qualifier,
- @Nullable PermissionTemplateDto permissionTemplateDto) {
- this(dto.getUuid(), dto.getComponentUuid(), componentKey, dto.getComponentName(), dto.getRole(), dto.getGroupUuid(),
- dto.getGroupName(), qualifier, permissionTemplateDto);
+ public GroupPermissionNewValue(GroupPermissionDto dto, String componentKey, String qualifier, PermissionTemplateDto permissionTemplate) {
+ this(dto.getUuid(), dto.getComponentUuid(), componentKey, dto.getComponentName(), dto.getRole(), dto.getGroupUuid(), dto.getGroupName(), qualifier, permissionTemplate);
}
@Nullable
addField(sb, "\"componentName\": ", this.componentName, true);
addField(sb, "\"permissionTemplateUuid\": ", this.permissionTemplateId, true);
addField(sb, "\"permissionTemplateName\": ", this.permissionTemplateName, true);
- addField(sb, "\"qualifier\": ", this.qualifier, true);
+ addField(sb, "\"qualifier\": ", getQualifier(this.qualifier), true);
endString(sb);
return sb.toString();
}
public class LicenseNewValue extends NewValue {
@Nullable
- private String edition;
+ private final String edition;
public LicenseNewValue(@Nullable String edition) {
this.edition = edition;
*/
package org.sonar.db.audit.model;
+import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import static com.google.common.base.Strings.isNullOrEmpty;
public abstract class NewValue {
- protected void addField(StringBuilder sb, String field, String value, boolean isString) {
+ protected void addField(StringBuilder sb, String field, @Nullable String value, boolean isString) {
if (!isNullOrEmpty(value)) {
sb.append(field);
addQuote(sb, isString);
}
}
+ @CheckForNull
protected static String getQualifier(@Nullable String qualifier) {
if (qualifier == null) {
return null;
this.componentUuid = componentUuid;
this.componentKey = componentKey;
this.componentName = componentName;
- this.qualifier = getQualifier(qualifier);
+ this.qualifier = qualifier;
this.permission = permission;
this.permissionTemplateId = permissionTemplateDto == null ? null : permissionTemplateDto.getUuid();
this.permissionTemplateName = permissionTemplateDto == null ? null : permissionTemplateDto.getName();
import org.sonar.db.plugin.PluginDto;
public class PluginNewValue extends NewValue {
- private String pluginUuid;
- private String kee;
- private String basePluginKey;
- private String type;
+ private final String pluginUuid;
+ private final String kee;
+ private final String basePluginKey;
+ private final String type;
public PluginNewValue(PluginDto pluginDto) {
this.pluginUuid = pluginDto.getUuid();
import org.sonar.db.user.UserPropertyDto;
public class PropertyNewValue extends NewValue {
- @Nullable
private String propertyKey;
@Nullable
setValue(propertyKey, userPropertyDto.getValue());
}
- public PropertyNewValue(PropertyDto propertyDto, @Nullable String userLogin, @Nullable String componentKey,
- @Nullable String componentName, @Nullable String qualifier) {
+ public PropertyNewValue(PropertyDto propertyDto, @Nullable String userLogin, @Nullable String componentKey, @Nullable String componentName, @Nullable String qualifier) {
this.propertyKey = propertyDto.getKey();
this.userUuid = propertyDto.getUserUuid();
this.userLogin = userLogin;
this.componentUuid = propertyDto.getComponentUuid();
this.componentKey = componentKey;
this.componentName = componentName;
- this.qualifier = getQualifier(qualifier);
+ this.qualifier = qualifier;
setValue(propertyKey, propertyDto.getValue());
}
setValue(propertyKey, propertyValue);
}
- public PropertyNewValue(@Nullable String propertyKey, @Nullable String projectUuid, @Nullable String componentKey,
+ public PropertyNewValue(String propertyKey, @Nullable String projectUuid, @Nullable String componentKey,
@Nullable String componentName, @Nullable String qualifier, @Nullable String userUuid) {
this.propertyKey = propertyKey;
this.componentUuid = projectUuid;
this.componentKey = componentKey;
this.componentName = componentName;
this.userUuid = userUuid;
- this.qualifier = getQualifier(qualifier);
+ this.qualifier = qualifier;
}
- @CheckForNull
public String getPropertyKey() {
return this.propertyKey;
}
addField(sb, "\"componentUuid\": ", this.componentUuid, true);
addField(sb, "\"componentKey\": ", this.componentKey, true);
addField(sb, "\"componentName\": ", this.componentName, true);
- addField(sb, "\"qualifier\": ", this.qualifier, true);
+ addField(sb, "\"qualifier\": ", getQualifier(this.qualifier), true);
endString(sb);
return sb.toString();
}
import org.sonar.db.user.UserDto;
import org.sonar.db.user.UserGroupDto;
-public class UserGroupNewValue extends NewValue {
-
- @Nullable
- private String groupUuid;
-
- @Nullable
- private String name;
+import static com.google.common.base.Preconditions.checkState;
- @Nullable
- private String description;
-
- @Nullable
- private String userUuid;
-
- @Nullable
- private String userLogin;
+public class UserGroupNewValue extends NewValue {
+ private final String groupUuid;
+ private final String name;
+ private final String userUuid;
+ private final String userLogin;
+ private final String description;
public UserGroupNewValue(String groupUuid, String name) {
- this.groupUuid = groupUuid;
- this.name = name;
+ this(groupUuid, name, null, null, null);
}
public UserGroupNewValue(GroupDto groupDto) {
- this.groupUuid = groupDto.getUuid();
- this.name = groupDto.getName();
- this.description = groupDto.getDescription();
+ this(groupDto.getUuid(), groupDto.getName(), null, null, groupDto.getDescription());
}
public UserGroupNewValue(GroupDto groupDto, UserDto userDto) {
- this.groupUuid = groupDto.getUuid();
- this.name = groupDto.getName();
- this.userUuid = userDto.getUuid();
- this.userLogin = userDto.getLogin();
+ this(groupDto.getUuid(), groupDto.getName(), userDto.getUuid(), userDto.getLogin(), null);
}
public UserGroupNewValue(UserDto userDto) {
- this.userUuid = userDto.getUuid();
- this.userLogin = userDto.getLogin();
+ this(null, null, userDto.getUuid(), userDto.getLogin(), null);
}
public UserGroupNewValue(UserGroupDto userGroupDto, String groupName, String userLogin) {
- this.groupUuid = userGroupDto.getGroupUuid();
- this.userUuid = userGroupDto.getUserUuid();
- this.name = groupName;
+ this(userGroupDto.getGroupUuid(), groupName, userGroupDto.getUserUuid(), userLogin, null);
+ }
+
+ private UserGroupNewValue(@Nullable String groupUuid, @Nullable String name, @Nullable String userUuid, @Nullable String userLogin, @Nullable String description) {
+ checkState((groupUuid != null && name != null) || (userUuid != null && userLogin != null));
+ this.groupUuid = groupUuid;
+ this.name = name;
+ this.userUuid = userUuid;
this.userLogin = userLogin;
+ this.description = description;
}
@CheckForNull
import org.apache.commons.lang.ObjectUtils;
import org.sonar.db.user.UserDto;
+import static java.util.Objects.requireNonNull;
+
public class UserNewValue extends NewValue {
private String userUuid;
private String userLogin;
private Long lastConnectionDate;
public UserNewValue(String userUuid, String userLogin) {
- this.userUuid = userUuid;
- this.userLogin = userLogin;
+ this.userUuid = requireNonNull(userUuid);
+ this.userLogin = requireNonNull(userLogin);
}
public UserNewValue(UserDto userDto) {
public UserPermissionNewValue(UserPermissionDto permissionDto, @Nullable String componentKey, @Nullable String componentName,
@Nullable UserId userId, String qualifier, @Nullable PermissionTemplateDto templateDto) {
- super(permissionDto.getUuid(), permissionDto.getComponentUuid(), componentKey, componentName, permissionDto.getPermission(),
- qualifier, templateDto);
+ super(permissionDto.getUuid(), permissionDto.getComponentUuid(), componentKey, componentName, permissionDto.getPermission(), qualifier, templateDto);
this.userUuid = userId != null ? userId.getUuid() : null;
this.userLogin = userId != null ? userId.getLogin() : null;
}
addField(sb, "\"permissionTemplateName\": ", this.permissionTemplateName, true);
addField(sb, "\"userUuid\": ", this.userUuid, true);
addField(sb, "\"userLogin\": ", this.userLogin, true);
- addField(sb, "\"qualifier\": ", this.qualifier, true);
+ addField(sb, "\"qualifier\": ", getQualifier(this.qualifier), true);
endString(sb);
return sb.toString();
}
import static org.sonar.db.component.ComponentDto.generatePullRequestKey;
public class ComponentDao implements Dao {
- private AuditPersister auditPersister;
-
- public ComponentDao() {
- //intentionally empty
- }
+ private final AuditPersister auditPersister;
public ComponentDao(AuditPersister auditPersister) {
this.auditPersister = auditPersister;
}
public void insert(DbSession session, ComponentDto item) {
- if (auditPersister != null) {
- auditPersister.addComponent(session, new ComponentNewValue(item.uuid(), item.name(), item.getKey(), item.qualifier()), item.qualifier());
- }
mapper(session).insert(item);
+ auditPersister.addComponent(session, new ComponentNewValue(item));
}
public void insert(DbSession session, Collection<ComponentDto> items) {
}
public void update(DbSession session, ComponentUpdateDto component, String qualifier) {
- if (auditPersister != null) {
- auditPersister.updateComponent(session, new ComponentNewValue(component.getUuid(), component.getBName(),
- component.getBKey(), component.isBEnabled(), component.getBPath(), qualifier), qualifier);
- }
+ auditPersister.updateComponent(session, new ComponentNewValue(component.getUuid(), component.getBName(),
+ component.getBKey(), component.isBEnabled(), component.getBPath(), qualifier));
mapper(session).update(component);
}
mapper(session).resetBChangedForRootComponentUuid(projectUuid);
}
+ public void setPrivateForRootComponentUuidWithoutAudit(DbSession session, String projectUuid, boolean isPrivate) {
+ mapper(session).setPrivateForRootComponentUuid(projectUuid, isPrivate);
+ }
+
public void setPrivateForRootComponentUuid(DbSession session, String projectUuid, boolean isPrivate,
- String key, @Nullable String qualifier, String componentName, boolean track) {
- if (track && auditPersister != null) {
- ComponentNewValue componentNewValue = new ComponentNewValue(projectUuid, componentName, key, isPrivate, qualifier);
- auditPersister.updateComponentVisibility(session, componentNewValue, qualifier);
- }
+ @Nullable String qualifier, String componentKey, String componentName) {
+ ComponentNewValue componentNewValue = new ComponentNewValue(projectUuid, componentName, componentKey, isPrivate, qualifier);
+ auditPersister.updateComponentVisibility(session, componentNewValue);
mapper(session).setPrivateForRootComponentUuid(projectUuid, isPrivate);
}
* @since 3.2
*/
public class ComponentKeyUpdaterDao implements Dao {
-
- private AuditPersister auditPersister;
-
- public ComponentKeyUpdaterDao() {
- }
+ private final AuditPersister auditPersister;
public ComponentKeyUpdaterDao(AuditPersister auditPersister) {
this.auditPersister = auditPersister;
appBranch.setKey(newAppBranchKey);
mapper.updateComponent(appBranch);
- if(auditPersister != null) {
- auditPersister.componentKeyBranchUpdate(dbSession, new ComponentKeyNewValue(appBranchUuid, appBranchOldKey, newAppBranchKey), Qualifiers.APP);
- }
+ auditPersister.componentKeyBranchUpdate(dbSession, new ComponentKeyNewValue(appBranchUuid, appBranchOldKey, newAppBranchKey), Qualifiers.APP);
String oldAppBranchFragment = appBranchOldKey.replace(BRANCH_KEY_SEPARATOR, "");
String newAppBranchFragment = appKey + newBranchName;
}
mapper.updateComponent(resource);
if (resource.getScope().equals(Scopes.PROJECT) && (resource.getQualifier().equals(Qualifiers.PROJECT) || resource.getQualifier().equals(Qualifiers.APP))) {
- if(auditPersister != null) {
- auditPersister.componentKeyUpdate(dbSession,
- new ComponentKeyNewValue(resource.getUuid(), oldResourceKey, newResourceKey), resource.getQualifier());
- }
+ auditPersister.componentKeyUpdate(dbSession, new ComponentKeyNewValue(resource.getUuid(), oldResourceKey, newResourceKey), resource.getQualifier());
mapper.updateProject(oldResourceKey, newResourceKey);
}
private static final String ANYONE_GROUP_PARAMETER = "anyoneGroup";
- private AuditPersister auditPersister;
-
- public GroupPermissionDao() {
- }
+ private final AuditPersister auditPersister;
public GroupPermissionDao(AuditPersister auditPersister) {
this.auditPersister = auditPersister;
return mapper(session).selectGroupUuidsWithPermissionOnProjectBut(projectUuid, permission);
}
- public void insert(DbSession dbSession, GroupPermissionDto groupPermissionDto, @Nullable ComponentDto componentDto,
- @Nullable PermissionTemplateDto permissionTemplateDto) {
+ public void insert(DbSession dbSession, GroupPermissionDto groupPermissionDto, @Nullable ComponentDto componentDto, @Nullable PermissionTemplateDto permissionTemplateDto) {
mapper(dbSession).insert(groupPermissionDto);
- if (auditPersister != null) {
- String componentKey = (componentDto != null) ? componentDto.getKey() : null;
- String qualifier = (componentDto != null) ? componentDto.qualifier() : null;
- auditPersister.addGroupPermission(dbSession, new GroupPermissionNewValue(groupPermissionDto, componentKey, qualifier, permissionTemplateDto));
- }
+ String componentKey = (componentDto != null) ? componentDto.getKey() : null;
+ String qualifier = (componentDto != null) ? componentDto.qualifier() : null;
+ auditPersister.addGroupPermission(dbSession, new GroupPermissionNewValue(groupPermissionDto, componentKey, qualifier, permissionTemplateDto));
}
/**
public void deleteByRootComponentUuid(DbSession dbSession, ComponentDto component) {
int deletedRecords = mapper(dbSession).deleteByRootComponentUuid(component.uuid());
- if (deletedRecords > 0 && auditPersister != null) {
+ if (deletedRecords > 0) {
auditPersister.deleteGroupPermission(dbSession, new GroupPermissionNewValue(component.uuid(),
component.getKey(), component.name(), null, null, null, component.qualifier()));
}
public int deleteByRootComponentUuidAndGroupUuid(DbSession dbSession, @Nullable String groupUuid, ComponentDto component) {
int deletedRecords = mapper(dbSession).deleteByRootComponentUuidAndGroupUuid(component.uuid(), groupUuid);
- if (deletedRecords > 0 && auditPersister != null) {
+ if (deletedRecords > 0) {
auditPersister.deleteGroupPermission(dbSession, new GroupPermissionNewValue(component.uuid(),
component.getKey(), component.name(), null, groupUuid, "", component.qualifier()));
}
public int deleteByRootComponentUuidForAnyOne(DbSession dbSession, ComponentDto component) {
int deletedRecords = mapper(dbSession).deleteByRootComponentUuidAndGroupUuid(component.uuid(), null);
- if (deletedRecords > 0 && auditPersister != null) {
+ if (deletedRecords > 0) {
auditPersister.deleteGroupPermission(dbSession, new GroupPermissionNewValue(component.uuid(),
component.getKey(), component.name(), null, null, null, component.qualifier()));
}
public int deleteByRootComponentUuidAndPermission(DbSession dbSession, String permission, ComponentDto component) {
int deletedRecords = mapper(dbSession).deleteByRootComponentUuidAndPermission(component.uuid(), permission);
- if (deletedRecords > 0 && auditPersister != null) {
+ if (deletedRecords > 0) {
auditPersister.deleteGroupPermission(dbSession, new GroupPermissionNewValue(component.uuid(),
component.getKey(), component.name(), permission, null, null, component.qualifier()));
}
int deletedRecords = mapper(dbSession).delete(permission, groupUuid, rootComponentUuid);
- if (deletedRecords > 0 && auditPersister != null) {
+ if (deletedRecords > 0) {
String qualifier = (componentDto != null) ? componentDto.qualifier() : null;
String componentKey = (componentDto != null) ? componentDto.getKey() : null;
String componentName = (componentDto != null) ? componentDto.name() : null;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
public class UserPermissionDao implements Dao {
- private AuditPersister auditPersister;
-
- public UserPermissionDao() {
- }
+ private final AuditPersister auditPersister;
public UserPermissionDao(AuditPersister auditPersister) {
this.auditPersister = auditPersister;
@Nullable UserId userId, @Nullable PermissionTemplateDto templateDto) {
mapper(dbSession).insert(dto);
- if (auditPersister != null) {
- String componentName = (componentDto != null) ? componentDto.name() : null;
- String componentKey = (componentDto != null) ? componentDto.getKey() : null;
- String qualifier = (componentDto != null) ? componentDto.qualifier() : null;
- auditPersister.addUserPermission(dbSession, new UserPermissionNewValue(dto, componentKey, componentName, userId, qualifier,
- templateDto));
- }
+ String componentName = (componentDto != null) ? componentDto.name() : null;
+ String componentKey = (componentDto != null) ? componentDto.getKey() : null;
+ String qualifier = (componentDto != null) ? componentDto.qualifier() : null;
+ auditPersister.addUserPermission(dbSession, new UserPermissionNewValue(dto, componentKey, componentName, userId, qualifier,
+ templateDto));
}
/**
public void deleteGlobalPermission(DbSession dbSession, UserId user, String permission) {
int deletedRows = mapper(dbSession).deleteGlobalPermission(user.getUuid(), permission);
- if (deletedRows > 0 && auditPersister != null) {
+ if (deletedRows > 0) {
auditPersister.deleteUserPermission(dbSession, new UserPermissionNewValue(permission, null, null, null, user, null));
}
}
public void deleteProjectPermission(DbSession dbSession, UserId user, String permission, ComponentDto component) {
int deletedRows = mapper(dbSession).deleteProjectPermission(user.getUuid(), permission, component.uuid());
- if (deletedRows > 0 && auditPersister != null) {
- auditPersister.deleteUserPermission(dbSession, new UserPermissionNewValue(permission, component.uuid(), component.getKey(),
- component.name(), user, component.qualifier()));
+ if (deletedRows > 0) {
+ auditPersister.deleteUserPermission(dbSession, new UserPermissionNewValue(permission, component.uuid(), component.getKey(), component.name(), user, component.qualifier()));
}
}
public void deleteProjectPermissions(DbSession dbSession, ComponentDto component) {
int deletedRows = mapper(dbSession).deleteProjectPermissions(component.uuid());
- if (deletedRows > 0 && auditPersister != null) {
+ if (deletedRows > 0) {
auditPersister.deleteUserPermission(dbSession, new UserPermissionNewValue(null, component.uuid(), component.getKey(),
component.name(), null, component.qualifier()));
}
public int deleteProjectPermissionOfAnyUser(DbSession dbSession, String permission, ComponentDto project) {
int deletedRows = mapper(dbSession).deleteProjectPermissionOfAnyUser(project.uuid(), permission);
- if (deletedRows > 0 && auditPersister != null) {
- auditPersister.deleteUserPermission(dbSession, new UserPermissionNewValue(permission, project.uuid(), project.getKey(),
- project.name(), null, project.qualifier()));
+ if (deletedRows > 0) {
+ auditPersister.deleteUserPermission(dbSession, new UserPermissionNewValue(permission, project.uuid(), project.getKey(), project.name(), null, project.qualifier()));
}
return deletedRows;
public void deleteByUserUuid(DbSession dbSession, UserId userId) {
int deletedRows = mapper(dbSession).deleteByUserUuid(userId.getUuid());
- if (deletedRows > 0 && auditPersister != null) {
+ if (deletedRows > 0) {
auditPersister.deleteUserPermission(dbSession, new UserPermissionNewValue(userId, null));
}
}
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
public class PermissionTemplateCharacteristicDao implements Dao {
- private AuditPersister auditPersister;
-
- public PermissionTemplateCharacteristicDao() {
- }
+ private final AuditPersister auditPersister;
public PermissionTemplateCharacteristicDao(AuditPersister auditPersister) {
this.auditPersister = auditPersister;
checkArgument(dto.getCreatedAt() != 0L && dto.getUpdatedAt() != 0L);
mapper(dbSession).insert(dto);
- if (auditPersister != null) {
- auditPersister.addCharacteristicToPermissionTemplate(dbSession, new PermissionTemplateNewValue(dto.getTemplateUuid(),
- dto.getPermission(), templateName, dto.getWithProjectCreator()));
- }
+ auditPersister.addCharacteristicToPermissionTemplate(dbSession, new PermissionTemplateNewValue(dto.getTemplateUuid(),
+ dto.getPermission(), templateName, dto.getWithProjectCreator()));
return dto;
}
requireNonNull(templatePermissionDto.getUuid());
mapper(dbSession).update(templatePermissionDto);
- if (auditPersister != null) {
- auditPersister.updateCharacteristicInPermissionTemplate(dbSession, new PermissionTemplateNewValue(templatePermissionDto.getTemplateUuid(),
- templatePermissionDto.getPermission(), templateName, templatePermissionDto.getWithProjectCreator()));
- }
+ auditPersister.updateCharacteristicInPermissionTemplate(dbSession, new PermissionTemplateNewValue(templatePermissionDto.getTemplateUuid(),
+ templatePermissionDto.getPermission(), templateName, templatePermissionDto.getWithProjectCreator()));
return templatePermissionDto;
}
private final System2 system;
private final UuidFactory uuidFactory;
+ private final AuditPersister auditPersister;
- private AuditPersister auditPersister;
-
- public PermissionTemplateDao(UuidFactory uuidFactory, System2 system) {
+ public PermissionTemplateDao(UuidFactory uuidFactory, System2 system, AuditPersister auditPersister) {
this.uuidFactory = uuidFactory;
this.system = system;
- }
-
- public PermissionTemplateDao(UuidFactory uuidFactory, System2 system, AuditPersister auditPersister) {
- this(uuidFactory, system);
this.auditPersister = auditPersister;
}
dto.setUuid(uuidFactory.create());
}
mapper(session).insert(dto);
-
- if (auditPersister != null) {
- auditPersister.addPermissionTemplate(session, new PermissionTemplateNewValue(dto.getUuid(), dto.getName()));
- }
+ auditPersister.addPermissionTemplate(session, new PermissionTemplateNewValue(dto.getUuid(), dto.getName()));
return dto;
}
session.getMapper(PermissionTemplateCharacteristicMapper.class).deleteByTemplateUuid(templateUuid);
int deletedRows = mapper.deleteByUuid(templateUuid);
- if (deletedRows > 0 && auditPersister != null) {
+ if (deletedRows > 0) {
auditPersister.deletePermissionTemplate(session, new PermissionTemplateNewValue(templateUuid, templateName));
}
}
public PermissionTemplateDto update(DbSession session, PermissionTemplateDto permissionTemplate) {
mapper(session).update(permissionTemplate);
- if (auditPersister != null) {
- auditPersister.updatePermissionTemplate(session, new PermissionTemplateNewValue(permissionTemplate));
- }
+ auditPersister.updatePermissionTemplate(session, new PermissionTemplateNewValue(permissionTemplate));
return permissionTemplate;
}
mapper(session).insertUserPermission(permissionTemplateUser);
- if (auditPersister != null) {
- auditPersister.addUserToPermissionTemplate(session, new PermissionTemplateNewValue(templateUuid, templateName,
- permission, userUuid, userLogin, null, null));
- }
+ auditPersister.addUserToPermissionTemplate(session, new PermissionTemplateNewValue(templateUuid, templateName, permission, userUuid, userLogin, null, null));
session.commit();
}
.setUserUuid(userUuid);
int deletedRows = mapper(session).deleteUserPermission(permissionTemplateUser);
- if (deletedRows > 0 && auditPersister != null) {
- auditPersister.deleteUserFromPermissionTemplate(session, new PermissionTemplateNewValue(templateUuid, templateName,
- permission, userUuid, userLogin, null, null));
+ if (deletedRows > 0) {
+ auditPersister.deleteUserFromPermissionTemplate(session, new PermissionTemplateNewValue(templateUuid, templateName, permission, userUuid, userLogin, null, null));
}
session.commit();
public void deleteUserPermissionsByUserUuid(DbSession dbSession, String userUuid, String userLogin) {
int deletedRows = mapper(dbSession).deleteUserPermissionsByUserUuid(userUuid);
- if (deletedRows > 0 && auditPersister != null) {
- auditPersister.deleteUserFromPermissionTemplate(dbSession, new PermissionTemplateNewValue(null, null,
- null, userUuid, userLogin, null, null));
+ if (deletedRows > 0) {
+ auditPersister.deleteUserFromPermissionTemplate(dbSession, new PermissionTemplateNewValue(null, null, null, userUuid, userLogin, null, null));
}
}
.setUpdatedAt(now());
mapper(session).insertGroupPermission(permissionTemplateGroup);
- if (auditPersister != null) {
- auditPersister.addGroupToPermissionTemplate(session, new PermissionTemplateNewValue(templateUuid, templateName,
- permission, null, null, groupUuid, groupName));
- }
+ auditPersister.addGroupToPermissionTemplate(session, new PermissionTemplateNewValue(templateUuid, templateName, permission, null, null, groupUuid, groupName));
}
public void insertGroupPermission(DbSession session, PermissionTemplateGroupDto permissionTemplateGroup, String templateName) {
mapper(session).insertGroupPermission(permissionTemplateGroup);
- if (auditPersister != null) {
- auditPersister.addGroupToPermissionTemplate(session, new PermissionTemplateNewValue(permissionTemplateGroup.getTemplateUuid(), templateName,
- permissionTemplateGroup.getPermission(), null, null, permissionTemplateGroup.getGroupUuid(), permissionTemplateGroup.getGroupName()));
- }
+ auditPersister.addGroupToPermissionTemplate(session, new PermissionTemplateNewValue(permissionTemplateGroup.getTemplateUuid(), templateName,
+ permissionTemplateGroup.getPermission(), null, null, permissionTemplateGroup.getGroupUuid(), permissionTemplateGroup.getGroupName()));
}
public void deleteGroupPermission(DbSession session, String templateUuid, @Nullable String groupUuid, String permission, String templateName,
.setGroupUuid(groupUuid);
int deletedRows = mapper(session).deleteGroupPermission(permissionTemplateGroup);
- if (deletedRows > 0 && auditPersister != null) {
+ if (deletedRows > 0) {
auditPersister.deleteGroupFromPermissionTemplate(session, new PermissionTemplateNewValue(permissionTemplateGroup.getTemplateUuid(), templateName,
permissionTemplateGroup.getPermission(), null, null, permissionTemplateGroup.getGroupUuid(), groupName));
}
public void deleteByGroup(DbSession session, String groupUuid, String groupName) {
int deletedRows = session.getMapper(PermissionTemplateMapper.class).deleteByGroupUuid(groupUuid);
- if (deletedRows > 0 && auditPersister != null) {
- auditPersister.deleteGroupFromPermissionTemplate(session, new PermissionTemplateNewValue(null, null,
- null, null, null, groupUuid, groupName));
+ if (deletedRows > 0) {
+ auditPersister.deleteGroupFromPermissionTemplate(session, new PermissionTemplateNewValue(null, null, null, null, null, groupUuid, groupName));
}
}
import org.sonar.db.audit.model.PluginNewValue;
public class PluginDao implements Dao {
-
- private AuditPersister auditPersister;
-
- public PluginDao() {
- }
+ private final AuditPersister auditPersister;
public PluginDao(AuditPersister auditPersister) {
this.auditPersister = auditPersister;
public void insert(DbSession dbSession, PluginDto dto) {
mapper(dbSession).insert(dto);
-
- if (auditPersister != null) {
- auditPersister.addPlugin(dbSession, new PluginNewValue(dto));
- }
+ auditPersister.addPlugin(dbSession, new PluginNewValue(dto));
}
public void update(DbSession dbSession, PluginDto dto) {
mapper(dbSession).update(dto);
-
- if (auditPersister != null) {
- auditPersister.updatePlugin(dbSession, new PluginNewValue(dto));
- }
+ auditPersister.updatePlugin(dbSession, new PluginNewValue(dto));
}
private static PluginMapper mapper(DbSession dbSession) {
public class ProjectDao implements Dao {
private final System2 system2;
- private AuditPersister auditPersister;
-
- public ProjectDao(System2 system2) {
- this.system2 = system2;
- }
+ private final AuditPersister auditPersister;
public ProjectDao(System2 system2, AuditPersister auditPersister) {
this.system2 = system2;
}
public void insert(DbSession session, ProjectDto project, boolean track) {
- if (track && auditPersister != null) {
- auditPersister.addComponent(session, new ComponentNewValue(project.getUuid(), project.getName(), project.getKey(), project.getQualifier()),
- project.getQualifier());
+ if (track) {
+ auditPersister.addComponent(session, new ComponentNewValue(project));
}
mapper(session).insert(project);
}
}
public void update(DbSession session, ProjectDto project) {
- if (auditPersister != null) {
- auditPersister.updateComponent(session, new ComponentNewValue(project.getUuid(), project.isPrivate(),
- project.getName(), project.getKey(), project.getDescription(), project.getQualifier()), project.getQualifier());
- }
-
+ auditPersister.updateComponent(session, new ComponentNewValue(project));
mapper(session).update(project);
}
private final MyBatis mybatis;
private final System2 system2;
private final UuidFactory uuidFactory;
- private AuditPersister auditPersister;
+ private final AuditPersister auditPersister;
- public PropertiesDao(MyBatis mybatis, System2 system2, UuidFactory uuidFactory) {
+ public PropertiesDao(MyBatis mybatis, System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) {
this.mybatis = mybatis;
this.system2 = system2;
this.uuidFactory = uuidFactory;
- }
-
- public PropertiesDao(MyBatis mybatis, System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) {
- this(mybatis, system2, uuidFactory);
this.auditPersister = auditPersister;
}
}
try (DbSession session = mybatis.openSession(false);
- Connection connection = session.getConnection();
- PreparedStatement pstmt = createStatement(projectUuid, dispatcherKeys, connection);
- ResultSet rs = pstmt.executeQuery()) {
+ Connection connection = session.getConnection();
+ PreparedStatement pstmt = createStatement(projectUuid, dispatcherKeys, connection);
+ ResultSet rs = pstmt.executeQuery()) {
return rs.next() && rs.getInt(1) > 0;
} catch (SQLException e) {
throw new IllegalStateException("Fail to execute SQL for hasProjectNotificationSubscribersForDispatchers", e);
saveProperty(session, property, null, null, null, null);
}
- public void saveProperty(DbSession session, PropertyDto property, @Nullable String userLogin, @Nullable String projectKey,
- @Nullable String projectName, @Nullable String qualifier) {
+ public void saveProperty(DbSession session, PropertyDto property, @Nullable String userLogin, @Nullable String projectKey, @Nullable String projectName,
+ @Nullable String qualifier) {
int affectedRows = save(getMapper(session), property.getKey(), property.getUserUuid(), property.getComponentUuid(), property.getValue());
- if (auditPersister != null && auditPersister.isTrackedProperty(property.getKey())) {
- if (affectedRows > 0) {
- auditPersister.updateProperty(session, new PropertyNewValue(property, userLogin, projectKey, projectName, qualifier), false);
- } else {
- auditPersister.addProperty(session, new PropertyNewValue(property, userLogin, projectKey, projectName, qualifier), false);
- }
+ if (affectedRows > 0) {
+ auditPersister.updateProperty(session, new PropertyNewValue(property, userLogin, projectKey, projectName, qualifier), false);
+ } else {
+ auditPersister.addProperty(session, new PropertyNewValue(property, userLogin, projectKey, projectName, qualifier), false);
}
}
public int deleteByQuery(DbSession dbSession, PropertyQuery query) {
int deletedRows = getMapper(dbSession).deleteByQuery(query);
- if (deletedRows > 0 && auditPersister != null && query.key() != null && auditPersister.isTrackedProperty(query.key())) {
+ if (deletedRows > 0 && query.key() != null) {
auditPersister.deleteProperty(dbSession, new PropertyNewValue(query.key(), query.componentUuid(),
null, null, null, query.userUuid()), false);
}
@Nullable String projectName, @Nullable String qualifier) {
int deletedRows = getMapper(dbSession).delete(dto.getKey(), dto.getUserUuid(), dto.getComponentUuid());
- if (deletedRows > 0 && auditPersister != null && auditPersister.isTrackedProperty(dto.getKey())) {
+ if (deletedRows > 0) {
auditPersister.deleteProperty(dbSession, new PropertyNewValue(dto, userLogin, projectKey, projectName, qualifier),
false);
}
String projectName, String qualifier) {
int deletedRows = getMapper(session).deleteProjectProperty(key, projectUuid);
- if (deletedRows > 0 && auditPersister != null && auditPersister.isTrackedProperty(key)) {
+ if (deletedRows > 0) {
auditPersister.deleteProperty(session, new PropertyNewValue(key, projectUuid, projectKey, projectName, qualifier,
null), false);
}
public void deleteProjectProperties(String key, String value, DbSession session) {
int deletedRows = getMapper(session).deleteProjectProperties(key, value);
- if (deletedRows > 0 && auditPersister != null && auditPersister.isTrackedProperty(key)) {
+ if (deletedRows > 0) {
auditPersister.deleteProperty(session, new PropertyNewValue(key, value), false);
}
}
public void deleteGlobalProperty(String key, DbSession session) {
int deletedRows = getMapper(session).deleteGlobalProperty(key);
- if (deletedRows > 0 && auditPersister != null && auditPersister.isTrackedProperty(key)) {
+ if (deletedRows > 0) {
auditPersister.deleteProperty(session, new PropertyNewValue(key), false);
}
}
public void deleteByKeyAndValue(DbSession dbSession, String key, String value) {
int deletedRows = getMapper(dbSession).deleteByKeyAndValue(key, value);
- if (deletedRows > 0 && auditPersister != null && auditPersister.isTrackedProperty(key)) {
+ if (deletedRows > 0) {
auditPersister.deleteProperty(dbSession, new PropertyNewValue(key, value), false);
}
}
properties.forEach((key, value) -> {
int affectedRows = save(mapper, key, null, null, value);
- if (auditPersister != null && auditPersister.isTrackedProperty(key)) {
+ if (auditPersister.isTrackedProperty(key)) {
if (affectedRows > 0) {
auditPersister.updateProperty(session, new PropertyNewValue(key, value), false);
} else {
}
private void persistDeletedProperties(DbSession dbSession, @Nullable String userUuid, String userLogin, List<String> uuids) {
- if (!uuids.isEmpty() && auditPersister != null) {
+ if (!uuids.isEmpty()) {
List<PropertyDto> properties = executeLargeInputs(uuids, subList -> getMapper(dbSession).selectByUuids(subList));
properties
private static final String SCOPE_PROJECT = "PRJ";
private final System2 system2;
- private AuditPersister auditPersister;
-
- public PurgeDao(System2 system2) {
- this.system2 = system2;
- }
+ private final AuditPersister auditPersister;
public PurgeDao(System2 system2, AuditPersister auditPersister) {
this.system2 = system2;
long start = System2.INSTANCE.now();
List<String> branchUuids = session.getMapper(BranchMapper.class).selectByProjectUuid(uuid).stream()
- .filter(branch -> !uuid.equals(branch.getUuid()))
.map(BranchDto::getUuid)
+ .filter(branchUuid -> !uuid.equals(branchUuid))
.collect(Collectors.toList());
- branchUuids.stream()
- .forEach(id -> deleteRootComponent(id, purgeMapper, purgeCommands));
+ branchUuids.forEach(id -> deleteRootComponent(id, purgeMapper, purgeCommands));
deleteRootComponent(uuid, purgeMapper, purgeCommands);
-
- if (auditPersister != null) {
- auditPersister.deleteComponent(session, new ComponentNewValue(uuid, name, key, qualifier), qualifier);
- }
-
+ auditPersister.deleteComponent(session, new ComponentNewValue(uuid, name, key, qualifier));
logProfiling(profiler, start);
}
public class GroupDao implements Dao {
private final System2 system;
- private AuditPersister auditPersister;
-
- public GroupDao(System2 system) {
- this.system = system;
- }
+ private final AuditPersister auditPersister;
public GroupDao(System2 system, AuditPersister auditPersister) {
- this(system);
+ this.system = system;
this.auditPersister = auditPersister;
}
public void deleteByUuid(DbSession dbSession, String groupUuid, String groupName) {
int deletedRows = mapper(dbSession).deleteByUuid(groupUuid);
- if (deletedRows > 0 && auditPersister != null) {
+ if (deletedRows > 0) {
auditPersister.deleteUserGroup(dbSession, new UserGroupNewValue(groupUuid, groupName));
}
}
item.setCreatedAt(createdAt)
.setUpdatedAt(createdAt);
mapper(session).insert(item);
-
- if (auditPersister != null) {
- auditPersister.addUserGroup(session, new UserGroupNewValue(item.getUuid(), item.getName()));
- }
-
+ auditPersister.addUserGroup(session, new UserGroupNewValue(item.getUuid(), item.getName()));
return item;
}
public GroupDto update(DbSession session, GroupDto item) {
item.setUpdatedAt(new Date(system.now()));
mapper(session).update(item);
-
- if (auditPersister != null) {
- auditPersister.updateUserGroup(session, new UserGroupNewValue(item));
- }
-
+ auditPersister.updateUserGroup(session, new UserGroupNewValue(item));
return item;
}
private static final long WEEK_IN_MS = DAYS.toMillis(7L);
private final System2 system2;
private final UuidFactory uuidFactory;
+ private final AuditPersister auditPersister;
- private AuditPersister auditPersister;
-
- public UserDao(System2 system2, UuidFactory uuidFactory) {
+ public UserDao(System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) {
this.system2 = system2;
this.uuidFactory = uuidFactory;
- }
-
- public UserDao(System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) {
- this(system2, uuidFactory);
this.auditPersister = auditPersister;
}
public UserDto insert(DbSession session, UserDto dto) {
long now = system2.now();
mapper(session).insert(dto.setUuid(uuidFactory.create()).setCreatedAt(now).setUpdatedAt(now));
-
- if (auditPersister != null) {
- auditPersister.addUser(session, new UserNewValue(dto.getUuid(), dto.getLogin()));
- }
-
+ auditPersister.addUser(session, new UserNewValue(dto.getUuid(), dto.getLogin()));
return dto;
}
public UserDto update(DbSession session, UserDto dto, boolean track) {
mapper(session).update(dto.setUpdatedAt(system2.now()));
- if (track && auditPersister != null) {
+ if (track) {
auditPersister.updateUser(session, new UserNewValue(dto));
}
return dto;
public void deactivateUser(DbSession dbSession, UserDto user) {
mapper(dbSession).deactivateUser(user.getLogin(), system2.now());
-
- if (auditPersister != null) {
- auditPersister.deactivateUser(dbSession, new UserNewValue(user.getUuid(), user.getLogin()));
- }
+ auditPersister.deactivateUser(dbSession, new UserNewValue(user.getUuid(), user.getLogin()));
}
public void cleanHomepage(DbSession dbSession, ProjectDto project) {
import org.sonar.db.audit.model.UserGroupNewValue;
public class UserGroupDao implements Dao {
-
- private AuditPersister auditPersister;
-
- public UserGroupDao() {
- }
+ private final AuditPersister auditPersister;
public UserGroupDao(AuditPersister auditPersister) {
this.auditPersister = auditPersister;
public UserGroupDto insert(DbSession session, UserGroupDto dto, String groupName, String login) {
mapper(session).insert(dto);
-
- if (auditPersister != null) {
- auditPersister.addUserToGroup(session, new UserGroupNewValue(dto, groupName, login));
- }
-
+ auditPersister.addUserToGroup(session, new UserGroupNewValue(dto, groupName, login));
return dto;
}
public void delete(DbSession session, GroupDto group, UserDto user) {
int deletedRows = mapper(session).delete(group.getUuid(), user.getUuid());
- if (deletedRows > 0 && auditPersister != null) {
+ if (deletedRows > 0) {
auditPersister.deleteUserFromGroup(session, new UserGroupNewValue(group, user));
}
}
public void deleteByGroupUuid(DbSession session, String groupUuid, String groupName) {
int deletedRows = mapper(session).deleteByGroupUuid(groupUuid);
- if (deletedRows > 0 && auditPersister != null) {
+ if (deletedRows > 0) {
auditPersister.deleteUserFromGroup(session, new UserGroupNewValue(groupUuid, groupName));
}
}
public void deleteByUserUuid(DbSession dbSession, UserDto userDto) {
int deletedRows = mapper(dbSession).deleteByUserUuid(userDto.getUuid());
- if (deletedRows > 0 && auditPersister != null) {
+ if (deletedRows > 0) {
auditPersister.deleteUserFromGroup(dbSession, new UserGroupNewValue(userDto));
}
}
private final System2 system2;
private final UuidFactory uuidFactory;
+ private final AuditPersister auditPersister;
- private AuditPersister auditPersister;
-
- public UserPropertiesDao(System2 system2, UuidFactory uuidFactory) {
+ public UserPropertiesDao(System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) {
this.system2 = system2;
this.uuidFactory = uuidFactory;
- }
-
- public UserPropertiesDao(System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) {
- this(system2, uuidFactory);
this.auditPersister = auditPersister;
}
isUpdate = false;
}
- if (auditPersister != null && auditPersister.isTrackedProperty(dto.getKey())) {
- if (isUpdate) {
- auditPersister.updateProperty(session, new PropertyNewValue(dto, login), true);
- } else {
- auditPersister.addProperty(session, new PropertyNewValue(dto, login), true);
- }
+ if (isUpdate) {
+ auditPersister.updateProperty(session, new PropertyNewValue(dto, login), true);
+ } else {
+ auditPersister.addProperty(session, new PropertyNewValue(dto, login), true);
}
return dto;
List<UserPropertyDto> userProperties = selectByUser(session, user);
int deletedRows = mapper(session).deleteByUserUuid(user.getUuid());
- if (deletedRows > 0 && auditPersister != null) {
+ if (deletedRows > 0) {
userProperties.stream()
.filter(p -> auditPersister.isTrackedProperty(p.getKey()))
.forEach(p -> auditPersister.deleteProperty(session, new PropertyNewValue(p, user.getLogin()), true));
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
public class UserTokenDao implements Dao {
-
- private UuidFactory uuidFactory;
- private AuditPersister auditPersister;
-
- public UserTokenDao(UuidFactory uuidFactory) {
- this.uuidFactory = uuidFactory;
- }
+ private final UuidFactory uuidFactory;
+ private final AuditPersister auditPersister;
public UserTokenDao(UuidFactory uuidFactory, AuditPersister auditPersister) {
- this(uuidFactory);
+ this.uuidFactory = uuidFactory;
this.auditPersister = auditPersister;
}
public void insert(DbSession dbSession, UserTokenDto userTokenDto, String userLogin) {
userTokenDto.setUuid(uuidFactory.create());
mapper(dbSession).insert(userTokenDto);
-
- if (auditPersister != null) {
- auditPersister.addUserToken(dbSession, new UserTokenNewValue(userTokenDto, userLogin));
- }
+ auditPersister.addUserToken(dbSession, new UserTokenNewValue(userTokenDto, userLogin));
}
- public void update(DbSession session, UserTokenDto userTokenDto, @Nullable String userLogin) {
- update(session, userTokenDto, true, userLogin);
+ public void update(DbSession dbSession, UserTokenDto userTokenDto, @Nullable String userLogin) {
+ mapper(dbSession).update(userTokenDto);
+ auditPersister.updateUserToken(dbSession, new UserTokenNewValue(userTokenDto, userLogin));
}
- public void update(DbSession dbSession, UserTokenDto userTokenDto, boolean track, @Nullable String userLogin) {
+ public void updateWithoutAudit(DbSession dbSession, UserTokenDto userTokenDto) {
mapper(dbSession).update(userTokenDto);
-
- if (track && auditPersister != null) {
- auditPersister.updateUserToken(dbSession, new UserTokenNewValue(userTokenDto, userLogin));
- }
}
@CheckForNull
public void deleteByUser(DbSession dbSession, UserDto user) {
int deletedRows = mapper(dbSession).deleteByUserUuid(user.getUuid());
- if (deletedRows > 0 && auditPersister != null) {
+ if (deletedRows > 0) {
auditPersister.deleteUserToken(dbSession, new UserTokenNewValue(user));
}
}
public void deleteByUserAndName(DbSession dbSession, UserDto user, String name) {
int deletedRows = mapper(dbSession).deleteByUserUuidAndName(user.getUuid(), name);
- if (deletedRows > 0 && auditPersister != null) {
+ if (deletedRows > 0) {
auditPersister.deleteUserToken(dbSession, new UserTokenNewValue(user, name));
}
}
public class WebhookDao implements Dao {
private final System2 system2;
- private AuditPersister auditPersister;
-
- public WebhookDao(System2 system2) {
- this.system2 = system2;
- }
+ private final AuditPersister auditPersister;
public WebhookDao(System2 system2, AuditPersister auditPersister) {
this.system2 = system2;
public void insert(DbSession dbSession, WebhookDto dto, @Nullable String projectKey, @Nullable String projectName) {
mapper(dbSession).insert(dto.setCreatedAt(system2.now()).setUpdatedAt(system2.now()));
-
- if (auditPersister != null) {
- auditPersister.addWebhook(dbSession, new WebhookNewValue(dto, projectKey, projectName));
- }
+ auditPersister.addWebhook(dbSession, new WebhookNewValue(dto, projectKey, projectName));
}
public void update(DbSession dbSession, WebhookDto dto, @Nullable String projectKey, @Nullable String projectName) {
mapper(dbSession).update(dto.setUpdatedAt(system2.now()));
-
- if (auditPersister != null) {
- if (dto.getSecret() != null) {
- auditPersister.updateWebhookSecret(dbSession, new SecretNewValue("webhook_name", dto.getName()));
- }
- auditPersister.updateWebhook(dbSession, new WebhookNewValue(dto, projectKey, projectName));
+ if (dto.getSecret() != null) {
+ auditPersister.updateWebhookSecret(dbSession, new SecretNewValue("webhook_name", dto.getName()));
}
+ auditPersister.updateWebhook(dbSession, new WebhookNewValue(dto, projectKey, projectName));
}
public void delete(DbSession dbSession, String uuid, String webhookName) {
int deletedRows = mapper(dbSession).delete(uuid);
- if (deletedRows > 0 && auditPersister != null) {
+ if (deletedRows > 0) {
auditPersister.deleteWebhook(dbSession, new WebhookNewValue(uuid, webhookName));
}
}
public void deleteByProject(DbSession dbSession, ProjectDto projectDto) {
int deletedRows = mapper(dbSession).deleteForProjectUuid(projectDto.getUuid());
- if (deletedRows > 0 && auditPersister != null) {
+ if (deletedRows > 0) {
auditPersister.deleteWebhook(dbSession, new WebhookNewValue(projectDto));
}
}
import org.sonar.db.DbTester;
import org.sonar.db.alm.setting.AlmSettingDao;
import org.sonar.db.alm.setting.AlmSettingDto;
+import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.db.user.UserDto;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
private DbSession dbSession = db.getSession();
private UuidFactory uuidFactory = mock(UuidFactory.class);
- private AlmSettingDao almSettingDao = new AlmSettingDao(system2, uuidFactory);
+ private AlmSettingDao almSettingDao = new AlmSettingDao(system2, uuidFactory, new NoOpAuditPersister());
- private AlmPatDao underTest = new AlmPatDao(system2, uuidFactory);
+ private AlmPatDao underTest = new AlmPatDao(system2, uuidFactory, new NoOpAuditPersister());
@Test
public void selectByUuid() {
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
private static final long NOW = 1000000L;
private static final String A_UUID = "SOME_UUID";
+
private final AuditPersister auditPersister = mock(AuditPersister.class);
private final ArgumentCaptor<PersonalAccessTokenNewValue> newValueCaptor = ArgumentCaptor.forClass(PersonalAccessTokenNewValue.class);
- private TestSystem2 system2 = new TestSystem2().setNow(NOW);
+ private final TestSystem2 system2 = new TestSystem2().setNow(NOW);
@Rule
public DbTester db = DbTester.create(system2, auditPersister);
- private DbSession dbSession = db.getSession();
- private UuidFactory uuidFactory = mock(UuidFactory.class);
+ private final DbSession dbSession = db.getSession();
+ private final UuidFactory uuidFactory = mock(UuidFactory.class);
- private AlmPatDao underTest = db.getDbClient().almPatDao();
+ private final AlmPatDao underTest = db.getDbClient().almPatDao();
@Test
public void insertAndUpdateArePersisted() {
@Test
public void deleteByAlmSettingWithoutAffectedRowsIsNotPersisted() {
AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting();
-
+ clearInvocations(auditPersister);
underTest.deleteByAlmSetting(dbSession, almSettingDto);
verifyNoInteractions(auditPersister);
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.almsettings.AlmSettingsTesting;
+import org.sonar.db.audit.NoOpAuditPersister;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
private DbSession dbSession = db.getSession();
private UuidFactory uuidFactory = mock(UuidFactory.class);
- private AlmSettingDao underTest = new AlmSettingDao(system2, uuidFactory);
+ private AlmSettingDao underTest = new AlmSettingDao(system2, uuidFactory, new NoOpAuditPersister());
@Test
public void selectByUuid() {
import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.db.project.ProjectDto;
import static org.assertj.core.api.Assertions.assertThat;
private DbSession dbSession = db.getSession();
private UuidFactory uuidFactory = mock(UuidFactory.class);
- private ProjectAlmSettingDao underTest = new ProjectAlmSettingDao(system2, uuidFactory);
+ private ProjectAlmSettingDao underTest = new ProjectAlmSettingDao(system2, uuidFactory, new NoOpAuditPersister());
@Test
public void select_by_project() {
import org.mockito.ArgumentCaptor;
import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.core.util.UuidFactory;
+import org.sonar.core.util.UuidFactoryFast;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.audit.AuditPersister;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
+import static org.sonar.db.almsettings.AlmSettingsTesting.newGithubAlmSettingDto;
import static org.sonar.db.almsettings.AlmSettingsTesting.newGithubProjectAlmSettingDto;
public class ProjectAlmSettingDaoWithPersisterTest {
public final DbTester db = DbTester.create(system2, auditPersister);
private final DbSession dbSession = db.getSession();
- private final UuidFactory uuidFactory = mock(UuidFactory.class);
+ private final UuidFactory uuidFactory = UuidFactoryFast.getInstance();
private final ProjectAlmSettingDao underTest = db.getDbClient().projectAlmSettingDao();
@Test
public void insertAndUpdateExistingBindingArePersisted() {
- when(uuidFactory.create()).thenReturn(A_UUID);
- AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
+ AlmSettingDto githubAlmSetting = newGithubAlmSettingDto().setUuid(uuidFactory.create());
ProjectDto project = db.components().insertPrivateProjectDto();
ProjectAlmSettingDto projectAlmSettingDto = newGithubProjectAlmSettingDto(githubAlmSetting, project)
.setSummaryCommentEnabled(false);
@Test
public void deleteByProjectIsPersisted() {
- when(uuidFactory.create()).thenReturn(A_UUID);
- AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
+ AlmSettingDto githubAlmSetting = newGithubAlmSettingDto().setUuid(uuidFactory.create());
ProjectDto project = db.components().insertPrivateProjectDto();
ProjectAlmSettingDto projectAlmSettingDto = newGithubProjectAlmSettingDto(githubAlmSetting, project)
.setSummaryCommentEnabled(false);
underTest.deleteByProject(dbSession, project);
- verify(auditPersister).addComponent(any(), any(), any());
+ verify(auditPersister).addComponent(any(), any());
verifyNoMoreInteractions(auditPersister);
}
-
- @Test
- public void deleteByAlmSettingNotTrackedIsNotPersisted() {
- AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
- underTest.deleteByAlmSetting(dbSession, githubAlmSetting);
-
- verifyNoInteractions(auditPersister);
- }
}
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mockito;
import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Scopes;
import org.sonar.db.DbTester;
import org.sonar.db.RowNotFoundException;
import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.db.audit.model.ComponentNewValue;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.metric.MetricDto;
import static org.assertj.core.api.Assertions.entry;
import static org.assertj.core.api.Assertions.tuple;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
private final Random random = new Random();
private final DbSession dbSession = db.getSession();
- private final ComponentDao underTest = new ComponentDao();
+ private final ComponentDao underTest = new ComponentDao(new NoOpAuditPersister());
private final ComponentDao underTestWithAuditPersister = new ComponentDao(auditPersister);
private static ComponentTreeQuery.Builder newTreeQuery(String baseUuid) {
db.components().insertComponent(newPrivateProjectDto().setRootUuid(uuid1).setProjectUuid("foo").setPrivate(false)).uuid(),
};
- underTest.setPrivateForRootComponentUuid(db.getSession(), uuid1, true, "key", null, "name", true);
+ underTest.setPrivateForRootComponentUuidWithoutAudit(db.getSession(), uuid1, true);
assertThat(privateFlagOfUuid(uuids[0])).isTrue();
assertThat(privateFlagOfUuid(uuids[1])).isTrue();
assertThat(privateFlagOfUuid(uuids[3])).isFalse();
assertThat(privateFlagOfUuid(uuids[4])).isFalse();
- underTest.setPrivateForRootComponentUuid(db.getSession(), uuid1, false, "key", null, "name", true);
+ underTest.setPrivateForRootComponentUuidWithoutAudit(db.getSession(), uuid1, false);
assertThat(privateFlagOfUuid(uuids[0])).isFalse();
assertThat(privateFlagOfUuid(uuids[1])).isFalse();
assertThat(privateFlagOfUuid(uuids[3])).isFalse();
assertThat(privateFlagOfUuid(uuids[4])).isFalse();
- underTest.setPrivateForRootComponentUuid(db.getSession(), uuid2, false, "key", null, "name", true);
+ underTest.setPrivateForRootComponentUuidWithoutAudit(db.getSession(), uuid2, false);
assertThat(privateFlagOfUuid(uuids[0])).isFalse();
assertThat(privateFlagOfUuid(uuids[1])).isFalse();
assertThat(privateFlagOfUuid(uuids[3])).isFalse();
assertThat(privateFlagOfUuid(uuids[4])).isFalse();
- underTest.setPrivateForRootComponentUuid(db.getSession(), uuid2, true, "key", null, "name", true);
+ underTest.setPrivateForRootComponentUuidWithoutAudit(db.getSession(), uuid2, true);
assertThat(privateFlagOfUuid(uuids[0])).isFalse();
assertThat(privateFlagOfUuid(uuids[1])).isFalse();
@Test
public void setPrivateForRootComponentUuid_auditPersisterIsCalled() {
- underTestWithAuditPersister.setPrivateForRootComponentUuid(dbSession, "anyUuid", false, "key", APP, "appName", true);
+ underTestWithAuditPersister.setPrivateForRootComponentUuid(dbSession, "anyUuid", false, "key", APP, "appName");
- verify(auditPersister, Mockito.times(1))
- .updateComponentVisibility(any(DbSession.class), any(ComponentNewValue.class), anyString());
+ verify(auditPersister).updateComponentVisibility(any(DbSession.class), any(ComponentNewValue.class));
}
@Test
- public void setPrivateForRootComponentUuid_withoutTrack_auditPersisterIsNotCalled() {
- underTestWithAuditPersister.setPrivateForRootComponentUuid(dbSession, "anyUuid", false, "key", APP, "appName", false);
+ public void setPrivateForRootComponentUuidWithoutAudit_auditPersisterIsNotCalled() {
+ underTestWithAuditPersister.setPrivateForRootComponentUuidWithoutAudit(dbSession, "anyUuid", false);
verifyNoInteractions(auditPersister);
}
@Test
public void update_auditPersisterIsCalled() {
- ComponentUpdateDto app = new ComponentUpdateDto();
+ ComponentUpdateDto app = new ComponentUpdateDto().setUuid("uuid");
app.setBQualifier(APP);
underTestWithAuditPersister.update(dbSession, app, APP);
- verify(auditPersister, Mockito.times(1))
- .updateComponent(any(DbSession.class), any(ComponentNewValue.class), anyString());
+ verify(auditPersister).updateComponent(any(DbSession.class), any(ComponentNewValue.class));
}
@Test
underTestWithAuditPersister.insert(dbSession, app);
- verify(auditPersister, Mockito.times(1))
- .addComponent(any(DbSession.class), any(ComponentNewValue.class), anyString());
+ verify(auditPersister).addComponent(any(DbSession.class), any(ComponentNewValue.class));
}
private boolean privateFlagOfUuid(String uuid) {
import org.sonar.api.utils.System2;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.db.source.FileSourceDto;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
private Random random = new Random();
private DbSession dbSession = db.getSession();
- private ComponentDao underTest = new ComponentDao();
+ private ComponentDao underTest = new ComponentDao(new NoOpAuditPersister());
@Test
public void scrollAllFilesForFileMove_has_no_effect_if_project_does_not_exist() {
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.user.GroupDto;
public DbTester db = DbTester.create(System2.INSTANCE);
private final DbSession dbSession = db.getSession();
- private final GroupPermissionDao underTest = new GroupPermissionDao();
+ private final GroupPermissionDao underTest = new GroupPermissionDao(new NoOpAuditPersister());
@Test
public void group_count_by_permission_and_component_id_on_private_projects() {
import org.sonar.db.user.GroupDto;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.sonar.api.web.UserRole.ADMIN;
public class GroupPermissionDaoWithPersisterTest {
private final AuditPersister auditPersister = mock(AuditPersister.class);
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE, auditPersister);
+ public DbTester db = DbTester.create(System2.INSTANCE);
private final SequenceUuidFactory uuidFactory = new SequenceUuidFactory();
private final ArgumentCaptor<GroupPermissionNewValue> newValueCaptor = ArgumentCaptor.forClass(GroupPermissionNewValue.class);
private final DbSession dbSession = db.getSession();
- private final GroupPermissionDao underTest = db.getDbClient().groupPermissionDao();
+ private final GroupPermissionDao underTest = new GroupPermissionDao(auditPersister);
private GroupDto group;
private ComponentDto project;
verify(auditPersister).addGroupPermission(eq(dbSession), newValueCaptor.capture());
GroupPermissionNewValue newValue = newValueCaptor.getValue();
assertNewValue(newValue, dto.getUuid(), group.getUuid(), group.getName(), project.uuid(), dto.getRole(), project.getKey(),
- project.name(), "project");
+ project.name(), "TRK");
assertThat(newValue).hasToString("{\"permissionUuid\": \"1\", \"permission\": \"admin\", \"groupUuid\": \"guuid\", \"groupName\": \"gname\"," +
" \"componentUuid\": \"cuuid\", \"componentKey\": \"cKey\", \"componentName\": \"cname\", \"qualifier\": \"project\" }");
verify(auditPersister).deleteGroupPermission(eq(dbSession), newValueCaptor.capture());
newValue = newValueCaptor.getValue();
- assertNewValue(newValue, null, null, null, project.uuid(), null, project.getKey(), project.name(), "project");
+ assertNewValue(newValue, null, null, null, project.uuid(), null, project.getKey(), project.name(), "TRK");
assertThat(newValue).hasToString("{\"componentUuid\": \"cuuid\", \"componentKey\": \"cKey\", \"componentName\": \"cname\", \"qualifier\": \"project\" }");
}
underTest.deleteByRootComponentUuid(dbSession, project);
- verify(auditPersister).addComponent(any(), any(), any());
- verifyNoMoreInteractions(auditPersister);
+ verifyNoInteractions(auditPersister);
}
@Test
verify(auditPersister).addGroupPermission(eq(dbSession), newValueCaptor.capture());
GroupPermissionNewValue newValue = newValueCaptor.getValue();
- assertNewValue(newValue, dto.getUuid(), null, null, project.uuid(), dto.getRole(), project.getKey(), project.name(), "project");
+ assertNewValue(newValue, dto.getUuid(), null, null, project.uuid(), dto.getRole(), project.getKey(), project.name(), "TRK");
assertThat(newValue).hasToString("{\"permissionUuid\": \"1\", \"permission\": \"admin\", \"componentUuid\": \"cuuid\", "
+ "\"componentKey\": \"cKey\", \"componentName\": \"cname\", \"qualifier\": \"project\" }");
verify(auditPersister).deleteGroupPermission(eq(dbSession), newValueCaptor.capture());
newValue = newValueCaptor.getValue();
- assertNewValue(newValue, null, null, null, project.uuid(), null, project.getKey(), project.name(), "project");
+ assertNewValue(newValue, null, null, null, project.uuid(), null, project.getKey(), project.name(), "TRK");
assertThat(newValue).hasToString("{\"componentUuid\": \"cuuid\", \"componentKey\": \"cKey\", " +
"\"componentName\": \"cname\", \"qualifier\": \"project\" }");
}
underTest.deleteByRootComponentUuidForAnyOne(dbSession, project);
- verify(auditPersister).addComponent(any(), any(), any());
- verifyNoMoreInteractions(auditPersister);
+ verifyNoInteractions(auditPersister);
}
@Test
verify(auditPersister).addGroupPermission(eq(dbSession), newValueCaptor.capture());
GroupPermissionNewValue newValue = newValueCaptor.getValue();
- assertNewValue(newValue, dto.getUuid(), group.getUuid(), group.getName(), project.uuid(), dto.getRole(), project.getKey(), project.name(), "project");
+ assertNewValue(newValue, dto.getUuid(), group.getUuid(), group.getName(), project.uuid(), dto.getRole(), project.getKey(), project.name(), "TRK");
assertThat(newValue).hasToString("{\"permissionUuid\": \"1\", \"permission\": \"admin\", \"groupUuid\": \"guuid\", \"groupName\": \"gname\", "
+ "\"componentUuid\": \"cuuid\", \"componentKey\": \"cKey\", \"componentName\": \"cname\", \"qualifier\": \"project\" }");
verify(auditPersister).deleteGroupPermission(eq(dbSession), newValueCaptor.capture());
newValue = newValueCaptor.getValue();
- assertNewValue(newValue, null, null, null, project.uuid(), ADMIN, project.getKey(), project.name(), "project");
+ assertNewValue(newValue, null, null, null, project.uuid(), ADMIN, project.getKey(), project.name(), "TRK");
assertThat(newValue).hasToString("{\"permission\": \"admin\", \"componentUuid\": \"cuuid\", \"componentKey\": \"cKey\"," +
" \"componentName\": \"cname\", \"qualifier\": \"project\" }");
}
underTest.deleteByRootComponentUuidAndPermission(dbSession, dto.getRole(), project);
- verify(auditPersister).addComponent(any(), any(), any());
- verifyNoMoreInteractions(auditPersister);
+ verifyNoInteractions(auditPersister);
}
private void assertNewValue(GroupPermissionNewValue newValue, String uuid, String groupUuid, String groupName, String cUuid, String permission,
String componentKey, String cName, String qualifier) {
assertThat(newValue)
- .extracting("permissionUuid", "groupUuid", "groupName", "componentUuid", "permission",
- "componentKey", "componentName", "qualifier")
- .containsExactly(uuid, groupUuid, groupName, cUuid, permission, componentKey,
- cName, qualifier);
+ .extracting("permissionUuid", "groupUuid", "groupName", "componentUuid", "permission", "componentKey", "componentName", "qualifier")
+ .containsExactly(uuid, groupUuid, groupName, cUuid, permission, componentKey, cName, qualifier);
}
private void addGroupPermission() {
import org.sonar.core.util.Uuids;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.user.UserDto;
public DbTester db = DbTester.create(System2.INSTANCE);
private DbSession dbSession = db.getSession();
- private UserPermissionDao underTest = new UserPermissionDao();
+ private UserPermissionDao underTest = new UserPermissionDao(new NoOpAuditPersister());
@Test
public void select_global_permissions() {
assertThat(newValue.toString()).doesNotContain("projectUuid");
}
- @Test
- public void userGlobalPermissionDeleteWithoutAffectedRowsIsNotPersisted() {
- UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
-
- underTest.deleteGlobalPermission(dbSession, user, SYSTEM_ADMIN);
-
- verify(auditPersister).addUser(any(), any());
- verifyNoMoreInteractions(auditPersister);
- }
-
@Test
public void userProjectPermissionInsertAndDeleteArePersisted() {
UserDto user = insertUser(u -> u.setLogin("login1").setName("Marius").setEmail("email1@email.com"));
verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture());
UserPermissionNewValue newValue = newValueCaptor.getValue();
assertNewValue(newValue, dto.getUuid(), user.getUuid(), user.getLogin(), project.uuid(), dto.getPermission(),
- project.getKey(), project.name(), "project");
+ project.getKey(), project.name(), "TRK");
assertThat(newValue.toString()).contains("componentUuid");
underTest.deleteProjectPermission(dbSession, user, SYSTEM_ADMIN, project);
verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture());
newValue = newValueCaptor.getValue();
assertNewValue(newValue, null, user.getUuid(), user.getLogin(), project.uuid(), dto.getPermission(),
- project.getKey(), project.name(), "project");
+ project.getKey(), project.name(), "TRK");
assertThat(newValue.toString()).doesNotContain("permissionUuid");
}
underTest.deleteProjectPermission(dbSession, user, SYSTEM_ADMIN, project);
verify(auditPersister).addUser(any(), any());
- verify(auditPersister).addComponent(any(), any(), any());
+ verify(auditPersister).addComponent(any(), any());
verifyNoMoreInteractions(auditPersister);
}
verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture());
UserPermissionNewValue newValue = newValueCaptor.getValue();
assertNewValue(newValue, dto.getUuid(), user.getUuid(), user.getLogin(), portfolio.uuid(), dto.getPermission(),
- portfolio.getKey(), portfolio.name(), "portfolio");
+ portfolio.getKey(), portfolio.name(), "VW");
assertThat(newValue.toString()).contains("componentUuid");
}
verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture());
UserPermissionNewValue newValue = newValueCaptor.getValue();
assertNewValue(newValue, dto.getUuid(), user.getUuid(), user.getLogin(), application.uuid(), dto.getPermission(),
- application.getKey(), application.name(), "application");
+ application.getKey(), application.name(), "APP");
assertThat(newValue.toString()).contains("componentUuid");
}
verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture());
UserPermissionNewValue newValue = newValueCaptor.getValue();
assertNewValue(newValue, null, null, null, project.uuid(), dto.getPermission(),
- project.getKey(), project.name(), "project");
+ project.getKey(), project.name(), "TRK");
assertThat(newValue.toString()).doesNotContain("userUuid");
}
underTest.deleteProjectPermissionOfAnyUser(dbSession, SCAN_EXECUTION, project);
- verify(auditPersister).addComponent(any(), any(), any());
+ verify(auditPersister).addComponent(any(), any());
verifyNoMoreInteractions(auditPersister);
}
import org.sonar.api.web.UserRole;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.audit.NoOpAuditPersister;
import static com.google.common.collect.Lists.newArrayList;
import static java.util.Arrays.asList;
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
private final DbSession dbSession = db.getSession();
- private final PermissionTemplateCharacteristicDao underTest = new PermissionTemplateCharacteristicDao();
+ private final PermissionTemplateCharacteristicDao underTest = new PermissionTemplateCharacteristicDao(new NoOpAuditPersister());
@Test
public void selectByTemplateId_filter_by_template_uuid() {
import org.sonar.core.util.UuidFactoryFast;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
private PermissionTemplateDbTester templateDb = db.permissionTemplates();
private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
- private PermissionTemplateDao underTest = new PermissionTemplateDao(uuidFactory, system2);
+ private PermissionTemplateDao underTest = new PermissionTemplateDao(uuidFactory, system2, new NoOpAuditPersister());
@Before
public void setUp() {
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.NoOpAuditPersister;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
private final AuditPersister auditPersister = mock(AuditPersister.class);
- private final ProjectDao projectDao = new ProjectDao(system2);
+ private final ProjectDao projectDao = new ProjectDao(system2, new NoOpAuditPersister());
private final ProjectDao projectDaoWithAuditPersister = new ProjectDao(system2, auditPersister);
@Test
projectDaoWithAuditPersister.insert(db.getSession(), dto1, true);
- verify(auditPersister, times(1)).addComponent(any(), any(), any());
+ verify(auditPersister, times(1)).addComponent(any(), any());
}
@Test
projectDaoWithAuditPersister.update(db.getSession(), dto1);
- verify(auditPersister, times(1)).updateComponent(any(), any(), any());
+ verify(auditPersister, times(1)).updateComponent(any(), any());
}
private void assertProject(ProjectDto dto, String name, String kee, String uuid, String desc, @Nullable String tags, boolean isPrivate) {
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
@RunWith(DataProviderRunner.class)
when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
underTest.saveProperty(new PropertyDto().setKey(KEY).setValue(VALUE));
- verify(auditPersister).isTrackedProperty(KEY);
verify(auditPersister).addProperty(any(), newValueCaptor.capture(), eq(false));
PropertyNewValue newValue = newValueCaptor.getValue();
assertThat(newValue.toString()).doesNotContain("projectUuid");
}
- @Test
- public void saveGlobalNotTrackedPropertyIsNotPersisted() {
- when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
-
- underTest.saveProperty(new PropertyDto().setKey(KEY).setValue(VALUE));
-
- verify(auditPersister).isTrackedProperty(KEY);
- verifyNoMoreInteractions(auditPersister);
- }
-
@Test
public void saveGlobalTrackedAndSecuredPropertyIsPersisted() {
when(auditPersister.isTrackedProperty(SECURED_KEY)).thenReturn(true);
underTest.saveProperty(new PropertyDto().setKey(SECURED_KEY).setValue(VALUE));
- verify(auditPersister).isTrackedProperty(SECURED_KEY);
verify(auditPersister).addProperty(any(), newValueCaptor.capture(), eq(false));
PropertyNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
}
@Test
- public void saveProjectTrackedPropertyIsPersisted() {
+ public void saveProjectPropertyIsPersisted() {
when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID);
underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT);
- verify(auditPersister).isTrackedProperty(KEY);
verify(auditPersister).addProperty(any(), newValueCaptor.capture(), eq(false));
PropertyNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentKey,
PropertyNewValue::getComponentName, PropertyNewValue::getQualifier)
.containsExactly(propertyDto.getKey(), propertyDto.getValue(), propertyDto.getUserUuid(),
- USER_LOGIN, propertyDto.getComponentUuid(), PROJECT_KEY, PROJECT_NAME, "project");
+ USER_LOGIN, propertyDto.getComponentUuid(), PROJECT_KEY, PROJECT_NAME, "TRK");
assertThat(newValue.toString()).contains("componentUuid");
}
PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID);
underTest.saveProperty(session, propertyDto, USER_LOGIN, "app-key", "app-name", Qualifiers.APP);
- verify(auditPersister).isTrackedProperty(KEY);
verify(auditPersister).addProperty(any(), newValueCaptor.capture(), eq(false));
PropertyNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentKey,
PropertyNewValue::getComponentName, PropertyNewValue::getQualifier)
.containsExactly(propertyDto.getKey(), propertyDto.getValue(), propertyDto.getUserUuid(),
- USER_LOGIN, propertyDto.getComponentUuid(), "app-key", "app-name", "application");
+ USER_LOGIN, propertyDto.getComponentUuid(), "app-key", "app-name", "APP");
assertThat(newValue.toString())
.contains("componentUuid");
}
PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID);
underTest.saveProperty(session, propertyDto, USER_LOGIN, "portfolio-key", "portfolio-name", Qualifiers.VIEW);
- verify(auditPersister).isTrackedProperty(KEY);
verify(auditPersister).addProperty(any(), newValueCaptor.capture(), eq(false));
PropertyNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentKey,
PropertyNewValue::getComponentName, PropertyNewValue::getQualifier)
.containsExactly(propertyDto.getKey(), propertyDto.getValue(), propertyDto.getUserUuid(),
- USER_LOGIN, propertyDto.getComponentUuid(), "portfolio-key", "portfolio-name", "portfolio");
+ USER_LOGIN, propertyDto.getComponentUuid(), "portfolio-key", "portfolio-name", "VW");
assertThat(newValue.toString())
.contains("componentUuid");
}
PropertyDto propertyDto = getPropertyDto(SECURED_KEY, PROJECT_UUID, USER_UUID);
underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT);
- verify(auditPersister).isTrackedProperty(SECURED_KEY);
verify(auditPersister).addProperty(any(), newValueCaptor.capture(), eq(false));
PropertyNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentKey,
PropertyNewValue::getComponentName, PropertyNewValue::getQualifier)
.containsExactly(propertyDto.getKey(), null, propertyDto.getUserUuid(),
- USER_LOGIN, propertyDto.getComponentUuid(), PROJECT_KEY, PROJECT_NAME, "project");
+ USER_LOGIN, propertyDto.getComponentUuid(), PROJECT_KEY, PROJECT_NAME, "TRK");
assertThat(newValue.toString()).contains("componentUuid");
}
underTest.deleteByQuery(session, query);
- verify(auditPersister, times(2)).isTrackedProperty(KEY);
verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
PropertyNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
verifyNoInteractions(auditPersister);
}
- @Test
- public void deleteNotTrackedPropertyByQueryIsNotPersisted() {
- when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
- PropertyQuery query = getPropertyQuery(KEY);
- PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID);
- underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT);
-
- underTest.deleteByQuery(session, query);
-
- verify(auditPersister, times(2)).isTrackedProperty(KEY);
- verifyNoMoreInteractions(auditPersister);
- }
-
@Test
public void deleteTrackedPropertyIsPersisted() {
when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT);
- verify(auditPersister, times(2)).isTrackedProperty(KEY);
verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
PropertyNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
verifyNoInteractions(auditPersister);
}
- @Test
- public void deleteNotTrackedPropertyIsNotPersisted() {
- when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
- PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID);
- underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT);
-
- underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT);
-
- verify(auditPersister, times(2)).isTrackedProperty(KEY);
- verifyNoMoreInteractions(auditPersister);
- }
-
@Test
public void deleteTrackedProjectPropertyIsPersisted() {
when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
underTest.deleteProjectProperty(KEY, PROJECT_UUID, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT);
- verify(auditPersister, times(2)).isTrackedProperty(KEY);
verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
PropertyNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
verifyNoInteractions(auditPersister);
}
- @Test
- public void deleteNotTrackedProjectPropertyIsNotPersisted() {
- when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
- PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID);
- underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT);
-
- underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT);
-
- verify(auditPersister, times(2)).isTrackedProperty(KEY);
- verifyNoMoreInteractions(auditPersister);
- }
-
@Test
public void deleteTrackedProjectPropertiesIsPersisted() {
when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
underTest.deleteProjectProperties(KEY, VALUE);
- verify(auditPersister, times(2)).isTrackedProperty(KEY);
verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
PropertyNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
verifyNoInteractions(auditPersister);
}
- @Test
- public void deleteNotTrackedProjectPropertiesIsNotPersisted() {
- when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
- PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, null);
- underTest.saveProperty(propertyDto);
-
- underTest.deleteProjectProperties(KEY, VALUE);
-
- verify(auditPersister, times(2)).isTrackedProperty(KEY);
- verifyNoMoreInteractions(auditPersister);
- }
-
@Test
public void deleteTrackedGlobalPropertyIsPersisted() {
when(auditPersister.isTrackedProperty(KEY)).thenReturn(true);
underTest.deleteGlobalProperty(KEY, session);
- verify(auditPersister, times(2)).isTrackedProperty(KEY);
verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
PropertyNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
verifyNoInteractions(auditPersister);
}
- @Test
- public void deleteNotTrackedGlobalPropertyIsNotPersisted() {
- when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
- PropertyDto propertyDto = getPropertyDto(KEY, null, null);
- underTest.saveProperty(session, propertyDto, null, null, null, null);
-
- underTest.deleteGlobalProperty(KEY, session);
-
- verify(auditPersister, times(2)).isTrackedProperty(KEY);
- verifyNoMoreInteractions(auditPersister);
- }
-
@Test
public void deletePropertyByUserIsPersisted() {
UserDto user = setUserProperties(VALUE);
underTest.deleteByUser(session, user.getUuid(), user.getLogin());
- verify(auditPersister, times(2)).isTrackedProperty(KEY);
- verify(auditPersister, times(2)).isTrackedProperty(ANOTHER_KEY);
- verify(auditPersister, times(2)).isTrackedProperty(SECURED_KEY);
verify(auditPersister, times(2)).deleteProperty(any(), newValueCaptor.capture(), eq(false));
List<PropertyNewValue> newValues = newValueCaptor.getAllValues();
assertThat(newValues.get(0))
UserDto user = setUserProperties(null);
underTest.deleteByMatchingLogin(session, user.getLogin(), newArrayList(KEY, ANOTHER_KEY, SECURED_KEY));
- verify(auditPersister, times(2)).isTrackedProperty(KEY);
- verify(auditPersister, times(2)).isTrackedProperty(ANOTHER_KEY);
- verify(auditPersister, times(2)).isTrackedProperty(SECURED_KEY);
verify(auditPersister, times(2)).deleteProperty(any(), newValueCaptor.capture(), eq(false));
List<PropertyNewValue> newValues = newValueCaptor.getAllValues();
assertThat(newValues.get(0))
underTest.saveProperty(session, propertyDto, USER_LOGIN, null, null, null);
underTest.deleteByKeyAndValue(session, KEY, VALUE);
- verify(auditPersister, times(2)).isTrackedProperty(KEY);
verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false));
PropertyNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
verifyNoInteractions(auditPersister);
}
- @Test
- public void deleteNotTrackedPropertyByKeyAndValueIsNotPersisted() {
- when(auditPersister.isTrackedProperty(KEY)).thenReturn(false);
- PropertyDto propertyDto = getPropertyDto(KEY, null, USER_UUID);
- underTest.saveProperty(session, propertyDto, USER_LOGIN, null, null, null);
-
- underTest.deleteByKeyAndValue(session, KEY, VALUE);
-
- verify(auditPersister, times(2)).isTrackedProperty(KEY);
- verifyNoMoreInteractions(auditPersister);
- }
-
private PropertyDto getPropertyDto(String key, @Nullable String projectUuid, @Nullable String userUuid) {
return new PropertyDto()
.setKey(key)
underTestWithPersister.deleteProject(dbSession, project.uuid(), project.qualifier(), project.name(), project.getKey());
- verify(auditPersister).deleteComponent(any(DbSession.class), newValueCaptor.capture(), eq(project.qualifier()));
+ verify(auditPersister).deleteComponent(any(DbSession.class), newValueCaptor.capture());
ComponentNewValue componentNewValue = newValueCaptor.getValue();
assertThat(componentNewValue)
- .extracting(ComponentNewValue::getComponentUuid, ComponentNewValue::getComponentName, ComponentNewValue::getComponentKey,
- ComponentNewValue::getQualifier)
- .containsExactly(project.uuid(), project.name(), project.getKey(), "project");
+ .extracting(ComponentNewValue::getComponentUuid, ComponentNewValue::getComponentName, ComponentNewValue::getComponentKey, ComponentNewValue::getQualifier)
+ .containsExactly(project.uuid(), project.name(), project.getKey(), "TRK");
}
}
underTest.deleteByGroupUuid(db.getSession(), group1.getUuid(), group1.getName());
db.getSession().commit();
- verifyNoInteractions(auditPersister);
+ verify(auditPersister).addUserGroup(any(), any());
+ verifyNoMoreInteractions(auditPersister);
}
@Test
}
@Test
- public void deletByUserAndGroupWithoutAffectedRowsIsNotPersisted() {
+ public void deleteByUserAndGroupWithoutAffectedRowsIsNotPersisted() {
UserDto user1 = db.users().insertUser();
GroupDto group1 = db.users().insertGroup();
underTest.delete(db.getSession(), group1, user1);
db.getSession().commit();
verify(auditPersister).addUser(any(), any());
+ verify(auditPersister).addUserGroup(any(), any());
verifyNoMoreInteractions(auditPersister);
}
}
@Test
public void insertTrackedUserPropertyIsPersisted() {
- when(auditPersister.isTrackedProperty(PROPERTY_KEY)).thenReturn(true);
-
UserDto user = db.users().insertUser();
verify(auditPersister).addUser(eq(db.getSession()), any());
user.getLogin());
verify(auditPersister).addProperty(eq(db.getSession()), newValueCaptor.capture(), eq(true));
- verify(auditPersister).isTrackedProperty(PROPERTY_KEY);
assertThat(newValueCaptor.getValue())
.extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid,
PropertyNewValue::getUserLogin)
@Test
public void insertTrackedAndSecuredUserPropertyIsPersisted() {
- when(auditPersister.isTrackedProperty(SECURED_PROPERTY_KEY)).thenReturn(true);
-
UserDto user = db.users().insertUser();
verify(auditPersister).addUser(eq(db.getSession()), any());
.setValue("a_value"),
user.getLogin());
- verify(auditPersister).isTrackedProperty(SECURED_PROPERTY_KEY);
verify(auditPersister).addProperty(eq(db.getSession()), newValueCaptor.capture(), eq(true));
PropertyNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
assertThat(newValue.toString()).doesNotContain("propertyValue");
}
- @Test
- public void insertNotTrackedUserPropertyIsNotPersisted() {
- when(auditPersister.isTrackedProperty(PROPERTY_KEY)).thenReturn(false);
-
- UserDto user = db.users().insertUser();
- underTest.insertOrUpdate(db.getSession(), new UserPropertyDto()
- .setUserUuid(user.getUuid())
- .setKey(PROPERTY_KEY)
- .setValue("a_value"),
- user.getLogin());
-
- verify(auditPersister).addUser(eq(db.getSession()), any());
- verify(auditPersister).isTrackedProperty(PROPERTY_KEY);
- verifyNoMoreInteractions(auditPersister);
- }
-
@Test
public void updateTrackedUserPropertyIsPersisted() {
- when(auditPersister.isTrackedProperty(PROPERTY_KEY)).thenReturn(true);
-
UserDto user = db.users().insertUser();
underTest.insertOrUpdate(db.getSession(), new UserPropertyDto()
.setUserUuid(user.getUuid())
underTest.deleteByUser(db.getSession(), user);
verify(auditPersister).addUser(eq(db.getSession()), any());
- verify(auditPersister).addProperty(eq(db.getSession()), any(), eq(true));
- verify(auditPersister).addProperty(eq(db.getSession()), any(), eq(true));
- verify(auditPersister, times(2)).isTrackedProperty(PROPERTY_KEY);
- verify(auditPersister, times(2)).isTrackedProperty(SECURED_PROPERTY_KEY);
+ verify(auditPersister, times(2)).addProperty(eq(db.getSession()), any(), eq(true));
+ verify(auditPersister).isTrackedProperty(PROPERTY_KEY);
+ verify(auditPersister).isTrackedProperty(SECURED_PROPERTY_KEY);
verify(auditPersister).deleteProperty(eq(db.getSession()), newValueCaptor.capture(), eq(true));
verifyNoMoreInteractions(auditPersister);
assertThat(newValueCaptor.getValue())
UserTokenDto userToken2 = db.users().insertToken(user1);
assertThat(underTest.selectByTokenHash(dbSession, userToken1.getTokenHash()).getLastConnectionDate()).isNull();
- underTest.update(dbSession, userToken1.setLastConnectionDate(10_000_000_000L), false, null);
+ underTest.updateWithoutAudit(dbSession, userToken1.setLastConnectionDate(10_000_000_000L));
UserTokenDto userTokenReloaded = underTest.selectByTokenHash(dbSession, userToken1.getTokenHash());
assertThat(userTokenReloaded.getLastConnectionDate()).isEqualTo(10_000_000_000L);
assertThat(underTest.selectByTokenHash(dbSession, userToken1.getTokenHash()).getLastConnectionDate()).isNull();
- underTest.update(dbSession, userToken1.setLastConnectionDate(10_000_000_000L), false, null);
+ underTest.updateWithoutAudit(dbSession, userToken1.setLastConnectionDate(10_000_000_000L));
underTest.update(dbSession, userToken1.setName("new_name"), user1.getLogin());
verify(auditPersister).updateUserToken(eq(db.getSession()), newValueCaptor.capture());
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
underTest.deleteByProject(dbSession, projectDto);
- verify(auditPersister).addComponent(any(), any(), any());
+ verify(auditPersister).addComponent(any(), any());
verifyNoMoreInteractions(auditPersister);
}
import org.sonar.db.almsettings.AlmSettingsDbTester;
import org.sonar.db.audit.AuditDbTester;
import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ProjectLinkDbTester;
import org.sonar.db.event.EventDbTester;
private final UuidFactory uuidFactory = new SequenceUuidFactory();
private final System2 system2;
+ private final AuditPersister auditPersister;
private DbClient client;
private DbSession session = null;
private final UserDbTester userTester;
private DbTester(System2 system2, @Nullable String schemaPath, AuditPersister auditPersister, MyBatisConfExtension... confExtensions) {
super(TestDbImpl.create(schemaPath, confExtensions));
this.system2 = system2;
+ this.auditPersister = auditPersister;
- initDbClient(auditPersister);
+ initDbClient();
this.userTester = new UserDbTester(this);
this.componentTester = new ComponentDbTester(this);
this.componentLinkTester = new ProjectLinkDbTester(this);
}
public static DbTester create() {
- return new DbTester(System2.INSTANCE, null, null);
+ return new DbTester(System2.INSTANCE, null, new NoOpAuditPersister());
}
public static DbTester create(AuditPersister auditPersister) {
}
public static DbTester create(System2 system2) {
- return new DbTester(system2, null, null);
+ return new DbTester(system2, null, new NoOpAuditPersister());
}
public static DbTester createWithExtensionMappers(System2 system2, Class<?> firstMapperClass, Class<?>... otherMapperClasses) {
- return new DbTester(system2, null, null, new DbTesterMyBatisConfExtension(firstMapperClass, otherMapperClasses));
+ return new DbTester(system2, null, new NoOpAuditPersister(), new DbTesterMyBatisConfExtension(firstMapperClass, otherMapperClasses));
}
- private void initDbClient(AuditPersister auditPersister) {
+ private void initDbClient() {
TransientPicoContainer ioc = new TransientPicoContainer();
- if (auditPersister != null) {
- ioc.addComponent(auditPersister);
- }
+ ioc.addComponent(auditPersister);
ioc.addComponent(db.getMyBatis());
ioc.addComponent(system2);
ioc.addComponent(uuidFactory);
protected void before() {
db.start();
db.truncateTables();
- initDbClient(null);
+ initDbClient();
}
public UserDbTester users() {
return new ComponentDto()
.setUuid(uuid)
.setUuidPath(formatUuidPathFromParent(parent))
+ .setDbKey(uuid)
.setProjectUuid(moduleOrProject.projectUuid())
.setRootUuid(moduleOrProject.uuid())
.setModuleUuid(moduleOrProject.uuid())
return;
}
try (DbSession dbSession = dbClient.openSession(false)) {
- dbClient.userTokenDao().update(dbSession, userToken.setLastConnectionDate(now), false, null);
+ dbClient.userTokenDao().updateWithoutAudit(dbSession, userToken.setLastConnectionDate(now));
userToken.setLastConnectionDate(now);
dbSession.commit();
}
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.utils.System2;
import org.sonar.api.impl.utils.TestSystem2;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.user.UserDto;
import org.sonar.db.user.UserTokenDto;
public void update_last_connection_date_from_user_token_when_last_connection_was_more_than_one_hour() {
UserDto user = db.users().insertUser();
UserTokenDto userToken = db.users().insertToken(user);
- db.getDbClient().userTokenDao().update(db.getSession(), userToken.setLastConnectionDate(NOW - TWO_HOUR), false, null);
+ db.getDbClient().userTokenDao().updateWithoutAudit(db.getSession(), userToken.setLastConnectionDate(NOW - TWO_HOUR));
db.commit();
underTest.updateLastConnectionDateIfNeeded(userToken);
public void do_not_update_when_last_connection_from_user_token_was_less_than_one_hour() {
UserDto user = db.users().insertUser();
UserTokenDto userToken = db.users().insertToken(user);
- db.getDbClient().userTokenDao().update(db.getSession(), userToken.setLastConnectionDate(NOW - ONE_MINUTE), false, null);
+ db.getDbClient().userTokenDao().updateWithoutAudit(db.getSession(), userToken.setLastConnectionDate(NOW - ONE_MINUTE));
db.commit();
underTest.updateLastConnectionDateIfNeeded(userToken);
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
import org.sonar.core.util.UuidFactory;
import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
private void setPrivateForRootComponentUuid(DbSession dbSession, ComponentDto component, boolean isPrivate) {
String uuid = component.uuid();
- dbClient.componentDao().setPrivateForRootComponentUuid(dbSession, uuid, isPrivate, component.getKey(),
- component.qualifier(), component.name(), true);
+ dbClient.componentDao().setPrivateForRootComponentUuid(dbSession, uuid, isPrivate, component.getKey(), component.qualifier(), component.name());
if (component.qualifier().equals(Qualifiers.PROJECT) || component.qualifier().equals(Qualifiers.APP)) {
dbClient.projectDao().updateVisibility(dbSession, uuid, isPrivate);
});
}
-
private void insertProjectPermissionOnUser(DbSession dbSession, ComponentDto component, String permission, UserId userId) {
dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto(Uuids.create(), permission, userId.getUuid(), component.uuid()),
component, userId, null);
private final DbClient dbClient;
private final Settings settings;
private final UserSession userSession;
- private AuditPersister auditPersister;
-
- public GenerateSecretKeyAction(DbClient dbClient, Settings settings, UserSession userSession) {
- this.dbClient = dbClient;
- this.settings = settings;
- this.userSession = userSession;
- }
+ private final AuditPersister auditPersister;
public GenerateSecretKeyAction(DbClient dbClient, Settings settings, UserSession userSession, AuditPersister auditPersister) {
this.dbClient = dbClient;
writeProtobuf(GenerateSecretKeyWsResponse.newBuilder().setSecretKey(settings.getEncryption().generateRandomSecretKey()).build(), request, response);
- if (auditPersister != null) {
- try (DbSession dbSession = dbClient.openSession(false)) {
- auditPersister.generateSecretKey(dbSession);
- dbSession.commit();
- }
+ try (DbSession dbSession = dbClient.openSession(false)) {
+ auditPersister.generateSecretKey(dbSession);
+ dbSession.commit();
}
}
}
import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
+import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsActionTester;
private DbClient dbClient = db.getDbClient();
private MapSettings settings = new MapSettings();
private Encryption encryption = settings.getEncryption();
- private GenerateSecretKeyAction underTest = new GenerateSecretKeyAction(dbClient, settings, userSession);
+ private GenerateSecretKeyAction underTest = new GenerateSecretKeyAction(dbClient, settings, userSession, new NoOpAuditPersister());
private WsActionTester ws = new WsActionTester(underTest);
@Test
import org.sonar.api.web.UserRole;
import org.sonar.core.util.Uuids;
import org.sonar.db.DbTester;
+import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.db.component.ComponentDao;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDao;
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
- private final ComponentDao componentDao = new ComponentDao();
+ private final ComponentDao componentDao = new ComponentDao(new NoOpAuditPersister());
private final SnapshotDao snapshotDao = new SnapshotDao();
private final HtmlSourceDecorator htmlSourceDecorator = mock(HtmlSourceDecorator.class);
private final SourceService sourceService = new SourceService(db.getDbClient(), htmlSourceDecorator);
UserDto user = db.users().insertUser();
UserTokenDto token1 = db.users().insertToken(user);
UserTokenDto token2 = db.users().insertToken(user);
- db.getDbClient().userTokenDao().update(db.getSession(), token1.setLastConnectionDate(10_000_000_000L), false, user.getLogin());
+ db.getDbClient().userTokenDao().updateWithoutAudit(db.getSession(), token1.setLastConnectionDate(10_000_000_000L));
db.commit();
logInAsSystemAdministrator();
import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.Version;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.server.issue.index.IssueIndexSyncProgressChecker;
import org.sonar.server.platform.DockerSupportImpl;
import org.sonar.server.util.GlobalLockManagerImpl;
.load();
get(WebCoreExtensionsInstaller.class)
.install(getContainer(), hasPlatformLevel(1), noAdditionalSideFilter());
+ if (getOptional(AuditPersister.class).isEmpty()) {
+ add(NoOpAuditPersister.class);
+ }
return super.start();
}