use of com.google.gerrit.server.restapi.change.QueryChanges in project gerrit by GerritCodeReview.
the class ChangesImpl method get.
private List<ChangeInfo> get(QueryRequest q) throws RestApiException {
try (DynamicOptions dynamicOptions = new DynamicOptions(injector, dynamicBeans)) {
QueryChanges qc = queryProvider.get();
if (q.getQuery() != null) {
qc.addQuery(q.getQuery());
}
qc.setLimit(q.getLimit());
qc.setStart(q.getStart());
qc.setNoLimit(q.getNoLimit());
for (ListChangesOption option : q.getOptions()) {
qc.addOption(option);
}
dynamicOptionParser.parseDynamicOptions(qc, q.getPluginOptions(), dynamicOptions);
try {
List<?> result = qc.apply(TopLevelResource.INSTANCE).value();
if (result.isEmpty()) {
return ImmutableList.of();
}
// Check type safety of result; the extension API should be safer than the
// REST API in this case, since it's intended to be used in Java.
Object first = requireNonNull(result.iterator().next());
checkState(first instanceof ChangeInfo);
@SuppressWarnings("unchecked") List<ChangeInfo> infos = (List<ChangeInfo>) result;
return ImmutableList.copyOf(infos);
} catch (Exception e) {
throw asRestApiException("Cannot query changes", e);
}
}
}
use of com.google.gerrit.server.restapi.change.QueryChanges in project gerrit by GerritCodeReview.
the class QueryChangesIT method aliasQuery.
@Test
@SuppressWarnings("unchecked")
@GerritConfig(name = "operator-alias.change.numberaliastest", value = "change")
public void aliasQuery() throws Exception {
String cId1 = createChange().getChangeId();
String cId2 = createChange().getChangeId();
int numericId1 = gApi.changes().id(cId1).get()._number;
int numericId2 = gApi.changes().id(cId2).get()._number;
QueryChanges queryChanges = queryChangesProvider.get();
queryChanges.addQuery("numberaliastest:12345");
queryChanges.addQuery("numberaliastest:" + numericId1);
queryChanges.addQuery("numberaliastest:" + numericId2);
List<List<ChangeInfo>> result = (List<List<ChangeInfo>>) queryChanges.apply(TopLevelResource.INSTANCE).value();
assertThat(result).hasSize(3);
assertThat(result.get(0)).hasSize(0);
assertThat(result.get(1)).hasSize(1);
assertThat(result.get(2)).hasSize(1);
assertThat(result.get(1).get(0)._number).isEqualTo(numericId1);
assertThat(result.get(2).get(0)._number).isEqualTo(numericId2);
}
use of com.google.gerrit.server.restapi.change.QueryChanges in project gerrit by GerritCodeReview.
the class QueryChangesIT method skipVisibility_privateChange.
@Test
@SuppressWarnings("unchecked")
public void skipVisibility_privateChange() throws Exception {
TestRepository<InMemoryRepository> userRepo = cloneProject(project, user);
PushOneCommit.Result result = pushFactory.create(user.newIdent(), userRepo).to("refs/for/master");
requestScopeOperations.setApiUser(user.id());
gApi.changes().id(result.getChangeId()).setPrivate(true);
requestScopeOperations.setApiUser(admin.id());
QueryChanges queryChanges = queryChangesProvider.get();
queryChanges.addQuery("is:open repo:" + project.get());
List<List<ChangeInfo>> result2 = (List<List<ChangeInfo>>) queryChanges.apply(TopLevelResource.INSTANCE).value();
assertThat(result2).hasSize(0);
queryChanges = queryChangesProvider.get();
queryChanges.addQuery("is:open repo:" + project.get());
queryChanges.skipVisibility(true);
List<List<ChangeInfo>> result3 = (List<List<ChangeInfo>>) queryChanges.apply(TopLevelResource.INSTANCE).value();
assertThat(result3).hasSize(1);
}
use of com.google.gerrit.server.restapi.change.QueryChanges in project gerrit by GerritCodeReview.
the class QueryChangesIT method usingOutOfRangeLabelValuesDoesNotCauseError.
@Test
public void usingOutOfRangeLabelValuesDoesNotCauseError() throws Exception {
for (String operator : ImmutableList.of("=", ">", ">=", "<", "<=")) {
QueryChanges queryChanges = queryChangesProvider.get();
queryChanges.addQuery("label:Code-Review" + operator + "10");
queryChanges.addQuery("label:Code-Review" + operator + "-10");
queryChanges.addQuery("Code-Review" + operator + "10");
queryChanges.addQuery("Code-Review" + operator + "-10");
assertThat(queryChanges.apply(TopLevelResource.INSTANCE).statusCode()).isEqualTo(SC_OK);
}
}
use of com.google.gerrit.server.restapi.change.QueryChanges in project gerrit by GerritCodeReview.
the class QueryChangesIT method defaultQueryCannotBeParsedDueToInvalidRegEx.
@Test
public void defaultQueryCannotBeParsedDueToInvalidRegEx() throws Exception {
QueryChanges queryChanges = queryChangesProvider.get();
queryChanges.addQuery("^[A");
BadRequestException e = assertThrows(BadRequestException.class, () -> queryChanges.apply(TopLevelResource.INSTANCE));
assertThat(e).hasMessageThat().contains("no viable alternative at character '['");
}
Aggregations