}
public void clean(long projectId) {
- doClean(projectId, new Filters(settings).getFilters());
+ doClean(projectId, new Filters(settings).all());
}
@VisibleForTesting
import java.util.Date;
import java.util.List;
-class DeleteAllFilter extends Filter {
+class DeleteAllFilter implements Filter {
private final Date before;
public DeleteAllFilter(Date before) {
}
@Override
- List<PurgeableSnapshotDto> filter(List<PurgeableSnapshotDto> history) {
+ public List<PurgeableSnapshotDto> filter(List<PurgeableSnapshotDto> history) {
List<PurgeableSnapshotDto> result = Lists.newArrayList();
for (PurgeableSnapshotDto snapshot : history) {
if (snapshot.getDate().before(before)) {
}
@Override
- void log() {
+ public void log() {
LoggerFactory.getLogger(getClass()).info("-> Delete data prior to: " + DateUtils.formatDate(before));
}
}
import java.util.List;
-abstract class Filter {
- abstract List<PurgeableSnapshotDto> filter(List<PurgeableSnapshotDto> snapshots);
+interface Filter {
+ List<PurgeableSnapshotDto> filter(List<PurgeableSnapshotDto> snapshots);
- abstract void log();
+ void log();
}
import java.util.List;
class Filters {
- private final List<Filter> filters = Lists.newArrayList();
+ private final List<Filter> all = Lists.newArrayList();
Filters(Settings settings) {
Date dateToStartKeepingOneSnapshotByDay = getDateFromHours(settings, DbCleanerConstants.HOURS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_DAY);
Date dateToStartKeepingOneSnapshotByMonth = getDateFromWeeks(settings, DbCleanerConstants.WEEKS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_MONTH);
Date dateToStartDeletingAllSnapshots = getDateFromWeeks(settings, DbCleanerConstants.WEEKS_BEFORE_DELETING_ALL_SNAPSHOTS);
- filters.add(new KeepOneFilter(dateToStartKeepingOneSnapshotByWeek, dateToStartKeepingOneSnapshotByDay, Calendar.DAY_OF_YEAR, "day"));
- filters.add(new KeepOneFilter(dateToStartKeepingOneSnapshotByMonth, dateToStartKeepingOneSnapshotByWeek, Calendar.WEEK_OF_YEAR, "week"));
- filters.add(new KeepOneFilter(dateToStartDeletingAllSnapshots, dateToStartKeepingOneSnapshotByMonth, Calendar.MONTH, "month"));
- filters.add(new DeleteAllFilter(dateToStartDeletingAllSnapshots));
+ all.add(new KeepOneFilter(dateToStartKeepingOneSnapshotByWeek, dateToStartKeepingOneSnapshotByDay, Calendar.DAY_OF_YEAR, "day"));
+ all.add(new KeepOneFilter(dateToStartKeepingOneSnapshotByMonth, dateToStartKeepingOneSnapshotByWeek, Calendar.WEEK_OF_YEAR, "week"));
+ all.add(new KeepOneFilter(dateToStartDeletingAllSnapshots, dateToStartKeepingOneSnapshotByMonth, Calendar.MONTH, "month"));
+ all.add(new DeleteAllFilter(dateToStartDeletingAllSnapshots));
}
- List<Filter> getFilters() {
- return filters;
+ List<Filter> all() {
+ return all;
}
static Date getDateFromWeeks(Settings settings, String propertyKey) {
import java.util.Date;
import java.util.List;
-class KeepOneFilter extends Filter {
+class KeepOneFilter implements Filter {
private final Date start;
private final Date end;
}
@Override
- List<PurgeableSnapshotDto> filter(List<PurgeableSnapshotDto> history) {
+ public List<PurgeableSnapshotDto> filter(List<PurgeableSnapshotDto> history) {
List<Interval> intervals = Interval.group(history, start, end, dateField);
List<PurgeableSnapshotDto> result = Lists.newArrayList();
for (Interval interval : intervals) {
}
@Override
- void log() {
+ public void log() {
LoggerFactory.getLogger(getClass()).info("-> Keep one snapshot per " + label + " between " + DateUtils.formatDate(start) + " and " + DateUtils.formatDate(end));
}
measureToSave.setData(((String) measure.value()));
break;
case WORK_DUR:
- measureToSave.setValue(Double.valueOf(((Long) measure.value())));
+ measureToSave.setValue(Double.valueOf((Long) measure.value()));
break;
default:
if (m.isNumericType()) {
- measureToSave.setValue(((Double) measure.value()));
+ measureToSave.setValue((Double) measure.value());
} else if (m.isDataType()) {
- measureToSave.setData(((String) measure.value()));
+ measureToSave.setData((String) measure.value());
} else {
throw new UnsupportedOperationException("Unsupported type :" + m.getType());
}
/**
* @deprecated profile versioning is dropped in 4.4. Always returns -1.
*/
+ @CheckForNull
@Deprecated
public Boolean getUsed() {
return null;
import java.util.Map;
/**
- * TODO should be an interface
- *
* @since 2.3
*/
public class XMLProfileParser implements ServerComponent {
@Test
public void param_as_long() throws Exception {
assertThat(request.setParam("a_number", "123").paramAsLong("a_number")).isEqualTo(123L);
+ assertThat(request.setParam("a_number", "123").paramAsLong("a_number", 42L)).isEqualTo(123L);
+ assertThat(request.setParam("a_number", null).paramAsLong("a_number", 42L)).isEqualTo(123L);
}
@Test
--- /dev/null
+/*
+ * 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.api.server.ws.internal;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class SimpleGetRequestTest {
+
+ @Test
+ public void method() throws Exception {
+ SimpleGetRequest request = new SimpleGetRequest();
+ assertThat(request.method()).isEqualTo("GET");
+
+ request.setParam("foo", "bar");
+ assertThat(request.param("foo")).isEqualTo("bar");
+ assertThat(request.param("unknown")).isNull();
+ }
+}
} else {
categoriesSplit = new String[nbValues];
for (int i = 0; i < nbValues; i++) {
- categoriesSplit[i] = DEFAULT_NAME_CATEGORY + i;
+ categoriesSplit[i] = new StringBuilder().append(DEFAULT_NAME_CATEGORY).append(i).toString();
}
}
private void processRuleChange(ActiveRuleChange ruleChange, ChangeLog change) {
ruleChange.setSeverity(SeverityUtil.getSeverityFromOrdinal(change.getSeverity()));
- String param_name = change.getParamKey();
- String param_value = change.getParamValue();
- if (StringUtils.isNotEmpty(param_name)) {
- ruleChange.setParameter(param_name, param_value);
+ String paramName = change.getParamKey();
+ String paramValue = change.getParamValue();
+ if (StringUtils.isNotEmpty(paramName)) {
+ ruleChange.setParameter(paramName, paramValue);
}
}
}
}
- private static class BlockComparator implements Comparator<Block> {
+ private static class BlockComparator implements Comparator<Block>, Serializable {
@Override
public int compare(@Nullable Block b1,
@Nullable Block b2) {
if (params != null) {
activation.setParameters(KeyValueFormat.parse(params));
}
- activation.setReset(request.paramAsBoolean(RESET) == Boolean.TRUE);
+ activation.setReset(Boolean.TRUE.equals(request.paramAsBoolean(RESET)));
service.activate(request.mandatoryParam(PROFILE_KEY), activation);
}
@Override
public List<RuleParam> params() {
List<RuleParam> params = new ArrayList<RuleParam>();
- List<Map<String, Object>> esParams = getNullableField(RuleNormalizer.RuleField.PARAMS.field());
+ final List<Map<String, Object>> esParams = getNullableField(RuleNormalizer.RuleField.PARAMS.field());
if (esParams != null) {
for (final Map<String, Object> esParam : esParams) {
params.add(new RuleParam() {
- {
- this.fields = esParam;
- }
-
- Map<String, Object> fields;
-
@Override
public String key() {
return (String) esParam.get(RuleNormalizer.RuleParamField.NAME.field());
@Override
public RuleParamType type() {
- return RuleParamType
- .parse((String) esParam.get(RuleNormalizer.RuleParamField.TYPE.field()));
+ return RuleParamType.parse((String) esParam.get(RuleNormalizer.RuleParamField.TYPE.field()));
}
});
}
this.addTermFilter(fb, RuleNormalizer.RuleField._TAGS.field(), query.getTags());
// Construct the debt filter on effective char and subChar
- if (query.getDebtCharacteristics() != null && !query.getDebtCharacteristics().isEmpty()) {
+ Collection<String> characteristics = query.getDebtCharacteristics();
+ if (characteristics != null && !characteristics.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(), query.getDebtCharacteristics()),
- FilterBuilders.termsFilter(RuleNormalizer.RuleField.CHARACTERISTIC.field(), query.getDebtCharacteristics()))
+ FilterBuilders.termsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field(), characteristics),
+ FilterBuilders.termsFilter(RuleNormalizer.RuleField.CHARACTERISTIC.field(), characteristics))
),
// 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(), query.getDebtCharacteristics()),
- FilterBuilders.termsFilter(RuleNormalizer.RuleField.DEFAULT_CHARACTERISTIC.field(), query.getDebtCharacteristics())))
+ FilterBuilders.termsFilter(RuleNormalizer.RuleField.DEFAULT_SUB_CHARACTERISTIC.field(), characteristics),
+ FilterBuilders.termsFilter(RuleNormalizer.RuleField.DEFAULT_CHARACTERISTIC.field(), characteristics)))
)
);
}
// Debt char exist filter
- if (query.getHasDebtCharacteristic() != null && query.getHasDebtCharacteristic()) {
+ if (Boolean.TRUE.equals(query.getHasDebtCharacteristic())) {
fb.must(FilterBuilders.existsFilter(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field()));
}
.gte(query.getAvailableSince()));
}
- if (query.getStatuses() != null && !query.getStatuses().isEmpty()) {
+ Collection<RuleStatus> statuses = query.getStatuses();
+ if (statuses != null && !statuses.isEmpty()) {
Collection<String> stringStatus = new ArrayList<String>();
- for (RuleStatus status : query.getStatuses()) {
+ for (RuleStatus status : statuses) {
stringStatus.add(status.name());
}
this.addTermFilter(fb, RuleNormalizer.RuleField.STATUS.field(), stringStatus);
return tags;
}
+ /**
+ * @deprecated do not use ids but keys
+ */
@Deprecated
@CheckForNull
public Rule getById(int id) {
}
}
+ /**
+ * @deprecated do not use ids but keys
+ */
@Deprecated
public List<Rule> getByIds(Collection<Integer> ids) {
SearchResponse response = getClient().prepareSearch(this.getIndexName())
long start = System.currentTimeMillis();
dao.synchronizeAfter(session,
index.getLastSynchronization());
- LOG.info("-- Synchronized {} in {}ms", index.getIndexType(), (System.currentTimeMillis() - start));
+ LOG.info("-- Synchronized {} in {}ms", index.getIndexType(), System.currentTimeMillis() - start);
}
}
private static void appendColumns(Filter filter, List<String> fields) {
List<String> columnFields = Lists.newArrayList();
for (FilterColumn column : filter.getColumns()) {
- String columnKey = column.getFamily();
+ StringBuilder columnKey = new StringBuilder().append(column.getFamily());
if (StringUtils.isNotBlank(column.getKey()) && !column.isVariation()) {
- columnKey += ":" + column.getKey();
+ columnKey.append(":").append(column.getKey());
}
- columnFields.add(columnKey);
+ columnFields.add(columnKey.toString());
}
if (!columnFields.isEmpty()) {
fields.add("cols=" + Joiner.on(",").join(columnFields));