use of com.google.gerrit.server.query.QueryParseException in project gerrit by GerritCodeReview.
the class FuzzyTopicPredicate method match.
@Override
public boolean match(final ChangeData cd) throws OrmException {
Change change = cd.change();
if (change == null) {
return false;
}
String t = change.getTopic();
if (t == null) {
return false;
}
try {
Predicate<ChangeData> thisId = new LegacyChangeIdPredicate(cd.getId());
Iterable<ChangeData> results = index.getSource(and(thisId, this), IndexedChangeQuery.oneResult()).read();
return !Iterables.isEmpty(results);
} catch (QueryParseException e) {
throw new OrmException(e);
}
}
use of com.google.gerrit.server.query.QueryParseException in project gerrit by GerritCodeReview.
the class IsWatchedByPredicate method filters.
protected static List<Predicate<ChangeData>> filters(ChangeQueryBuilder.Arguments args, boolean checkIsVisible) throws QueryParseException {
List<Predicate<ChangeData>> r = new ArrayList<>();
ChangeQueryBuilder builder = new ChangeQueryBuilder(args);
for (ProjectWatchKey w : getWatches(args)) {
Predicate<ChangeData> f = null;
if (w.filter() != null) {
try {
f = builder.parse(w.filter());
if (QueryBuilder.find(f, IsWatchedByPredicate.class) != null) {
// another user is filtering on. :-)
continue;
}
} catch (QueryParseException e) {
continue;
}
}
Predicate<ChangeData> p;
if (w.project().equals(args.allProjectsName)) {
p = null;
} else {
p = builder.project(w.project().get());
}
if (p != null && f != null) {
r.add(and(p, f));
} else if (p != null) {
r.add(p);
} else if (f != null) {
r.add(f);
} else {
r.add(builder.status_open());
}
}
if (r.isEmpty()) {
return none();
} else if (checkIsVisible) {
return ImmutableList.of(or(r), builder.is_visible());
} else {
return ImmutableList.of(or(r));
}
}
use of com.google.gerrit.server.query.QueryParseException in project gerrit by GerritCodeReview.
the class ConflictsPredicate method predicates.
public static List<Predicate<ChangeData>> predicates(final Arguments args, String value, List<Change> changes) throws QueryParseException, OrmException {
int indexTerms = 0;
List<Predicate<ChangeData>> changePredicates = Lists.newArrayListWithCapacity(changes.size());
final Provider<ReviewDb> db = args.db;
for (final Change c : changes) {
final ChangeDataCache changeDataCache = new ChangeDataCache(c, db, args.changeDataFactory, args.projectCache);
List<String> files = listFiles(c, args, changeDataCache);
indexTerms += 3 + files.size();
if (indexTerms > args.indexConfig.maxTerms()) {
// later on in the query parsing.
throw new QueryParseException(TOO_MANY_FILES);
}
List<Predicate<ChangeData>> filePredicates = Lists.newArrayListWithCapacity(files.size());
for (String file : files) {
filePredicates.add(new EqualsPathPredicate(ChangeQueryBuilder.FIELD_PATH, file));
}
List<Predicate<ChangeData>> predicatesForOneChange = Lists.newArrayListWithCapacity(5);
predicatesForOneChange.add(not(new LegacyChangeIdPredicate(c.getId())));
predicatesForOneChange.add(new ProjectPredicate(c.getProject().get()));
predicatesForOneChange.add(new RefPredicate(c.getDest().get()));
predicatesForOneChange.add(or(or(filePredicates), new IsMergePredicate(args, value)));
predicatesForOneChange.add(new ChangeOperatorPredicate(ChangeQueryBuilder.FIELD_CONFLICTS, value) {
@Override
public boolean match(ChangeData object) throws OrmException {
Change otherChange = object.change();
if (otherChange == null) {
return false;
}
if (!otherChange.getDest().equals(c.getDest())) {
return false;
}
SubmitTypeRecord str = object.submitTypeRecord();
if (!str.isOk()) {
return false;
}
ObjectId other = ObjectId.fromString(object.currentPatchSet().getRevision().get());
ConflictKey conflictsKey = new ConflictKey(changeDataCache.getTestAgainst(), other, str.type, changeDataCache.getProjectState().isUseContentMerge());
Boolean conflicts = args.conflictsCache.getIfPresent(conflictsKey);
if (conflicts != null) {
return conflicts;
}
try (Repository repo = args.repoManager.openRepository(otherChange.getProject());
CodeReviewRevWalk rw = CodeReviewCommit.newRevWalk(repo)) {
conflicts = !args.submitDryRun.run(str.type, repo, rw, otherChange.getDest(), changeDataCache.getTestAgainst(), other, getAlreadyAccepted(repo, rw));
args.conflictsCache.put(conflictsKey, conflicts);
return conflicts;
} catch (IntegrationException | NoSuchProjectException | IOException e) {
throw new OrmException(e);
}
}
@Override
public int getCost() {
return 5;
}
private Set<RevCommit> getAlreadyAccepted(Repository repo, RevWalk rw) throws IntegrationException {
try {
Set<RevCommit> accepted = new HashSet<>();
SubmitDryRun.addCommits(changeDataCache.getAlreadyAccepted(repo), rw, accepted);
ObjectId tip = changeDataCache.getTestAgainst();
if (tip != null) {
accepted.add(rw.parseCommit(tip));
}
return accepted;
} catch (OrmException | IOException e) {
throw new IntegrationException("Failed to determine already accepted commits.", e);
}
}
});
changePredicates.add(and(predicatesForOneChange));
}
return changePredicates;
}
use of com.google.gerrit.server.query.QueryParseException in project gerrit by GerritCodeReview.
the class ReviewerRecommender method baseRankingForCandidateList.
private Map<Account.Id, MutableDouble> baseRankingForCandidateList(List<Account.Id> candidates, ProjectControl projectControl, double baseWeight) throws OrmException {
// Get each reviewer's activity based on number of applied labels
// (weighted 10d), number of comments (weighted 0.5d) and number of owned
// changes (weighted 1d).
Map<Account.Id, MutableDouble> reviewers = new LinkedHashMap<>();
if (candidates.size() == 0) {
return reviewers;
}
List<Predicate<ChangeData>> predicates = new ArrayList<>();
for (Account.Id id : candidates) {
try {
Predicate<ChangeData> projectQuery = changeQueryBuilder.project(projectControl.getProject().getName());
// Get all labels for this project and create a compound OR query to
// fetch all changes where users have applied one of these labels
List<LabelType> labelTypes = projectControl.getLabelTypes().getLabelTypes();
List<Predicate<ChangeData>> labelPredicates = new ArrayList<>(labelTypes.size());
for (LabelType type : labelTypes) {
labelPredicates.add(changeQueryBuilder.label(type.getName() + ",user=" + id));
}
Predicate<ChangeData> reviewerQuery = Predicate.and(projectQuery, Predicate.or(labelPredicates));
Predicate<ChangeData> ownerQuery = Predicate.and(projectQuery, changeQueryBuilder.owner(id.toString()));
Predicate<ChangeData> commentedByQuery = Predicate.and(projectQuery, changeQueryBuilder.commentby(id.toString()));
predicates.add(reviewerQuery);
predicates.add(ownerQuery);
predicates.add(commentedByQuery);
reviewers.put(id, new MutableDouble());
} catch (QueryParseException e) {
// Unhandled: If an exception is thrown, we won't increase the
// candidates's score
log.error("Exception while suggesting reviewers", e);
}
}
List<List<ChangeData>> result = internalChangeQuery.setLimit(25).setRequestedFields(ImmutableSet.of()).query(predicates);
Iterator<List<ChangeData>> queryResultIterator = result.iterator();
Iterator<Account.Id> reviewersIterator = reviewers.keySet().iterator();
int i = 0;
Account.Id currentId = null;
while (queryResultIterator.hasNext()) {
List<ChangeData> currentResult = queryResultIterator.next();
if (i % WEIGHTS.length == 0) {
currentId = reviewersIterator.next();
}
reviewers.get(currentId).add(WEIGHTS[i % WEIGHTS.length] * baseWeight * currentResult.size());
i++;
}
return reviewers;
}
use of com.google.gerrit.server.query.QueryParseException in project gerrit by GerritCodeReview.
the class Index method get.
/**
* Get a single document from the index.
*
* @param key document key.
* @param opts query options. Options that do not make sense in the context of a single document,
* such as start, will be ignored.
* @return a single document if present.
* @throws IOException
*/
default default Optional<V> get(K key, QueryOptions opts) throws IOException {
opts = opts.withStart(0).withLimit(2);
List<V> results;
try {
results = getSource(keyPredicate(key), opts).read().toList();
} catch (QueryParseException e) {
throw new IOException("Unexpected QueryParseException during get()", e);
} catch (OrmException e) {
throw new IOException(e);
}
switch(results.size()) {
case 0:
return Optional.empty();
case 1:
return Optional.of(results.get(0));
default:
throw new IOException("Multiple results found in index for key " + key + ": " + results);
}
}
Aggregations