Adding REST API support for adding and removing jobs from ListView instances

This commit is contained in:
Stephen Connolly committed 2012-07-23 10:53:49 +01:00
1 parent 437f7afb53
commit 2ea067a8d3
2 files changed
+70

No files matched your search

@@ -39,6 +39,7 @@ import org.kohsuke.stapler.StaplerResponse;
import javax.annotation.concurrent.GuardedBy;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashSet;
@@ -214,6 +215,35 @@ public class ListView extends View implements Saveable {
return null;
}
public void doAddJobToView(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
checkPermission(View.CONFIGURE);
String name = req.getParameter("name");
if(name==null)
throw new Failure("Query parameter 'name' is required");
if (getOwnerItemGroup().getItem(name) == null)
throw new Failure("Query parameter 'name' does not correspond to a known item");
if (jobNames.add(name))
owner.save();
rsp.setStatus(HttpServletResponse.SC_OK);
}
public void doRemoveJobFromView(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
checkPermission(View.CONFIGURE);
String name = req.getParameter("name");
if(name==null)
throw new Failure("Query parameter 'name' is required");
if (jobNames.remove(name))
owner.save();
rsp.setStatus(HttpServletResponse.SC_OK);
}
@Override
public synchronized void onJobRenamed(Item item, String oldName, String newName) {
if(jobNames.remove(oldName) && newName!=null)
@@ -0,0 +1,40 @@
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<h2>Add Job to View</h2>
<p>
To add a job to this view, send a POST request to <a href="../addJobToView">this URL</a> with
query parameter <tt>name=<i>JOBNAME</i></tt>. You'll get 200 status code if the job was successfully added to
this view, or 4xx/5xx code if it fails.
</p>
<h2>Remove Job from View</h2>
<p>
To remove a job from this view, send a POST request to <a href="../removeJobFromView">this URL</a> with
query parameter <tt>name=<i>JOBNAME</i></tt>. You'll get 200 status code if the job was successfully removed
from this view, or 4xx/5xx code if it fails.
</p>
</j:jelly>