Use ProjectCache.getChecked() in ProjectControl.GenericFactory.controlFor().
Propagate the IOException up the stack so it can be handled properly. Add a TODO in ChangeControl to propagate the exception. Change-Id: Ie265e40ef62309537ebd3230c9814020cd352d13
This commit is contained in:
@@ -46,6 +46,7 @@ import com.google.inject.Provider;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -218,7 +219,8 @@ class SuggestServiceImpl extends BaseServiceImplementation implements
|
||||
final String query, final int limit,
|
||||
final AsyncCallback<List<ReviewerInfo>> callback) {
|
||||
run(callback, new Action<List<ReviewerInfo>>() {
|
||||
public List<ReviewerInfo> run(final ReviewDb db) throws OrmException {
|
||||
public List<ReviewerInfo> run(final ReviewDb db)
|
||||
throws OrmException, Failure {
|
||||
final ChangeControl changeControl;
|
||||
try {
|
||||
changeControl = changeControlFactory.controlFor(change);
|
||||
@@ -273,7 +275,7 @@ class SuggestServiceImpl extends BaseServiceImplementation implements
|
||||
}
|
||||
|
||||
private boolean suggestGroupAsReviewer(final Project.NameKey project,
|
||||
final GroupReference group) throws OrmException {
|
||||
final GroupReference group) throws OrmException, Failure {
|
||||
if (!PostReviewers.isLegalReviewerGroup(group.getUUID())) {
|
||||
return false;
|
||||
}
|
||||
@@ -296,6 +298,8 @@ class SuggestServiceImpl extends BaseServiceImplementation implements
|
||||
return false;
|
||||
} catch (NoSuchProjectException e) {
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
throw new Failure(e);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@@ -28,6 +28,7 @@ import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -58,13 +59,13 @@ public class GroupMembers {
|
||||
|
||||
public Set<Account> listAccounts(final AccountGroup.UUID groupUUID,
|
||||
final Project.NameKey project) throws NoSuchGroupException,
|
||||
NoSuchProjectException, OrmException {
|
||||
NoSuchProjectException, OrmException, IOException {
|
||||
return listAccounts(groupUUID, project, new HashSet<AccountGroup.UUID>());
|
||||
}
|
||||
|
||||
private Set<Account> listAccounts(final AccountGroup.UUID groupUUID,
|
||||
final Project.NameKey project, final Set<AccountGroup.UUID> seen)
|
||||
throws NoSuchGroupException, OrmException, NoSuchProjectException {
|
||||
throws NoSuchGroupException, OrmException, NoSuchProjectException, IOException {
|
||||
if (AccountGroup.PROJECT_OWNERS.equals(groupUUID)) {
|
||||
return getProjectOwners(project, seen);
|
||||
} else {
|
||||
@@ -79,7 +80,7 @@ public class GroupMembers {
|
||||
|
||||
private Set<Account> getProjectOwners(final Project.NameKey project,
|
||||
final Set<AccountGroup.UUID> seen) throws NoSuchProjectException,
|
||||
NoSuchGroupException, OrmException {
|
||||
NoSuchGroupException, OrmException, IOException {
|
||||
seen.add(AccountGroup.PROJECT_OWNERS);
|
||||
if (project == null) {
|
||||
return Collections.emptySet();
|
||||
@@ -100,7 +101,7 @@ public class GroupMembers {
|
||||
|
||||
private Set<Account> getGroupMembers(final AccountGroup group,
|
||||
final Project.NameKey project, final Set<AccountGroup.UUID> seen)
|
||||
throws NoSuchGroupException, OrmException, NoSuchProjectException {
|
||||
throws NoSuchGroupException, OrmException, NoSuchProjectException, IOException {
|
||||
seen.add(group.getGroupUUID());
|
||||
final GroupDetail groupDetail =
|
||||
groupDetailFactory.create(group.getId()).call();
|
||||
|
@@ -56,6 +56,7 @@ import com.google.inject.Provider;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -120,7 +121,7 @@ public class PostReviewers implements RestModifyView<ChangeResource, Input> {
|
||||
@Override
|
||||
public PostResult apply(ChangeResource rsrc, Input input)
|
||||
throws BadRequestException, ResourceNotFoundException, AuthException,
|
||||
UnprocessableEntityException, OrmException, EmailException {
|
||||
UnprocessableEntityException, OrmException, EmailException, IOException {
|
||||
if (input.reviewer == null) {
|
||||
throw new BadRequestException("missing reviewer field");
|
||||
}
|
||||
@@ -147,8 +148,8 @@ public class PostReviewers implements RestModifyView<ChangeResource, Input> {
|
||||
}
|
||||
|
||||
private PostResult putGroup(ChangeResource rsrc, Input input)
|
||||
throws ResourceNotFoundException, AuthException, BadRequestException,
|
||||
UnprocessableEntityException, OrmException, EmailException {
|
||||
throws BadRequestException,
|
||||
UnprocessableEntityException, OrmException, EmailException, IOException {
|
||||
GroupDescription.Basic group = groupsCollection.get().parseInternal(input.reviewer);
|
||||
PostResult result = new PostResult();
|
||||
if (!isLegalReviewerGroup(group.getGroupUUID())) {
|
||||
|
@@ -42,6 +42,7 @@ import com.googlecode.prolog_cafe.lang.Term;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -71,6 +72,9 @@ public class ChangeControl {
|
||||
return projectControl.controlFor(projectKey, user).controlFor(change);
|
||||
} catch (NoSuchProjectException e) {
|
||||
throw new NoSuchChangeException(change.getId(), e);
|
||||
} catch (IOException e) {
|
||||
// TODO: propagate this exception
|
||||
throw new NoSuchChangeException(change.getId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -35,6 +35,7 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@RequiresCapability(GlobalCapability.CREATE_PROJECT)
|
||||
@@ -79,7 +80,7 @@ class CreateProject implements RestModifyView<TopLevelResource, Input> {
|
||||
@Override
|
||||
public Object apply(TopLevelResource resource, Input input)
|
||||
throws BadRequestException, UnprocessableEntityException,
|
||||
ProjectCreationFailedException {
|
||||
ProjectCreationFailedException, IOException {
|
||||
if (input == null) {
|
||||
input = new Input();
|
||||
}
|
||||
|
@@ -38,6 +38,7 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -62,8 +63,8 @@ public class ProjectControl {
|
||||
}
|
||||
|
||||
public ProjectControl controlFor(Project.NameKey nameKey, CurrentUser user)
|
||||
throws NoSuchProjectException {
|
||||
final ProjectState p = projectCache.get(nameKey);
|
||||
throws NoSuchProjectException, IOException {
|
||||
final ProjectState p = projectCache.checkedGet(nameKey);
|
||||
if (p == null) {
|
||||
throw new NoSuchProjectException(nameKey);
|
||||
}
|
||||
|
@@ -28,6 +28,8 @@ import com.google.gerrit.server.OutputFormat;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ProjectsCollection implements
|
||||
RestCollection<TopLevelResource, ProjectResource>,
|
||||
AcceptsCreate<TopLevelResource> {
|
||||
@@ -56,7 +58,7 @@ public class ProjectsCollection implements
|
||||
|
||||
@Override
|
||||
public ProjectResource parse(TopLevelResource parent, IdString id)
|
||||
throws ResourceNotFoundException {
|
||||
throws ResourceNotFoundException, IOException {
|
||||
ProjectResource rsrc = _parse(id.get());
|
||||
if (rsrc == null) {
|
||||
throw new ResourceNotFoundException(id);
|
||||
@@ -71,8 +73,10 @@ public class ProjectsCollection implements
|
||||
* @return the project
|
||||
* @throws UnprocessableEntityException thrown if the project ID cannot be
|
||||
* resolved or if the project is not visible to the calling user
|
||||
* @throws IOException thrown when there is an error.
|
||||
*/
|
||||
public ProjectResource parse(String id) throws UnprocessableEntityException {
|
||||
public ProjectResource parse(String id)
|
||||
throws UnprocessableEntityException, IOException {
|
||||
ProjectResource rsrc = _parse(id);
|
||||
if (rsrc == null) {
|
||||
throw new UnprocessableEntityException(String.format(
|
||||
@@ -81,7 +85,7 @@ public class ProjectsCollection implements
|
||||
return rsrc;
|
||||
}
|
||||
|
||||
private ProjectResource _parse(String id) {
|
||||
private ProjectResource _parse(String id) throws IOException {
|
||||
ProjectControl ctl;
|
||||
try {
|
||||
ctl = controlFactory.controlFor(
|
||||
|
Reference in New Issue
Block a user