forked from SonarSource/sonarqube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-11038 Add table: alm_project_mappings (SonarSource#559)
- Loading branch information
Janos Gyerik
authored and
SonarTech
committed
Aug 10, 2018
1 parent
b08814f
commit c243453
Showing
23 changed files
with
772 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
server/sonar-db-dao/src/main/java/org/sonar/db/alm/ALM.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2018 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; | ||
|
||
import java.util.Locale; | ||
|
||
public enum ALM { | ||
BITBUCKETCLOUD, | ||
GITHUB; | ||
|
||
String getId() { | ||
return this.name().toLowerCase(Locale.ENGLISH); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmProjectMappingsDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2018 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; | ||
|
||
import java.util.Objects; | ||
import javax.annotation.Nullable; | ||
import org.sonar.api.utils.System2; | ||
import org.sonar.core.util.UuidFactory; | ||
import org.sonar.db.Dao; | ||
import org.sonar.db.DbSession; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static org.apache.commons.lang.StringUtils.isNotEmpty; | ||
|
||
public class AlmProjectMappingsDao implements Dao { | ||
|
||
private final System2 system2; | ||
private final UuidFactory uuidFactory; | ||
|
||
public AlmProjectMappingsDao(System2 system2, UuidFactory uuidFactory) { | ||
this.system2 = system2; | ||
this.uuidFactory = uuidFactory; | ||
} | ||
|
||
public void insertOrUpdate(DbSession dbSession, ALM alm, String repoId, String projectUuid, @Nullable String githubSlug, String url) { | ||
checkAlm(alm); | ||
checkRepoId(repoId); | ||
checkArgument(isNotEmpty(projectUuid), "projectUuid can't be null nor empty"); | ||
checkArgument(isNotEmpty(url), "url can't be null nor empty"); | ||
|
||
AlmProjectMappingsMapper mapper = getMapper(dbSession); | ||
long now = system2.now(); | ||
|
||
if (mapper.update(alm.getId(), repoId, projectUuid, githubSlug, url, now) == 0) { | ||
mapper.insert(uuidFactory.create(), alm.getId(), repoId, projectUuid, githubSlug, url, now); | ||
} | ||
} | ||
|
||
public boolean mappingExists(DbSession dbSession, ALM alm, String repoId) { | ||
checkAlm(alm); | ||
checkRepoId(repoId); | ||
|
||
return getMapper(dbSession).mappingCount(alm.getId(), repoId) == 1; | ||
} | ||
|
||
private static void checkAlm(@Nullable ALM alm) { | ||
Objects.requireNonNull(alm, "alm can't be null"); | ||
} | ||
|
||
private static void checkRepoId(@Nullable String repoId) { | ||
checkArgument(isNotEmpty(repoId), "repoId can't be null nor empty"); | ||
} | ||
|
||
private static AlmProjectMappingsMapper getMapper(DbSession dbSession) { | ||
return dbSession.getMapper(AlmProjectMappingsMapper.class); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmProjectMappingsMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2018 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; | ||
|
||
import javax.annotation.Nullable; | ||
import org.apache.ibatis.annotations.Param; | ||
|
||
public interface AlmProjectMappingsMapper { | ||
|
||
int mappingCount(@Param("almId") String almId, @Param("repoId") String repoId); | ||
|
||
void insert(@Param("uuid") String uuid, @Param("almId") String almId, @Param("repoId") String repoId, @Param("projectUuid") String projectUuid, | ||
@Nullable @Param("githubSlug") String githubSlug, @Param("url") String url, @Param("now") long now); | ||
|
||
int update(@Param("almId") String almId, @Param("repoId") String repoId, @Param("projectUuid") String projectUuid, | ||
@Nullable @Param("githubSlug") String githubSlug, @Param("url") String url, @Param("now") long now); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
server/sonar-db-dao/src/main/resources/org/sonar/db/alm/AlmProjectMappingsMapper.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd"> | ||
|
||
<mapper namespace="org.sonar.db.alm.AlmProjectMappingsMapper"> | ||
|
||
<select id="mappingCount" parameterType="Map" resultType="int"> | ||
select | ||
count(*) as count | ||
from | ||
alm_project_mappings | ||
where | ||
alm_id = #{almId, jdbcType=VARCHAR} | ||
and repo_id = #{repoId, jdbcType=VARCHAR} | ||
</select> | ||
|
||
<insert id="insert" parameterType="Map" useGeneratedKeys="false"> | ||
INSERT INTO alm_project_mappings | ||
( | ||
uuid, | ||
alm_id, | ||
repo_id, | ||
project_uuid, | ||
github_slug, | ||
url, | ||
created_at, | ||
updated_at | ||
) | ||
VALUES ( | ||
#{uuid, jdbcType=VARCHAR}, | ||
#{almId, jdbcType=VARCHAR}, | ||
#{repoId, jdbcType=VARCHAR}, | ||
#{projectUuid, jdbcType=VARCHAR}, | ||
#{githubSlug, jdbcType=VARCHAR}, | ||
#{url, jdbcType=VARCHAR}, | ||
#{now, jdbcType=BIGINT}, | ||
#{now, jdbcType=BIGINT} | ||
) | ||
</insert> | ||
|
||
<update id="update" parameterType="map"> | ||
update alm_project_mappings set | ||
project_uuid = #{projectUuid, jdbcType=VARCHAR}, | ||
github_slug = #{githubSlug, jdbcType=VARCHAR}, | ||
url = #{url, jdbcType=VARCHAR}, | ||
updated_at = #{now, jdbcType=BIGINT} | ||
where | ||
alm_id = #{almId, jdbcType=VARCHAR} | ||
and repo_id = #{repoId, jdbcType=VARCHAR} | ||
</update> | ||
|
||
</mapper> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.