From b83c4eed1a75e9e68279ab6f84cd7b5eb602abec Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 22 Jan 2013 22:52:09 +0100 Subject: NavbarService: o Storing the current tab with $location.search. JenkinsApp: o Implementing job search. --- .../io/trygvis/esper/testing/jenkins/JenkinsDao.java | 18 +++++++++++++++--- .../esper/testing/web/resource/JenkinsResource.java | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 5 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java index f8291b5..bd85e89 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java @@ -91,7 +91,7 @@ public class JenkinsDao { String sql = "SELECT " + JENKINS_SERVER + " FROM jenkins_server"; if (enabledOnly) { - sql += " WHERE enabled=true"; + sql += " WHERE enabled=TRUE"; } sql += " ORDER BY url"; @@ -119,10 +119,22 @@ public class JenkinsDao { } } - public List selectJobsByServer(UUID server, PageRequest page) throws SQLException { - try (PreparedStatement s = c.prepareStatement("SELECT " + JENKINS_JOB + " FROM jenkins_job WHERE server=? ORDER BY created_date DESC LIMIT ? OFFSET ?")) { + public List selectJobsByServer(UUID server, PageRequest page, Option name) throws SQLException { + String sql = "SELECT " + JENKINS_JOB + " FROM jenkins_job WHERE server=?"; + + if (name.isSome()) { + sql += " AND lower(display_name) LIKE '%' || lower(?) || '%'"; + } + + sql += orderBy(ifEmpty(page.orderBy, "created_date-"), "created_date"); + sql += " LIMIT ? OFFSET ?"; + + try (PreparedStatement s = c.prepareStatement(sql)) { int i = 1; s.setString(i++, server.toString()); + if (name.isSome()) { + s.setString(i++, name.some()); + } s.setInt(i++, page.count.orSome(10)); s.setInt(i, page.startIndex.orSome(0)); return toList(s, jenkinsJob); diff --git a/src/main/java/io/trygvis/esper/testing/web/resource/JenkinsResource.java b/src/main/java/io/trygvis/esper/testing/web/resource/JenkinsResource.java index fd8ea91..450463b 100755 --- a/src/main/java/io/trygvis/esper/testing/web/resource/JenkinsResource.java +++ b/src/main/java/io/trygvis/esper/testing/web/resource/JenkinsResource.java @@ -16,6 +16,9 @@ import java.util.List; import javax.ws.rs.*; import javax.ws.rs.core.*; +import static fj.data.Option.fromNull; +import static org.apache.commons.lang.StringUtils.trimToNull; + @Path("/resource/jenkins") public class JenkinsResource extends AbstractResource { @@ -54,11 +57,21 @@ public class JenkinsResource extends AbstractResource { @GET @Path("/job") @Produces(MediaType.APPLICATION_JSON) - public List getJobs(@MagicParam(query = "server") final UUID server, @MagicParam final PageRequest page) throws Exception { + public List getJobs(@MagicParam(query = "server") final UUID server, + @MagicParam final PageRequest page, + @QueryParam("query") final String query) throws Exception { + if (server == null) { + throw new WebApplicationException(Response.Status.BAD_REQUEST); + } + return da.inTransaction(new JenkinsDaosCallback>() { protected List run() throws SQLException { + List dtos; + + dtos = daos.jenkinsDao.selectJobsByServer(server, page, fromNull(trimToNull(query))); + List jobs = new ArrayList<>(); - for (JenkinsJobDto job : daos.jenkinsDao.selectJobsByServer(server, page)) { + for (JenkinsJobDto job : dtos) { jobs.add(getJenkinsJobJson.apply(job)); } return jobs; -- cgit v1.2.3