]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 drop tables RULE_TAGS and RULES_RULE_TAGS
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 15 May 2014 12:52:25 +0000 (14:52 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 15 May 2014 12:52:35 +0000 (14:52 +0200)
78 files changed:
sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java
sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java
sonar-core/src/main/java/org/sonar/core/rule/RuleRuleTagDto.java [deleted file]
sonar-core/src/main/java/org/sonar/core/rule/RuleTagDao.java [deleted file]
sonar-core/src/main/java/org/sonar/core/rule/RuleTagDto.java [deleted file]
sonar-core/src/main/java/org/sonar/core/rule/RuleTagMapper.java [deleted file]
sonar-core/src/main/java/org/sonar/core/rule/RuleTagType.java [deleted file]
sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml
sonar-core/src/main/resources/org/sonar/core/rule/RuleTagMapper.xml [deleted file]
sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java
sonar-core/src/test/java/org/sonar/core/rule/RuleTagDaoTest.java [deleted file]
sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_tags_by_rule_id.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_tags_by_rule_ids.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/delete-result.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/insert-result.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/select-unused.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/shared.xml [deleted file]
sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
sonar-server/src/main/java/org/sonar/server/rule/ESRuleTags.java [deleted file]
sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java [deleted file]
sonar-server/src/main/java/org/sonar/server/rule/RubyRuleService.java
sonar-server/src/main/java/org/sonar/server/rule/RuleOperations.java
sonar-server/src/main/java/org/sonar/server/rule/RuleRegistry.java
sonar-server/src/main/java/org/sonar/server/rule/RuleTagDocument.java [deleted file]
sonar-server/src/main/java/org/sonar/server/rule/RuleTagLookup.java [deleted file]
sonar-server/src/main/java/org/sonar/server/rule/RuleTagOperations.java [deleted file]
sonar-server/src/main/java/org/sonar/server/rule/RuleTags.java [deleted file]
sonar-server/src/main/java/org/sonar/server/rule/Rules.java
sonar-server/src/main/java/org/sonar/server/rule/ws/AbstractUpdateTagsWsHandler.java [deleted file]
sonar-server/src/main/java/org/sonar/server/rule/ws/AddTagsWsHandler.java [deleted file]
sonar-server/src/main/java/org/sonar/server/rule/ws/RemoveTagsWsHandler.java [deleted file]
sonar-server/src/main/java/org/sonar/server/rule/ws/RuleTagsWs.java [deleted file]
sonar-server/src/main/java/org/sonar/server/rule/ws/RulesWs.java
sonar-server/src/main/java/org/sonar/server/rule2/RegisterRules.java
sonar-server/src/main/java/org/sonar/server/rule2/index/RuleIndexDefinition.java
sonar-server/src/main/java/org/sonar/server/search/Result.java
sonar-server/src/main/webapp/WEB-INF/app/models/internal.rb
sonar-server/src/main/webapp/WEB-INF/db/migrate/537_drop_rule_tags_tables.rb [new file with mode: 0644]
sonar-server/src/test/java/org/sonar/server/rule/ESRuleTagsTest.java [deleted file]
sonar-server/src/test/java/org/sonar/server/rule/RubyRuleServiceTest.java
sonar-server/src/test/java/org/sonar/server/rule/RuleOperationsTest.java
sonar-server/src/test/java/org/sonar/server/rule/RuleRegistryTest.java
sonar-server/src/test/java/org/sonar/server/rule/RuleTagLookupTest.java [deleted file]
sonar-server/src/test/java/org/sonar/server/rule/RuleTagOperationsTest.java [deleted file]
sonar-server/src/test/java/org/sonar/server/rule/RuleTagsTest.java [deleted file]
sonar-server/src/test/java/org/sonar/server/rule/RulesTest.java
sonar-server/src/test/java/org/sonar/server/rule/ws/AddTagsWsHandlerTest.java [deleted file]
sonar-server/src/test/java/org/sonar/server/rule/ws/RemoveTagsWsHandlerTest.java [deleted file]
sonar-server/src/test/java/org/sonar/server/rule/ws/RuleSearchWsHandlerTest.java
sonar-server/src/test/java/org/sonar/server/rule/ws/RuleShowWsHandlerTest.java
sonar-server/src/test/java/org/sonar/server/rule/ws/RuleTagsWsTest.java [deleted file]
sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsTest.java
sonar-server/src/test/java/org/sonar/server/rule2/RegisterRulesMediumTest.java [new file with mode: 0644]
sonar-server/src/test/java/org/sonar/server/rule2/RegisterRulesTest.java
sonar-server/src/test/java/org/sonar/server/rule2/persistence/RuleDaoTest.java
sonar-server/src/test/java/org/sonar/server/tester/DataStoreCleanup.java
sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java
sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_repositories-result.xml
sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_rules-result.xml
sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/disable_deprecated_rules.xml
sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/insert_new_rules-result.xml
sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/update_rule_fields-result.xml
sonar-server/src/test/resources/org/sonar/server/rule/RegisterRulesTest/update_rule_fields.xml
sonar-server/src/test/resources/org/sonar/server/rule/ws/RuleTagsWsTest/create_ok.json [deleted file]
sonar-server/src/test/resources/org/sonar/server/rule/ws/RuleTagsWsTest/list.json [deleted file]
sonar-server/src/test/resources/org/sonar/server/rule2/RegisterRulesTest/disable_deprecated_repositories-result.xml
sonar-server/src/test/resources/org/sonar/server/rule2/persistence/RuleDaoTest/select_tags_by_rule_id.xml [deleted file]
sonar-server/src/test/resources/org/sonar/server/rule2/persistence/RuleDaoTest/select_tags_by_rule_ids.xml [deleted file]
sonar-ws-client/src/main/java/org/sonar/wsclient/SonarClient.java
sonar-ws-client/src/main/java/org/sonar/wsclient/rule/RuleTagClient.java [deleted file]
sonar-ws-client/src/main/java/org/sonar/wsclient/rule/internal/DefaultRuleTagClient.java [deleted file]
sonar-ws-client/src/test/java/org/sonar/wsclient/SonarClientTest.java
sonar-ws-client/src/test/java/org/sonar/wsclient/rule/internal/DefaultRuleTagClientTest.java [deleted file]

index bcccf44a798b72f3180e7cb45baefadd752f22b1..5c3e7b9ab73808141a853e5d6b55844b21a320d0 100644 (file)
@@ -38,7 +38,6 @@ import org.sonar.core.resource.ResourceDao;
 import org.sonar.core.resource.ResourceIndexerDao;
 import org.sonar.core.resource.ResourceKeyUpdaterDao;
 import org.sonar.core.rule.RuleDao;
-import org.sonar.core.rule.RuleTagDao;
 import org.sonar.core.source.db.SnapshotDataDao;
 import org.sonar.core.source.db.SnapshotSourceDao;
 import org.sonar.core.technicaldebt.db.CharacteristicDao;
@@ -87,7 +86,6 @@ public final class DaoUtils {
       ResourceKeyUpdaterDao.class,
       RoleDao.class,
       RuleDao.class,
-      RuleTagDao.class,
       SemaphoreDao.class,
       SnapshotDataDao.class,
       SnapshotSourceDao.class,
index 2b125c1ff7a14f7f6b367cb530c13512cedcc5e3..d18002ce85973c9cea3cbef8e32b91545952d8db 100644 (file)
@@ -33,7 +33,7 @@ import java.util.List;
  */
 public class DatabaseVersion implements BatchComponent, ServerComponent {
 
-  public static final int LAST_VERSION = 536;
+  public static final int LAST_VERSION = 537;
 
   public static enum Status {
     UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL
@@ -84,8 +84,6 @@ public class DatabaseVersion implements BatchComponent, ServerComponent {
     "rules",
     "rules_parameters",
     "rules_profiles",
-    "rule_tags",
-    "rules_rule_tags",
     "semaphores",
     "schema_migrations",
     "snapshots",
index e113adbe9ab23d465ded1182371e2383652132e8..8998f8da543be827a4e8a61337397f0d9eed44a2 100644 (file)
@@ -105,9 +105,6 @@ import org.sonar.core.resource.SnapshotDto;
 import org.sonar.core.rule.RuleDto;
 import org.sonar.core.rule.RuleMapper;
 import org.sonar.core.rule.RuleParamDto;
-import org.sonar.core.rule.RuleRuleTagDto;
-import org.sonar.core.rule.RuleTagDto;
-import org.sonar.core.rule.RuleTagMapper;
 import org.sonar.core.source.db.SnapshotDataDto;
 import org.sonar.core.source.db.SnapshotDataMapper;
 import org.sonar.core.source.db.SnapshotSourceMapper;
@@ -178,8 +175,6 @@ public class MyBatis implements BatchComponent, ServerComponent {
     loadAlias(conf, "ResourceSnapshot", ResourceSnapshotDto.class);
     loadAlias(conf, "Rule", RuleDto.class);
     loadAlias(conf, "RuleParam", RuleParamDto.class);
-    loadAlias(conf, "RuleTag", RuleTagDto.class);
-    loadAlias(conf, "RuleRuleTag", RuleRuleTagDto.class);
     loadAlias(conf, "Snapshot", SnapshotDto.class);
     loadAlias(conf, "Semaphore", SemaphoreDto.class);
     loadAlias(conf, "SchemaMigration", SchemaMigrationDto.class);
@@ -220,7 +215,7 @@ public class MyBatis implements BatchComponent, ServerComponent {
       ResourceKeyUpdaterMapper.class, ResourceIndexerMapper.class, ResourceSnapshotMapper.class, RoleMapper.class, RuleMapper.class,
       SchemaMigrationMapper.class, SemaphoreMapper.class, UserMapper.class, WidgetMapper.class, WidgetPropertyMapper.class,
       MeasureMapper.class, SnapshotDataMapper.class, SnapshotSourceMapper.class, ActionPlanMapper.class, ActionPlanStatsMapper.class,
-      NotificationQueueMapper.class, CharacteristicMapper.class, RuleTagMapper.class,
+      NotificationQueueMapper.class, CharacteristicMapper.class,
       GroupMembershipMapper.class, QualityProfileMapper.class, ActiveRuleMapper.class,
       MeasureDataMapper.class, QualityGateMapper.class, QualityGateConditionMapper.class, ComponentMapper.class, ProjectQgateAssociationMapper.class,
       RequirementMapper.class
index 3b5677fc9b90179452f1491a177be71f12e44f05..b46bde45fe3658dfb7c0a05d74ce0e95abad1c46 100644 (file)
@@ -27,7 +27,6 @@ import org.sonar.api.rule.RuleKey;
 import org.sonar.core.persistence.MyBatis;
 
 import javax.annotation.CheckForNull;
-
 import java.util.Collection;
 import java.util.List;
 
@@ -251,60 +250,4 @@ public class RuleDao implements BatchComponent, ServerComponent {
   private RuleMapper getMapper(SqlSession session) {
     return session.getMapper(RuleMapper.class);
   }
-
-  //***************************
-  // Methods for Rule Tags
-  //***************************
-
-
-  public void insert(RuleRuleTagDto newTag, SqlSession session) {
-    getMapper(session).insertTag(newTag);
-  }
-
-  public void deleteParam(RuleParamDto persistedParam, SqlSession sqlSession) {
-    getMapper(sqlSession).deleteParameter(persistedParam.getId());
-  }
-
-  public void deleteTag(RuleRuleTagDto tagToDelete, SqlSession session) {
-    getMapper(session).deleteTag(tagToDelete.getId().intValue());
-  }
-
-  public void update(RuleRuleTagDto existingTag, SqlSession session) {
-    getMapper(session).updateTag(existingTag);
-  }
-
-  public List<RuleRuleTagDto> selectTags(SqlSession session) {
-    return getMapper(session).selectAllTags();
-  }
-
-  public List<RuleRuleTagDto> selectTagsByRuleId(Integer ruleId) {
-    SqlSession session = mybatis.openSession();
-    try {
-      return selectTagsByRuleIds(ruleId, session);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public List<RuleRuleTagDto> selectTagsByRuleIds(Integer ruleId, SqlSession session) {
-    return selectTagsByRuleIds(newArrayList(ruleId), session);
-  }
-
-  public List<RuleRuleTagDto> selectTagsByRuleIds(List<Integer> ruleIds) {
-    SqlSession session = mybatis.openSession();
-    try {
-      return selectTagsByRuleIds(ruleIds, session);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public List<RuleRuleTagDto> selectTagsByRuleIds(List<Integer> ruleIds, SqlSession session) {
-    List<RuleRuleTagDto> dtos = newArrayList();
-    List<List<Integer>> partitionList = Lists.partition(newArrayList(ruleIds), 1000);
-    for (List<Integer> partition : partitionList) {
-      dtos.addAll(getMapper(session).selectTagsByRuleIds(partition));
-    }
-    return dtos;
-  }
 }
index 9ee3d44e23c26f9763d1ff5459626d1576526aca..5aeb9fbfaa7d799b7d2ea6f4236a16d6275ea8e0 100644 (file)
@@ -60,14 +60,4 @@ public interface RuleMapper {
 
   void deleteParameter(Integer paramId);
 
-  List<RuleRuleTagDto> selectAllTags();
-
-  void insertTag(RuleRuleTagDto newTag);
-
-  void deleteTag(Integer tagId);
-
-  void updateTag(RuleRuleTagDto existingTag);
-
-  List<RuleRuleTagDto> selectTagsByRuleIds(@Param("ruleIds") List<Integer> ruleIds);
-
 }
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleRuleTagDto.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleRuleTagDto.java
deleted file mode 100644 (file)
index b2058b3..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.rule;
-
-
-public class RuleRuleTagDto {
-
-  private Long id;
-  private Integer ruleId;
-  private Long tagId;
-  private String tag;
-  private String type;
-
-  public Long getId() {
-    return id;
-  }
-
-  public RuleRuleTagDto setId(Long id) {
-    this.id = id;
-    return this;
-  }
-
-  public Integer getRuleId() {
-    return ruleId;
-  }
-
-  public RuleRuleTagDto setRuleId(Integer ruleId) {
-    this.ruleId = ruleId;
-    return this;
-  }
-
-  public Long getTagId() {
-    return tagId;
-  }
-
-  public RuleRuleTagDto setTagId(Long tagId) {
-    this.tagId = tagId;
-    return this;
-  }
-
-  public String getTag() {
-    return tag;
-  }
-
-  public RuleRuleTagDto setTag(String tag) {
-    this.tag = tag;
-    return this;
-  }
-
-  public RuleTagType getType() {
-    return RuleTagType.valueOf(type);
-  }
-
-  public RuleRuleTagDto setType(RuleTagType type) {
-    this.type = type.name();
-    return this;
-  }
-
-  @Override
-  public String toString() {
-    return String.format("RuleRuleTag[id=%d, ruleId=%d, tagId=%d, tag=%s, type=%s]",
-        id, ruleId, tagId, tag, type);
-  }
-
-  public boolean isSystemTag(){
-    return this.getType().equals(RuleTagType.SYSTEM);
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleTagDao.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleTagDao.java
deleted file mode 100644 (file)
index ab22764..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.rule;
-
-import org.apache.ibatis.session.SqlSession;
-import org.sonar.api.ServerExtension;
-import org.sonar.core.persistence.MyBatis;
-
-import java.util.List;
-
-public class RuleTagDao implements ServerExtension {
-
-  private final MyBatis myBatis;
-
-  public RuleTagDao(MyBatis myBatis) {
-    this.myBatis = myBatis;
-  }
-
-  public List<RuleTagDto> selectAll() {
-    SqlSession session = myBatis.openSession(false);
-    try {
-      return selectAll(session);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public List<RuleTagDto> selectAll(SqlSession session) {
-    return getMapper(session).selectAll();
-  }
-
-  public void insert(RuleTagDto newRuleTag) {
-    SqlSession session = myBatis.openSession(false);
-    try {
-      insert(newRuleTag, session);
-      session.commit();
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public void insert(RuleTagDto newRuleTag, SqlSession session) {
-    getMapper(session).insert(newRuleTag);
-  }
-
-  public void delete(Long tagId) {
-    SqlSession session = myBatis.openSession(false);
-    try {
-      delete(tagId, session);
-      session.commit();
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public void delete(long tagId, SqlSession session) {
-    getMapper(session).delete(tagId);
-  }
-
-  public Long selectId(String tag) {
-    SqlSession session = myBatis.openSession(false);
-    try {
-      return selectId(tag, session);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public Long selectId(String tag, SqlSession session) {
-    return getMapper(session).selectId(tag);
-  }
-
-  public List<RuleTagDto> selectUnused() {
-    SqlSession session = myBatis.openSession(false);
-    try {
-      return selectUnused(session);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  public List<RuleTagDto> selectUnused(SqlSession session) {
-    return getMapper(session).selectUnused();
-  }
-
-  private RuleTagMapper getMapper(SqlSession session) {
-    return session.getMapper(RuleTagMapper.class);
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleTagDto.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleTagDto.java
deleted file mode 100644 (file)
index 39da820..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.rule;
-
-
-public class RuleTagDto {
-
-  private Long id;
-  private String tag;
-
-  public Long getId() {
-    return id;
-  }
-
-  public RuleTagDto setId(Long id) {
-    this.id = id;
-    return this;
-  }
-
-  public String getTag() {
-    return tag;
-  }
-
-  public RuleTagDto setTag(String tag) {
-    this.tag = tag;
-    return this;
-  }
-
-  @Override
-  public String toString() {
-    return String.format("RuleTag[id=%d, tag=%s]", id, tag);
-  }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleTagMapper.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleTagMapper.java
deleted file mode 100644 (file)
index 7eb52ec..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.rule;
-
-import java.util.List;
-
-public interface RuleTagMapper {
-
-  List<RuleTagDto> selectAll();
-
-  void insert(RuleTagDto newTag);
-
-  void delete(Long tagId);
-
-  Long selectId(String tag);
-
-  List<RuleTagDto> selectUnused();
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleTagType.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleTagType.java
deleted file mode 100644 (file)
index 8c94549..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.rule;
-
-public enum RuleTagType {
-
-  SYSTEM, ADMIN;
-}
index e6e974e9d54464c344cc1b01152736dba7936f4b..acf291ae4ce6b9f9c667b519ea62985e61687e3b 100644 (file)
@@ -232,6 +232,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('533');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('534');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('535');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('536');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('537');
 
 INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null);
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index 7871f4f5e6bf8361555fa13eb6025917a7a72bf7..962392da0ed539de8f0580e83317555edba005a7 100644 (file)
@@ -163,17 +163,6 @@ CREATE TABLE "RULES" (
   "UPDATED_AT" TIMESTAMP
 );
 
-CREATE TABLE "RULE_TAGS" (
-  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
-  "TAG" VARCHAR(100) NOT NULL
-);
-
-CREATE TABLE "RULES_RULE_TAGS" (
-  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
-  "RULE_ID" INTEGER NOT NULL,
-  "RULE_TAG_ID" INTEGER NOT NULL,
-  "TAG_TYPE" VARCHAR (20) NOT NULL
-);
 
 CREATE TABLE "WIDGET_PROPERTIES" (
   "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
@@ -692,8 +681,6 @@ CREATE INDEX "GROUP_ROLES_ROLE" ON "GROUP_ROLES" ("ROLE");
 
 CREATE UNIQUE INDEX "RULES_PLUGIN_KEY_AND_NAME" ON "RULES" ("PLUGIN_RULE_KEY", "PLUGIN_NAME");
 
-CREATE UNIQUE INDEX "RULE_TAGS_UNIQUE" ON "RULES_RULE_TAGS" ("RULE_ID", "RULE_TAG_ID");
-
 CREATE INDEX "CHARACTERISTICS_ENABLED" ON "CHARACTERISTICS" ("ENABLED");
 
 CREATE UNIQUE INDEX "QUALITY_GATES_UNIQUE" ON "QUALITY_GATES" ("NAME");
index 66a330b03b64ec43f9cb0546affdfd6d2b1f2ec8..643d7b5c71220e86cdbb8d79d535dfec58bc5d94 100644 (file)
     WHERE id=#{id}
   </update>
 
-  <sql id="tagColumns">
-    rrt.id, rrt.rule_id as "ruleId", rrt.rule_tag_id as "tagId", rrt.tag_type as "type", rt.tag
-  </sql>
-
-  <select id="selectAllTags" resultType="RuleRuleTag">
-    SELECT <include refid="tagColumns"/>
-    FROM rules_rule_tags rrt
-    JOIN rule_tags rt ON rrt.rule_tag_id = rt.id
-  </select>
-
-  <select id="selectTagsByRuleIds" resultType="RuleRuleTag">
-    SELECT <include refid="tagColumns"/>
-    FROM rules_rule_tags rrt
-    JOIN rule_tags rt ON rrt.rule_tag_id = rt.id
-    <where>
-      AND (<foreach item="id" index="index" collection="ruleIds" open="(" separator=" or " close=")">rrt.rule_id=#{id}</foreach>)
-    </where>
-  </select>
-
-  <insert id="insertTag" parameterType="RuleRuleTag" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
-    INSERT INTO rules_rule_tags (rule_id, rule_tag_id, tag_type)
-    VALUES (#{ruleId}, #{tagId}, #{type})
-  </insert>
-
-  <update id="updateTag" parameterType="RuleRuleTag">
-    UPDATE rules_rule_tags
-    SET tag_type=#{type}
-    WHERE id=#{id}
-  </update>
-
-  <update id="deleteTag" parameterType="Integer">
-    DELETE FROM rules_rule_tags WHERE id=#{tagId}
-  </update>
-
-
   <select id="selectKeysOfRulesUpdatedSince" resultType="map">
     SELECT r.plugin_name as "repo", r.plugin_rule_key as "rule"
     FROM rules r
diff --git a/sonar-core/src/main/resources/org/sonar/core/rule/RuleTagMapper.xml b/sonar-core/src/main/resources/org/sonar/core/rule/RuleTagMapper.xml
deleted file mode 100644 (file)
index 5fb61f6..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.core.rule.RuleTagMapper">
-
-  <select id="selectAll" resultType="RuleTag">
-    SELECT id, tag
-    FROM rule_tags
-  </select>
-
-  <insert id="insert" parameterType="RuleTag" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
-    INSERT INTO rule_tags (tag)
-    VALUES (#{tag})
-  </insert>
-
-  <update id="delete" parameterType="Integer">
-    DELETE FROM rule_tags WHERE id=#{tagId}
-  </update>
-
-  <select id="selectId" resultType="Long" parameterType="String">
-    SELECT id
-    FROM rule_tags
-    WHERE tag=#{tag}
-  </select>
-
-  <select id="selectUnused" resultType="RuleTag">
-    SELECT r.id, r.tag FROM rule_tags r LEFT JOIN rules_rule_tags rr ON rr.rule_tag_id = r.id WHERE rr.rule_id IS NULL
-  </select>
-
-</mapper>
-
index 9cd518afedb95756e8a674077925a8d189bc8e3b..8b0c63095db51d329d9abf36585a56a25c6c585f 100644 (file)
@@ -357,20 +357,6 @@ public class RuleDaoTest extends AbstractDaoTestCase {
     checkTables("update_parameter", "rules_parameters");
   }
 
-  @Test
-  public void select_tags_by_rule_id() throws Exception {
-    setupData("select_tags_by_rule_id");
-
-    assertThat(dao.selectTagsByRuleId(3)).hasSize(2);
-  }
-
-  @Test
-  public void select_tags_by_rule_ids() throws Exception {
-    setupData("select_tags_by_rule_ids");
-
-    assertThat(dao.selectTagsByRuleIds(newArrayList(3, 4))).hasSize(3);
-  }
-
   private List<Integer> idsFromRuleDtos(List<RuleDto> ruleDtos){
     return newArrayList(Iterables.transform(ruleDtos, new Function<RuleDto, Integer>() {
       @Override
diff --git a/sonar-core/src/test/java/org/sonar/core/rule/RuleTagDaoTest.java b/sonar-core/src/test/java/org/sonar/core/rule/RuleTagDaoTest.java
deleted file mode 100644 (file)
index d7aab3a..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.rule;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.core.persistence.AbstractDaoTestCase;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class RuleTagDaoTest extends AbstractDaoTestCase {
-
-  RuleTagDao dao;
-
-  @Before
-  public void createDao() {
-    dao = new RuleTagDao(getMyBatis());
-  }
-
-  @Test
-  public void should_select_all_tags() {
-    setupData("shared");
-
-    assertThat(dao.selectAll()).hasSize(3);
-  }
-
-  @Test
-  public void should_select_id() {
-    setupData("shared");
-
-    assertThat(dao.selectId("tag1")).isEqualTo(1L);
-    assertThat(dao.selectId("unknown")).isNull();
-  }
-
-  @Test
-  public void should_insert_tag() {
-    setupData("shared");
-
-    dao.insert(new RuleTagDto().setTag("tag4"));
-    checkTable("insert", "rule_tags");
-  }
-
-  @Test
-  public void should_delete_tag() {
-    setupData("shared");
-
-    dao.delete(1L);
-    checkTable("delete", "rule_tags");
-  }
-
-  @Test
-  public void should_select_unused_tags() {
-    setupData("select-unused");
-
-    assertThat(dao.selectUnused()).hasSize(2);
-  }
-
-}
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_tags_by_rule_id.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_tags_by_rule_id.xml
deleted file mode 100644 (file)
index 8d252e5..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<dataset>
-
-  <rule_tags id="3" tag="tag1"/>
-  <rule_tags id="4" tag="tag3"/>
-  <rule_tags id="5" tag="tag5"/>
-
-  <rules_rule_tags id="3" rule_id="3" rule_tag_id="3" tag_type="SYSTEM"/>
-  <rules_rule_tags id="4" rule_id="3" rule_tag_id="4" tag_type="SYSTEM"/>
-  <rules_rule_tags id="5" rule_id="4" rule_tag_id="5" tag_type="SYSTEM"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_tags_by_rule_ids.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_tags_by_rule_ids.xml
deleted file mode 100644 (file)
index 8d252e5..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<dataset>
-
-  <rule_tags id="3" tag="tag1"/>
-  <rule_tags id="4" tag="tag3"/>
-  <rule_tags id="5" tag="tag5"/>
-
-  <rules_rule_tags id="3" rule_id="3" rule_tag_id="3" tag_type="SYSTEM"/>
-  <rules_rule_tags id="4" rule_id="3" rule_tag_id="4" tag_type="SYSTEM"/>
-  <rules_rule_tags id="5" rule_id="4" rule_tag_id="5" tag_type="SYSTEM"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/delete-result.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/delete-result.xml
deleted file mode 100644 (file)
index 8c9c2d0..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<dataset>
-
-  <rule_tags id="2" tag="tag2"/>
-  <rule_tags id="3" tag="tag3"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/insert-result.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/insert-result.xml
deleted file mode 100644 (file)
index 3b80513..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<dataset>
-
-  <rule_tags id="1" tag="tag1"/>
-  <rule_tags id="2" tag="tag2"/>
-  <rule_tags id="3" tag="tag3"/>
-  <rule_tags id="4" tag="tag4"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/select-unused.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/select-unused.xml
deleted file mode 100644 (file)
index dcae0d0..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<dataset>
-
-  <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="rule1" plugin_name="fake" plugin_config_key="old_config_key" name="old name" description="old description"
-         status="READY" priority="2" cardinality="SINGLE" parent_id="[null]" />
-
-  <rule_tags id="1" tag="tag1"/>
-  <rule_tags id="2" tag="tag2"/>
-  <rule_tags id="3" tag="tag3"/>
-  <rule_tags id="4" tag="tag4"/>
-
-  <rules_rule_tags id="1" rule_id="1" rule_tag_id="1" tag_type="ADMIN"/>
-  <rules_rule_tags id="2" rule_id="1" rule_tag_id="2" tag_type="SYSTEM"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleTagDaoTest/shared.xml
deleted file mode 100644 (file)
index e708579..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<dataset>
-
-  <rule_tags id="1" tag="tag1"/>
-  <rule_tags id="2" tag="tag2"/>
-  <rule_tags id="3" tag="tag3"/>
-
-</dataset>
index 9bfaf3e41c0ede56cdaba2537b9b3f8597dfd6db..335dbabe63aeb634514beff9b9c8d684f9b2a1e6 100644 (file)
@@ -326,8 +326,6 @@ class ServerComponents {
     pico.addSingleton(RulesWs.class);
     pico.addSingleton(RuleShowWsHandler.class);
     pico.addSingleton(RuleSearchWsHandler.class);
-    pico.addSingleton(AddTagsWsHandler.class);
-    pico.addSingleton(RemoveTagsWsHandler.class);
     pico.addSingleton(RulesDefinitionXmlLoader.class);
 
     // experimental rules
@@ -339,13 +337,6 @@ class ServerComponents {
     pico.addSingleton(SetTagsAction.class);
     pico.addSingleton(org.sonar.server.rule2.ws.AppAction.class);
 
-    // rule tags
-    pico.addSingleton(ESRuleTags.class);
-    pico.addSingleton(RuleTagLookup.class);
-    pico.addSingleton(RuleTagOperations.class);
-    pico.addSingleton(RuleTags.class);
-    pico.addSingleton(RuleTagsWs.class);
-
     // measure
     pico.addComponent(MeasuresDao.class, false);
     pico.addSingleton(MeasureFilterFactory.class);
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/ESRuleTags.java b/sonar-server/src/main/java/org/sonar/server/rule/ESRuleTags.java
deleted file mode 100644 (file)
index 2c08117..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.server.rule;
-
-import org.elasticsearch.common.io.BytesStream;
-import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentFactory;
-import org.elasticsearch.index.query.FilterBuilders;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.elasticsearch.search.sort.SortOrder;
-import org.sonar.core.rule.RuleTagDto;
-import org.sonar.server.es.ESIndex;
-
-import java.io.IOException;
-import java.util.Collection;
-
-/**
- * @deprecated to be dropped in 4.4
- */
-@Deprecated
-public class ESRuleTags {
-
-  public static final String TYPE_TAG = "tag";
-
-  private final ESIndex index;
-
-  public ESRuleTags(ESIndex index) {
-    this.index = index;
-  }
-
-  public void start() {
-    index.addMappingFromClasspath(RuleRegistry.INDEX_RULES, TYPE_TAG, "/org/sonar/server/es/config/mappings/tag_mapping.json");
-  }
-
-  public void putAllTags(Collection<RuleTagDto> tags) {
-    String[] ids = new String[tags.size()];
-    try {
-      if (!tags.isEmpty()) {
-        BytesStream[] sources = new BytesStream[tags.size()];
-        int tagCounter = 0;
-        for (RuleTagDto tag: tags) {
-          ids[tagCounter] = tag.getTag();
-          sources[tagCounter] = ruleTagDocument(tag);
-          tagCounter ++;
-        }
-        index.bulkIndex(RuleRegistry.INDEX_RULES, TYPE_TAG, ids, sources);
-      }
-      index.client().prepareDeleteByQuery(RuleRegistry.INDEX_RULES).setTypes(TYPE_TAG)
-      .setQuery(
-          QueryBuilders.filteredQuery(
-              QueryBuilders.matchAllQuery(),
-              FilterBuilders.notFilter(
-                  FilterBuilders.termsFilter(RuleTagDocument.FIELD_VALUE, ids))))
-                  .execute().actionGet();
-    } catch(IOException ioException) {
-      throw new IllegalStateException("Unable to index tags", ioException);
-    }
-  }
-
-  public void put(RuleTagDto tag) {
-    try {
-      index.putSynchronous(RuleRegistry.INDEX_RULES, TYPE_TAG, tag.getTag(), ruleTagDocument(tag));
-    } catch (IOException ioException) {
-      throw new IllegalStateException("Unable to index tag "+tag.getTag(), ioException);
-    }
-  }
-
-  public Collection<String> searchAllTags() {
-    final int scrollSize = 50;
-    return index.findDocumentIds(index.client().prepareSearch(RuleRegistry.INDEX_RULES)
-      .setTypes(TYPE_TAG)
-      .addSort(RuleTagDocument.FIELD_VALUE, SortOrder.ASC), scrollSize);
-  }
-
-  private XContentBuilder ruleTagDocument(RuleTagDto tag) throws IOException {
-    return XContentFactory.jsonBuilder()
-      .startObject()
-      .field(RuleTagDocument.FIELD_VALUE, tag.getTag())
-      .endObject();
-  }
-
-  public void delete(String... deleted) {
-    index.bulkDelete(RuleRegistry.INDEX_RULES, TYPE_TAG, deleted);
-  }
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java b/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
deleted file mode 100644 (file)
index 84c9c48..0000000
+++ /dev/null
@@ -1,597 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.server.rule;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.Sets;
-import org.apache.commons.lang.ObjectUtils;
-import org.apache.commons.lang.StringUtils;
-import org.picocontainer.Startable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.server.debt.DebtRemediationFunction;
-import org.sonar.api.server.rule.RulesDefinition;
-import org.sonar.api.utils.MessageException;
-import org.sonar.api.utils.System2;
-import org.sonar.api.utils.TimeProfiler;
-import org.sonar.check.Cardinality;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
-import org.sonar.core.qualityprofile.db.ActiveRuleDao;
-import org.sonar.core.rule.RuleDao;
-import org.sonar.core.rule.RuleDto;
-import org.sonar.core.rule.RuleParamDto;
-import org.sonar.core.rule.RuleRuleTagDto;
-import org.sonar.core.rule.RuleTagDao;
-import org.sonar.core.rule.RuleTagDto;
-import org.sonar.core.rule.RuleTagType;
-import org.sonar.core.technicaldebt.db.CharacteristicDao;
-import org.sonar.core.technicaldebt.db.CharacteristicDto;
-import org.sonar.server.qualityprofile.ProfilesManager;
-import org.sonar.server.startup.RegisterDebtModel;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import static com.google.common.collect.Lists.newArrayList;
-
-/**
- * @deprecated to be dropped in 4.4
- */
-@Deprecated
-public class RegisterRules implements Startable {
-
-  private static final Logger LOG = LoggerFactory.getLogger(RegisterRules.class);
-
-  private final RuleDefinitionsLoader defLoader;
-  private final ProfilesManager profilesManager;
-  private final RuleRegistry ruleRegistry;
-  private final ESRuleTags esRuleTags;
-  private final MyBatis myBatis;
-  private final RuleDao ruleDao;
-  private final RuleTagDao ruleTagDao;
-  private final RuleTagOperations ruleTagOperations;
-  private final ActiveRuleDao activeRuleDao;
-  private final CharacteristicDao characteristicDao;
-  private final System2 system;
-
-  /**
-   * @param registerDebtModel used only to be started after init of the technical debt model
-   */
-  public RegisterRules(RuleDefinitionsLoader defLoader, ProfilesManager profilesManager,
-                       RuleRegistry ruleRegistry, ESRuleTags esRuleTags, RuleTagOperations ruleTagOperations,
-                       MyBatis myBatis, RuleDao ruleDao, RuleTagDao ruleTagDao, ActiveRuleDao activeRuleDao, CharacteristicDao characteristicDao,
-                       RegisterDebtModel registerDebtModel) {
-    this(defLoader, profilesManager, ruleRegistry, esRuleTags, ruleTagOperations, myBatis, ruleDao, ruleTagDao, activeRuleDao, characteristicDao, System2.INSTANCE);
-  }
-
-  @VisibleForTesting
-  RegisterRules(RuleDefinitionsLoader defLoader, ProfilesManager profilesManager,
-                RuleRegistry ruleRegistry, ESRuleTags esRuleTags, RuleTagOperations ruleTagOperations,
-                MyBatis myBatis, RuleDao ruleDao, RuleTagDao ruleTagDao, ActiveRuleDao activeRuleDao, CharacteristicDao characteristicDao, System2 system) {
-    this.defLoader = defLoader;
-    this.profilesManager = profilesManager;
-    this.ruleRegistry = ruleRegistry;
-    this.esRuleTags = esRuleTags;
-    this.ruleTagOperations = ruleTagOperations;
-    this.myBatis = myBatis;
-    this.ruleDao = ruleDao;
-    this.ruleTagDao = ruleTagDao;
-    this.activeRuleDao = activeRuleDao;
-    this.characteristicDao = characteristicDao;
-    this.system = system;
-  }
-
-  @Override
-  public void start() {
-    TimeProfiler profiler = new TimeProfiler().start("Register rules");
-    DbSession sqlSession = myBatis.openSession(false);
-    try {
-      RulesDefinition.Context context = defLoader.load();
-      Buffer buffer = new Buffer(system.now());
-      selectRulesFromDb(buffer, sqlSession);
-      enableRuleDefinitions(context, buffer, sqlSession);
-      List<RuleDto> removedRules = processRemainingDbRules(buffer, sqlSession);
-      removeActiveRulesOnStillExistingRepositories(removedRules, context);
-      index(buffer, sqlSession);
-      ruleTagOperations.deleteUnusedTags(sqlSession);
-      sqlSession.commit();
-
-    } finally {
-      sqlSession.close();
-      profiler.stop();
-    }
-  }
-
-  @Override
-  public void stop() {
-    // nothing
-  }
-
-  private void selectRulesFromDb(Buffer buffer, DbSession sqlSession) {
-    for (RuleDto ruleDto : ruleDao.selectNonManual(sqlSession)) {
-      buffer.add(ruleDto);
-      buffer.markUnprocessed(ruleDto);
-    }
-    for (RuleParamDto paramDto : ruleDao.selectParameters(sqlSession)) {
-      buffer.add(paramDto);
-    }
-    for (RuleTagDto tagDto : ruleTagDao.selectAll(sqlSession)) {
-      buffer.add(tagDto);
-    }
-    for (RuleRuleTagDto tagDto : ruleDao.selectTags(sqlSession)) {
-      buffer.add(tagDto);
-    }
-    for (CharacteristicDto characteristicDto : characteristicDao.selectEnabledCharacteristics(sqlSession)) {
-      buffer.add(characteristicDto);
-    }
-  }
-
-  private void enableRuleDefinitions(RulesDefinition.Context context, Buffer buffer, DbSession sqlSession) {
-    for (RulesDefinition.Repository repoDef : context.repositories()) {
-      enableRepository(buffer, sqlSession, repoDef);
-    }
-    for (RulesDefinition.ExtendedRepository extendedRepoDef : context.extendedRepositories()) {
-      if (context.repository(extendedRepoDef.key()) == null) {
-        LOG.warn(String.format("Extension is ignored, repository %s does not exist", extendedRepoDef.key()));
-      } else {
-        enableRepository(buffer, sqlSession, extendedRepoDef);
-      }
-    }
-  }
-
-  private void enableRepository(Buffer buffer, DbSession sqlSession, RulesDefinition.ExtendedRepository repoDef) {
-    int count = 0;
-    for (RulesDefinition.Rule ruleDef : repoDef.rules()) {
-      RuleDto dto = buffer.rule(RuleKey.of(ruleDef.repository().key(), ruleDef.key()));
-      if (dto == null) {
-        dto = enableAndInsert(buffer, sqlSession, ruleDef);
-      } else {
-        enableAndUpdate(buffer, sqlSession, ruleDef, dto);
-      }
-      buffer.markProcessed(dto);
-      count++;
-      if (count % 100 == 0) {
-        sqlSession.commit();
-      }
-    }
-    sqlSession.commit();
-  }
-
-  private RuleDto enableAndInsert(Buffer buffer, DbSession sqlSession, RulesDefinition.Rule ruleDef) {
-    RuleDto ruleDto = new RuleDto()
-      .setCardinality(ruleDef.template() ? Cardinality.MULTIPLE : Cardinality.SINGLE)
-      .setConfigKey(ruleDef.internalKey())
-      .setDescription(ruleDef.htmlDescription())
-      .setLanguage(ruleDef.repository().language())
-      .setName(ruleDef.name())
-      .setRepositoryKey(ruleDef.repository().key())
-      .setRuleKey(ruleDef.key())
-      .setSeverity(ruleDef.severity())
-      .setStatus(ruleDef.status().name());
-
-    CharacteristicDto characteristic = buffer.characteristic(ruleDef.debtSubCharacteristic(), ruleDef.repository().key(), ruleDef.key(), null);
-    DebtRemediationFunction remediationFunction = ruleDef.debtRemediationFunction();
-    if (characteristic != null && remediationFunction != null) {
-      ruleDto.setDefaultSubCharacteristicId(characteristic.getId())
-        .setDefaultRemediationFunction(remediationFunction.type().name())
-        .setDefaultRemediationCoefficient(remediationFunction.coefficient())
-        .setDefaultRemediationOffset(remediationFunction.offset())
-        .setEffortToFixDescription(ruleDef.effortToFixDescription());
-    }
-
-    ruleDao.insert(ruleDto, sqlSession);
-    buffer.add(ruleDto);
-
-    for (RulesDefinition.Param param : ruleDef.params()) {
-      RuleParamDto paramDto = new RuleParamDto()
-        .setRuleId(ruleDto.getId())
-        .setDefaultValue(param.defaultValue())
-        .setDescription(param.description())
-        .setName(param.name())
-        .setType(param.type().toString());
-      ruleDao.insert(paramDto, sqlSession);
-      buffer.add(paramDto);
-    }
-    mergeTags(buffer, sqlSession, ruleDef, ruleDto);
-    return ruleDto;
-  }
-
-  private void enableAndUpdate(Buffer buffer, DbSession sqlSession, RulesDefinition.Rule ruleDef, RuleDto dto) {
-    if (mergeRule(buffer, ruleDef, dto)) {
-      ruleDao.update(dto, sqlSession);
-    }
-    mergeParams(buffer, sqlSession, ruleDef, dto);
-    mergeTags(buffer, sqlSession, ruleDef, dto);
-    buffer.markProcessed(dto);
-  }
-
-  private boolean mergeRule(Buffer buffer, RulesDefinition.Rule def, RuleDto dto) {
-    boolean changed = false;
-    if (!StringUtils.equals(dto.getName(), def.name())) {
-      dto.setName(def.name());
-      changed = true;
-    }
-    if (!StringUtils.equals(dto.getDescription(), def.htmlDescription())) {
-      dto.setDescription(def.htmlDescription());
-      changed = true;
-    }
-    if (!StringUtils.equals(dto.getConfigKey(), def.internalKey())) {
-      dto.setConfigKey(def.internalKey());
-      changed = true;
-    }
-    String severity = def.severity();
-    if (!ObjectUtils.equals(dto.getSeverityString(), severity)) {
-      dto.setSeverity(severity);
-      changed = true;
-    }
-    Cardinality cardinality = def.template() ? Cardinality.MULTIPLE : Cardinality.SINGLE;
-    if (!cardinality.equals(dto.getCardinality())) {
-      dto.setCardinality(cardinality);
-      changed = true;
-    }
-    String status = def.status().name();
-    if (!StringUtils.equals(dto.getStatus(), status)) {
-      dto.setStatus(status);
-      changed = true;
-    }
-    if (!StringUtils.equals(dto.getLanguage(), def.repository().language())) {
-      dto.setLanguage(def.repository().language());
-      changed = true;
-    }
-    CharacteristicDto subCharacteristic = buffer.characteristic(def.debtSubCharacteristic(), def.repository().key(), def.key(), dto.getSubCharacteristicId());
-    changed = mergeDebtDefinitions(def, dto, subCharacteristic) || changed;
-    if (changed) {
-      dto.setUpdatedAt(buffer.now());
-    }
-    return changed;
-  }
-
-  private boolean mergeDebtDefinitions(RulesDefinition.Rule def, RuleDto dto, @Nullable CharacteristicDto subCharacteristic) {
-    // Debt definitions are set to null if the sub-characteristic and the remediation function are null
-    DebtRemediationFunction debtRemediationFunction = subCharacteristic != null ? def.debtRemediationFunction() : null;
-    boolean hasDebt = subCharacteristic != null && debtRemediationFunction != null;
-    return mergeDebtDefinitions(def, dto,
-      hasDebt ? subCharacteristic.getId() : null,
-      debtRemediationFunction != null ? debtRemediationFunction.type().name() : null,
-      hasDebt ? debtRemediationFunction.coefficient() : null,
-      hasDebt ? debtRemediationFunction.offset() : null,
-      hasDebt ? def.effortToFixDescription() : null);
-  }
-
-  private boolean mergeDebtDefinitions(RulesDefinition.Rule def, RuleDto dto, @Nullable Integer characteristicId, @Nullable String remediationFunction,
-                                       @Nullable String remediationCoefficient, @Nullable String remediationOffset, @Nullable String effortToFixDescription) {
-    boolean changed = false;
-
-    if (!ObjectUtils.equals(dto.getDefaultSubCharacteristicId(), characteristicId)) {
-      dto.setDefaultSubCharacteristicId(characteristicId);
-      changed = true;
-    }
-    if (!StringUtils.equals(dto.getDefaultRemediationFunction(), remediationFunction)) {
-      dto.setDefaultRemediationFunction(remediationFunction);
-      changed = true;
-    }
-    if (!StringUtils.equals(dto.getDefaultRemediationCoefficient(), remediationCoefficient)) {
-      dto.setDefaultRemediationCoefficient(remediationCoefficient);
-      changed = true;
-    }
-    if (!StringUtils.equals(dto.getDefaultRemediationOffset(), remediationOffset)) {
-      dto.setDefaultRemediationOffset(remediationOffset);
-      changed = true;
-    }
-    if (!StringUtils.equals(dto.getEffortToFixDescription(), effortToFixDescription)) {
-      dto.setEffortToFixDescription(effortToFixDescription);
-      changed = true;
-    }
-    return changed;
-  }
-
-  private void mergeParams(Buffer buffer, DbSession sqlSession, RulesDefinition.Rule ruleDef, RuleDto dto) {
-    Collection<RuleParamDto> paramDtos = buffer.paramsForRuleId(dto.getId());
-    Set<String> persistedParamKeys = Sets.newHashSet();
-    for (RuleParamDto paramDto : paramDtos) {
-      RulesDefinition.Param paramDef = ruleDef.param(paramDto.getName());
-      if (paramDef == null) {
-        activeRuleDao.deleteParametersWithParamId(paramDto.getId(), sqlSession);
-        ruleDao.deleteParam(paramDto, sqlSession);
-      } else {
-        // TODO validate that existing active rules still match constraints
-        // TODO store param name
-        if (mergeParam(paramDto, paramDef)) {
-          ruleDao.update(paramDto, sqlSession);
-        }
-        persistedParamKeys.add(paramDto.getName());
-      }
-    }
-    for (RulesDefinition.Param param : ruleDef.params()) {
-      if (!persistedParamKeys.contains(param.key())) {
-        RuleParamDto paramDto = new RuleParamDto()
-          .setRuleId(dto.getId())
-          .setName(param.key())
-          .setDescription(param.description())
-          .setDefaultValue(param.defaultValue())
-          .setType(param.type().toString());
-        ruleDao.insert(paramDto, sqlSession);
-        buffer.add(paramDto);
-      }
-    }
-  }
-
-  private boolean mergeParam(RuleParamDto paramDto, RulesDefinition.Param paramDef) {
-    boolean changed = false;
-    if (!StringUtils.equals(paramDto.getType(), paramDef.type().toString())) {
-      paramDto.setType(paramDef.type().toString());
-      changed = true;
-    }
-    if (!StringUtils.equals(paramDto.getDefaultValue(), paramDef.defaultValue())) {
-      paramDto.setDefaultValue(paramDef.defaultValue());
-      changed = true;
-    }
-    if (!StringUtils.equals(paramDto.getDescription(), paramDef.description())) {
-      paramDto.setDescription(paramDef.description());
-      changed = true;
-    }
-    return changed;
-  }
-
-  private void mergeTags(Buffer buffer, DbSession sqlSession, RulesDefinition.Rule ruleDef, RuleDto dto) {
-    Set<String> existingSystemTags = Sets.newHashSet();
-
-    Collection<RuleRuleTagDto> tagDtos = ImmutableList.copyOf(buffer.tagsForRuleId(dto.getId()));
-    for (RuleRuleTagDto tagDto : tagDtos) {
-      String tag = tagDto.getTag();
-
-      if (tagDto.getType() == RuleTagType.SYSTEM) {
-        // tag previously declared by plugin
-        if (!ruleDef.tags().contains(tag)) {
-          // not declared anymore
-          ruleDao.deleteTag(tagDto, sqlSession);
-          buffer.remove(tagDto);
-        } else {
-          existingSystemTags.add(tagDto.getTag());
-        }
-      } else {
-        // tags created by end-users
-        if (ruleDef.tags().contains(tag)) {
-          long tagId = getOrCreateReferenceTagId(buffer, tag, sqlSession);
-          tagDto.setId(tagId);
-          tagDto.setType(RuleTagType.SYSTEM);
-          ruleDao.update(tagDto, sqlSession);
-          existingSystemTags.add(tag);
-        }
-      }
-    }
-
-    for (String tag : ruleDef.tags()) {
-      if (!existingSystemTags.contains(tag)) {
-        long tagId = getOrCreateReferenceTagId(buffer, tag, sqlSession);
-        RuleRuleTagDto newTagDto = new RuleRuleTagDto()
-          .setRuleId(dto.getId())
-          .setTagId(tagId)
-          .setTag(tag)
-          .setType(RuleTagType.SYSTEM);
-        ruleDao.insert(newTagDto, sqlSession);
-        buffer.add(newTagDto);
-      }
-    }
-  }
-
-  private long getOrCreateReferenceTagId(Buffer buffer, String tag, DbSession sqlSession) {
-    // End-user tag is converted to system tag
-    long tagId = 0L;
-    if (buffer.referenceTagExists(tag)) {
-      tagId = buffer.referenceTagIdForValue(tag);
-    } else {
-      RuleTagDto newRuleTag = new RuleTagDto().setTag(tag);
-      ruleTagDao.insert(newRuleTag, sqlSession);
-      buffer.add(newRuleTag);
-      tagId = newRuleTag.getId();
-    }
-    return tagId;
-  }
-
-  private List<RuleDto> processRemainingDbRules(Buffer buffer, DbSession sqlSession) {
-    List<RuleDto> removedRules = newArrayList();
-    for (Integer unprocessedRuleId : buffer.unprocessedRuleIds) {
-      RuleDto ruleDto = buffer.rulesById.get(unprocessedRuleId);
-      boolean toBeRemoved = true;
-      // Update custom rules from template
-      if (ruleDto.getParentId() != null) {
-        RuleDto parent = buffer.rulesById.get(ruleDto.getParentId());
-        if (parent != null && !Rule.STATUS_REMOVED.equals(parent.getStatus())) {
-          ruleDto.setLanguage(parent.getLanguage());
-          ruleDto.setStatus(parent.getStatus());
-          ruleDto.setDefaultSubCharacteristicId(parent.getDefaultSubCharacteristicId());
-          ruleDto.setDefaultRemediationFunction(parent.getDefaultRemediationFunction());
-          ruleDto.setDefaultRemediationCoefficient(parent.getDefaultRemediationCoefficient());
-          ruleDto.setDefaultRemediationOffset(parent.getDefaultRemediationOffset());
-          ruleDto.setEffortToFixDescription(parent.getEffortToFixDescription());
-          ruleDto.setUpdatedAt(buffer.now());
-          ruleDao.update(ruleDto, sqlSession);
-          toBeRemoved = false;
-        }
-      }
-      if (toBeRemoved && !Rule.STATUS_REMOVED.equals(ruleDto.getStatus())) {
-        LOG.info(String.format("Disable rule %s:%s", ruleDto.getRepositoryKey(), ruleDto.getRuleKey()));
-        ruleDto.setStatus(Rule.STATUS_REMOVED);
-        ruleDto.setUpdatedAt(buffer.now());
-        for (RuleRuleTagDto removed : buffer.tagsByRuleId.removeAll(ruleDto.getId())) {
-          ruleDao.deleteTag(removed, sqlSession);
-        }
-        ruleDao.update(ruleDto, sqlSession);
-        removedRules.add(ruleDto);
-        if (removedRules.size() % 100 == 0) {
-          sqlSession.commit();
-        }
-      }
-    }
-    sqlSession.commit();
-
-    return removedRules;
-  }
-
-  /**
-   * SONAR-4642
-   * <p/>
-   * Remove active rules on repositories that still exists.
-   * <p/>
-   * For instance, if the javascript repository do not provide anymore some rules, active rules related to this rules will be removed.
-   * But if the javascript repository do not exists anymore, then related active rules will not be removed.
-   * <p/>
-   * The side effect of this approach is that extended repositories will not be managed the same way.
-   * If an extended repository do not exists anymore, then related active rules will be removed.
-   */
-  private void removeActiveRulesOnStillExistingRepositories(List<RuleDto> removedRules, RulesDefinition.Context context) {
-    List<String> repositoryKeys = newArrayList(Iterables.transform(context.repositories(), new Function<RulesDefinition.Repository, String>() {
-        @Override
-        public String apply(RulesDefinition.Repository input) {
-          return input.key();
-        }
-      }
-    ));
-
-    for (RuleDto rule : removedRules) {
-      // SONAR-4642 Remove active rules only when repository still exists
-      if (repositoryKeys.contains(rule.getRepositoryKey())) {
-        profilesManager.removeActivatedRules(rule.getId());
-      }
-    }
-  }
-
-  private void index(Buffer buffer, DbSession sqlSession) {
-    String[] ids = ruleRegistry.reindex(buffer.rulesById.values(), sqlSession);
-    ruleRegistry.removeDeletedRules(ids);
-    esRuleTags.putAllTags(buffer.referenceTagsByTagValue.values());
-  }
-
-  static class Buffer {
-    private Date now;
-    private List<Integer> unprocessedRuleIds = newArrayList();
-    private Map<RuleKey, RuleDto> rulesByKey = Maps.newHashMap();
-    private Map<Integer, RuleDto> rulesById = Maps.newHashMap();
-    private Multimap<Integer, RuleParamDto> paramsByRuleId = ArrayListMultimap.create();
-    private Multimap<Integer, RuleRuleTagDto> tagsByRuleId = ArrayListMultimap.create();
-    private Map<String, RuleTagDto> referenceTagsByTagValue = Maps.newHashMap();
-    private Map<Integer, CharacteristicDto> characteristicsById = Maps.newHashMap();
-
-    Buffer(long now) {
-      this.now = new Date(now);
-    }
-
-    Date now() {
-      return now;
-    }
-
-    void add(RuleDto rule) {
-      rulesById.put(rule.getId(), rule);
-      rulesByKey.put(RuleKey.of(rule.getRepositoryKey(), rule.getRuleKey()), rule);
-    }
-
-    void add(CharacteristicDto characteristicDto) {
-      characteristicsById.put(characteristicDto.getId(), characteristicDto);
-    }
-
-    void add(RuleTagDto tag) {
-      referenceTagsByTagValue.put(tag.getTag(), tag);
-    }
-
-    void add(RuleParamDto param) {
-      paramsByRuleId.put(param.getRuleId(), param);
-    }
-
-    void add(RuleRuleTagDto tag) {
-      tagsByRuleId.put(tag.getRuleId(), tag);
-    }
-
-    void remove(RuleRuleTagDto tag) {
-      tagsByRuleId.remove(tag.getRuleId(), tag);
-    }
-
-    @CheckForNull
-    RuleDto rule(RuleKey key) {
-      return rulesByKey.get(key);
-    }
-
-    Collection<RuleParamDto> paramsForRuleId(Integer ruleId) {
-      return paramsByRuleId.get(ruleId);
-    }
-
-    Collection<RuleRuleTagDto> tagsForRuleId(Integer ruleId) {
-      return tagsByRuleId.get(ruleId);
-    }
-
-    boolean referenceTagExists(String tagValue) {
-      return referenceTagsByTagValue.containsKey(tagValue);
-    }
-
-    Long referenceTagIdForValue(String tagValue) {
-      return referenceTagsByTagValue.get(tagValue).getId();
-    }
-
-    void markUnprocessed(RuleDto ruleDto) {
-      unprocessedRuleIds.add(ruleDto.getId());
-    }
-
-    void markProcessed(RuleDto ruleDto) {
-      unprocessedRuleIds.remove(ruleDto.getId());
-    }
-
-    CharacteristicDto characteristic(@Nullable String subCharacteristic, String repo, String ruleKey, @Nullable Integer overridingCharacteristicId) {
-      // Rule is not linked to a default characteristic or characteristic has been disabled by user
-      if (subCharacteristic == null) {
-        return null;
-      }
-      CharacteristicDto characteristicDto = findCharacteristic(subCharacteristic);
-      if (characteristicDto == null) {
-        // Log a warning only if rule has not been overridden by user
-        if (overridingCharacteristicId == null) {
-          LOG.warn(String.format("Characteristic '%s' has not been found on rule '%s:%s'", subCharacteristic, repo, ruleKey));
-        }
-      } else if (characteristicDto.getParentId() == null) {
-        throw MessageException.of(String.format("Rule '%s:%s' cannot be linked on the root characteristic '%s'", repo, ruleKey, subCharacteristic));
-      }
-      return characteristicDto;
-    }
-
-    @CheckForNull
-    private CharacteristicDto findCharacteristic(final String key) {
-      return Iterables.find(characteristicsById.values(), new Predicate<CharacteristicDto>() {
-        @Override
-        public boolean apply(@Nullable CharacteristicDto input) {
-          return input != null && key.equals(input.getKey());
-        }
-      }, null);
-    }
-  }
-}
index 6d4d445fc9f39cd43d043720946f00f8f9c52993..e33c061605edb33a0a5ec12494e66a5f251bb410 100644 (file)
@@ -109,10 +109,6 @@ public class RubyRuleService implements ServerComponent, Startable {
     rules.deleteCustomRule(ruleId);
   }
 
-  public void updateRuleTags(int ruleId, Object tags) {
-    rules.updateRuleTags(ruleId, tags);
-  }
-
   @Override
   public void start() {
     // used to force pico to instantiate the singleton at startup
index 83a4804e68afe96bb973c0d9c64cd1fef5c3c1b7..62ada1b54274ce982b9ad9261099ada9391b653a 100644 (file)
@@ -24,9 +24,6 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Function;
 import com.google.common.base.Strings;
 import com.google.common.collect.Iterables;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.builder.EqualsBuilder;
 import org.apache.ibatis.session.SqlSession;
 import org.sonar.api.ServerComponent;
@@ -44,9 +41,6 @@ import org.sonar.core.qualityprofile.db.ActiveRuleDto;
 import org.sonar.core.rule.RuleDao;
 import org.sonar.core.rule.RuleDto;
 import org.sonar.core.rule.RuleParamDto;
-import org.sonar.core.rule.RuleRuleTagDto;
-import org.sonar.core.rule.RuleTagDao;
-import org.sonar.core.rule.RuleTagType;
 import org.sonar.core.technicaldebt.db.CharacteristicDao;
 import org.sonar.core.technicaldebt.db.CharacteristicDto;
 import org.sonar.server.exceptions.BadRequestException;
@@ -56,11 +50,9 @@ import org.sonar.server.user.UserSession;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
-
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import static com.google.common.collect.Lists.newArrayList;
 
@@ -73,28 +65,24 @@ public class RuleOperations implements ServerComponent {
   private final MyBatis myBatis;
   private final ActiveRuleDao activeRuleDao;
   private final RuleDao ruleDao;
-  private final RuleTagDao ruleTagDao;
   private final CharacteristicDao characteristicDao;
-  private final RuleTagOperations ruleTagOperations;
   private final ESActiveRule esActiveRule;
   private final RuleRegistry ruleRegistry;
 
   private final System2 system;
 
-  public RuleOperations(MyBatis myBatis, ActiveRuleDao activeRuleDao, RuleDao ruleDao, RuleTagDao ruleTagDao, CharacteristicDao characteristicDao,
-                        RuleTagOperations ruleTagOperations, ESActiveRule esActiveRule, RuleRegistry ruleRegistry) {
-    this(myBatis, activeRuleDao, ruleDao, ruleTagDao, characteristicDao, ruleTagOperations, esActiveRule, ruleRegistry, System2.INSTANCE);
+  public RuleOperations(MyBatis myBatis, ActiveRuleDao activeRuleDao, RuleDao ruleDao, CharacteristicDao characteristicDao,
+                        ESActiveRule esActiveRule, RuleRegistry ruleRegistry) {
+    this(myBatis, activeRuleDao, ruleDao, characteristicDao, esActiveRule, ruleRegistry, System2.INSTANCE);
   }
 
   @VisibleForTesting
-  RuleOperations(MyBatis myBatis, ActiveRuleDao activeRuleDao, RuleDao ruleDao, RuleTagDao ruleTagDao, CharacteristicDao characteristicDao, RuleTagOperations ruleTagOperations,
+  RuleOperations(MyBatis myBatis, ActiveRuleDao activeRuleDao, RuleDao ruleDao, CharacteristicDao characteristicDao,
                  ESActiveRule esActiveRule, RuleRegistry ruleRegistry, System2 system) {
     this.myBatis = myBatis;
     this.activeRuleDao = activeRuleDao;
     this.ruleDao = ruleDao;
-    this.ruleTagDao = ruleTagDao;
     this.characteristicDao = characteristicDao;
-    this.ruleTagOperations = ruleTagOperations;
     this.esActiveRule = esActiveRule;
     this.ruleRegistry = ruleRegistry;
     this.system = system;
@@ -175,16 +163,6 @@ public class RuleOperations implements ServerComponent {
         ruleDao.insert(param, session);
       }
 
-      List<RuleRuleTagDto> templateRuleTags = ruleDao.selectTagsByRuleIds(templateRule.getId(), session);
-      for (RuleRuleTagDto tag : templateRuleTags) {
-        RuleRuleTagDto newTag = new RuleRuleTagDto()
-          .setRuleId(rule.getId())
-          .setTagId(tag.getTagId())
-          .setTag(tag.getTag())
-          .setType(tag.getType());
-        ruleDao.insert(newTag, session);
-      }
-
       session.commit();
       reindexRule(rule, session);
       return rule;
@@ -246,26 +224,6 @@ public class RuleOperations implements ServerComponent {
     }
   }
 
-  public void updateRuleTags(RuleDto rule, List<String> newTags, UserSession userSession) {
-    checkPermission(userSession);
-    DbSession session = myBatis.openSession(false);
-    try {
-      Map<String, Long> neededTagIds = validateAndGetTagIds(newTags, session);
-
-      final Integer ruleId = rule.getId();
-
-      boolean ruleChanged = synchronizeTags(ruleId, newTags, neededTagIds, session);
-      if (ruleChanged) {
-        rule.setUpdatedAt(new Date(system.now()));
-        ruleDao.update(rule, session);
-        session.commit();
-        reindexRule(rule, session);
-      }
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
   public void updateRule(RuleChange ruleChange, UserSession userSession) {
     checkPermission(userSession);
     DbSession session = myBatis.openSession(false);
@@ -344,14 +302,14 @@ public class RuleOperations implements ServerComponent {
   }
 
   private static boolean isRuleDebtSameAsDefaultValues(RuleDto ruleDto, CharacteristicDto newSubCharacteristic, @Nullable String newFunction,
-                                              @Nullable String newCoefficient, @Nullable String newOffset) {
+                                                       @Nullable String newCoefficient, @Nullable String newOffset) {
     return newSubCharacteristic.getId().equals(ruleDto.getDefaultSubCharacteristicId()) &&
       isSameRemediationFunction(newFunction, newCoefficient, newOffset, ruleDto.getDefaultRemediationFunction(), ruleDto.getDefaultRemediationCoefficient(),
         ruleDto.getDefaultRemediationOffset());
   }
 
   private static boolean isRuleDebtSameAsOverriddenValues(RuleDto ruleDto, CharacteristicDto newSubCharacteristic, @Nullable String newFunction,
-                                                 @Nullable String newCoefficient, @Nullable String newOffset) {
+                                                          @Nullable String newCoefficient, @Nullable String newOffset) {
     return newSubCharacteristic.getId().equals(ruleDto.getSubCharacteristicId())
       && isSameRemediationFunction(newFunction, newCoefficient, newOffset, ruleDto.getRemediationFunction(), ruleDto.getRemediationCoefficient(), ruleDto.getRemediationOffset());
   }
@@ -365,50 +323,6 @@ public class RuleOperations implements ServerComponent {
       .isEquals();
   }
 
-  private Map<String, Long> validateAndGetTagIds(List<String> newTags, SqlSession session) {
-    Map<String, Long> neededTagIds = Maps.newHashMap();
-    Set<String> unknownTags = Sets.newHashSet();
-    for (String tag : newTags) {
-      Long tagId = ruleTagDao.selectId(tag, session);
-      if (tagId == null) {
-        unknownTags.add(tag);
-      } else {
-        neededTagIds.put(tag, tagId);
-      }
-    }
-    if (!unknownTags.isEmpty()) {
-      throw new NotFoundException("The following tags are unknown and must be created before association: "
-        + StringUtils.join(unknownTags, ", "));
-    }
-    return neededTagIds;
-  }
-
-  private boolean synchronizeTags(final Integer ruleId, List<String> newTags, Map<String, Long> neededTagIds, SqlSession session) {
-    boolean ruleChanged = false;
-
-    Set<String> tagsToKeep = Sets.newHashSet();
-    List<RuleRuleTagDto> currentTags = ruleDao.selectTagsByRuleIds(ruleId, session);
-    for (RuleRuleTagDto existingTag : currentTags) {
-      if (existingTag.getType() == RuleTagType.ADMIN && !newTags.contains(existingTag.getTag())) {
-        ruleDao.deleteTag(existingTag, session);
-        ruleChanged = true;
-      } else {
-        tagsToKeep.add(existingTag.getTag());
-      }
-    }
-
-    for (String tag : newTags) {
-      if (!tagsToKeep.contains(tag)) {
-        ruleDao.insert(new RuleRuleTagDto().setRuleId(ruleId).setTagId(neededTagIds.get(tag)).setType(RuleTagType.ADMIN), session);
-        ruleChanged = true;
-      }
-    }
-
-    ruleTagOperations.deleteUnusedTags(session);
-
-    return ruleChanged;
-  }
-
   private void reindexRule(RuleDto rule, SqlSession session) {
     ruleRegistry.reindex(rule, session);
   }
index 24ee11f0614b3870ac1dbe3fe252753dc5feeed9..b80114ca3740d9c71043e3e3cea520499976b37c 100644 (file)
@@ -30,7 +30,6 @@ import org.elasticsearch.ElasticSearchException;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.action.search.SearchType;
-import org.elasticsearch.common.collect.Lists;
 import org.elasticsearch.common.collect.Maps;
 import org.elasticsearch.common.io.BytesStream;
 import org.elasticsearch.common.unit.TimeValue;
@@ -123,7 +122,6 @@ public class RuleRegistry {
    */
   public String[] reindex(Collection<RuleDto> rules, SqlSession session) {
     Multimap<Integer, RuleParamDto> paramsByRuleId = ArrayListMultimap.create();
-    Multimap<Integer, RuleRuleTagDto> tagsByRuleId = ArrayListMultimap.create();
     Map<Integer, CharacteristicDto> characteristicsById = newHashMap();
 
     List<Integer> ruleIds = newArrayList();
@@ -148,13 +146,10 @@ public class RuleRegistry {
     for (RuleParamDto paramDto : ruleDao.selectParametersByRuleIds(ruleIds, session)) {
       paramsByRuleId.put(paramDto.getRuleId(), paramDto);
     }
-    for (RuleRuleTagDto tagDto : ruleDao.selectTagsByRuleIds(ruleIds, session)) {
-      tagsByRuleId.put(tagDto.getRuleId(), tagDto);
-    }
     for (CharacteristicDto characteristicDto : allCharacteristicDtos) {
       characteristicsById.put(characteristicDto.getId(), characteristicDto);
     }
-    return bulkIndexRules(rules, characteristicsById, paramsByRuleId, tagsByRuleId);
+    return bulkIndexRules(rules, characteristicsById, paramsByRuleId);
   }
 
   /**
@@ -180,15 +175,13 @@ public class RuleRegistry {
         characteristicDao.selectById(parentId, session) : null;
       searchIndex.putSynchronous(INDEX_RULES, TYPE_RULE, Long.toString(ruleId), ruleDocument(rule,
         characteristic, subCharacteristic,
-        ruleDao.selectParametersByRuleIds(newArrayList(ruleId), session),
-        ruleDao.selectTagsByRuleIds(newArrayList(ruleId), session)));
+        ruleDao.selectParametersByRuleIds(newArrayList(ruleId), session)));
     } catch (IOException ioexception) {
       throw new IllegalStateException("Unable to index rule with id=" + rule.getId(), ioexception);
     }
   }
 
-  private String[] bulkIndexRules(Collection<RuleDto> rules, Map<Integer, CharacteristicDto> characteristicsById, Multimap<Integer, RuleParamDto> paramsByRule,
-    Multimap<Integer, RuleRuleTagDto> tagsByRule) {
+  private String[] bulkIndexRules(Collection<RuleDto> rules, Map<Integer, CharacteristicDto> characteristicsById, Multimap<Integer, RuleParamDto> paramsByRule) {
     try {
       String[] ids = new String[rules.size()];
       BytesStream[] docs = new BytesStream[rules.size()];
@@ -199,7 +192,7 @@ public class RuleRegistry {
         CharacteristicDto effectiveSubCharacteristic =
           characteristicsById.get(rule.getSubCharacteristicId() != null ? rule.getSubCharacteristicId() : rule.getDefaultSubCharacteristicId());
         CharacteristicDto effectiveCharacteristic = effectiveSubCharacteristic != null ? characteristicsById.get(effectiveSubCharacteristic.getParentId()) : null;
-        docs[index] = ruleDocument(rule, effectiveCharacteristic, effectiveSubCharacteristic, paramsByRule.get(rule.getId()), tagsByRule.get(rule.getId()));
+        docs[index] = ruleDocument(rule, effectiveCharacteristic, effectiveSubCharacteristic, paramsByRule.get(rule.getId()));
         index++;
       }
       TIME_PROFILER.stop();
@@ -226,7 +219,7 @@ public class RuleRegistry {
   }
 
   private XContentBuilder ruleDocument(RuleDto rule, @Nullable CharacteristicDto characteristicDto, @Nullable CharacteristicDto subCharacteristicDto,
-    Collection<RuleParamDto> params, Collection<RuleRuleTagDto> tags) throws IOException {
+    Collection<RuleParamDto> params) throws IOException {
     XContentBuilder document = XContentFactory.jsonBuilder()
       .startObject()
       .field(RuleDocument.FIELD_ID, rule.getId())
@@ -244,7 +237,6 @@ public class RuleRegistry {
     addRuleDebt(document, rule, characteristicDto, subCharacteristicDto);
     addRuleNote(document, rule);
     addRuleParams(document, rule, params);
-    addRuleTags(document, rule, tags);
     document.endObject();
     return document;
   }
@@ -290,24 +282,6 @@ public class RuleRegistry {
     }
   }
 
-  private void addRuleTags(XContentBuilder document, RuleDto rule, Collection<RuleRuleTagDto> tags) throws IOException {
-    List<String> systemTags = Lists.newArrayList();
-    List<String> adminTags = Lists.newArrayList();
-    for (RuleRuleTagDto tag : tags) {
-      if (tag.getType() == RuleTagType.SYSTEM) {
-        systemTags.add(tag.getTag());
-      } else {
-        adminTags.add(tag.getTag());
-      }
-    }
-    if (!systemTags.isEmpty()) {
-      document.array(RuleDocument.FIELD_SYSTEM_TAGS, systemTags.toArray());
-    }
-    if (!adminTags.isEmpty()) {
-      document.array(RuleDocument.FIELD_ADMIN_TAGS, adminTags.toArray());
-    }
-  }
-
   /**
    * <p>Find rule IDs matching the given criteria.</p>
    *
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RuleTagDocument.java b/sonar-server/src/main/java/org/sonar/server/rule/RuleTagDocument.java
deleted file mode 100644 (file)
index 2c35de5..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.server.rule;
-
-/**
- * @deprecated to be dropped in 4.4
- */
-@Deprecated
-public class RuleTagDocument {
-
-  public static final String FIELD_VALUE = "value";
-
-  private RuleTagDocument() {
-    // Only constants
-  }
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RuleTagLookup.java b/sonar-server/src/main/java/org/sonar/server/rule/RuleTagLookup.java
deleted file mode 100644 (file)
index 475407b..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.server.rule;
-
-import org.sonar.api.ServerComponent;
-
-import java.util.Collection;
-
-/**
- * @deprecated to be dropped in 4.4
- */
-@Deprecated
-public class RuleTagLookup implements ServerComponent  {
-
-  private final ESRuleTags esRuleTags;
-
-  public RuleTagLookup(ESRuleTags esRuleTags) {
-    this.esRuleTags = esRuleTags;
-  }
-
-  public Collection<String> listAllTags() {
-    return esRuleTags.searchAllTags();
-  }
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RuleTagOperations.java b/sonar-server/src/main/java/org/sonar/server/rule/RuleTagOperations.java
deleted file mode 100644 (file)
index 8b50e6b..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.server.rule;
-
-import org.apache.ibatis.session.SqlSession;
-import org.elasticsearch.common.collect.Sets;
-import org.sonar.api.ServerExtension;
-import org.sonar.api.server.rule.RuleTagFormat;
-import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.core.rule.RuleTagDao;
-import org.sonar.core.rule.RuleTagDto;
-import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.user.UserSession;
-
-import java.util.Set;
-
-/**
- * @deprecated to be dropped in 4.4
- */
-@Deprecated
-public class RuleTagOperations implements ServerExtension {
-
-  private final RuleTagDao ruleTagDao;
-  private final ESRuleTags esRuleTags;
-
-  public RuleTagOperations(RuleTagDao ruleTagDao, ESRuleTags esRuleTags) {
-    this.ruleTagDao = ruleTagDao;
-    this.esRuleTags = esRuleTags;
-  }
-
-  public RuleTagDto create(String tag, UserSession userSession) {
-    checkPermission(userSession);
-    validateTagFormat(tag);
-    checkDuplicateTag(tag);
-
-    RuleTagDto newTag = new RuleTagDto().setTag(tag);
-    ruleTagDao.insert(newTag);
-    esRuleTags.put(newTag);
-    return newTag;
-  }
-
-  private void checkDuplicateTag(String tag) {
-    if (ruleTagDao.selectId(tag) != null) {
-      throw new BadRequestException(String.format("Tag %s already exists", tag));
-    }
-  }
-
-  private void validateTagFormat(String tag) {
-    try {
-      RuleTagFormat.validate(tag);
-    } catch(IllegalArgumentException iae) {
-      throw new BadRequestException(iae.getMessage());
-    }
-  }
-
-  private void checkPermission(UserSession userSession) {
-    userSession.checkLoggedIn();
-    userSession.checkGlobalPermission(GlobalPermissions.QUALITY_PROFILE_ADMIN);
-  }
-
-  public void deleteUnusedTags(SqlSession session) {
-    Set<String> deleted = Sets.newHashSet();
-    for (RuleTagDto unused: ruleTagDao.selectUnused(session)) {
-      deleted.add(unused.getTag());
-      ruleTagDao.delete(unused.getId(), session);
-    }
-    if (!deleted.isEmpty()) {
-      esRuleTags.delete(deleted.toArray(new String[0]));
-    }
-  }
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RuleTags.java b/sonar-server/src/main/java/org/sonar/server/rule/RuleTags.java
deleted file mode 100644 (file)
index d87df4c..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.server.rule;
-
-import org.sonar.api.ServerExtension;
-import org.sonar.core.rule.RuleTagDto;
-import org.sonar.server.user.UserSession;
-
-import java.util.Collection;
-
-/**
- * @deprecated to be dropped in 4.4
- */
-@Deprecated
-public class RuleTags implements ServerExtension {
-
-  private final RuleTagLookup ruleTagLookup;
-  private final RuleTagOperations ruleTagOperations;
-
-  public RuleTags(RuleTagLookup ruleTagLookup, RuleTagOperations ruleTagOperations) {
-    this.ruleTagLookup = ruleTagLookup;
-    this.ruleTagOperations = ruleTagOperations;
-  }
-
-  public Collection<String> listAllTags() {
-    return ruleTagLookup.listAllTags();
-  }
-
-  public RuleTagDto create(String tag) {
-    return ruleTagOperations.create(tag, UserSession.get());
-  }
-}
index 625a62870a22bc5e21b439ef95b4fc67366e915e..7d909603deb4d3f6e56afca36022c456fe20cfa9 100644 (file)
@@ -106,15 +106,6 @@ public class Rules implements ServerExtension {
     ruleOperations.deleteCustomRule(rule, UserSession.get());
   }
 
-  public void updateRuleTags(int ruleId, Object tags) {
-    RuleDto rule = findRuleNotNull(ruleId);
-    List<String> newTags = RubyUtils.toStrings(tags);
-    if (newTags == null) {
-      newTags = ImmutableList.of();
-    }
-    ruleOperations.updateRuleTags(rule, newTags, UserSession.get());
-  }
-
   @CheckForNull
   public Rule findByKey(RuleKey key) {
     return ruleRegistry.findByKey(key);
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/ws/AbstractUpdateTagsWsHandler.java b/sonar-server/src/main/java/org/sonar/server/rule/ws/AbstractUpdateTagsWsHandler.java
deleted file mode 100644 (file)
index 7c64895..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.server.rule.ws;
-
-import org.sonar.server.exceptions.NotFoundException;
-
-import com.google.common.collect.Sets;
-import org.elasticsearch.common.collect.Lists;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.RequestHandler;
-import org.sonar.api.server.ws.Response;
-import org.sonar.server.rule.Rule;
-import org.sonar.server.rule.Rules;
-
-import java.util.Set;
-
-/**
- * @deprecated to be dropped in 4.4
- */
-@Deprecated
-public abstract class AbstractUpdateTagsWsHandler implements RequestHandler {
-
-  private final Rules rules;
-
-  protected AbstractUpdateTagsWsHandler(Rules rules) {
-    this.rules = rules;
-  }
-
-  @Override
-  public void handle(Request request, Response response) {
-    RuleKey ruleKey = RuleKey.parse(request.mandatoryParam("key"));
-    Rule rule = rules.findByKey(ruleKey);
-    if (rule == null) {
-      throw new NotFoundException("No rule found for key " + ruleKey);
-    }
-    Set<String> allAdminTags = Sets.newHashSet(rule.adminTags());
-    String[] tagsFromRequest = request.mandatoryParam("tags").split(",");
-    updateTags(allAdminTags, tagsFromRequest);
-    rules.updateRuleTags(rule.id(), Lists.newArrayList(allAdminTags));
-
-    response.noContent();
-  }
-
-  protected abstract void updateTags(Set<String> currentTags, String[] tagsFromRequest);
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/ws/AddTagsWsHandler.java b/sonar-server/src/main/java/org/sonar/server/rule/ws/AddTagsWsHandler.java
deleted file mode 100644 (file)
index 38d2d26..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.server.rule.ws;
-
-import org.sonar.server.rule.Rules;
-
-import java.util.Arrays;
-import java.util.Set;
-
-/**
- * @deprecated to be dropped in 4.4
- */
-@Deprecated
-public class AddTagsWsHandler extends AbstractUpdateTagsWsHandler {
-
-  public AddTagsWsHandler(Rules rules) {
-    super(rules);
-  }
-
-  @Override
-  protected void updateTags(Set<String> currentTags, String[] tagsFromRequest) {
-    currentTags.addAll(Arrays.asList(tagsFromRequest));
-  }
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/ws/RemoveTagsWsHandler.java b/sonar-server/src/main/java/org/sonar/server/rule/ws/RemoveTagsWsHandler.java
deleted file mode 100644 (file)
index 9fe9c5a..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.server.rule.ws;
-
-import org.sonar.server.rule.Rules;
-
-import java.util.Arrays;
-import java.util.Set;
-
-/**
- * @deprecated to be dropped in 4.4
- */
-@Deprecated
-public class RemoveTagsWsHandler extends AbstractUpdateTagsWsHandler {
-
-  public RemoveTagsWsHandler(Rules rules) {
-    super(rules);
-  }
-
-  @Override
-  protected void updateTags(Set<String> currentTags, String[] tagsFromRequest) {
-    currentTags.removeAll(Arrays.asList(tagsFromRequest));
-  }
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleTagsWs.java b/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleTagsWs.java
deleted file mode 100644 (file)
index 2628ee3..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.server.rule.ws;
-
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.RequestHandler;
-import org.sonar.api.server.ws.Response;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.core.rule.RuleTagDto;
-import org.sonar.server.rule.RuleTags;
-
-/**
- * @deprecated to be dropped in 4.4
- */
-@Deprecated
-public class RuleTagsWs implements WebService {
-
-  private final RuleTags ruleTags;
-
-  public RuleTagsWs(RuleTags ruleTags) {
-    this.ruleTags = ruleTags;
-  }
-
-  @Override
-  public void define(Context context) {
-    NewController controller = context.createController("api/rule_tags")
-      .setDescription("Rule tags management");
-
-    controller.createAction("list")
-      .setDescription("List all available rule tags")
-      .setSince("4.2")
-      .setHandler(new RequestHandler() {
-        @Override
-        public void handle(Request request, Response response) {
-          list(response);
-        }
-      });
-
-    controller.createAction("create")
-      .setPost(true)
-      .setDescription("Create a new rule tag")
-      .setSince("4.2")
-      .setHandler(new RequestHandler() {
-        @Override
-        public void handle(Request request, Response response) {
-          create(request, response);
-        }
-      })
-      .createParam("tag")
-      .setDescription("Value of the new rule tag")
-      .setExampleValue("java8");
-
-    controller.done();
-  }
-
-  private void list(Response response) {
-    JsonWriter writer = response.newJsonWriter();
-    writer.beginArray();
-    for (String tag : ruleTags.listAllTags()) {
-      writer.value(tag);
-    }
-    writer.endArray().close();
-  }
-
-  private void create(Request request, Response response) {
-    RuleTagDto newTag = ruleTags.create(request.mandatoryParam("tag"));
-    response.newJsonWriter()
-      .beginObject()
-      .prop("id", newTag.getId())
-      .prop("tag", newTag.getTag())
-      .endObject()
-      .close();
-  }
-}
index 75a4e13b64e9b0248ab98150357b30c0dfd01da4..74c52e969a7af7db47c48d1e47e02397eee03577 100644 (file)
@@ -29,14 +29,10 @@ public class RulesWs implements WebService {
 
   private final RuleSearchWsHandler searchHandler;
   private final RuleShowWsHandler showHandler;
-  private final AddTagsWsHandler addTagsWsHandler;
-  private final RemoveTagsWsHandler removeTagsWsHandler;
 
-  public RulesWs(RuleSearchWsHandler searchHandler, RuleShowWsHandler showHandler, AddTagsWsHandler addTagsWsHandler, RemoveTagsWsHandler removeTagsWsHandler) {
+  public RulesWs(RuleSearchWsHandler searchHandler, RuleShowWsHandler showHandler) {
     this.searchHandler = searchHandler;
     this.showHandler = showHandler;
-    this.addTagsWsHandler = addTagsWsHandler;
-    this.removeTagsWsHandler = removeTagsWsHandler;
   }
 
   @Override
@@ -67,23 +63,6 @@ public class RulesWs implements WebService {
       .setHandler(showHandler)
       .createParam("key", "Mandatory key of rule");
 
-    addTagParams(controller.createAction("add_tags")
-      .setDescription("Add tags to a rule")
-      .setSince("4.2")
-      .setPost(true)
-      .setHandler(addTagsWsHandler));
-
-    addTagParams(controller.createAction("remove_tags")
-      .setDescription("Remove tags from a rule")
-      .setSince("4.2")
-      .setPost(true)
-      .setHandler(removeTagsWsHandler));
-
     controller.done();
   }
-
-  private void addTagParams(final NewAction action) {
-    action.createParam("key", "Full key of the rule");
-    action.createParam("tags", "Comma separated list of tags");
-  }
 }
index 9b6c1121d1967afcd7be2da5eba1ecce3227fe98..55eb6660214f30fb983a242c7f1164daca921c1d 100644 (file)
@@ -44,6 +44,10 @@ import org.sonar.core.technicaldebt.db.CharacteristicDto;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.qualityprofile.ProfilesManager;
 import org.sonar.server.rule.RuleDefinitionsLoader;
+import org.sonar.server.rule2.index.RuleIndexDefinition;
+import org.sonar.server.search.action.EmbeddedIndexAction;
+import org.sonar.server.search.action.IndexAction;
+import org.sonar.server.search.action.KeyIndexAction;
 
 import javax.annotation.Nullable;
 import java.util.ArrayList;
@@ -95,7 +99,6 @@ public class RegisterRules implements Startable {
       RulesDefinition.Context context = defLoader.load();
       for (RulesDefinition.ExtendedRepository repoDef : getRepositories(context)) {
         for (RulesDefinition.Rule ruleDef : repoDef.rules()) {
-
           RuleKey ruleKey = RuleKey.of(ruleDef.repository().key(), ruleDef.key());
 
           RuleDto rule = allRules.containsKey(ruleKey) ? allRules.remove(ruleKey) : createRuleDto(ruleDef, session);
@@ -118,6 +121,9 @@ public class RegisterRules implements Startable {
 
           if (executeUpdate) {
             dbClient.ruleDao().update(rule, session);
+          } else {
+            // TODO replace this hack by index synchronizer
+            session.enqueue(new KeyIndexAction<RuleKey>(RuleIndexDefinition.INDEX_TYPE, IndexAction.Method.UPDATE, rule.getKey()));
           }
 
           mergeParams(ruleDef, rule, session);
@@ -276,6 +282,9 @@ public class RegisterRules implements Startable {
         // TODO store param name
         if (mergeParam(paramDto, paramDef)) {
           dbClient.ruleDao().updateRuleParam(rule, paramDto, session);
+        }  else {
+          // TODO to be replaced by synchronizer
+          session.enqueue(new EmbeddedIndexAction<RuleKey>(RuleIndexDefinition.INDEX_TYPE, IndexAction.Method.UPDATE, paramDto, rule.getKey()));
         }
         existingParamDtoNames.add(paramDto.getName());
       }
@@ -312,9 +321,8 @@ public class RegisterRules implements Startable {
   private boolean mergeTags(RulesDefinition.Rule ruleDef, RuleDto dto) {
     boolean changed = false;
 
-    if (Rule.STATUS_REMOVED.equals(ruleDef.status())) {
+    if (RuleStatus.REMOVED == ruleDef.status()) {
       dto.setSystemTags(Collections.EMPTY_SET);
-      dto.setTags(Collections.EMPTY_SET);
       changed = true;
     } else if (!dto.getSystemTags().containsAll(ruleDef.tags())) {
       dto.setSystemTags(ruleDef.tags());
index 8482e3333479ee6b5b857b7ff300b2981e8689a4..9519da264c87b150d8bf25e25cb572906b4b2b1b 100644 (file)
@@ -23,9 +23,8 @@ import org.sonar.server.search.IndexDefinition;
 
 public final class RuleIndexDefinition implements IndexDefinition {
 
-  private static final String INDEX_NAME = "rules2";
-  private static final String INDEX_DOMAIN = "rules";
-  private static final String INDEX_TYPE = "rule2";
+  public static final String INDEX_NAME = "rules2";
+  public static final String INDEX_TYPE = "rule2";
 
   @Override
   public String getIndexName() {
@@ -36,4 +35,4 @@ public final class RuleIndexDefinition implements IndexDefinition {
   public String getIndexType() {
     return RuleIndexDefinition.INDEX_TYPE;
   }
-}
\ No newline at end of file
+}
index 1ab0cfd120803a4ae65462e9b1a6377c9024da4a..a6aaa09dc92392eefe93e0d896070d66c8234eea 100644 (file)
@@ -36,7 +36,7 @@ import java.util.Map;
 
 public abstract class Result<K> {
 
-  private final Collection<K> hits;
+  private final List<K> hits;
   private final Map<String, Collection<FacetValue>> facets;
   private final long total;
   private final long timeInMillis;
@@ -79,7 +79,7 @@ public abstract class Result<K> {
     return this.getSearchResult(fields);
   }
 
-  public Collection<K> getHits() {
+  public List<K> getHits() {
     return hits;
   }
 
index b5a114bb17c8dbe248d3d965dd4de36f595aafe0..c4091a7798bf881fdda2219b0de34e11b7321687 100644 (file)
@@ -82,10 +82,6 @@ class Internal
     component(Java::OrgSonarServerRule::RubyRuleService.java_class)
   end
 
-  def self.rule_tags
-    component(Java::OrgSonarServerRule::RuleTags.java_class)
-  end
-
   def self.durations
     component(Java::OrgSonarApiUtils::Durations.java_class)
   end
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/537_drop_rule_tags_tables.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/537_drop_rule_tags_tables.rb
new file mode 100644 (file)
index 0000000..6019912
--- /dev/null
@@ -0,0 +1,77 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube 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.
+#
+# SonarQube 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.
+#
+
+#
+# SonarQube 4.4
+# SONAR-5007
+#
+class DropRuleTagsTables < ActiveRecord::Migration
+
+  class Rule < ActiveRecord::Base
+  end
+
+  class Tag < ActiveRecord::Base
+    set_table_name 'rule_tags'
+  end
+
+  class RuleTag < ActiveRecord::Base
+    set_table_name 'rules_rule_tags'
+  end
+
+  def self.up
+    # load tags
+    tags_by_id={}
+    Tag.find(:all).inject(tags_by_id) do |h, tag|
+      h[tag.id]=tag.tag
+      h
+    end
+
+    # load associations between rules and tags
+    rule_tags_by_rule_id={}
+    RuleTag.find(:all).inject(rule_tags_by_rule_id) do |h, rule_tag|
+      h[rule_tag.rule_id]||=[]
+      h[rule_tag.rule_id]<<rule_tag
+      h
+    end
+
+    # move tags to RULES.TAGS and RULES.SYSTEM_TAGS (see migration 533)
+    rule_tags_by_rule_id.each do |rule_id, rule_tags|
+      rule=Rule.find(rule_id)
+      if rule
+        system_tags=[]
+        user_tags=[]
+        rule_tags.each do |rule_tag|
+          if rule_tag.tag_type=='SYSTEM'
+            system_tags<<tags_by_id[rule_tag.rule_tag_id]
+          else
+            user_tags<<tags_by_id[rule_tag.rule_tag_id]
+          end
+        end
+        rule.tags=user_tags.join(',')
+        rule.system_tags=system_tags.join(',')
+        rule.save!
+      end
+    end
+
+    drop_table(:rules_rule_tags)
+    drop_table(:rule_tags)
+  end
+
+end
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/ESRuleTagsTest.java b/sonar-server/src/test/java/org/sonar/server/rule/ESRuleTagsTest.java
deleted file mode 100644 (file)
index c040bb5..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.server.rule;
-
-import com.github.tlrx.elasticsearch.test.EsSetup;
-import com.github.tlrx.elasticsearch.test.request.Index;
-import com.google.common.collect.ImmutableList;
-import org.elasticsearch.common.settings.ImmutableSettings;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.config.Settings;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.rule.RuleTagDto;
-import org.sonar.server.es.ESIndex;
-import org.sonar.server.es.ESNode;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class ESRuleTagsTest {
-
-  EsSetup esSetup;
-
-  ESIndex searchIndex;
-
-  ESRuleTags ruleTags;
-
-  @Before
-  public void setUp() throws Exception {
-    esSetup = new EsSetup(ImmutableSettings.builder().loadFromUrl(ESNode.class.getResource("config/elasticsearch.json")).build());
-    esSetup.execute(EsSetup.deleteAll());
-
-    ESNode node = mock(ESNode.class);
-    when(node.client()).thenReturn(esSetup.client());
-
-    Settings settings = new Settings();
-    settings.setProperty("sonar.log.profilingLevel", "FULL");
-    Profiling profiling = new Profiling(settings);
-    searchIndex = new ESIndex(node, profiling);
-    searchIndex.start();
-
-    ruleTags = new ESRuleTags(searchIndex);
-    ruleTags.start();
-  }
-
-  @After
-  public void tearDown() {
-    searchIndex.stop();
-    esSetup.terminate();
-  }
-
-  @Test
-  public void should_register_mapping_at_startup() {
-    assertThat(esSetup.exists("rules")).isTrue();
-    assertThat(esSetup.client().admin().indices().prepareTypesExists("rules").setTypes("tag").execute().actionGet().isExists()).isTrue();
-  }
-
-  @Test
-  public void should_skip_bulk_if_no_tag() {
-    esSetup.execute(
-      indexTagDocument("tag5"),
-      indexTagDocument("tag6"),
-      indexTagDocument("tag7"));
-    ruleTags.putAllTags(ImmutableList.<RuleTagDto>of());
-    checkTagCount(0L);
-  }
-
-  @Test
-  public void should_register_new_tags() throws Exception {
-    ruleTags.putAllTags(ImmutableList.of(
-      newRuleTagDto("tag1"),
-      newRuleTagDto("tag2"),
-      newRuleTagDto("tag3"),
-      newRuleTagDto("tag4"),
-      newRuleTagDto("tag5")
-    ));
-
-    checkTagCount(5L);
-  }
-
-
-  @Test
-  public void should_remove_unused_tags() throws Exception {
-
-    esSetup.execute(
-      indexTagDocument("tag4"),
-      indexTagDocument("tag5"),
-      indexTagDocument("tag6"),
-      indexTagDocument("tag7"));
-
-    ruleTags.putAllTags(ImmutableList.of(
-      newRuleTagDto("tag1"),
-      newRuleTagDto("tag2"),
-      newRuleTagDto("tag3"),
-      newRuleTagDto("tag4"),
-      newRuleTagDto("tag5")
-    ));
-
-    checkTagCount(5L);
-  }
-
-  @Test
-  public void should_delete_tags() throws Exception {
-
-    esSetup.execute(
-      indexTagDocument("tag1"),
-      indexTagDocument("tag2"),
-      indexTagDocument("tag3"),
-      indexTagDocument("tag4"));
-
-    ruleTags.delete("tag1", "tag2");
-
-    checkTagCount(2L);
-  }
-
-  private void checkTagCount(long count) {
-    assertThat(ruleTags.searchAllTags()).hasSize((int) count);
-  }
-
-  private RuleTagDto newRuleTagDto(String tagValue) {
-    return new RuleTagDto().setTag(tagValue);
-  }
-
-  private Index indexTagDocument(String tagValue) {
-    return EsSetup.index(RuleRegistry.INDEX_RULES, ESRuleTags.TYPE_TAG).withSource(String.format("{\"value\":\"%s\"}", tagValue));
-  }
-}
index 59c1cdcc04e3920d385ca47846af180184266335..23ec6119db4ee4ad8f6a7951ef30fb8bc1ff790c 100644 (file)
@@ -123,12 +123,6 @@ public class RubyRuleServiceTest {
     verify(rules).deleteCustomRule(10);
   }
 
-  @Test
-  public void update_rule_tags() {
-    facade.updateRuleTags(10, ImmutableList.of("tag1", "tag2"));
-    verify(rules).updateRuleTags(10, ImmutableList.of("tag1", "tag2"));
-  }
-
   @Test
   public void find_by_key() {
     facade.findByKey("repo:key");
index bc4abd910900445aaf427fb79184ecea6ba568d7..ac8c9b3181f2f2b58f5851e88a9688dc188766e3 100644 (file)
@@ -46,9 +46,6 @@ import org.sonar.core.qualityprofile.db.ActiveRuleDto;
 import org.sonar.core.rule.RuleDao;
 import org.sonar.core.rule.RuleDto;
 import org.sonar.core.rule.RuleParamDto;
-import org.sonar.core.rule.RuleRuleTagDto;
-import org.sonar.core.rule.RuleTagDao;
-import org.sonar.core.rule.RuleTagType;
 import org.sonar.core.technicaldebt.db.CharacteristicDao;
 import org.sonar.core.technicaldebt.db.CharacteristicDto;
 import org.sonar.server.exceptions.BadRequestException;
@@ -59,7 +56,6 @@ import org.sonar.server.rule.RuleOperations.RuleChange;
 import org.sonar.server.user.MockUserSession;
 import org.sonar.server.user.UserSession;
 
-import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -93,15 +89,9 @@ public class RuleOperationsTest {
   @Mock
   RuleDao ruleDao;
 
-  @Mock
-  RuleTagDao ruleTagDao;
-
   @Mock
   CharacteristicDao characteristicDao;
 
-  @Mock
-  RuleTagOperations ruleTagOperations;
-
   @Mock
   ESActiveRule esActiveRule;
 
@@ -139,7 +129,7 @@ public class RuleOperationsTest {
       }
     }).when(activeRuleDao).insert(any(ActiveRuleDto.class), any(SqlSession.class));
 
-    operations = new RuleOperations(myBatis, activeRuleDao, ruleDao, ruleTagDao, characteristicDao, ruleTagOperations, esActiveRule, ruleRegistry, system);
+    operations = new RuleOperations(myBatis, activeRuleDao, ruleDao, characteristicDao, esActiveRule, ruleRegistry, system);
   }
 
   @Test
@@ -148,8 +138,6 @@ public class RuleOperationsTest {
 
     List<RuleParamDto> ruleParams = newArrayList(new RuleParamDto().setId(20).setName("max").setDefaultValue("10"));
     when(ruleDao.selectParametersByRuleId(eq(10), eq(session))).thenReturn(ruleParams);
-    List<RuleRuleTagDto> ruleTags = newArrayList(new RuleRuleTagDto().setId(30L).setTag("style").setType(RuleTagType.SYSTEM));
-    when(ruleDao.selectTagsByRuleIds(eq(10), eq(session))).thenReturn(ruleTags);
 
     operations.updateRuleNote(rule, "My note", authorizedUserSession);
 
@@ -185,8 +173,6 @@ public class RuleOperationsTest {
 
     List<RuleParamDto> ruleParams = newArrayList(new RuleParamDto().setId(20).setName("max").setDefaultValue("10"));
     when(ruleDao.selectParametersByRuleId(eq(10), eq(session))).thenReturn(ruleParams);
-    List<RuleRuleTagDto> ruleTags = newArrayList(new RuleRuleTagDto().setId(30L).setTag("style").setType(RuleTagType.SYSTEM));
-    when(ruleDao.selectTagsByRuleIds(eq(10), eq(session))).thenReturn(ruleTags);
 
     operations.updateRuleNote(rule, "My new note", MockUserSession.create().setLogin("guy").setName("Guy").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN));
 
@@ -208,8 +194,6 @@ public class RuleOperationsTest {
 
     List<RuleParamDto> ruleParams = newArrayList(new RuleParamDto().setId(20).setName("max").setDefaultValue("10"));
     when(ruleDao.selectParametersByRuleId(eq(10), eq(session))).thenReturn(ruleParams);
-    List<RuleRuleTagDto> ruleTags = newArrayList(new RuleRuleTagDto().setId(30L).setTag("style").setType(RuleTagType.SYSTEM));
-    when(ruleDao.selectTagsByRuleIds(eq(10), eq(session))).thenReturn(ruleTags);
 
     long now = System.currentTimeMillis();
     doReturn(now).when(system).now();
@@ -232,7 +216,6 @@ public class RuleOperationsTest {
     RuleDto templateRule = new RuleDto().setId(10).setRepositoryKey("squid").setRuleKey("AvoidCycle").setConfigKey("Xpath")
       .setDefaultSubCharacteristicId(2).setDefaultRemediationFunction("LINEAR_OFFSET").setDefaultRemediationCoefficient("2h").setDefaultRemediationOffset("15min");
     when(ruleDao.selectParametersByRuleId(eq(10), eq(session))).thenReturn(newArrayList(new RuleParamDto().setId(20).setName("max").setDefaultValue("10")));
-    when(ruleDao.selectTagsByRuleIds(eq(10), eq(session))).thenReturn(newArrayList(new RuleRuleTagDto().setId(30L).setTag("style").setType(RuleTagType.SYSTEM)));
 
     Map<String, String> paramsByKey = ImmutableMap.of("max", "20");
     RuleDto result = operations.createCustomRule(templateRule, "My New Rule", Severity.BLOCKER, "Rule Description", paramsByKey, authorizedUserSession);
@@ -259,11 +242,6 @@ public class RuleOperationsTest {
     assertThat(ruleParamArgument.getValue().getName()).isEqualTo("max");
     assertThat(ruleParamArgument.getValue().getDefaultValue()).isEqualTo("20");
 
-    ArgumentCaptor<RuleRuleTagDto> ruleTagArgument = ArgumentCaptor.forClass(RuleRuleTagDto.class);
-    verify(ruleDao).insert(ruleTagArgument.capture(), eq(session));
-    assertThat(ruleTagArgument.getValue().getTag()).isEqualTo("style");
-    assertThat(ruleTagArgument.getValue().getType()).isEqualTo(RuleTagType.SYSTEM);
-
     verify(session).commit();
     verify(ruleRegistry).reindex(eq(ruleArgument.getValue()), eq(session));
   }
@@ -272,8 +250,6 @@ public class RuleOperationsTest {
   public void update_custom_rule() throws Exception {
     RuleDto rule = new RuleDto().setId(11).setRepositoryKey("squid").setRuleKey("XPath_1387869254").setConfigKey("Xpath");
     when(ruleDao.selectParametersByRuleId(eq(11), eq(session))).thenReturn(newArrayList(new RuleParamDto().setId(21).setName("max").setDefaultValue("20")));
-    ArrayList<RuleRuleTagDto> ruleTags = newArrayList(new RuleRuleTagDto().setId(30L).setTag("style").setType(RuleTagType.SYSTEM));
-    when(ruleDao.selectTagsByRuleIds(eq(11), eq(session))).thenReturn(ruleTags);
 
     Map<String, String> paramsByKey = ImmutableMap.of("max", "21");
     operations.updateCustomRule(rule, "Updated Rule", Severity.MAJOR, "Updated Description", paramsByKey, authorizedUserSession);
@@ -298,8 +274,6 @@ public class RuleOperationsTest {
     RuleDto rule = new RuleDto().setId(ruleId).setRepositoryKey("squid").setRuleKey("XPath_1387869254").setConfigKey("Xpath");//.setUpdatedAt(DateUtils.parseDate("2013-12-23"));
     RuleParamDto param = new RuleParamDto().setId(21).setName("max").setDefaultValue("20");
     when(ruleDao.selectParametersByRuleId(eq(ruleId), eq(session))).thenReturn(newArrayList(param));
-    ArrayList<RuleRuleTagDto> ruleTags = newArrayList(new RuleRuleTagDto().setId(30L).setTag("style").setType(RuleTagType.SYSTEM));
-    when(ruleDao.selectTagsByRuleIds(eq(ruleId), eq(session))).thenReturn(ruleTags);
 
     final int activeRuleId = 5;
     ActiveRuleDto activeRule = new ActiveRuleDto().setId(activeRuleId).setProfileId(1).setRuleId(ruleId).setSeverity(Severity.MINOR);
@@ -318,74 +292,6 @@ public class RuleOperationsTest {
     verify(esActiveRule).deleteActiveRules(newArrayList(activeRuleId));
   }
 
-  @Test(expected = ForbiddenException.class)
-  public void fail_to_update_tags_on_unauthorized_user() {
-    operations.updateRuleTags(new RuleDto(), ImmutableList.of("polop"), unauthorizedUserSession);
-  }
-
-  @Test(expected = NotFoundException.class)
-  public void fail_to_update_tags_on_unknown_tag() {
-    final String tag = "polop";
-    when(ruleTagDao.selectId(tag, session)).thenReturn(null);
-    operations.updateRuleTags(new RuleDto(), ImmutableList.of(tag), authorizedUserSession);
-  }
-
-  @Test
-  public void add_new_tags() {
-    final int ruleId = 24;
-    final RuleDto rule = new RuleDto().setId(ruleId);
-    final String tag = "polop";
-    final long tagId = 42L;
-    when(ruleTagDao.selectId(tag, session)).thenReturn(tagId);
-
-    operations.updateRuleTags(rule, ImmutableList.of(tag), authorizedUserSession);
-
-    verify(ruleTagDao).selectId(tag, session);
-    ArgumentCaptor<RuleRuleTagDto> capture = ArgumentCaptor.forClass(RuleRuleTagDto.class);
-    verify(ruleDao).insert(capture.capture(), eq(session));
-    final RuleRuleTagDto newTag = capture.getValue();
-    assertThat(newTag.getRuleId()).isEqualTo(ruleId);
-    assertThat(newTag.getTagId()).isEqualTo(tagId);
-    assertThat(newTag.getType()).isEqualTo(RuleTagType.ADMIN);
-    verify(ruleDao).update(rule, session);
-    verify(session).commit();
-  }
-
-  @Test
-  public void delete_removed_tags() {
-    final int ruleId = 24;
-    final RuleDto rule = new RuleDto().setId(ruleId);
-    final String tag = "polop";
-    RuleRuleTagDto existingTag = new RuleRuleTagDto().setTag(tag).setType(RuleTagType.ADMIN);
-    when(ruleDao.selectTagsByRuleIds(ruleId, session)).thenReturn(ImmutableList.of(existingTag));
-
-    operations.updateRuleTags(rule, ImmutableList.<String>of(), authorizedUserSession);
-
-    verify(ruleDao, atLeast(1)).selectTagsByRuleIds(ruleId, session);
-    verify(ruleDao).deleteTag(existingTag, session);
-    verify(ruleDao).update(rule, session);
-    verify(ruleTagOperations).deleteUnusedTags(session);
-    verify(session).commit();
-  }
-
-  @Test
-  public void not_update_rule_tags_if_tags_unchanged() {
-    final int ruleId = 24;
-    final RuleDto rule = new RuleDto().setId(ruleId);
-    final String tag = "polop";
-    final long tagId = 42L;
-    when(ruleTagDao.selectId(tag, session)).thenReturn(tagId);
-    RuleRuleTagDto existingTag = new RuleRuleTagDto().setTag(tag).setType(RuleTagType.ADMIN);
-    when(ruleDao.selectTagsByRuleIds(ruleId, session)).thenReturn(ImmutableList.of(existingTag));
-
-    operations.updateRuleTags(rule, ImmutableList.of(tag), authorizedUserSession);
-
-    verify(ruleTagDao).selectId(tag, session);
-    verify(ruleDao).selectTagsByRuleIds(ruleId, session);
-    verify(ruleTagOperations).deleteUnusedTags(session);
-    verify(ruleDao, never()).update(rule);
-  }
-
   @Test
   public void update_rule() throws Exception {
     RuleDto dto = new RuleDto().setId(1).setRepositoryKey("squid").setRuleKey("UselessImportCheck")
index 89fc2dcdbdaa7c89342967ca75632d3618812c18..32929d7b31ed753863c70be454d6cc50977329c0 100644 (file)
@@ -41,8 +41,6 @@ import org.sonar.core.profiling.Profiling;
 import org.sonar.core.rule.RuleDao;
 import org.sonar.core.rule.RuleDto;
 import org.sonar.core.rule.RuleParamDto;
-import org.sonar.core.rule.RuleRuleTagDto;
-import org.sonar.core.rule.RuleTagType;
 import org.sonar.core.technicaldebt.db.CharacteristicDao;
 import org.sonar.core.technicaldebt.db.CharacteristicDto;
 import org.sonar.server.es.ESIndex;
@@ -132,11 +130,6 @@ public class RuleRegistryTest {
       new RuleParamDto().setRuleId(3).setName("name")
     ));
 
-    when(ruleDao.selectTagsByRuleIds(newArrayList(3), session)).thenReturn(newArrayList(
-      new RuleRuleTagDto().setRuleId(3).setTag("tag1").setType(RuleTagType.SYSTEM),
-      new RuleRuleTagDto().setRuleId(3).setTag("tag2").setType(RuleTagType.SYSTEM),
-      new RuleRuleTagDto().setRuleId(3).setTag("tag").setType(RuleTagType.ADMIN)));
-
     when(characteristicDao.selectCharacteristicsByIds(newHashSet(11), session)).thenReturn(newArrayList(
       new CharacteristicDto().setId(11).setKey("MODULARITY").setName("Modularity").setParentId(10)));
     when(characteristicDao.selectCharacteristicsByIds(newHashSet(10), session)).thenReturn(newArrayList(
@@ -254,11 +247,6 @@ public class RuleRegistryTest {
       new RuleParamDto().setRuleId(3).setName("name")
     ));
 
-    when(ruleDao.selectTagsByRuleIds(newArrayList(3), session)).thenReturn(newArrayList(
-      new RuleRuleTagDto().setRuleId(3).setTag("tag1").setType(RuleTagType.SYSTEM),
-      new RuleRuleTagDto().setRuleId(3).setTag("tag2").setType(RuleTagType.SYSTEM),
-      new RuleRuleTagDto().setRuleId(3).setTag("tag").setType(RuleTagType.ADMIN)));
-
     when(characteristicDao.selectById(11, session)).thenReturn(new CharacteristicDto().setId(11).setKey("MODULARITY").setName("Modularity").setParentId(10));
     when(characteristicDao.selectById(10, session)).thenReturn(new CharacteristicDto().setId(10).setKey("REUSABILITY").setName("Reusability"));
 
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RuleTagLookupTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RuleTagLookupTest.java
deleted file mode 100644 (file)
index 4c0f494..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.server.rule;
-
-import com.google.common.collect.ImmutableList;
-import org.junit.Test;
-
-import java.util.Collection;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class RuleTagLookupTest {
-
-  @Test
-  public void should_pass_to_es_impl() {
-    ESRuleTags esRuleTags = mock(ESRuleTags.class);
-    Collection<String> tags = ImmutableList.of("tag1", "tag2");
-    when(esRuleTags.searchAllTags()).thenReturn(tags);
-    assertThat(new RuleTagLookup(esRuleTags).listAllTags()).isEqualTo(tags);
-    verify(esRuleTags).searchAllTags();
-  }
-}
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RuleTagOperationsTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RuleTagOperationsTest.java
deleted file mode 100644 (file)
index 471177b..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.server.rule;
-
-import com.google.common.collect.ImmutableList;
-import org.apache.ibatis.session.SqlSession;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.core.rule.RuleTagDao;
-import org.sonar.core.rule.RuleTagDto;
-import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.user.MockUserSession;
-import org.sonar.server.user.UserSession;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class RuleTagOperationsTest {
-
-  @Mock
-  private RuleTagDao ruleTagDao;
-
-  @Mock
-  private ESRuleTags esRuleTags;
-
-  UserSession authorizedUserSession = MockUserSession.create().setLogin("nicolas").setName("Nicolas").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
-  UserSession unauthorizedUserSession = MockUserSession.create().setLogin("nicolas").setName("Nicolas");
-
-  private RuleTagOperations operations;
-
-  @Before
-  public void setUp() {
-    operations = new RuleTagOperations(ruleTagDao, esRuleTags);
-  }
-
-  @Test(expected = ForbiddenException.class)
-  public void should_fail_on_unallowed_user() {
-    operations.create("polop", unauthorizedUserSession);
-  }
-
-  @Test(expected = BadRequestException.class)
-  public void should_fail_on_bad_tag() {
-    operations.create("! ! !", authorizedUserSession);
-  }
-
-  @Test(expected = BadRequestException.class)
-  public void should_fail_on_duplicate_tag() {
-    String newTag = "polop";
-    when(ruleTagDao.selectId(newTag)).thenReturn(42L);
-
-    operations.create(newTag, authorizedUserSession);
-  }
-
-  @Test
-  public void should_create_and_index_tag() {
-    String newTag = "polop";
-    when(ruleTagDao.selectId(newTag)).thenReturn(null);
-
-    operations.create(newTag, authorizedUserSession);
-
-    verify(ruleTagDao).selectId(newTag);
-    ArgumentCaptor<RuleTagDto> newTagDto = ArgumentCaptor.forClass(RuleTagDto.class);
-    verify(ruleTagDao).insert(newTagDto.capture());
-    assertThat(newTagDto.getValue().getTag()).isEqualTo(newTag);
-    verify(esRuleTags).put(newTagDto.getValue());
-  }
-
-  @Test
-  public void should_delete_unused_tags() {
-    long tagId = 42L;
-    String tagValue = "answerlifeanevrythng";
-    RuleTagDto unusedTag = new RuleTagDto().setId(tagId).setTag(tagValue);
-    SqlSession session = mock(SqlSession.class);
-    when(ruleTagDao.selectUnused(session)).thenReturn(ImmutableList.of(unusedTag));
-    operations.deleteUnusedTags(session);
-
-    verify(ruleTagDao).selectUnused(session);
-    verify(ruleTagDao).delete(tagId, session);
-    verify(esRuleTags).delete(tagValue);
-  }
-
-  @Test
-  public void should_do_nothing_if_no_unused_tags() {
-    SqlSession session = mock(SqlSession.class);
-    operations.deleteUnusedTags(session);
-
-    verify(ruleTagDao).selectUnused(session);
-    verifyNoMoreInteractions(ruleTagDao, esRuleTags);
-  }
-}
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RuleTagsTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RuleTagsTest.java
deleted file mode 100644 (file)
index f906ac5..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.server.rule;
-
-import com.google.common.collect.ImmutableList;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.core.rule.RuleTagDto;
-import org.sonar.server.user.UserSession;
-
-import java.util.Collection;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class RuleTagsTest {
-
-  @Mock
-  private RuleTagLookup ruleTagLookup;
-
-  @Mock
-  private RuleTagOperations ruleTagOperations;
-
-  private RuleTags ruleTags;
-
-  @Before
-  public void setUp() {
-    ruleTags = new RuleTags(ruleTagLookup, ruleTagOperations);
-  }
-
-  @Test
-  public void should_find_all_tags() {
-    Collection<String> tags = ImmutableList.of("tag1", "tag2");
-    when(ruleTagLookup.listAllTags()).thenReturn(tags);
-    assertThat(ruleTags.listAllTags()).isEqualTo(tags);
-    verify(ruleTagLookup).listAllTags();
-  }
-
-  @Test
-  public void should_create_tag() {
-    String tag = "polop";
-    RuleTagDto newTag = mock(RuleTagDto.class);
-    when(ruleTagOperations.create(eq(tag), any(UserSession.class))).thenReturn(newTag);
-    assertThat(ruleTags.create(tag)).isEqualTo(newTag);
-    verify(ruleTagOperations).create(eq(tag), any(UserSession.class));
-  }
-}
index d507fd008a9ab88ebce1e0b2db8e52e39d443c04..54684962be9b99fb7a8029f4c144171967575ea9 100644 (file)
@@ -200,27 +200,6 @@ public class RulesTest {
     verify(ruleOperations).deleteCustomRule(eq(rule), any(UserSession.class));
   }
 
-  @Test
-  public void pass_tags_to_update() {
-    final int ruleId = 11;
-    RuleDto rule = new RuleDto().setId(ruleId).setRepositoryKey("squid").setRuleKey("XPath_1387869254").setParentId(10);
-    when(ruleDao.selectById(ruleId)).thenReturn(rule);
-
-    rules.updateRuleTags(ruleId, null);
-    verify(ruleOperations).updateRuleTags(eq(rule), isA(List.class), any(UserSession.class));
-  }
-
-  @Test
-  public void prepare_empty_tag_list() {
-    final int ruleId = 11;
-    RuleDto rule = new RuleDto().setId(ruleId).setRepositoryKey("squid").setRuleKey("XPath_1387869254").setParentId(10);
-    when(ruleDao.selectById(ruleId)).thenReturn(rule);
-
-    List<String> tags = ImmutableList.of("tag1", "tag2");
-    rules.updateRuleTags(ruleId, tags);
-    verify(ruleOperations).updateRuleTags(eq(rule), eq(tags), any(UserSession.class));
-  }
-
   @Test
   public void find_by_key() {
     RuleKey key = RuleKey.of("polop", "palap");
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/ws/AddTagsWsHandlerTest.java b/sonar-server/src/test/java/org/sonar/server/rule/ws/AddTagsWsHandlerTest.java
deleted file mode 100644 (file)
index 3476eb1..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.server.rule.ws;
-
-import com.google.common.collect.ImmutableList;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.rule.Rule;
-import org.sonar.server.rule.Rules;
-import org.sonar.server.user.MockUserSession;
-import org.sonar.server.ws.WsTester;
-
-import java.util.List;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.isA;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class AddTagsWsHandlerTest {
-
-  @Mock
-  Rules rules;
-
-  WsTester tester;
-
-  @Before
-  public void setUp() throws Exception {
-    tester = new WsTester(new RulesWs(mock(RuleSearchWsHandler.class), mock(RuleShowWsHandler.class), new AddTagsWsHandler(rules), mock(RemoveTagsWsHandler.class)));
-  }
-
-  @Test
-  public void add_tags() throws Exception {
-    String ruleKey = "squid:AvoidCycle";
-    Rule rule = createStandardRule();
-    when(rules.findByKey(RuleKey.of("squid", "AvoidCycle"))).thenReturn(rule);
-
-    MockUserSession.set().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
-    WsTester.TestRequest request = tester.newPostRequest("api/rules", "add_tags").setParam("key", ruleKey).setParam("tags", "tag1,tag2");
-    request.execute().assertNoContent();
-
-    ArgumentCaptor<Object> newTagsCaptor = ArgumentCaptor.forClass(Object.class);
-    verify(rules).updateRuleTags(isA(Integer.class), newTagsCaptor.capture());
-    Object newTags = newTagsCaptor.getValue();
-    assertThat(newTags).isInstanceOf(List.class);
-    assertThat((List<String>) newTags).hasSize(4).containsOnly("admin1", "admin2", "tag1", "tag2");
-  }
-
-  @Test(expected = NotFoundException.class)
-  public void add_tags_key_not_found() throws Exception {
-    tester.newPostRequest("api/rules", "add_tags").setParam("key", "polop:palap").setParam("tags", "tag1,tag2").execute();
-  }
-
-  private Rule create(String repoKey, String key, String name, String description) {
-    Rule mockRule = mock(Rule.class);
-    when(mockRule.adminTags()).thenReturn(ImmutableList.of("admin1", "admin2"));
-    return mockRule;
-  }
-
-  private Rule createStandardRule() {
-    return create("xoo", "RuleWithTags", "Rule with tags", "This rule has tags set");
-  }
-}
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/ws/RemoveTagsWsHandlerTest.java b/sonar-server/src/test/java/org/sonar/server/rule/ws/RemoveTagsWsHandlerTest.java
deleted file mode 100644 (file)
index 37b5c1a..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.server.rule.ws;
-
-import com.google.common.collect.ImmutableList;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.server.rule.Rule;
-import org.sonar.server.rule.Rules;
-import org.sonar.server.user.MockUserSession;
-import org.sonar.server.ws.WsTester;
-
-import java.util.List;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.isA;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class RemoveTagsWsHandlerTest {
-
-  @Mock
-  Rules rules;
-
-  WsTester tester;
-
-  @Before
-  public void setUp() throws Exception {
-    tester = new WsTester(new RulesWs(mock(RuleSearchWsHandler.class), mock(RuleShowWsHandler.class), mock(AddTagsWsHandler.class), new RemoveTagsWsHandler(rules)));
-  }
-
-  @Test
-  public void add_tags() throws Exception {
-    String ruleKey = "squid:AvoidCycle";
-    Rule rule = createStandardRule();
-    when(rules.findByKey(RuleKey.of("squid", "AvoidCycle"))).thenReturn(rule);
-
-    MockUserSession.set().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
-    WsTester.TestRequest request = tester.newPostRequest("api/rules", "remove_tags").setParam("key", ruleKey).setParam("tags", "admin2,admin3,polop");
-    request.execute().assertNoContent();
-
-    ArgumentCaptor<Object> newTagsCaptor = ArgumentCaptor.forClass(Object.class);
-    verify(rules).updateRuleTags(isA(Integer.class), newTagsCaptor.capture());
-    Object newTags = newTagsCaptor.getValue();
-    assertThat(newTags).isInstanceOf(List.class);
-    assertThat((List<String>) newTags).hasSize(2).containsOnly("admin1", "admin4");
-  }
-
-  private Rule create(String repoKey, String key, String name, String description) {
-    Rule mockRule = mock(Rule.class);
-    when(mockRule.adminTags()).thenReturn(ImmutableList.of("admin1", "admin2", "admin3", "admin4"));
-    return mockRule;
-  }
-
-  private Rule createStandardRule() {
-    return create("xoo", "RuleWithTags", "Rule with tags", "This rule has tags set");
-  }
-}
index fb896e371ede7d311a0cd168ca3e04b94bb075a7..f9022f542712640afa572eb22e7c8e92c01b3600 100644 (file)
@@ -68,7 +68,7 @@ public class RuleSearchWsHandlerTest {
 
   @Before
   public void setUp() throws Exception {
-    tester = new WsTester(new RulesWs(new RuleSearchWsHandler(rules, languages), mock(RuleShowWsHandler.class), mock(AddTagsWsHandler.class), mock(RemoveTagsWsHandler.class)));
+    tester = new WsTester(new RulesWs(new RuleSearchWsHandler(rules, languages), mock(RuleShowWsHandler.class)));
   }
 
   @Test
index 62817bd59abfc9e652292055a0d43462782216c0..e426dd95bf826ba4e8f2d7879de877ce768983f7 100644 (file)
@@ -75,7 +75,7 @@ public class RuleShowWsHandlerTest {
 
   @Before
   public void setUp() throws Exception {
-    tester = new WsTester(new RulesWs(mock(RuleSearchWsHandler.class), new RuleShowWsHandler(rules, ruleFinder, i18n, languages), mock(AddTagsWsHandler.class), mock(RemoveTagsWsHandler.class)));
+    tester = new WsTester(new RulesWs(mock(RuleSearchWsHandler.class), new RuleShowWsHandler(rules, ruleFinder, i18n, languages)));
   }
 
   @Test
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleTagsWsTest.java b/sonar-server/src/test/java/org/sonar/server/rule/ws/RuleTagsWsTest.java
deleted file mode 100644 (file)
index 2981115..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.server.rule.ws;
-
-import com.google.common.collect.ImmutableList;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.core.rule.RuleTagDto;
-import org.sonar.server.rule.RuleTags;
-import org.sonar.server.ws.WsTester;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-import static org.mockito.Mockito.*;
-
-@RunWith(MockitoJUnitRunner.class)
-public class RuleTagsWsTest {
-
-  @Mock
-  RuleTags ruleTags;
-
-  WsTester tester;
-
-  @Before
-  public void setUp() {
-    tester = new WsTester(new RuleTagsWs(ruleTags));
-  }
-
-  @Test
-  public void define_ws() throws Exception {
-    WebService.Controller controller = tester.controller("api/rule_tags");
-    assertThat(controller).isNotNull();
-    assertThat(controller.path()).isEqualTo("api/rule_tags");
-    assertThat(controller.description()).isNotEmpty();
-    assertThat(controller.actions()).hasSize(2);
-
-    WebService.Action search = controller.action("list");
-    assertThat(search).isNotNull();
-    assertThat(search.key()).isEqualTo("list");
-    assertThat(search.handler()).isNotNull();
-    assertThat(search.since()).isEqualTo("4.2");
-    assertThat(search.isPost()).isFalse();
-
-    WebService.Action create = controller.action("create");
-    assertThat(create).isNotNull();
-    assertThat(create.key()).isEqualTo("create");
-    assertThat(create.handler()).isNotNull();
-    assertThat(create.since()).isEqualTo("4.2");
-    assertThat(create.isPost()).isTrue();
-    assertThat(create.params()).hasSize(1);
-    assertThat(create.param("tag")).isNotNull();
-  }
-
-  @Test
-  public void list_tags() throws Exception {
-    when(ruleTags.listAllTags()).thenReturn(ImmutableList.of("tag1", "tag2", "tag3"));
-    tester.newGetRequest("api/rule_tags", "list").execute().assertJson(getClass(), "list.json");
-    verify(ruleTags).listAllTags();
-  }
-
-  @Test
-  public void create_ok() throws Exception {
-    String tag = "newtag";
-    Long tagId = 42L;
-    RuleTagDto newTag = new RuleTagDto().setId(tagId).setTag(tag);
-    when(ruleTags.create("newtag")).thenReturn(newTag);
-
-    WsTester.TestRequest request = tester.newPostRequest("api/rule_tags", "create").setParam("tag", tag);
-    request.execute().assertJson(getClass(), "create_ok.json");
-    verify(ruleTags).create(tag);
-  }
-
-  @Test
-  public void create_missing_parameter() throws Exception {
-    WsTester.TestRequest request = tester.newPostRequest("api/rule_tags", "create");
-    try {
-      request.execute();
-      fail();
-    } catch (IllegalArgumentException e) {
-      verifyZeroInteractions(ruleTags);
-    }
-  }
-}
index a513d509ff4fe7a4a705753489b304fa497ea578..45cbb6b365ecd21112bf44e29b31a6a915b907e1 100644 (file)
@@ -38,17 +38,11 @@ public class RulesWsTest {
   @Mock
   RuleShowWsHandler showHandler;
 
-  @Mock
-  AddTagsWsHandler addTagsWsHandler;
-
-  @Mock
-  RemoveTagsWsHandler removeTagsWsHandler;
-
   WsTester tester;
 
   @Before
   public void setUp() {
-    tester = new WsTester(new RulesWs(searchHandler, showHandler, addTagsWsHandler, removeTagsWsHandler));
+    tester = new WsTester(new RulesWs(searchHandler, showHandler));
   }
 
   @Test
@@ -57,7 +51,7 @@ public class RulesWsTest {
     assertThat(controller).isNotNull();
     assertThat(controller.path()).isEqualTo("api/rules");
     assertThat(controller.description()).isNotEmpty();
-    assertThat(controller.actions()).hasSize(4);
+    assertThat(controller.actions()).hasSize(2);
 
     WebService.Action list = controller.action("list");
     assertThat(list).isNotNull();
@@ -73,21 +67,5 @@ public class RulesWsTest {
     assertThat(show.since()).isEqualTo("4.2");
     assertThat(show.isPost()).isFalse();
     assertThat(show.isInternal()).isFalse();
-
-    WebService.Action addTags = controller.action("add_tags");
-    assertThat(addTags).isNotNull();
-    assertThat(addTags.handler()).isNotNull();
-    assertThat(addTags.since()).isEqualTo("4.2");
-    assertThat(addTags.isPost()).isTrue();
-    assertThat(addTags.isInternal()).isFalse();
-    assertThat(addTags.params()).hasSize(2);
-
-    WebService.Action removeTags = controller.action("remove_tags");
-    assertThat(removeTags).isNotNull();
-    assertThat(removeTags.handler()).isNotNull();
-    assertThat(removeTags.since()).isEqualTo("4.2");
-    assertThat(removeTags.isPost()).isTrue();
-    assertThat(removeTags.isInternal()).isFalse();
-    assertThat(removeTags.params()).hasSize(2);
   }
 }
diff --git a/sonar-server/src/test/java/org/sonar/server/rule2/RegisterRulesMediumTest.java b/sonar-server/src/test/java/org/sonar/server/rule2/RegisterRulesMediumTest.java
new file mode 100644 (file)
index 0000000..aaa75d5
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.server.rule2;
+
+import org.junit.Test;
+import org.sonar.api.rule.Severity;
+import org.sonar.api.server.rule.RuleParamType;
+import org.sonar.api.server.rule.RulesDefinition;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.rule.RuleDto;
+import org.sonar.core.rule.RuleParamDto;
+import org.sonar.server.db.DbClient;
+import org.sonar.server.platform.Platform;
+import org.sonar.server.rule2.index.RuleIndex;
+import org.sonar.server.rule2.index.RuleQuery;
+import org.sonar.server.rule2.index.RuleResult;
+import org.sonar.server.rule2.persistence.RuleDao;
+import org.sonar.server.search.QueryOptions;
+import org.sonar.server.tester.ServerTester;
+
+import java.util.List;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class RegisterRulesMediumTest {
+
+  @org.junit.Rule
+  public ServerTester tester = new ServerTester().addComponents(XooRulesDefinition.class);
+
+  @Test
+  public void register_rules_at_startup() throws Exception {
+    verifyRulesInDb();
+
+    RuleIndex index = tester.get(RuleIndex.class);
+    index.refresh();
+
+    RuleResult searchResult = index.search(new RuleQuery(), new QueryOptions());
+    assertThat(searchResult.getTotal()).isEqualTo(2);
+    assertThat(searchResult.getHits()).hasSize(2);
+  }
+
+  @Test
+  public void index_even_if_no_changes() throws Exception {
+    RuleIndex index = tester.get(RuleIndex.class);
+
+    verifyRulesInDb();
+
+    // clear ES but keep db
+    tester.clearIndexes();
+    verifyRulesInDb();
+    RuleResult searchResult = index.search(new RuleQuery(), new QueryOptions());
+    assertThat(searchResult.getTotal()).isEqualTo(0);
+    assertThat(searchResult.getHits()).hasSize(0);
+
+    // db is not updated (same rules) but es must be reindexed
+    tester.get(Platform.class).restart();
+
+    index = tester.get(RuleIndex.class);
+    index.refresh();
+    verifyRulesInDb();
+    searchResult = index.search(new RuleQuery().setKey("xoo:x1"), new QueryOptions());
+    assertThat(searchResult.getTotal()).isEqualTo(1);
+    assertThat(searchResult.getHits()).hasSize(1);
+    assertThat(searchResult.getHits().get(0).params()).hasSize(1);
+  }
+
+  private void verifyRulesInDb() {
+    RuleDao dao = tester.get(RuleDao.class);
+    DbClient dbClient = tester.get(DbClient.class);
+    DbSession session = dbClient.openSession(false);
+    List<RuleDto> rules = dao.findAll(session);
+    assertThat(rules).hasSize(2);
+    List<RuleParamDto> ruleParams = dao.findAllRuleParams(session);
+    assertThat(ruleParams).hasSize(1);
+  }
+
+  public static class XooRulesDefinition implements RulesDefinition {
+    @Override
+    public void define(Context context) {
+      NewRepository repository = context.createRepository("xoo", "xoo").setName("Xoo Repo");
+      repository.createRule("x1")
+        .setName("x1 name")
+        .setHtmlDescription("x1 desc")
+        .setSeverity(Severity.MINOR)
+        .createParam("acceptWhitespace")
+        .setDefaultValue("false")
+        .setType(RuleParamType.BOOLEAN)
+        .setDescription("Accept whitespaces on the line");
+
+
+
+      repository.createRule("x2")
+        .setName("x2 name")
+        .setHtmlDescription("x2 desc")
+        .setSeverity(Severity.MAJOR);
+      repository.done();
+    }
+  }
+}
index 2c7e8890be179df4237a9b1f6fe5a766ae84d3f3..a5865a143f5decd4cf7223bb99c208aa83919d80 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.rule2;
 
+import com.google.common.collect.Sets;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -80,6 +81,7 @@ public class RegisterRulesTest extends AbstractDaoTestCase {
   public void insert_new_rules() {
     execute(new FakeRepositoryV1());
 
+    // verify db
     assertThat(dbClient.ruleDao().findAll(dbSession)).hasSize(2);
     RuleKey ruleKey1 = RuleKey.of("fake", "rule1");
     RuleDto rule1 = dbClient.ruleDao().getByKey(ruleKey1, dbSession);
@@ -121,16 +123,22 @@ public class RegisterRulesTest extends AbstractDaoTestCase {
     execute(new FakeRepositoryV1());
     assertThat(dbClient.ruleDao().findAll(dbSession)).hasSize(2);
 
+    // user adds tags
+    RuleKey ruleKey1 = RuleKey.of("fake", "rule1");
+    RuleDto rule1 = dbClient.ruleDao().getByKey(ruleKey1, dbSession);
+    rule1.setTags(Sets.newHashSet("usertag1", "usertag2"));
+    dbClient.ruleDao().update(rule1, dbSession);
+    dbSession.commit();
+
     when(system.now()).thenReturn(DATE2.getTime());
     execute(new FakeRepositoryV2());
 
     // rule1 has been updated
-    RuleKey ruleKey1 = RuleKey.of("fake", "rule1");
-    RuleDto rule1 = dbClient.ruleDao().getByKey(ruleKey1, dbSession);
+    rule1 = dbClient.ruleDao().getByKey(ruleKey1, dbSession);
     assertThat(rule1.getName()).isEqualTo("One v2");
     assertThat(rule1.getDescription()).isEqualTo("Description of One v2");
     assertThat(rule1.getSeverityString()).isEqualTo(Severity.INFO);
-    assertThat(rule1.getTags()).isEmpty();
+    assertThat(rule1.getTags()).containsOnly("usertag1", "usertag2");
     assertThat(rule1.getSystemTags()).containsOnly("tag1", "tag4");
     assertThat(rule1.getConfigKey()).isEqualTo("config1 v2");
     assertThat(rule1.getStatus()).isEqualTo(RuleStatus.READY.toString());
@@ -152,6 +160,7 @@ public class RegisterRulesTest extends AbstractDaoTestCase {
     // rule3 has been created
     RuleDto rule3 = dbClient.ruleDao().getByKey(RuleKey.of("fake", "rule3"), dbSession);
     assertThat(rule3).isNotNull();
+    assertThat(rule3.getStatus()).isEqualTo(RuleStatus.READY.toString());
   }
 
   @Test
index 86a2f90a317aad1f73a030b50f22b58be5edb308..37bd788237cb881d56cad66736dc34fb5a2ce508 100644 (file)
@@ -386,16 +386,4 @@ public class RuleDaoTest extends AbstractDaoTestCase {
 
     checkTables("update_parameter", "rules_parameters");
   }
-
-  @Test
-  public void select_tags_by_rule() throws Exception {
-    setupData("select_tags_by_rule_id");
-
-    RuleDto rule = dao.getById(1, session);
-    assertThat(rule.getSystemTags()).hasSize(2);
-    assertThat(rule.getTags()).hasSize(3);
-    assertThat(rule.getTags()).containsOnly("tag1", "tag2","tag3");
-    assertThat(rule.getSystemTags()).containsOnly("systag1", "systag2");
-
-  }
 }
index 0e1da62275368e5cc5869ecba49f3fdbc23ce2d6..2437b39df8924cd3bffe055da57940290193fb08 100644 (file)
@@ -43,12 +43,12 @@ public class DataStoreCleanup implements ServerComponent {
     this.myBatis = myBatis;
   }
 
-  public void clear() {
-    truncateDb();
-    truncateEs();
+  public void clearAll() {
+    clearDb();
+    clearIndexes();
   }
 
-  private void truncateDb() {
+  public void clearDb() {
     DbSession dbSession = myBatis.openSession(false);
     Connection connection = dbSession.getConnection();
     try {
@@ -68,7 +68,7 @@ public class DataStoreCleanup implements ServerComponent {
     }
   }
 
-  private void truncateEs() {
+  public void clearIndexes() {
     LOG.info("Truncate es indices");
     Client client = esNode.client();
     client.prepareDeleteByQuery(
index 783cff96a7c48520a693c0e4d4d80f32c9623f1f..5e5c1d4dc281c5611aa301a0935917672c19b5db 100644 (file)
@@ -159,7 +159,12 @@ public class ServerTester extends ExternalResource {
    */
   public void clearDataStores() {
     checkStarted();
-    get(DataStoreCleanup.class).clear();
+    get(DataStoreCleanup.class).clearAll();
+  }
+
+  public void clearIndexes() {
+    checkStarted();
+    get(DataStoreCleanup.class).clearIndexes();
   }
 
   /**
index f350c52f77bfc70534c2a9ec435f97aa51b55129..0c0534a73ab698d30a743c6aba774f814e3a1faf 100644 (file)
@@ -7,9 +7,6 @@
                    status="READY" priority="4" cardinality="SINGLE" parent_id="[null]" language="java"/>
   <rules_parameters id="1" rule_id="2" default_value="default value one" description="parameter one" name="param1" param_type="STRING"/>
   <rules_parameters id="2" rule_id="2" default_value="default value two" description="parameter two" name="param2" param_type="STRING"/>
-  <rule_tags id="1" rule_id="2" tag="tag1" tag_type="SYSTEM"/>
-  <rule_tags id="2" rule_id="2" tag="tag3" tag_type="SYSTEM"/>
-  <rule_tags id="3" rule_id="2" tag="tag5" tag_type="SYSTEM"/>
 
   <rules tags="[null]" system_tags="[null]" id="3" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="rule2" name="Two" description="Description of Two"
                    status="DEPRECATED" priority="0" cardinality="SINGLE" parent_id="[null]" language="java"/>
index fdf0c45f4891ca2c03a93551ce71d9e64dee661b..2b80f2f44660ef706695988644ba70d73d854a7b 100644 (file)
   <rules tags="[null]" system_tags="[null]" id="4" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="[null]" name="Two" description="Description of Two"
          status="DEPRECATED" priority="0" cardinality="SINGLE" parent_id="[null]" language="java"/>
 
-  <rule_tags id="3" tag="tag1"/>
-  <rule_tags id="4" tag="tag3"/>
-  <rule_tags id="5" tag="tag5"/>
-
-  <rules_rule_tags id="3" rule_id="3" rule_tag_id="3" tag_type="SYSTEM"/>
-  <rules_rule_tags id="4" rule_id="3" rule_tag_id="4" tag_type="SYSTEM"/>
-  <rules_rule_tags id="5" rule_id="3" rule_tag_id="5" tag_type="SYSTEM"/>
-
 </dataset>
index 2c47ca230049911e65cad8cad40d67d37051eab1..c894e0097fd7afd4bbdfab5feb5bb7ff7ac5dc93 100644 (file)
@@ -8,10 +8,4 @@
 
   <rules_parameters id="1" rule_id="1" name="deprecated-prop" description="[null]" param_type="STRING"/>
 
-  <rule_tags id="1" tag="formertag1"/>
-  <rule_tags id="2" tag="formertag2"/>
-
-  <rules_rule_tags id="1" rule_id="1" rule_tag_id="1" tag_type="SYSTEM"/>
-  <rules_rule_tags id="2" rule_id="1" rule_tag_id="2" tag_type="ADMIN"/>
-
 </dataset>
index 0578a3d9262fa703b07b3ea99f4070a8c67e7fa2..24c65625e65deae231817d5fba13eaad223f6c38 100644 (file)
   <rules_parameters id="1" rule_id="2" default_value="default value one" description="parameter one" name="param1" param_type="STRING"/>
   <rules_parameters id="2" rule_id="2" default_value="default value two" description="parameter two" name="param2" param_type="STRING"/>
 
-  <rule_tags id="1" tag="tag1"/>
-  <rule_tags id="2" tag="tag3"/>
-  <rule_tags id="3" tag="tag5"/>
-
-  <rules_rule_tags id="1" rule_id="2" rule_tag_id="1" tag_type="SYSTEM"/>
-  <rules_rule_tags id="2" rule_id="2" rule_tag_id="2" tag_type="SYSTEM"/>
-  <rules_rule_tags id="3" rule_id="2" rule_tag_id="3" tag_type="SYSTEM"/>
-
   <rules tags="[null]" system_tags="[null]" id="3" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="[null]" name="Two" description="Description of Two"
          status="DEPRECATED" priority="0" cardinality="SINGLE" parent_id="[null]" language="java"
          characteristic_id="[null]" default_characteristic_id="[null]"
index 7ac8818755730dfd3eea012cd504593a8fbb9381..733251902b626a7ad04ab1862a4f5b193c08bc18 100644 (file)
   <rules_parameters id="1" rule_id="1" default_value="default value one" description="parameter one" name="param1" param_type="STRING"/>
   <rules_parameters id="2" rule_id="1" default_value="default value two" description="parameter two" name="param2" param_type="STRING"/>
 
-  <rule_tags id="1" tag="tag1"/>
-  <rule_tags id="3" tag="tag3"/>
-  <rule_tags id="4" tag="tag4"/>
-  <rule_tags id="5" tag="tag5"/>
-
-  <rules_rule_tags id="1" rule_id="1" rule_tag_id="1" tag_type="SYSTEM"/>
-  <rules_rule_tags id="3" rule_id="1" rule_tag_id="3" tag_type="SYSTEM"/>
-  <rules_rule_tags id="4" rule_id="1" rule_tag_id="4" tag_type="ADMIN"/>
-  <rules_rule_tags id="5" rule_id="1" rule_tag_id="5" tag_type="SYSTEM"/>
-
   <rules tags="[null]" system_tags="[null]" id="2" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="[null]" name="Two" description="Description of Two"
          status="DEPRECATED" priority="0" cardinality="SINGLE" parent_id="[null]" language="java"
          characteristic_id="[null]" default_characteristic_id="[null]"
index dddc193f1d819d4bf8def4d1a33f77ddb28d009f..7f35c78b072de0bc17487331f3edb78e996f6b1b 100644 (file)
 
   <rules_parameters id="1" rule_id="1" name="param1" description="[null]" param_type="STRING"/>
 
-  <rule_tags id="1" tag="tag1"/>
-  <rule_tags id="2" tag="tag2"/>
-  <rule_tags id="3" tag="tag3"/>
-  <rule_tags id="4" tag="tag4"/>
-
-  <rules_rule_tags id="1" rule_id="1" rule_tag_id="1" tag_type="SYSTEM"/>
-  <rules_rule_tags id="2" rule_id="1" rule_tag_id="2" tag_type="SYSTEM"/>
-  <rules_rule_tags id="3" rule_id="1" rule_tag_id="3" tag_type="ADMIN"/>
-  <rules_rule_tags id="4" rule_id="1" rule_tag_id="4" tag_type="ADMIN"/>
-
   <rules tags="[null]" system_tags="[null]" id="2" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="old_config_key2" name="old name2" description="old description2"
          status="READY" priority="1" cardinality="SINGLE" parent_id="[null]"/>
 
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/ws/RuleTagsWsTest/create_ok.json b/sonar-server/src/test/resources/org/sonar/server/rule/ws/RuleTagsWsTest/create_ok.json
deleted file mode 100644 (file)
index 708d9ff..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"id":42,"tag":"newtag"}
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/ws/RuleTagsWsTest/list.json b/sonar-server/src/test/resources/org/sonar/server/rule/ws/RuleTagsWsTest/list.json
deleted file mode 100644 (file)
index eeeb09c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-["tag1","tag2","tag3"]
index f350c52f77bfc70534c2a9ec435f97aa51b55129..0c0534a73ab698d30a743c6aba774f814e3a1faf 100644 (file)
@@ -7,9 +7,6 @@
                    status="READY" priority="4" cardinality="SINGLE" parent_id="[null]" language="java"/>
   <rules_parameters id="1" rule_id="2" default_value="default value one" description="parameter one" name="param1" param_type="STRING"/>
   <rules_parameters id="2" rule_id="2" default_value="default value two" description="parameter two" name="param2" param_type="STRING"/>
-  <rule_tags id="1" rule_id="2" tag="tag1" tag_type="SYSTEM"/>
-  <rule_tags id="2" rule_id="2" tag="tag3" tag_type="SYSTEM"/>
-  <rule_tags id="3" rule_id="2" tag="tag5" tag_type="SYSTEM"/>
 
   <rules tags="[null]" system_tags="[null]" id="3" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="rule2" name="Two" description="Description of Two"
                    status="DEPRECATED" priority="0" cardinality="SINGLE" parent_id="[null]" language="java"/>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/persistence/RuleDaoTest/select_tags_by_rule_id.xml b/sonar-server/src/test/resources/org/sonar/server/rule2/persistence/RuleDaoTest/select_tags_by_rule_id.xml
deleted file mode 100644 (file)
index 3feba4d..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<dataset>
-
-    <rules tags="tag1,tag2,tag3" system_tags="systag1,systag2" id="1" plugin_rule_key="NewRuleKey" plugin_name="plugin" name="new name" description="new description" status="DEPRECATED"
-           plugin_config_key="NewConfigKey" priority="0" cardinality="MULTIPLE" language="dart" created_at="2013-12-16" updated_at="2013-12-17" parent_id="3"
-           note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]"
-           characteristic_id="100" default_characteristic_id="101"
-           remediation_function="linear" default_remediation_function="linear_offset"
-           remediation_coeff="1h" default_remediation_coeff="5d"
-           remediation_offset="5min" default_remediation_offset="10h"
-           effort_to_fix_description="squid.S115.effortToFix"
-            />
-
-</dataset>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/persistence/RuleDaoTest/select_tags_by_rule_ids.xml b/sonar-server/src/test/resources/org/sonar/server/rule2/persistence/RuleDaoTest/select_tags_by_rule_ids.xml
deleted file mode 100644 (file)
index 8d252e5..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<dataset>
-
-  <rule_tags id="3" tag="tag1"/>
-  <rule_tags id="4" tag="tag3"/>
-  <rule_tags id="5" tag="tag5"/>
-
-  <rules_rule_tags id="3" rule_id="3" rule_tag_id="3" tag_type="SYSTEM"/>
-  <rules_rule_tags id="4" rule_id="3" rule_tag_id="4" tag_type="SYSTEM"/>
-  <rules_rule_tags id="5" rule_id="4" rule_tag_id="5" tag_type="SYSTEM"/>
-
-</dataset>
index 7e06483dcd548789e796998af962d88946ea3637..beabf3d073590886876ca5c53f69f35bdbef16ca 100644 (file)
@@ -33,9 +33,7 @@ import org.sonar.wsclient.qprofile.internal.DefaultQProfileClient;
 import org.sonar.wsclient.qualitygate.QualityGateClient;
 import org.sonar.wsclient.qualitygate.internal.DefaultQualityGateClient;
 import org.sonar.wsclient.rule.RuleClient;
-import org.sonar.wsclient.rule.RuleTagClient;
 import org.sonar.wsclient.rule.internal.DefaultRuleClient;
-import org.sonar.wsclient.rule.internal.DefaultRuleTagClient;
 import org.sonar.wsclient.system.SystemClient;
 import org.sonar.wsclient.system.internal.DefaultSystemClient;
 import org.sonar.wsclient.user.UserClient;
@@ -111,13 +109,6 @@ public class SonarClient {
     return new DefaultProjectClient(requestFactory);
   }
 
-  /**
-   * New client to interact with web services related to rule tags
-   */
-  public RuleTagClient ruleTagClient() {
-    return new DefaultRuleTagClient(requestFactory);
-  }
-
   /**
    * New client to interact with web services related to rules
    */
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/rule/RuleTagClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/rule/RuleTagClient.java
deleted file mode 100644 (file)
index b1d8e93..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.wsclient.rule;
-
-import java.util.Collection;
-
-/**
- * Allows management of rule tags
- * @since 4.2
- */
-public interface RuleTagClient {
-
-  /**
-   * List all tags
-   */
-  Collection<String> list();
-
-  /**
-   * Create a new tag
-   */
-  void create(String tag);
-}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/rule/internal/DefaultRuleTagClient.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/rule/internal/DefaultRuleTagClient.java
deleted file mode 100644 (file)
index 62f15a1..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.wsclient.rule.internal;
-
-import org.json.simple.JSONValue;
-import org.sonar.wsclient.internal.HttpRequestFactory;
-import org.sonar.wsclient.rule.RuleTagClient;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Do not instantiate this class, but use {@link org.sonar.wsclient.SonarClient#ruleTagClient()}.
- */
-public class DefaultRuleTagClient implements RuleTagClient {
-
-  private static final String ROOT_URL = "/api/rule_tags";
-  private static final String LIST_URL = ROOT_URL + "/list";
-  private static final String CREATE_URL = ROOT_URL + "/create";
-
-  private final HttpRequestFactory requestFactory;
-
-  public DefaultRuleTagClient(HttpRequestFactory requestFactory) {
-    this.requestFactory = requestFactory;
-  }
-
-  @Override
-  @SuppressWarnings("unchecked")
-  public Collection<String> list() {
-    String json = requestFactory.get(LIST_URL, Collections.<String, Object> emptyMap());
-    return (Collection<String>) JSONValue.parse(json);
-  }
-
-  @Override
-  public void create(String tag) {
-    Map<String, Object> params = new HashMap<String, Object>();
-    params.put("tag", tag);
-    requestFactory.post(CREATE_URL, params);
-  }
-}
index 1ca87ea7322b2ff8df4531153187e74559f69189..3f3c6e53050908dbaf4565082ed5b72f8f390e11 100644 (file)
@@ -27,7 +27,6 @@ import org.sonar.wsclient.project.internal.DefaultProjectClient;
 import org.sonar.wsclient.qprofile.internal.DefaultQProfileClient;
 import org.sonar.wsclient.qualitygate.internal.DefaultQualityGateClient;
 import org.sonar.wsclient.rule.internal.DefaultRuleClient;
-import org.sonar.wsclient.rule.internal.DefaultRuleTagClient;
 import org.sonar.wsclient.system.internal.DefaultSystemClient;
 import org.sonar.wsclient.user.internal.DefaultUserClient;
 
@@ -43,7 +42,6 @@ public class SonarClientTest {
     assertThat(client.userClient()).isNotNull().isInstanceOf(DefaultUserClient.class);
     assertThat(client.permissionClient()).isNotNull().isInstanceOf(DefaultPermissionClient.class);
     assertThat(client.projectClient()).isNotNull().isInstanceOf(DefaultProjectClient.class);
-    assertThat(client.ruleTagClient()).isNotNull().isInstanceOf(DefaultRuleTagClient.class);
     assertThat(client.ruleClient()).isNotNull().isInstanceOf(DefaultRuleClient.class);
     assertThat(client.qualityGateClient()).isNotNull().isInstanceOf(DefaultQualityGateClient.class);
     assertThat(client.qProfileClient()).isNotNull().isInstanceOf(DefaultQProfileClient.class);
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/rule/internal/DefaultRuleTagClientTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/rule/internal/DefaultRuleTagClientTest.java
deleted file mode 100644 (file)
index ae85b5b..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.wsclient.rule.internal;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.wsclient.MockHttpServerInterceptor;
-import org.sonar.wsclient.internal.HttpRequestFactory;
-
-import java.util.Collection;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.MapAssert.entry;
-
-public class DefaultRuleTagClientTest {
-
-  @Rule
-  public MockHttpServerInterceptor httpServer = new MockHttpServerInterceptor();
-
-  private DefaultRuleTagClient client;
-
-  @Before
-  public void initClient() {
-    HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url());
-    this.client = new DefaultRuleTagClient(requestFactory);
-  }
-
-  @Test
-  public void should_list_tags() {
-    httpServer.stubResponseBody("[\"tag1\",\"tag2\",\"tag3\"]");
-
-    Collection<String> result = client.list();
-
-    assertThat(httpServer.requestedPath()).isEqualTo("/api/rule_tags/list");
-    assertThat(result).containsOnly("tag1", "tag2", "tag3");
-  }
-
-  @Test
-  public void should_create_rule_tag() {
-    httpServer.stubStatusCode(200);
-
-    final String newTag = "polop";
-    client.create(newTag);
-
-    assertThat(httpServer.requestedPath()).isEqualTo("/api/rule_tags/create");
-    assertThat(httpServer.requestParams()).includes(entry("tag", newTag));
-  }
-
-}