From fd953370ba0daea03c5de58aac30e097f86826c6 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 19 Jan 2013 10:20:43 +0100 Subject: o Making sure every resource that supports paging has a default ordering. o Fixing mis-mapped JenkinsJob. o Better navigation in the Jenkins app, links are now proper links. --- src/main/java/io/trygvis/esper/testing/Util.java | 10 +++++- .../io/trygvis/esper/testing/core/db/BuildDao.java | 4 +-- .../trygvis/esper/testing/core/db/PersonDao.java | 10 +++--- .../trygvis/esper/testing/jenkins/JenkinsDao.java | 11 ++++-- .../esper/testing/jenkins/JenkinsJobDto.java | 4 ++- .../esper/testing/util/sql/PageRequest.java | 6 ++-- .../esper/testing/web/JerseyApplication.java | 4 +-- .../testing/web/resource/JenkinsResource.java | 22 ++++++------ .../resources/webapp/apps/jenkinsApp/build.html | 6 ++-- .../resources/webapp/apps/jenkinsApp/jenkinsApp.js | 39 ++++++++-------------- src/main/resources/webapp/apps/jenkinsApp/job.html | 8 ++--- .../webapp/apps/jenkinsApp/server-list.html | 2 +- .../resources/webapp/apps/jenkinsApp/server.html | 14 +++----- 13 files changed, 71 insertions(+), 69 deletions(-) mode change 100644 => 100755 src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java mode change 100644 => 100755 src/main/resources/webapp/apps/jenkinsApp/jenkinsApp.js mode change 100644 => 100755 src/main/resources/webapp/apps/jenkinsApp/server-list.html mode change 100644 => 100755 src/main/resources/webapp/apps/jenkinsApp/server.html diff --git a/src/main/java/io/trygvis/esper/testing/Util.java b/src/main/java/io/trygvis/esper/testing/Util.java index 849a6f9..1bba36c 100755 --- a/src/main/java/io/trygvis/esper/testing/Util.java +++ b/src/main/java/io/trygvis/esper/testing/Util.java @@ -77,11 +77,19 @@ public class Util { // SQL // ----------------------------------------------------------------------- + public static List ifEmpty(List inputs, String defaultValue) { + if (inputs.isEmpty()) { + return inputs; + } + + return Collections.singletonList(defaultValue); + } + public static String orderBy(String[] inputs, String... allowed) { return orderBy(Arrays.asList(inputs), allowed); } - public static String orderBy(Iterable inputs, String... allowed) { + public static String orderBy(List inputs, String... allowed) { StringBuilder buffer = new StringBuilder(); for (String input : inputs) { diff --git a/src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java b/src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java index c6a46c6..7c9ccb7 100755 --- a/src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java +++ b/src/main/java/io/trygvis/esper/testing/core/db/BuildDao.java @@ -92,7 +92,7 @@ public class BuildDao { public List selectBuildsByPerson(Uuid person, PageRequest page) throws SQLException { String sql = "SELECT " + BUILD + " FROM build b, build_participant bp WHERE bp.person=? AND b.uuid = bp.build"; - sql += orderBy(page.orderBy, "created_date", "timestamp"); + sql += orderBy(ifEmpty(page.orderBy, "created_date-"), "created_date", "timestamp"); sql += " LIMIT ? OFFSET ?"; try (PreparedStatement s = c.prepareStatement(sql)) { @@ -106,7 +106,7 @@ public class BuildDao { public List selectBuilds(PageRequest page) throws SQLException { String sql = "SELECT " + BUILD + " FROM build"; - sql += orderBy(page.orderBy, "created_date", "timestamp"); + sql += orderBy(ifEmpty(page.orderBy, "created_date-"), "created_date", "timestamp"); sql += " LIMIT ? OFFSET ?"; try (PreparedStatement s = c.prepareStatement(sql)) { diff --git a/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java b/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java index 290d6d5..2cfb16d 100755 --- a/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java +++ b/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java @@ -97,14 +97,14 @@ public class PersonDao { } } - public List selectPersons(PageRequest pageRequest, Option query) throws SQLException { + public List selectPersons(PageRequest page, Option query) throws SQLException { String sql = "SELECT " + PERSON + " FROM person"; if (query.isSome()) { sql += " WHERE lower(name) LIKE '%' || ? || '%'"; } - sql += orderBy(pageRequest.orderBy, "name", "created_date"); + sql += orderBy(ifEmpty(page.orderBy, "created_date-"), "name", "created_date"); sql += " LIMIT ? OFFSET ?"; @@ -115,8 +115,8 @@ public class PersonDao { s.setString(i++, query.some()); } - s.setInt(i++, pageRequest.count.orSome(10)); - s.setInt(i, pageRequest.startIndex.orSome(0)); + s.setInt(i++, page.count.orSome(10)); + s.setInt(i, page.startIndex.orSome(0)); return toList(s, person); } } @@ -216,7 +216,7 @@ public class PersonDao { sql += " AND level=?"; } - sql += orderBy(page.orderBy, "name", "created_date"); + sql += orderBy(ifEmpty(page.orderBy, "created_date-"), "name", "created_date"); sql += " LIMIT ? OFFSET ?"; 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 781df13..d21118d 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java @@ -22,8 +22,6 @@ public class JenkinsDao { public static final String JENKINS_SERVER = "uuid, created_date, name, url, enabled"; - public static final String JENKINS_JOB = "uuid, created_date, server, file, url, job_type, display_name"; - public static final String JENKINS_USER = "uuid, created_date, server, absolute_url"; public JenkinsDao(Connection c) { @@ -42,6 +40,8 @@ public class JenkinsDao { } }; + public static final String JENKINS_JOB = "uuid, created_date, server, file, url, job_type, display_name"; + public static final SqlF jenkinsJob = new SqlF() { public JenkinsJobDto apply(ResultSet rs) throws SQLException { int i = 1; @@ -51,6 +51,7 @@ public class JenkinsDao { UUID.fromString(rs.getString(i++)), UUID.fromString(rs.getString(i++)), URI.create(rs.getString(i++)), + rs.getString(i++), fromNull(rs.getString(i))); } }; @@ -172,7 +173,11 @@ public class JenkinsDao { } public List selectBuildByJob(UUID job, PageRequest page) throws SQLException { - try (PreparedStatement s = c.prepareStatement("SELECT " + JENKINS_BUILD + " FROM jenkins_build WHERE job=? ORDER BY created_date DESC LIMIT ? OFFSET ?")) { + String sql = "SELECT " + JENKINS_BUILD + " FROM jenkins_build WHERE job=?"; + sql += orderBy(ifEmpty(page.orderBy, "created_date-"), "created_date", "timestamp"); + sql += " LIMIT ? OFFSET ?"; + + try (PreparedStatement s = c.prepareStatement(sql)) { int i = 1; s.setString(i++, job.toString()); s.setInt(i++, page.count.orSome(10)); diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJobDto.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJobDto.java index e540a2a..2092d89 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJobDto.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsJobDto.java @@ -11,13 +11,15 @@ public class JenkinsJobDto extends AbstractEntity { public final UUID server; public final UUID file; public final URI url; + public final String jobType; public final Option displayName; - public JenkinsJobDto(UUID uuid, DateTime createdDate, UUID server, UUID file, URI url, Option displayName) { + public JenkinsJobDto(UUID uuid, DateTime createdDate, UUID server, UUID file, URI url, String jobType, Option displayName) { super(uuid, createdDate); this.server = server; this.file = file; this.url = url; + this.jobType = jobType; this.displayName = displayName; } } diff --git a/src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java b/src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java old mode 100644 new mode 100755 index b7c6750..7773e50 --- a/src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java +++ b/src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java @@ -1,12 +1,14 @@ package io.trygvis.esper.testing.util.sql; -import fj.data.*; +import fj.data.Option; + +import java.util.*; public class PageRequest { public final Option startIndex; public final Option count; public final List orderBy; - public static final PageRequest FIRST_PAGE = new PageRequest(Option.none(), Option.none(), List.nil()); + public static final PageRequest FIRST_PAGE = new PageRequest(Option.none(), Option.none(), Collections.emptyList()); public PageRequest(Option startIndex, Option count, List orderBy) { this.startIndex = startIndex; diff --git a/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java b/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java index 38cfd9d..b85dd7a 100755 --- a/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java +++ b/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java @@ -66,10 +66,10 @@ public class JerseyApplication extends Application { List list = queryParameters.get("orderBy"); - fj.data.List orderBy = nil(); + List orderBy = Collections.emptyList(); if (list != null) { - orderBy = iterableList(list); + orderBy = list; } return new PageRequest( 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 0c0c6a9..a6d8e8e 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 @@ -69,9 +69,9 @@ public class JenkinsResource extends AbstractResource { @GET @Path("/job/{uuid}") @Produces(MediaType.APPLICATION_JSON) - public JenkinsJobJsonDetail getJob(@MagicParam final UUID uuid) throws Exception { - return sql(new JenkinsDaosCallback>() { - protected SqlOption run() throws SQLException { + public JenkinsJobDetailJson getJob(@MagicParam final UUID uuid) throws Exception { + return sql(new JenkinsDaosCallback>() { + protected SqlOption run() throws SQLException { return daos.jenkinsDao.selectJob(uuid).map(getJenkinsJobJsonDetail); } }); @@ -149,13 +149,13 @@ public class JenkinsResource extends AbstractResource { protected SqlF getJenkinsJobJson = new SqlF() { public JenkinsJobJson apply(JenkinsJobDto job) throws SQLException { - return new JenkinsJobJson(job.uuid, job.createdDate, job.server, job.displayName.toNull()); + return new JenkinsJobJson(job.uuid, job.createdDate, job.server, job.url, job.displayName.toNull()); } }; - protected SqlF getJenkinsJobJsonDetail = new SqlF() { - public JenkinsJobJsonDetail apply(JenkinsJobDto dto) throws SQLException { - return new JenkinsJobJsonDetail( + protected SqlF getJenkinsJobJsonDetail = new SqlF() { + public JenkinsJobDetailJson apply(JenkinsJobDto dto) throws SQLException { + return new JenkinsJobDetailJson( getJenkinsJobJson.apply(dto), daos.jenkinsDao.selectBuildCountByJob(dto.uuid)); } @@ -223,21 +223,23 @@ class JenkinsJobJson { public final UUID uuid; public final DateTime createdDate; public final UUID server; + public final URI url; public final String displayName; - JenkinsJobJson(UUID uuid, DateTime createdDate, UUID server, String displayName) { + JenkinsJobJson(UUID uuid, DateTime createdDate, UUID server, URI url, String displayName) { this.uuid = uuid; this.createdDate = createdDate; this.server = server; + this.url = url; this.displayName = displayName; } } -class JenkinsJobJsonDetail { +class JenkinsJobDetailJson { public final JenkinsJobJson job; public final Integer buildCount; - JenkinsJobJsonDetail(JenkinsJobJson job, Integer buildCount) { + JenkinsJobDetailJson(JenkinsJobJson job, Integer buildCount) { this.job = job; this.buildCount = buildCount; } diff --git a/src/main/resources/webapp/apps/jenkinsApp/build.html b/src/main/resources/webapp/apps/jenkinsApp/build.html index 7239c90..13e3b8b 100755 --- a/src/main/resources/webapp/apps/jenkinsApp/build.html +++ b/src/main/resources/webapp/apps/jenkinsApp/build.html @@ -7,9 +7,9 @@ diff --git a/src/main/resources/webapp/apps/jenkinsApp/jenkinsApp.js b/src/main/resources/webapp/apps/jenkinsApp/jenkinsApp.js old mode 100644 new mode 100755 index e42c67b..68344cd --- a/src/main/resources/webapp/apps/jenkinsApp/jenkinsApp.js +++ b/src/main/resources/webapp/apps/jenkinsApp/jenkinsApp.js @@ -3,55 +3,44 @@ var jenkinsApp = angular.module('jenkinsApp', ['jenkinsServer', 'jenkinsJob', 'jenkinsBuild', 'core.directives', 'pagingTableService']).config(function ($routeProvider) { $routeProvider. when('/', {controller: ServerListCtrl, templateUrl: '/apps/jenkinsApp/server-list.html?noCache=' + noCache}). - when('/server/:uuid', {controller: ServerCtrl, templateUrl: '/apps/jenkinsApp/server.html?noCache=' + noCache}). - when('/job/:uuid', {controller: JobCtrl, templateUrl: '/apps/jenkinsApp/job.html?noCache=' + noCache}). - when('/build/:uuid', {controller: BuildCtrl, templateUrl: '/apps/jenkinsApp/build.html?noCache=' + noCache}); + when('/server/:serverUuid', {controller: ServerCtrl, templateUrl: '/apps/jenkinsApp/server.html?noCache=' + noCache}). + when('/server/:serverUuid/job/:jobUuid', {controller: JobCtrl, templateUrl: '/apps/jenkinsApp/job.html?noCache=' + noCache}). + when('/server/:serverUuid/job/:jobUuid/build/:buildUuid', {controller: BuildCtrl, templateUrl: '/apps/jenkinsApp/build.html?noCache=' + noCache}); }); function ServerListCtrl($scope, $location, JenkinsServer) { JenkinsServer.query(function (servers) { $scope.servers = servers; }); - - $scope.showServers = function () { $location.path('/'); }; - $scope.showServer = function (uuid) { $location.path('/server/' + uuid); }; } function ServerCtrl($scope, $location, $routeParams, JenkinsServer, JenkinsJob, PagingTableService) { - var serverUuid = $routeParams.uuid; + $scope.serverUuid = $routeParams.serverUuid; - JenkinsServer.get({uuid: serverUuid}, function (server) { + JenkinsServer.get({uuid: $scope.serverUuid}, function (server) { $scope.server = server; }); - $scope.jobs = PagingTableService.create($scope, PagingTableService.defaultCallback(JenkinsJob, {server: serverUuid})); - - $scope.showServers = function () { $location.path('/'); }; - $scope.showJob = function (uuid) { $location.path('/job/' + uuid); }; + $scope.jobs = PagingTableService.create($scope, PagingTableService.defaultCallback(JenkinsJob, {server: $scope.serverUuid})); } function JobCtrl($scope, $location, $routeParams, JenkinsJob, JenkinsBuild, PagingTableService) { - var jobUuid = $routeParams.uuid; + $scope.serverUuid = $routeParams.serverUuid; + $scope.jobUuid = $routeParams.jobUuid; - JenkinsJob.get({uuid: jobUuid}, function (details) { + JenkinsJob.get({uuid: $scope.jobUuid}, function (details) { $scope.details = details; }); - $scope.builds = PagingTableService.create($scope, PagingTableService.defaultCallback(JenkinsBuild, {job: jobUuid})); - - $scope.showServers = function () { $location.path('/'); }; - $scope.showServer = function () { $location.path('/server/' + $scope.job.server); }; - $scope.showBuild = function (uuid) { $location.path('/build/' + uuid); }; + $scope.builds = PagingTableService.create($scope, PagingTableService.defaultCallback(JenkinsBuild, {job: $scope.jobUuid, orderBy: "timestamp-"})); } function BuildCtrl($scope, $location, $routeParams, JenkinsBuild) { - var buildUuid = $routeParams.uuid; + $scope.serverUuid = $routeParams.serverUuid; + $scope.jobUuid = $routeParams.jobUuid; + $scope.buildUuid = $routeParams.buildUuid; - JenkinsBuild.get({uuid: buildUuid}, function (details) { + JenkinsBuild.get({uuid: $scope.buildUuid}, function (details) { $scope.details = details; }); - - $scope.showServers = function () { $location.path('/'); }; - $scope.showServer = function (uuid) { $location.path('/server/' + $scope.server.uuid); }; - $scope.showJob = function (uuid) { $location.path('/job/' + $scope.build.job); }; } diff --git a/src/main/resources/webapp/apps/jenkinsApp/job.html b/src/main/resources/webapp/apps/jenkinsApp/job.html index 8942ab7..4f21fad 100755 --- a/src/main/resources/webapp/apps/jenkinsApp/job.html +++ b/src/main/resources/webapp/apps/jenkinsApp/job.html @@ -7,8 +7,8 @@ @@ -18,7 +18,7 @@ URL - {{details.job.displayName}} + {{details.job.displayName}} Build count @@ -40,7 +40,7 @@ {{build.timestamp | date:'medium'}} {{build.result}} - + diff --git a/src/main/resources/webapp/apps/jenkinsApp/server-list.html b/src/main/resources/webapp/apps/jenkinsApp/server-list.html old mode 100644 new mode 100755 index 9e297e6..93e5e9e --- a/src/main/resources/webapp/apps/jenkinsApp/server-list.html +++ b/src/main/resources/webapp/apps/jenkinsApp/server-list.html @@ -24,7 +24,7 @@ {{server.url}} {{server.enabled}} Visit - + diff --git a/src/main/resources/webapp/apps/jenkinsApp/server.html b/src/main/resources/webapp/apps/jenkinsApp/server.html old mode 100644 new mode 100755 index 7fbd9f5..fb821d3 --- a/src/main/resources/webapp/apps/jenkinsApp/server.html +++ b/src/main/resources/webapp/apps/jenkinsApp/server.html @@ -8,7 +8,7 @@ @@ -25,24 +25,18 @@ Stats - {{server.jobCount}} jobs, {{server.buildCount}} builds + {{server.jobCount}} jobs

Recent Jobs

- - - - - - - - + + -- cgit v1.2.3
Job
{{job.createdDate | date:'medium'}} {{job.displayName}}{{job.uuid}}{{job.createdDate | date:'medium'}}