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

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

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