Search in sources :

Example 6 with RestApiException

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);
    }
}
Also used : ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) QueryChanges(com.google.gerrit.server.query.change.QueryChanges) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 7 with RestApiException

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);
    }
}
Also used : GroupInfo(com.google.gerrit.extensions.common.GroupInfo) CreateGroup(com.google.gerrit.server.group.CreateGroup) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 8 with RestApiException

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);
    }
}
Also used : ListGroupsOption(com.google.gerrit.extensions.client.ListGroupsOption) QueryGroups(com.google.gerrit.server.group.QueryGroups) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 9 with RestApiException

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);
    }
}
Also used : TopLevelResource(com.google.gerrit.extensions.restapi.TopLevelResource) ListGroups(com.google.gerrit.server.group.ListGroups) IdString(com.google.gerrit.extensions.restapi.IdString) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 10 with RestApiException

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);
    }
}
Also used : AgreementInput(com.google.gerrit.extensions.common.AgreementInput) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Aggregations

RestApiException (com.google.gerrit.extensions.restapi.RestApiException)50 ApiUtil.asRestApiException (com.google.gerrit.server.api.ApiUtil.asRestApiException)16 OrmException (com.google.gwtorm.server.OrmException)14 IOException (java.io.IOException)14 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)12 UpdateException (com.google.gerrit.server.update.UpdateException)12 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)10 Change (com.google.gerrit.reviewdb.client.Change)8 AuthException (com.google.gerrit.extensions.restapi.AuthException)7 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)7 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)7 BatchUpdateOp (com.google.gerrit.server.update.BatchUpdateOp)6 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)5 ArrayList (java.util.ArrayList)5 RevWalk (org.eclipse.jgit.revwalk.RevWalk)5 Test (org.junit.Test)5 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)4 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)4 ChangeContext (com.google.gerrit.server.update.ChangeContext)4 Provider (com.google.inject.Provider)4