ChildProjectResource: Use composition instead of inheritance
It was confusing that the project of the ChildProjectResource was actually the parent project, due to using inheritance. This was causing us to accidentally put the parent project name in the ResourceNotFoundException when parsing a resource. Change-Id: I94fe6522f1b11e81b677eb4cfda293ec991ff39f
This commit is contained in:
@@ -15,28 +15,34 @@
|
||||
package com.google.gerrit.server.project;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gerrit.extensions.restapi.RestResource;
|
||||
import com.google.gerrit.extensions.restapi.RestView;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
public class ChildProjectResource extends ProjectResource {
|
||||
public class ChildProjectResource implements RestResource {
|
||||
public static final TypeLiteral<RestView<ChildProjectResource>> CHILD_PROJECT_KIND =
|
||||
new TypeLiteral<RestView<ChildProjectResource>>() {};
|
||||
|
||||
private final ProjectResource parent;
|
||||
private final ProjectControl child;
|
||||
|
||||
public ChildProjectResource(ProjectResource project, ProjectControl child) {
|
||||
super(project);
|
||||
public ChildProjectResource(ProjectResource parent, ProjectControl child) {
|
||||
this.parent = parent;
|
||||
this.child = child;
|
||||
}
|
||||
|
||||
public ProjectResource getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public ProjectControl getChild() {
|
||||
return child;
|
||||
}
|
||||
|
||||
public boolean isDirectChild() {
|
||||
ProjectState parent =
|
||||
ProjectState firstParent =
|
||||
Iterables.getFirst(child.getProjectState().parents(), null);
|
||||
return parent != null
|
||||
&& getNameKey().equals(parent.getProject().getNameKey());
|
||||
return firstParent != null
|
||||
&& parent.getNameKey().equals(firstParent.getProject().getNameKey());
|
||||
}
|
||||
}
|
||||
|
@@ -38,6 +38,6 @@ public class GetChildProject implements RestReadView<ChildProjectResource> {
|
||||
if (recursive || rsrc.isDirectChild()) {
|
||||
return json.format(rsrc.getChild().getProject());
|
||||
}
|
||||
throw new ResourceNotFoundException(rsrc.getName());
|
||||
throw new ResourceNotFoundException(rsrc.getChild().getProject().getName());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user