*/
package org.sonar.server.qualityprofile.index;
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.collect.FluentIterable;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import javax.annotation.Nonnull;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.sonar.api.utils.System2;
+import org.sonar.core.util.stream.Collectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleKey;
}
private long doIndex(BulkIndexer bulk, long lastUpdatedAt) {
- DbSession dbSession = dbClient.openSession(false);
long maxDate;
- try {
+ try (DbSession dbSession = dbClient.openSession(false)) {
ActiveRuleResultSetIterator rowIt = ActiveRuleResultSetIterator.create(dbClient, dbSession, lastUpdatedAt);
maxDate = doIndex(bulk, rowIt);
rowIt.close();
return maxDate;
- } finally {
- dbSession.close();
}
}
}
public void index(List<ActiveRuleChange> changes) {
- deleteKeys(FluentIterable.from(changes)
- .filter(MatchDeactivatedRule.INSTANCE)
- .transform(ActiveRuleChangeToKey.INSTANCE)
- .toList());
+ deleteKeys(changes.stream()
+ .filter(c -> c.getType().equals(ActiveRuleChange.Type.DEACTIVATED))
+ .map(c -> c.getKey())
+ .collect(Collectors.toList(changes.size())));
+
index();
}
.parent(doc.key().ruleKey().toString())
.source(doc.getFields());
}
-
- private enum MatchDeactivatedRule implements Predicate<ActiveRuleChange> {
- INSTANCE;
-
- @Override
- public boolean apply(@Nonnull ActiveRuleChange input) {
- return input.getType().equals(ActiveRuleChange.Type.DEACTIVATED);
- }
- }
-
- private enum ActiveRuleChangeToKey implements Function<ActiveRuleChange, ActiveRuleKey> {
- INSTANCE;
-
- @Override
- public ActiveRuleKey apply(@Nonnull ActiveRuleChange input) {
- return input.getKey();
- }
- }
-
}