aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao/src/main/java
diff options
context:
space:
mode:
authorPierre Guillot <pierre.guillot@sonarsource.com>2020-01-30 11:46:37 +0100
committerSonarTech <sonartech@sonarsource.com>2020-02-20 20:46:16 +0100
commit7915d064a2d0740face4845dc0d8ea3732f236fb (patch)
treedd342e7e94750f6603be3440c8275500e93a0ed7 /server/sonar-db-dao/src/main/java
parent1fba92e6a849ab29a6d0889dfa56bbc60b5f275c (diff)
downloadsonarqube-7915d064a2d0740face4845dc0d8ea3732f236fb.tar.gz
sonarqube-7915d064a2d0740face4845dc0d8ea3732f236fb.zip
SONAR-13001 create endpoint alm_integrations/set_pat
Diffstat (limited to 'server/sonar-db-dao/src/main/java')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java8
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/AlmPatDao.java75
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/AlmPatDto.java82
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/AlmPatMapper.java42
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/package-info.java24
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/AlmSettingDto.java2
8 files changed, 236 insertions, 1 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java
index 9cf5de73ba4..05637e31fc6 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java
@@ -26,6 +26,7 @@ import org.sonar.core.platform.Module;
import org.sonar.db.alm.AlmAppInstallDao;
import org.sonar.db.alm.OrganizationAlmBindingDao;
import org.sonar.db.alm.ProjectAlmBindingDao;
+import org.sonar.db.alm.pat.AlmPatDao;
import org.sonar.db.alm.setting.AlmSettingDao;
import org.sonar.db.alm.setting.ProjectAlmSettingDao;
import org.sonar.db.ce.CeActivityDao;
@@ -119,6 +120,7 @@ public class DaoModule extends Module {
GroupPermissionDao.class,
AlmAppInstallDao.class,
AlmSettingDao.class,
+ AlmPatDao.class,
ProjectAlmSettingDao.class,
ProjectAlmBindingDao.class,
InternalComponentPropertiesDao.class,
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java
index 9707a025944..1ca65d852ae 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java
@@ -24,6 +24,7 @@ import java.util.Map;
import org.sonar.db.alm.AlmAppInstallDao;
import org.sonar.db.alm.OrganizationAlmBindingDao;
import org.sonar.db.alm.ProjectAlmBindingDao;
+import org.sonar.db.alm.pat.AlmPatDao;
import org.sonar.db.alm.setting.AlmSettingDao;
import org.sonar.db.alm.setting.ProjectAlmSettingDao;
import org.sonar.db.ce.CeActivityDao;
@@ -103,6 +104,7 @@ public class DbClient {
private final PropertiesDao propertiesDao;
private final AlmAppInstallDao almAppInstallDao;
private final AlmSettingDao almSettingDao;
+ private final AlmPatDao almPatDao;
private final ProjectAlmSettingDao projectAlmSettingDao;
private final ProjectAlmBindingDao projectAlmBindingDao;
private final InternalComponentPropertiesDao internalComponentPropertiesDao;
@@ -172,6 +174,7 @@ public class DbClient {
}
almAppInstallDao = getDao(map, AlmAppInstallDao.class);
almSettingDao = getDao(map, AlmSettingDao.class);
+ almPatDao = getDao(map, AlmPatDao.class);
projectAlmSettingDao = getDao(map, ProjectAlmSettingDao.class);
projectAlmBindingDao = getDao(map, ProjectAlmBindingDao.class);
schemaMigrationDao = getDao(map, SchemaMigrationDao.class);
@@ -254,6 +257,10 @@ public class DbClient {
return almSettingDao;
}
+ public AlmPatDao almPatDao() {
+ return almPatDao;
+ }
+
public ProjectAlmSettingDao projectAlmSettingDao() {
return projectAlmSettingDao;
}
@@ -519,4 +526,5 @@ public class DbClient {
public NewCodePeriodDao newCodePeriodDao() {
return newCodePeriodDao;
}
+
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
index 0fc20ca8a47..a4ed208f414 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
@@ -38,6 +38,7 @@ import org.sonar.db.alm.AlmAppInstallMapper;
import org.sonar.db.alm.OrganizationAlmBindingMapper;
import org.sonar.db.alm.ProjectAlmBindingDto;
import org.sonar.db.alm.ProjectAlmBindingMapper;
+import org.sonar.db.alm.pat.AlmPatMapper;
import org.sonar.db.alm.setting.AlmSettingMapper;
import org.sonar.db.alm.setting.ProjectAlmSettingMapper;
import org.sonar.db.ce.CeActivityMapper;
@@ -229,6 +230,7 @@ public class MyBatis implements Startable {
Class<?>[] mappers = {
ActiveRuleMapper.class,
AlmAppInstallMapper.class,
+ AlmPatMapper.class,
AlmSettingMapper.class,
AnalysisPropertiesMapper.class,
AuthorizationMapper.class,
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/AlmPatDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/AlmPatDao.java
new file mode 100644
index 00000000000..44447b942a0
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/AlmPatDao.java
@@ -0,0 +1,75 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.alm.pat;
+
+import java.util.List;
+import java.util.Optional;
+import org.sonar.api.utils.System2;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+import org.sonar.db.alm.setting.AlmSettingDto;
+
+public class AlmPatDao implements Dao {
+
+ private final System2 system2;
+ private final UuidFactory uuidFactory;
+
+ public AlmPatDao(System2 system2, UuidFactory uuidFactory) {
+ this.system2 = system2;
+ this.uuidFactory = uuidFactory;
+ }
+
+ private static AlmPatMapper getMapper(DbSession dbSession) {
+ return dbSession.getMapper(AlmPatMapper.class);
+ }
+
+ public Optional<AlmPatDto> selectByUuid(DbSession dbSession, String uuid) {
+ return Optional.ofNullable(getMapper(dbSession).selectByUuid(uuid));
+ }
+
+ public Optional<AlmPatDto> selectByAlmSetting(DbSession dbSession, String userUuid, AlmSettingDto almSettingDto) {
+ return Optional.ofNullable(getMapper(dbSession).selectByAlmSetting(userUuid, almSettingDto.getUuid()));
+ }
+
+ public List<AlmPatDto> selectAll(DbSession dbSession) {
+ return getMapper(dbSession).selectAll();
+ }
+
+ public void insert(DbSession dbSession, AlmPatDto almPatDto) {
+ String uuid = uuidFactory.create();
+ long now = system2.now();
+ getMapper(dbSession).insert(almPatDto, uuid, now);
+ almPatDto.setUuid(uuid);
+ almPatDto.setCreatedAt(now);
+ almPatDto.setUpdatedAt(now);
+ }
+
+ public void update(DbSession dbSession, AlmPatDto almPatDto) {
+ long now = system2.now();
+ getMapper(dbSession).update(almPatDto, now);
+ almPatDto.setUpdatedAt(now);
+ }
+
+ public void delete(DbSession dbSession, AlmPatDto almPatDto) {
+ getMapper(dbSession).deleteByUuid(almPatDto.getUuid());
+ }
+
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/AlmPatDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/AlmPatDto.java
new file mode 100644
index 00000000000..4bd42cc7bd2
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/AlmPatDto.java
@@ -0,0 +1,82 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.alm.pat;
+
+public class AlmPatDto {
+
+ private String uuid;
+ private String personalAccessToken;
+ private String userUuid;
+ private String almSettingUuid;
+
+ private long updatedAt;
+ private long createdAt;
+
+ public String getAlmSettingUuid() {
+ return almSettingUuid;
+ }
+
+ public AlmPatDto setAlmSettingUuid(String almSettingUuid) {
+ this.almSettingUuid = almSettingUuid;
+ return this;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+ public String getUserUuid() {
+ return userUuid;
+ }
+
+ public AlmPatDto setUserUuid(String userUuid) {
+ this.userUuid = userUuid;
+ return this;
+ }
+
+ public String getPersonalAccessToken() {
+ return personalAccessToken;
+ }
+
+ public AlmPatDto setPersonalAccessToken(String personalAccessToken) {
+ this.personalAccessToken = personalAccessToken;
+ return this;
+ }
+
+ public long getUpdatedAt() {
+ return updatedAt;
+ }
+
+ public void setUpdatedAt(long updatedAt) {
+ this.updatedAt = updatedAt;
+ }
+
+ public long getCreatedAt() {
+ return createdAt;
+ }
+
+ public void setCreatedAt(long createdAt) {
+ this.createdAt = createdAt;
+ }
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/AlmPatMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/AlmPatMapper.java
new file mode 100644
index 00000000000..eaf84b038e1
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/AlmPatMapper.java
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.alm.pat;
+
+import java.util.List;
+import javax.annotation.CheckForNull;
+import org.apache.ibatis.annotations.Param;
+
+public interface AlmPatMapper {
+
+ @CheckForNull
+ AlmPatDto selectByUuid(@Param("uuid") String uuid);
+
+ @CheckForNull
+ AlmPatDto selectByAlmSetting(@Param("userUuid") String userUuid, @Param("almSettingUuid") String almSettingUuid);
+
+ List<AlmPatDto> selectAll();
+
+ void insert(@Param("dto") AlmPatDto almPatDto, @Param("uuid") String uuid, @Param("now") long now);
+
+ void update(@Param("dto") AlmPatDto almPatDto, @Param("now") long now);
+
+ void deleteByUuid(@Param("uuid") String uuid);
+
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/package-info.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/package-info.java
new file mode 100644
index 00000000000..7202a3d6891
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.db.alm.pat;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/AlmSettingDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/AlmSettingDto.java
index 3ff78c6dc3a..a4f0badbb02 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/AlmSettingDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/AlmSettingDto.java
@@ -63,7 +63,7 @@ public class AlmSettingDto {
private String privateKey;
/**
- * Personal access token of the Azure DevOps instance. Max size is 2000.
+ * Personal access token of the Azure DevOps / Bitbucket instance. Max size is 2000.
* This column will only be fed when alm is Azure DevOps or Bitbucket.
* It will be null when the ALM is GitHub.
*/