use of com.google.gerrit.extensions.restapi.RestApiException in project gerrit by GerritCodeReview.
the class ChangesImpl method get.
private List<ChangeInfo> get(final QueryRequest q) throws RestApiException {
QueryChanges qc = queryProvider.get();
if (q.getQuery() != null) {
qc.addQuery(q.getQuery());
}
qc.setLimit(q.getLimit());
qc.setStart(q.getStart());
for (ListChangesOption option : q.getOptions()) {
qc.addOption(option);
}
try {
List<?> result = qc.apply(TopLevelResource.INSTANCE);
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 = checkNotNull(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.extensions.restapi.RestApiException in project gerrit by GerritCodeReview.
the class GroupsImpl method create.
@Override
public GroupApi create(GroupInput in) throws RestApiException {
if (checkNotNull(in, "GroupInput").name == null) {
throw new BadRequestException("GroupInput must specify name");
}
try {
CreateGroup impl = createGroup.create(in.name);
permissionBackend.user(user).checkAny(GlobalPermission.fromAnnotation(impl.getClass()));
GroupInfo info = impl.apply(TopLevelResource.INSTANCE, in);
return id(info.id);
} catch (Exception e) {
throw asRestApiException("Cannot create group " + in.name, e);
}
}
use of com.google.gerrit.extensions.restapi.RestApiException in project gerrit by GerritCodeReview.
the class GroupsImpl method query.
private List<GroupInfo> query(QueryRequest r) throws RestApiException {
try {
QueryGroups myQueryGroups = queryGroups.get();
myQueryGroups.setQuery(r.getQuery());
myQueryGroups.setLimit(r.getLimit());
myQueryGroups.setStart(r.getStart());
for (ListGroupsOption option : r.getOptions()) {
myQueryGroups.addOption(option);
}
return myQueryGroups.apply(TopLevelResource.INSTANCE);
} catch (Exception e) {
throw asRestApiException("Cannot query groups", e);
}
}
use of com.google.gerrit.extensions.restapi.RestApiException in project gerrit by GerritCodeReview.
the class GroupsImpl method list.
private SortedMap<String, GroupInfo> list(ListRequest req) throws RestApiException {
TopLevelResource tlr = TopLevelResource.INSTANCE;
ListGroups list = listGroups.get();
list.setOptions(req.getOptions());
for (String project : req.getProjects()) {
try {
list.addProject(projects.parse(tlr, IdString.fromDecoded(project)).getControl());
} catch (Exception e) {
throw asRestApiException("Error looking up project " + project, e);
}
}
for (String group : req.getGroups()) {
list.addGroup(groups.parse(group).getGroupUUID());
}
list.setVisibleToAll(req.getVisibleToAll());
if (req.getUser() != null) {
try {
list.setUser(accounts.parse(req.getUser()).getAccountId());
} catch (Exception e) {
throw asRestApiException("Error looking up user " + req.getUser(), e);
}
}
list.setOwned(req.getOwned());
list.setLimit(req.getLimit());
list.setStart(req.getStart());
list.setMatchSubstring(req.getSubstring());
list.setSuggest(req.getSuggest());
try {
return list.apply(tlr);
} catch (Exception e) {
throw asRestApiException("Cannot list groups", e);
}
}
use of com.google.gerrit.extensions.restapi.RestApiException in project gerrit by GerritCodeReview.
the class AccountApiImpl method signAgreement.
@Override
public void signAgreement(String agreementName) throws RestApiException {
try {
AgreementInput input = new AgreementInput();
input.name = agreementName;
putAgreement.apply(account, input);
} catch (Exception e) {
throw asRestApiException("Cannot sign agreement", e);
}
}
Aggregations