Search in sources :

Example 1 with UnloggedFailure

use of com.google.gerrit.sshd.BaseCommand.UnloggedFailure in project gerrit by GerritCodeReview.

the class ChangeArgumentParser method addChange.

public void addChange(String id, Map<Change.Id, ChangeResource> changes, ProjectControl projectControl, boolean useIndex) throws UnloggedFailure, OrmException {
    List<ChangeControl> matched = useIndex ? changeFinder.find(id, currentUser) : changeFromNotesFactory(id, currentUser);
    List<ChangeControl> toAdd = new ArrayList<>(changes.size());
    boolean canMaintainServer;
    try {
        permissionBackend.user(currentUser).check(GlobalPermission.MAINTAIN_SERVER);
        canMaintainServer = true;
    } catch (AuthException | PermissionBackendException e) {
        canMaintainServer = false;
    }
    for (ChangeControl ctl : matched) {
        if (!changes.containsKey(ctl.getId()) && inProject(projectControl, ctl.getProject()) && (canMaintainServer || ctl.isVisible(db))) {
            toAdd.add(ctl);
        }
    }
    if (toAdd.isEmpty()) {
        throw new UnloggedFailure(1, "\"" + id + "\" no such change");
    } else if (toAdd.size() > 1) {
        throw new UnloggedFailure(1, "\"" + id + "\" matches multiple changes");
    }
    ChangeControl ctl = toAdd.get(0);
    changes.put(ctl.getId(), changesCollection.parse(ctl));
}
Also used : UnloggedFailure(com.google.gerrit.sshd.BaseCommand.UnloggedFailure) ChangeControl(com.google.gerrit.server.project.ChangeControl) ArrayList(java.util.ArrayList) AuthException(com.google.gerrit.extensions.restapi.AuthException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException)

Aggregations

AuthException (com.google.gerrit.extensions.restapi.AuthException)1 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)1 ChangeControl (com.google.gerrit.server.project.ChangeControl)1 UnloggedFailure (com.google.gerrit.sshd.BaseCommand.UnloggedFailure)1 ArrayList (java.util.ArrayList)1