diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2013-01-22 23:39:51 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2013-01-22 23:39:51 +0100 |
commit | e0433a61af4e1b9796cee8f095486fec85eb136f (patch) | |
tree | e7ba14d6da8ef93100a4b5b0c8b2c0d4031bd9be /src/main/java | |
parent | b83c4eed1a75e9e68279ab6f84cd7b5eb602abec (diff) | |
download | esper-testing-e0433a61af4e1b9796cee8f095486fec85eb136f.tar.gz esper-testing-e0433a61af4e1b9796cee8f095486fec85eb136f.tar.bz2 esper-testing-e0433a61af4e1b9796cee8f095486fec85eb136f.tar.xz esper-testing-e0433a61af4e1b9796cee8f095486fec85eb136f.zip |
NavbarService:
o Renamed to NavTabService.
o Listing builds per server, with paging.
Diffstat (limited to 'src/main/java')
3 files changed, 35 insertions, 6 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 bd85e89..375187e 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java @@ -56,7 +56,7 @@ public class JenkinsDao { } }; - public static final String JENKINS_BUILD = "uuid, created_date, job, file, entry_id, url, users"; + public static final String JENKINS_BUILD = "jenkins_build.uuid, jenkins_build.created_date, jenkins_build.job, jenkins_build.file, jenkins_build.entry_id, jenkins_build.url, jenkins_build.users"; public static final SqlF<ResultSet, JenkinsBuildDto> jenkinsBuild = new SqlF<ResultSet, JenkinsBuildDto>() { public JenkinsBuildDto apply(ResultSet rs) throws SQLException { @@ -212,6 +212,20 @@ public class JenkinsDao { } } + public List<JenkinsBuildDto> selectBuildByServer(UUID server, PageRequest page) throws SQLException { + String sql = "SELECT " + JENKINS_BUILD + " FROM jenkins_build, jenkins_job WHERE jenkins_job.uuid = jenkins_build.job AND jenkins_job.server=?"; + 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()); + s.setInt(i++, page.count.orSome(10)); + s.setInt(i, page.startIndex.orSome(0)); + return toList(s, jenkinsBuild); + } + } + public SqlOption<JenkinsBuildDto> selectBuild(UUID uuid) throws SQLException { try (PreparedStatement s = c.prepareStatement("SELECT " + JENKINS_BUILD + " FROM jenkins_build WHERE uuid=?")) { int i = 1; diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java index f573b23..651d4b8 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java @@ -50,6 +50,9 @@ public class JenkinsServerActor implements TransactionalActor { logger.info("Got " + list.size() + " entries."); + // Process the list from the oldest first. + Collections.reverse(list); + int i = 0; Map<String, UUID> authors = new HashMap<>(); 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 450463b..e36952c 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 @@ -93,14 +93,26 @@ public class JenkinsResource extends AbstractResource { @GET @Path("/build") @Produces(MediaType.APPLICATION_JSON) - public List<JenkinsBuildJson> getBuilds(@MagicParam(query = "job") final UUID job, @MagicParam final PageRequest page) throws Exception { + public List<JenkinsBuildJson> getBuilds(@MagicParam(query = "job") final UUID job, + @MagicParam(query = "server") final UUID server, + @MagicParam final PageRequest page) throws Exception { return da.inTransaction(new JenkinsDaosCallback<List<JenkinsBuildJson>>() { protected List<JenkinsBuildJson> run() throws SQLException { - List<JenkinsBuildJson> builds = new ArrayList<>(); + List<JenkinsBuildDto> daos; + if(job != null) { - for (JenkinsBuildDto dto : daos.jenkinsDao.selectBuildByJob(job, page)) { - builds.add(getJenkinsBuildJson.apply(dto)); - } + daos = this.daos.jenkinsDao.selectBuildByJob(job, page); + } + else if(server != null) { + daos = this.daos.jenkinsDao.selectBuildByServer(server, page); + } + else { + throw new WebApplicationException(Response.Status.BAD_REQUEST); + } + + List<JenkinsBuildJson> builds = new ArrayList<>(); + for (JenkinsBuildDto dto : daos) { + builds.add(getJenkinsBuildJson.apply(dto)); } return builds; } |