提交 21ec2a72 编写于 作者: O Oliver Gondža

[JENKINS-22967] Make DirectlyModifiableView an interface rather than class

上级 8fc60f0c
......@@ -35,20 +35,12 @@ import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.interceptor.RequirePOST;
/**
* View its items can be modified.
* Marker interface for {@link View} its items can be modified.
*
* @author ogondza
* @since TODO
*/
public abstract class DirectlyModifiableView extends View {
public DirectlyModifiableView(String name) {
super(name);
}
public DirectlyModifiableView(String name, ViewGroup owner) {
super(name, owner);
}
public interface DirectlyModifiableView {
/**
* Remove item from this view.
......@@ -57,7 +49,7 @@ public abstract class DirectlyModifiableView extends View {
* @throws IOException Removal failed.
* @throws IllegalArgumentException View rejected to remove an item.
*/
public abstract boolean remove(@Nonnull TopLevelItem item) throws IOException, IllegalArgumentException;
boolean remove(@Nonnull TopLevelItem item) throws IOException, IllegalArgumentException;
/**
* Add item to this view.
......@@ -65,46 +57,23 @@ public abstract class DirectlyModifiableView extends View {
* @throws IOException Adding failed.
* @throws IllegalArgumentException View rejected to add an item.
*/
public abstract void add(@Nonnull TopLevelItem item) throws IOException, IllegalArgumentException;
void add(@Nonnull TopLevelItem item) throws IOException, IllegalArgumentException;
/**
* Handle addJobToView web method.
*
* This method should @RequirePOST.
*
* @param name Item name.
*/
@RequirePOST
public HttpResponse doAddJobToView(@QueryParameter String name) throws IOException, ServletException {
checkPermission(View.CONFIGURE);
if(name==null)
throw new Failure("Query parameter 'name' is required");
TopLevelItem item = getOwnerItemGroup().getItem(name);
if (item == null)
throw new Failure("Query parameter 'name' does not correspond to a known item");
if (contains(item)) return HttpResponses.ok();
add(item);
owner.save();
return HttpResponses.ok();
}
HttpResponse doAddJobToView(@QueryParameter String name) throws IOException, ServletException;
/**
* Handle removeJobFromView web method.
*
* This method should @RequirePOST.
*
* @param name Item name.
*/
@RequirePOST
public HttpResponse doRemoveJobFromView(@QueryParameter String name) throws IOException, ServletException {
checkPermission(View.CONFIGURE);
if(name==null)
throw new Failure("Query parameter 'name' is required");
TopLevelItem item = getOwnerItemGroup().getItem(name);
if (remove(item))
owner.save();
return HttpResponses.ok();
}
HttpResponse doRemoveJobFromView(@QueryParameter String name) throws IOException, ServletException;
}
......@@ -63,7 +63,7 @@ import org.kohsuke.stapler.interceptor.RequirePOST;
*
* @author Kohsuke Kawaguchi
*/
public class ListView extends DirectlyModifiableView {
public class ListView extends View implements DirectlyModifiableView {
/**
* List of job names. This is what gets serialized.
......@@ -305,6 +305,39 @@ public class ListView extends DirectlyModifiableView {
return null;
}
@Override
@RequirePOST
public HttpResponse doAddJobToView(@QueryParameter String name) throws IOException, ServletException {
checkPermission(View.CONFIGURE);
if(name==null)
throw new Failure("Query parameter 'name' is required");
TopLevelItem item = getOwnerItemGroup().getItem(name);
if (item == null)
throw new Failure("Query parameter 'name' does not correspond to a known item");
if (contains(item)) return HttpResponses.ok();
add(item);
owner.save();
return HttpResponses.ok();
}
@Override
@RequirePOST
public HttpResponse doRemoveJobFromView(@QueryParameter String name) throws IOException, ServletException {
checkPermission(View.CONFIGURE);
if(name==null)
throw new Failure("Query parameter 'name' is required");
TopLevelItem item = getOwnerItemGroup().getItem(name);
if (remove(item))
owner.save();
return HttpResponses.ok();
}
/**
* Handles the configuration submission.
*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册