import org.sonar.server.search.Result;
import javax.annotation.CheckForNull;
-
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
if (debtCharacteristics != null && !debtCharacteristics.isEmpty()) {
fb.must(
FilterBuilders.orFilter(
- // Match only when NOT NONE overriden
+ // Match only when NONE (overridden)
FilterBuilders.andFilter(
FilterBuilders.notFilter(
FilterBuilders.termsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field(), DebtCharacteristic.NONE)),
FilterBuilders.orFilter(
FilterBuilders.termsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field(), debtCharacteristics),
FilterBuilders.termsFilter(RuleNormalizer.RuleField.CHARACTERISTIC.field(), debtCharacteristics))
- ),
+ ),
- // Match only when NOT NONE overriden
+ // Match only when NOT NONE (not overridden)
FilterBuilders.andFilter(
FilterBuilders.orFilter(
FilterBuilders.termsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field(), ""),
FilterBuilders.orFilter(
FilterBuilders.termsFilter(RuleNormalizer.RuleField.DEFAULT_SUB_CHARACTERISTIC.field(), debtCharacteristics),
FilterBuilders.termsFilter(RuleNormalizer.RuleField.DEFAULT_CHARACTERISTIC.field(), debtCharacteristics)))
- )
- );
+ )
+ );
}
// Debt char exist filter
Boolean hasDebtCharacteristic = query.getHasDebtCharacteristic();
if (hasDebtCharacteristic != null && hasDebtCharacteristic) {
- fb.must(FilterBuilders.existsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field()));
+ fb.mustNot(
+ FilterBuilders.termsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field(), DebtCharacteristic.NONE))
+ .should(
+ FilterBuilders.existsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field()))
+ .should(
+ FilterBuilders.existsFilter(RuleNormalizer.RuleField.DEFAULT_SUB_CHARACTERISTIC.field()));
}
if (query.getAvailableSince() != null) {
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import org.apache.commons.lang.time.DateUtils;
-import org.junit.*;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.server.tester.ServerTester;
import javax.annotation.Nullable;
-
-import java.util.*;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
import static org.fest.assertions.Assertions.assertThat;
}
@Test
- @Ignore("To be fixed")
- public void search_by_has_debt_characteristic() {
+ public void search_by_has_debt_characteristic() throws InterruptedException {
CharacteristicDto char1 = DebtTesting.newCharacteristicDto("c1")
.setEnabled(true)
.setName("char1");