diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2017-07-28 10:27:21 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2017-08-07 11:44:06 +0200 |
commit | d43366ba83a9112bfe1b320640b9afc7d171d6c4 (patch) | |
tree | 0cf109a48d6d367314ba44389f7f773b6fb821a0 /server/sonar-db-dao | |
parent | f48a201c2a691281e689b2a4aee9df976a5f3986 (diff) | |
download | sonarqube-d43366ba83a9112bfe1b320640b9afc7d171d6c4.tar.gz sonarqube-d43366ba83a9112bfe1b320640b9afc7d171d6c4.zip |
SONAR-9639 Support CE task characteristics
Diffstat (limited to 'server/sonar-db-dao')
10 files changed, 282 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 a6f33ee50a6..bc5efc71ccb 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 @@ -25,6 +25,7 @@ import org.sonar.core.platform.Module; import org.sonar.db.ce.CeActivityDao; import org.sonar.db.ce.CeQueueDao; import org.sonar.db.ce.CeScannerContextDao; +import org.sonar.db.ce.CeTaskCharacteristicDao; import org.sonar.db.ce.CeTaskInputDao; import org.sonar.db.component.ComponentDao; import org.sonar.db.component.ComponentKeyUpdaterDao; @@ -79,6 +80,7 @@ public class DaoModule extends Module { CeActivityDao.class, CeQueueDao.class, CeScannerContextDao.class, + CeTaskCharacteristicDao.class, CeTaskInputDao.class, ComponentDao.class, ComponentKeyUpdaterDao.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 2948b8469f8..5d31776cf6e 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.ce.CeActivityDao; import org.sonar.db.ce.CeQueueDao; import org.sonar.db.ce.CeScannerContextDao; +import org.sonar.db.ce.CeTaskCharacteristicDao; import org.sonar.db.ce.CeTaskInputDao; import org.sonar.db.component.ComponentDao; import org.sonar.db.component.ComponentKeyUpdaterDao; @@ -98,6 +99,7 @@ public class DbClient { private final CeActivityDao ceActivityDao; private final CeQueueDao ceQueueDao; private final CeTaskInputDao ceTaskInputDao; + private final CeTaskCharacteristicDao ceTaskCharacteristicsDao; private final CeScannerContextDao ceScannerContextDao; private final FileSourceDao fileSourceDao; private final ComponentLinkDao componentLinkDao; @@ -154,6 +156,7 @@ public class DbClient { ceActivityDao = getDao(map, CeActivityDao.class); ceQueueDao = getDao(map, CeQueueDao.class); ceTaskInputDao = getDao(map, CeTaskInputDao.class); + ceTaskCharacteristicsDao = getDao(map, CeTaskCharacteristicDao.class); ceScannerContextDao = getDao(map, CeScannerContextDao.class); fileSourceDao = getDao(map, FileSourceDao.class); componentLinkDao = getDao(map, ComponentLinkDao.class); @@ -285,6 +288,10 @@ public class DbClient { return ceTaskInputDao; } + public CeTaskCharacteristicDao ceTaskCharacteristicsDao() { + return ceTaskCharacteristicsDao; + } + public CeScannerContextDao ceScannerContextDao() { return ceScannerContextDao; } 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 3e879c9e948..73f39eea73b 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 @@ -32,6 +32,8 @@ import org.sonar.api.Startable; import org.sonar.db.ce.CeActivityMapper; import org.sonar.db.ce.CeQueueMapper; import org.sonar.db.ce.CeScannerContextMapper; +import org.sonar.db.ce.CeTaskCharacteristicDto; +import org.sonar.db.ce.CeTaskCharacteristicMapper; import org.sonar.db.ce.CeTaskInputMapper; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentDtoWithSnapshotId; @@ -137,6 +139,7 @@ public class MyBatis implements Startable { // DTO aliases, keep them sorted alphabetically confBuilder.loadAlias("ActiveRule", ActiveRuleDto.class); confBuilder.loadAlias("ActiveRuleParam", ActiveRuleParamDto.class); + confBuilder.loadAlias("CeTaskCharacteristic", CeTaskCharacteristicDto.class); confBuilder.loadAlias("Component", ComponentDto.class); confBuilder.loadAlias("ComponentLink", ComponentLinkDto.class); confBuilder.loadAlias("ComponentWithSnapshot", ComponentDtoWithSnapshotId.class); @@ -188,6 +191,7 @@ public class MyBatis implements Startable { CeQueueMapper.class, CeScannerContextMapper.class, CeTaskInputMapper.class, + CeTaskCharacteristicMapper.class, ComponentKeyUpdaterMapper.class, ComponentLinkMapper.class, ComponentMapper.class, diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskCharacteristicDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskCharacteristicDao.java new file mode 100644 index 00000000000..ceebc8134d0 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskCharacteristicDao.java @@ -0,0 +1,47 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.ce; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.sonar.db.Dao; +import org.sonar.db.DbSession; + +public class CeTaskCharacteristicDao implements Dao { + public void insert(DbSession dbSession, Collection<CeTaskCharacteristicDto> characteristics) { + for (CeTaskCharacteristicDto dto : characteristics) { + mapper(dbSession).insert(dto); + } + } + + public Map<String, String> getTaskCharacteristics(DbSession dbSession, String taskUuid) { + Map<String, String> map = new LinkedHashMap<>(); + List<CeTaskCharacteristicDto> characteristics = mapper(dbSession).selectTaskCharacteristics(taskUuid); + characteristics.stream().forEach(dto -> map.put(dto.getKey(), dto.getValue())); + return map; + } + + private static CeTaskCharacteristicMapper mapper(DbSession session) { + return session.getMapper(CeTaskCharacteristicMapper.class); + } +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskCharacteristicDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskCharacteristicDto.java new file mode 100644 index 00000000000..993049aa93d --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskCharacteristicDto.java @@ -0,0 +1,59 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.ce; + +public class CeTaskCharacteristicDto { + private String uuid; + private String taskUuid; + private String key; + private String value; + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getTaskUuid() { + return taskUuid; + } + + public void setTaskUuid(String taskUuid) { + this.taskUuid = taskUuid; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskCharacteristicMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskCharacteristicMapper.java new file mode 100644 index 00000000000..492b88505e8 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskCharacteristicMapper.java @@ -0,0 +1,31 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.ce; + +import java.util.List; + +import org.apache.ibatis.annotations.Param; + +public interface CeTaskCharacteristicMapper { + List<CeTaskCharacteristicDto> selectTaskCharacteristics(@Param("taskUuid") String taskUuid); + + void insert(CeTaskCharacteristicDto taskCharacteristic); + +} diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeTaskCharacteristicMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeTaskCharacteristicMapper.xml new file mode 100644 index 00000000000..002219c4b71 --- /dev/null +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeTaskCharacteristicMapper.xml @@ -0,0 +1,31 @@ +<?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.ce.CeTaskCharacteristicMapper"> + <insert id="insert" parameterType="CeTaskCharacteristic" useGeneratedKeys="false"> + insert into ce_task_characteristics ( + uuid, + task_uuid, + kee, + text_value + ) + values ( + #{uuid,jdbcType=VARCHAR}, + #{taskUuid,jdbcType=VARCHAR}, + #{key,jdbcType=VARCHAR}, + #{value,jdbcType=VARCHAR} + ) + </insert> + + <select id="selectTaskCharacteristics" parameterType="map" resultType="CeTaskCharacteristic"> + SELECT + c.uuid as "uuid", + c.task_uuid as "taskUuid", + c.kee as "key", + c.text_value as "value" + FROM + ce_task_characteristics c + WHERE + c.task_uuid = #{taskUuid,jdbcType=VARCHAR} + </select> +</mapper> diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/DaoModuleTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/DaoModuleTest.java index 4e2c7cb812e..2ffc454abd9 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/DaoModuleTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/DaoModuleTest.java @@ -29,6 +29,6 @@ public class DaoModuleTest { public void verify_count_of_added_components() { ComponentContainer container = new ComponentContainer(); new DaoModule().configure(container); - assertThat(container.size()).isEqualTo(2 + 46); + assertThat(container.size()).isEqualTo(2 + 47); } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskCharacteristicDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskCharacteristicDaoTest.java new file mode 100644 index 00000000000..e4d3d3b9f9a --- /dev/null +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskCharacteristicDaoTest.java @@ -0,0 +1,59 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.ce; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; + +import java.util.Collections; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.utils.System2; +import org.sonar.db.DbTester; + +public class CeTaskCharacteristicDaoTest { + @Rule + public DbTester dbTester = DbTester.create(System2.INSTANCE); + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private CeTaskCharacteristicDao underTest = new CeTaskCharacteristicDao(); + + @Test + public void test_insert() { + CeTaskCharacteristicDto dto = new CeTaskCharacteristicDto(); + dto.setKey("key"); + dto.setValue("value"); + dto.setUuid("uuid"); + dto.setTaskUuid("task"); + underTest.insert(dbTester.getSession(), Collections.singletonList(dto)); + dbTester.getSession().commit(); + + assertThat(underTest.getTaskCharacteristics(dbTester.getSession(), "task")).containsOnly(entry("key", "value")); + } + + @Test + public void test_no_result() { + assertThat(underTest.getTaskCharacteristics(dbTester.getSession(), "task")).isEmpty(); + + } +} diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskCharacteristicDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskCharacteristicDtoTest.java new file mode 100644 index 00000000000..f25b71ebc98 --- /dev/null +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskCharacteristicDtoTest.java @@ -0,0 +1,41 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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.ce; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; + +public class CeTaskCharacteristicDtoTest { + + @Test + public void test_set_get() { + CeTaskCharacteristicDto dto = new CeTaskCharacteristicDto(); + dto.setKey("key"); + dto.setValue("value"); + dto.setTaskUuid("task"); + dto.setUuid("uuid"); + assertThat(dto.getKey()).isEqualTo("key"); + assertThat(dto.getValue()).isEqualTo("value"); + assertThat(dto.getTaskUuid()).isEqualTo("task"); + assertThat(dto.getUuid()).isEqualTo("uuid"); + + } +} |