diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2013-01-22 22:52:09 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2013-01-22 22:52:09 +0100 |
commit | b83c4eed1a75e9e68279ab6f84cd7b5eb602abec (patch) | |
tree | 0a1a24ba310fa53e793db3bb298536a81b01f3c3 /src/main/java/io | |
parent | 498fd62e043e31bf5beddfff0e9b5f7f889b884c (diff) | |
download | esper-testing-b83c4eed1a75e9e68279ab6f84cd7b5eb602abec.tar.gz esper-testing-b83c4eed1a75e9e68279ab6f84cd7b5eb602abec.tar.bz2 esper-testing-b83c4eed1a75e9e68279ab6f84cd7b5eb602abec.tar.xz esper-testing-b83c4eed1a75e9e68279ab6f84cd7b5eb602abec.zip |
NavbarService:
o Storing the current tab with $location.search.
JenkinsApp:
o Implementing job search.
Diffstat (limited to 'src/main/java/io')
-rwxr-xr-x | src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java | 18 | ||||
-rwxr-xr-x | src/main/java/io/trygvis/esper/testing/web/resource/JenkinsResource.java | 17 |
2 files changed, 30 insertions, 5 deletions
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<JenkinsJobDto> 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<JenkinsJobDto> selectJobsByServer(UUID server, PageRequest page, Option<String> 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<JenkinsJobJson> getJobs(@MagicParam(query = "server") final UUID server, @MagicParam final PageRequest page) throws Exception { + public List<JenkinsJobJson> 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<List<JenkinsJobJson>>() { protected List<JenkinsJobJson> run() throws SQLException { + List<JenkinsJobDto> dtos; + + dtos = daos.jenkinsDao.selectJobsByServer(server, page, fromNull(trimToNull(query))); + List<JenkinsJobJson> jobs = new ArrayList<>(); - for (JenkinsJobDto job : daos.jenkinsDao.selectJobsByServer(server, page)) { + for (JenkinsJobDto job : dtos) { jobs.add(getJenkinsJobJson.apply(job)); } return jobs; |