From afba94b772bf859f736f8874d4fa3bbaf2d7356d Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Wed, 21 May 2014 15:54:48 +0200 Subject: [PATCH] SONAR-5242 - Fixed deactiveRule for qualityprofile WS --- .../server/qualityprofile/persistence/ActiveRuleDao.java | 9 +++++++-- .../src/main/java/org/sonar/server/search/BaseIndex.java | 8 ++++---- .../qualityprofile/ActiveRuleServiceMediumTest.java | 3 --- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/persistence/ActiveRuleDao.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/persistence/ActiveRuleDao.java index 690eb101e9b..898593d0010 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/persistence/ActiveRuleDao.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/persistence/ActiveRuleDao.java @@ -188,8 +188,13 @@ public class ActiveRuleDao extends BaseDao findByProfileKey(QualityProfileKey profileKey, DbSession session) { - int id = this.getQualityProfileId(profileKey, session); - return mapper(session).selectByProfileId(id); + //TODO try/catch due to legacy selectByProfileId SQL. + try { + int id = this.getQualityProfileId(profileKey, session); + return mapper(session).selectByProfileId(id); + } catch (Exception e) { + throw new IllegalArgumentException("Quality profile not found: "+profileKey.toString()); + } } public void removeParamByProfileKey(QualityProfileKey profileKey, DbSession session) { diff --git a/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java b/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java index 4283af1c6ca..43aa32371df 100644 --- a/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java +++ b/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java @@ -255,8 +255,8 @@ public abstract class BaseIndex, K extends Serializable> getClient() .prepareDelete() .setIndex(this.getIndexName()) - .setType(this.indexDefinition.getIndexType()) - .setIndex(this.getKeyValue(key)) + .setType(this.getIndexType()) + .setId(this.getKeyValue(key)) .get(); } @@ -266,7 +266,7 @@ public abstract class BaseIndex, K extends Serializable> //TODO don't really know what to do here for the moment... } else { throw new IllegalStateException("Index " + this.getIndexName() + - " cannot execute INSERT for class: " + obj.getClass()); + " cannot execute DELETE for class: " + obj.getClass()); } } @@ -275,7 +275,7 @@ public abstract class BaseIndex, K extends Serializable> try { this.deleteDocument(key); } catch (Exception e) { - LOG.error("Could not DELETE _id:{} for index {}: {}", + LOG.error("Could not DELETE _id = '{}' for index '{}': {}", this.getKeyValue(key), this.getIndexName(), e.getMessage()); } } diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleServiceMediumTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleServiceMediumTest.java index e949da77da7..1c90461cf1f 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleServiceMediumTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleServiceMediumTest.java @@ -302,7 +302,6 @@ public class ActiveRuleServiceMediumTest { } @Test - @Ignore public void deactivate() throws Exception { // activation grantPermission(); @@ -343,7 +342,6 @@ public class ActiveRuleServiceMediumTest { } @Test - @Ignore public void deactivation_fails_if_profile_not_found() throws Exception { grantPermission(); ActiveRuleKey key = ActiveRuleKey.of(QualityProfileKey.of("other", "js"), RuleKey.of("xoo", "x1")); @@ -352,7 +350,6 @@ public class ActiveRuleServiceMediumTest { fail(); } catch (IllegalArgumentException e) { assertThat(e).hasMessage("Quality profile not found: other:js"); - verifyZeroActiveRules(key); } } -- 2.39.5