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