aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2023-06-06 09:21:12 +0200
committersonartech <sonartech@sonarsource.com>2023-06-19 20:03:14 +0000
commit4473576ffa2fe46b81ba91ffbc8a92581364fe74 (patch)
tree32133e469d332ba90b5a50eec3ea3330dd40de75 /server/sonar-db-dao
parent3a250934c669b497e4c115740ed5a3418ef81fdc (diff)
downloadsonarqube-4473576ffa2fe46b81ba91ffbc8a92581364fe74.tar.gz
sonarqube-4473576ffa2fe46b81ba91ffbc8a92581364fe74.zip
SONAR-19445 Review and improve the endpoints in WebAPI that rely on ComponentDto
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java13
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java18
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java14
3 files changed, 22 insertions, 23 deletions
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
index 107084fdb81..02085333860 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
@@ -275,8 +275,12 @@ public class ComponentDbTester {
}
public final ComponentDto insertSubportfolio(ComponentDto parentPortfolio) {
- ComponentDto subPortfolioComponent = ComponentTesting.newSubPortfolio(parentPortfolio);
- return insertComponentAndPortfolio(subPortfolioComponent, true, defaults(), sp -> sp.setParentUuid(sp.getRootUuid()));
+ return insertSubportfolio(parentPortfolio, defaults());
+ }
+
+ public final ComponentDto insertSubportfolio(ComponentDto parentPortfolio, Consumer<ComponentDto> consumer) {
+ ComponentDto subPortfolioComponent = ComponentTesting.newSubPortfolio(parentPortfolio).setPrivate(true);
+ return insertComponentAndPortfolio(subPortfolioComponent, true, consumer, sp -> sp.setParentUuid(sp.getRootUuid()));
}
public void addPortfolioReference(String portfolioUuid, String... referencerUuids) {
@@ -484,6 +488,11 @@ public class ComponentDbTester {
return insertSnapshot(snapshotDto);
}
+ public SnapshotDto insertSnapshot(PortfolioDto portfolio) {
+ SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(portfolio.getUuid());
+ return insertSnapshot(snapshotDto);
+ }
+
public SnapshotDto insertSnapshot(BranchDto branchDto, Consumer<SnapshotDto> consumer) {
SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(branchDto);
consumer.accept(snapshotDto);
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java
index f7ca6784397..9f8d04071b8 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/notification/NotificationDbTester.java
@@ -25,7 +25,7 @@ import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.property.PropertyDto;
import org.sonar.db.property.PropertyQuery;
@@ -42,22 +42,22 @@ public class NotificationDbTester {
this.dbSession = db.getSession();
}
- public void assertExists(String channel, String dispatcher, String userUuid, @Nullable ComponentDto component) {
+ public void assertExists(String channel, String dispatcher, String userUuid, @Nullable ProjectDto project) {
List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
- .setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel))
- .setEntityUuid(component == null ? null : component.uuid())
- .setUserUuid(userUuid)
- .build(), dbSession).stream()
- .filter(prop -> component == null ? prop.getEntityUuid() == null : prop.getEntityUuid() != null)
+ .setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel))
+ .setEntityUuid(project == null ? null : project.getUuid())
+ .setUserUuid(userUuid)
+ .build(), dbSession).stream()
+ .filter(prop -> project == null ? prop.getEntityUuid() == null : prop.getEntityUuid() != null)
.collect(MoreCollectors.toList());
assertThat(result).hasSize(1);
assertThat(result.get(0).getValue()).isEqualTo("true");
}
- public void assertDoesNotExist(String channel, String dispatcher, String userUuid, @Nullable ComponentDto component) {
+ public void assertDoesNotExist(String channel, String dispatcher, String userUuid, @Nullable ProjectDto project) {
List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
.setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel))
- .setEntityUuid(component == null ? null : component.uuid())
+ .setEntityUuid(project == null ? null : project.getUuid())
.setUserUuid(userUuid)
.build(), dbSession);
assertThat(result).isEmpty();
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
index 132681d52b2..4d08a86d156 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
@@ -300,11 +300,6 @@ public class UserDbTester {
return dto;
}
- public void deleteProjectPermissionFromAnyone(ComponentDto project, String permission) {
- db.getDbClient().groupPermissionDao().delete(db.getSession(), permission, null, null, project.uuid(), project);
- db.commit();
- }
-
public void deleteProjectPermissionFromAnyone(EntityDto project, String permission) {
db.getDbClient().groupPermissionDao().delete(db.getSession(), permission, null, null, project.getUuid(), project);
db.commit();
@@ -389,11 +384,6 @@ public class UserDbTester {
db.commit();
}
- public void deletePermissionFromUser(ComponentDto project, UserDto user, String permission) {
- db.getDbClient().userPermissionDao().deleteProjectPermission(db.getSession(), user, permission, project);
- db.commit();
- }
-
public void deletePermissionFromUser(EntityDto project, UserDto user, String permission) {
db.getDbClient().userPermissionDao().deleteProjectPermission(db.getSession(), user, permission, project);
db.commit();
@@ -406,10 +396,10 @@ public class UserDbTester {
checkArgument(project.isPrivate() || !PUBLIC_PERMISSIONS.contains(permission),
"%s can't be granted on a public project", permission);
EntityDto entityDto;
- if (project.qualifier().equals(Qualifiers.VIEW) || project.qualifier().equals(Qualifiers.SUBVIEW)){
+ if (project.qualifier().equals(Qualifiers.VIEW) || project.qualifier().equals(Qualifiers.SUBVIEW)) {
entityDto = db.getDbClient().portfolioDao().selectByUuid(db.getSession(), project.uuid())
.orElseThrow();
- }else{
+ } else {
BranchDto branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), project.branchUuid())
.orElseThrow();
// I don't know if this check is worth it