-/*
- * 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, open source software quality management tool.
* Copyright (C) 2008-2014 SonarSource
DbSession dbSession = db.openSession(false);
List<UpdateRequest> requests = new ArrayList<UpdateRequest>();
try {
- requests.addAll(normalize(db.activeRuleDao().getNullableByKey(dbSession, key)));
+ ActiveRuleDto activeRule = db.activeRuleDao().getByKey(dbSession, key);
+ requests.addAll(normalize(activeRule));
for (ActiveRuleParamDto param : db.activeRuleDao().findParamsByActiveRuleKey(dbSession, key)) {
requests.addAll(normalizeNested(param, key));
}
DbSession session = db.openSession(false);
try {
- // TODO because DTO uses legacy ID patter
+ // TODO because DTO uses legacy ID pattern
QualityProfileDto profile = db.qualityProfileDao().getById(activeRuleDto.getProfileId(), session);
newRule.put(ActiveRuleField.PROFILE_KEY.field(), profile.getKey());
// TODO this should be generated by RegisterRule and modified in DTO.
String parentKey = null;
if (activeRuleDto.getParentId() != null) {
-
ActiveRuleDto parentDto = db.activeRuleDao().getById(session, activeRuleDto.getParentId());
parentKey = parentDto.getKey().toString();
}
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
private void setSorting(RuleQuery query, SearchRequestBuilder esSearch) {
/* integrate Query Sort */
+ String queryText = query.getQueryText();
if (query.getSortField() != null) {
FieldSortBuilder sort = SortBuilders.fieldSort(query.getSortField().sortField());
if (query.isAscendingSort()) {
sort.order(SortOrder.DESC);
}
esSearch.addSort(sort);
- } else if (query.getQueryText() != null && !query.getQueryText().isEmpty()) {
+ } else if (queryText != null && !queryText.isEmpty()) {
esSearch.addSort(SortBuilders.scoreSort());
} else {
esSearch.addSort(RuleNormalizer.RuleField.UPDATED_AT.sortField(), SortOrder.DESC);
protected QueryBuilder getQuery(RuleQuery query, QueryOptions options) {
// No contextual query case
+ String queryText = query.getQueryText();
if (query.getQueryText() == null || query.getQueryText().isEmpty()) {
return QueryBuilders.matchAllQuery();
}
this.addTermFilter(fb, RuleNormalizer.RuleField._TAGS.field(), query.getTags());
// Construct the debt filter on effective char and subChar
- Collection<String> characteristics = query.getDebtCharacteristics();
- if (characteristics != null && !characteristics.isEmpty()) {
+ Collection<String> debtCharacteristics = query.getDebtCharacteristics();
+ if (debtCharacteristics != null && !debtCharacteristics.isEmpty()) {
fb.must(
FilterBuilders.orFilter(
// Match only when NOT NONE overriden
FilterBuilders.notFilter(
FilterBuilders.termsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field(), DebtCharacteristic.NONE)),
FilterBuilders.orFilter(
- FilterBuilders.termsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field(), characteristics),
- FilterBuilders.termsFilter(RuleNormalizer.RuleField.CHARACTERISTIC.field(), characteristics))
+ FilterBuilders.termsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field(), debtCharacteristics),
+ FilterBuilders.termsFilter(RuleNormalizer.RuleField.CHARACTERISTIC.field(), debtCharacteristics))
),
// Match only when NOT NONE overriden
FilterBuilders.termsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field(), ""),
FilterBuilders.notFilter(FilterBuilders.existsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field()))),
FilterBuilders.orFilter(
- FilterBuilders.termsFilter(RuleNormalizer.RuleField.DEFAULT_SUB_CHARACTERISTIC.field(), characteristics),
- FilterBuilders.termsFilter(RuleNormalizer.RuleField.DEFAULT_CHARACTERISTIC.field(), characteristics)))
+ FilterBuilders.termsFilter(RuleNormalizer.RuleField.DEFAULT_SUB_CHARACTERISTIC.field(), debtCharacteristics),
+ FilterBuilders.termsFilter(RuleNormalizer.RuleField.DEFAULT_CHARACTERISTIC.field(), debtCharacteristics)))
)
);
}
// Debt char exist filter
- if (Boolean.TRUE.equals(query.getHasDebtCharacteristic())) {
+ Boolean hasDebtCharacteristic = query.getHasDebtCharacteristic();
+ if (hasDebtCharacteristic != null && hasDebtCharacteristic) {
fb.must(FilterBuilders.existsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field()));
}
.gte(query.getAvailableSince()));
}
- Collection<RuleStatus> statuses = query.getStatuses();
- if (statuses != null && !statuses.isEmpty()) {
+ Collection<RuleStatus> statusValues = query.getStatuses();
+ if (statusValues != null && !statusValues.isEmpty()) {
Collection<String> stringStatus = new ArrayList<String>();
- for (RuleStatus status : statuses) {
+ for (RuleStatus status : statusValues) {
stringStatus.add(status.name());
}
this.addTermFilter(fb, RuleNormalizer.RuleField.STATUS.field(), stringStatus);
}
/** Implementation of activation query */
- if (query.getActivation() == Boolean.TRUE) {
+ if (query.getActivation().equals(Boolean.TRUE)) {
fb.must(FilterBuilders.hasChildFilter(IndexDefinition.ACTIVE_RULE.getIndexType(),
childQuery));
- } else if (query.getActivation() == Boolean.FALSE) {
+ } else if (query.getActivation().equals(Boolean.FALSE)) {
fb.mustNot(FilterBuilders.hasChildFilter(IndexDefinition.ACTIVE_RULE.getIndexType(),
childQuery));
}
}
/**
- * @deprecated do not use ids but keys
+ * @deprecated please use getByKey(RuleKey key)
*/
@Deprecated
@CheckForNull
}
/**
- * @deprecated do not use ids but keys
+ * @deprecated please use getByKey(RuleKey key)
*/
@Deprecated
public List<Rule> getByIds(Collection<Integer> ids) {
}
protected boolean needMultiField(IndexField field) {
- return ((field.type() == IndexField.Type.TEXT
+ return (field.type() == IndexField.Type.TEXT
|| field.type() == IndexField.Type.STRING)
- && (field.sortable() || field.searchable()));
+ && (field.sortable() || field.searchable());
}
protected Map mapSortField(IndexField field) {
return null;
}
- protected void updateDocument(Collection<UpdateRequest> requests, KEY key) throws Exception {
+ protected void updateDocument(Collection<UpdateRequest> requests, KEY key) {
LOG.debug("UPDATE _id:{} in index {}", key, this.getIndexName());
BulkRequestBuilder bulkRequest = getClient().prepareBulk();
for (UpdateRequest request : requests) {
this.deleteDocument(additionalKey);
}
} catch (Exception e) {
- LOG.error("Could not DELETE _id = '{}' for index '{}': {}",
- this.getKeyValue(key), this.getIndexName(), e.getMessage());
+ throw new IllegalStateException("Could not DELETE _id = '" + this.getKeyValue(key) + "' " +
+ "for index '" + this.getIndexName() + "': " + e.getMessage());
}
}
this.deleteDocument(additionalItem.getKey());
}
} catch (Exception e) {
- LOG.error("Could not DELETE _id:{} for index {}: {}",
- this.getKeyValue(item.getKey()), this.getIndexName(), e.getMessage());
+ throw new IllegalStateException("Could not DELETE _id = '" + this.getKeyValue(item.getKey()) + "' " +
+ "for index '" + this.getIndexName() + "': " + e.getMessage());
}
}
stats.put(aggregation.getName(), facetValue);
}
} else if (aggregation.getClass().isAssignableFrom(InternalValueCount.class)) {
- InternalValueCount count = ((InternalValueCount) aggregation);
+ InternalValueCount count = (InternalValueCount) aggregation;
FacetValue facetValue = new FacetValue(count.getName(), (int) count.getValue());
stats.put(count.getName(), facetValue);
}