From eb6cbd28992cec9025a8e95f8f03ae3839699e0b Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 19 Jan 2013 09:40:14 +0100 Subject: o Reverting the timestamp => createdDate change, it was wrong. Adding ability to sort on timestamp. Created date is when we discovered the build, the timestamp is when Jenkins did the build. --- src/main/java/io/trygvis/esper/testing/Daos.java | 15 ------------ src/main/java/io/trygvis/esper/testing/Util.java | 4 ++++ .../io/trygvis/esper/testing/core/db/BuildDao.java | 16 +++++++++---- .../gitorious/GitoriousProjectDiscovery.java | 4 ++-- .../testing/gitorious/GitoriousRepositoryDao.java | 27 +++++++++------------- src/main/resources/webapp/apps/buildApp/build.html | 2 +- .../resources/webapp/apps/frontPageApp/badge.html | 15 ++++++++---- .../resources/webapp/apps/frontPageApp/build.html | 2 +- .../webapp/apps/frontPageApp/buildList.html | 2 +- .../webapp/apps/frontPageApp/frontPageApp.js | 8 +++---- .../resources/webapp/apps/frontPageApp/person.html | 6 ++--- .../resources/webapp/apps/jenkinsApp/build.html | 2 +- src/main/resources/webapp/apps/jenkinsApp/job.html | 2 +- 13 files changed, 51 insertions(+), 54 deletions(-) mode change 100644 => 100755 src/main/java/io/trygvis/esper/testing/gitorious/GitoriousProjectDiscovery.java mode change 100644 => 100755 src/main/java/io/trygvis/esper/testing/gitorious/GitoriousRepositoryDao.java diff --git a/src/main/java/io/trygvis/esper/testing/Daos.java b/src/main/java/io/trygvis/esper/testing/Daos.java index 1a7cb0b..0242a3a 100755 --- a/src/main/java/io/trygvis/esper/testing/Daos.java +++ b/src/main/java/io/trygvis/esper/testing/Daos.java @@ -9,21 +9,6 @@ import java.sql.*; public class Daos implements Closeable { - public enum OrderDirection { - ASC, DESC, NONE; - - public String toSql(String expression) { - switch (this) { - case ASC: - return expression + "expression"; - case DESC: - return expression + "expression DESC"; - default: - return "1"; - } - } - } - private final Connection connection; public final FileDao fileDao; public final GitoriousEventDao gitoriousEventDao; diff --git a/src/main/java/io/trygvis/esper/testing/Util.java b/src/main/java/io/trygvis/esper/testing/Util.java index 68660c4..849a6f9 100755 --- a/src/main/java/io/trygvis/esper/testing/Util.java +++ b/src/main/java/io/trygvis/esper/testing/Util.java @@ -77,6 +77,10 @@ public class Util { // SQL // ----------------------------------------------------------------------- + public static String orderBy(String[] inputs, String... allowed) { + return orderBy(Arrays.asList(inputs), allowed); + } + public static String orderBy(Iterable inputs, String... allowed) { StringBuilder buffer = new StringBuilder(); 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 32afe42..c6a46c6 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 @@ -7,7 +7,7 @@ import org.joda.time.*; import java.sql.*; import java.util.*; -import static io.trygvis.esper.testing.Util.toList; +import static io.trygvis.esper.testing.Util.*; import static io.trygvis.esper.testing.util.sql.ResultSetF.*; import static io.trygvis.esper.testing.util.sql.SqlOption.fromRs; import static java.lang.System.*; @@ -15,7 +15,7 @@ import static java.lang.System.*; public class BuildDao { private final Connection c; - public static final String BUILD = "uuid, created_date, timestamp, success, reference_type, reference_uuid"; + public static final String BUILD = "UUID, created_date, TIMESTAMP, success, reference_type, reference_uuid"; public static final SqlF build = new SqlF() { public BuildDto apply(ResultSet rs) throws SQLException { @@ -91,7 +91,11 @@ public class BuildDao { } public List selectBuildsByPerson(Uuid person, PageRequest page) throws SQLException { - try (PreparedStatement s = c.prepareStatement("SELECT " + BUILD + " FROM build b, build_participant bp WHERE bp.person=? AND b.uuid = bp.build ORDER BY created_date DESC LIMIT ? OFFSET ?")) { + 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 += " LIMIT ? OFFSET ?"; + + try (PreparedStatement s = c.prepareStatement(sql)) { int i = 1; s.setString(i++, person.toUuidString()); s.setInt(i++, page.count.orSome(10)); @@ -101,7 +105,11 @@ public class BuildDao { } public List selectBuilds(PageRequest page) throws SQLException { - try (PreparedStatement s = c.prepareStatement("SELECT " + BUILD + " FROM build ORDER BY created_date DESC LIMIT ? OFFSET ?")) { + String sql = "SELECT " + BUILD + " FROM build"; + sql += orderBy(page.orderBy, "created_date", "timestamp"); + sql += " LIMIT ? OFFSET ?"; + + try (PreparedStatement s = c.prepareStatement(sql)) { int i = 1; s.setInt(i++, page.count.orSome(10)); s.setInt(i, page.startIndex.orSome(0)); diff --git a/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousProjectDiscovery.java b/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousProjectDiscovery.java old mode 100644 new mode 100755 index 67b6d17..d60956d --- a/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousProjectDiscovery.java +++ b/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousProjectDiscovery.java @@ -38,7 +38,7 @@ public class GitoriousProjectDiscovery { Set repositories = Collections.emptySet(); try (Connection c = boneCp.getConnection()) { - repositories = new HashSet<>(new Daos(c).gitoriousRepositoryDao.select(Daos.OrderDirection.ASC)); + repositories = new HashSet<>(new Daos(c).gitoriousRepositoryDao.select(true)); } catch (SQLException e) { // ignore } @@ -53,7 +53,7 @@ public class GitoriousProjectDiscovery { public void act(Connection c) throws Exception { try (Daos daos = new Daos(c)) { discoverProjects(daos); - repositoryManager.update(daos.gitoriousRepositoryDao.select(Daos.OrderDirection.NONE)); + repositoryManager.update(daos.gitoriousRepositoryDao.select(null)); daos.commit(); } } diff --git a/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousRepositoryDao.java b/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousRepositoryDao.java old mode 100644 new mode 100755 index 903d74c..27e66fe --- a/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousRepositoryDao.java +++ b/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousRepositoryDao.java @@ -2,8 +2,7 @@ package io.trygvis.esper.testing.gitorious; import fj.data.*; import io.trygvis.esper.testing.*; -import static io.trygvis.esper.testing.Util.dateToTimestamp; -import static io.trygvis.esper.testing.Util.timestampToDate; +import io.trygvis.esper.testing.util.sql.*; import java.net.*; import java.sql.*; @@ -11,6 +10,8 @@ import java.util.*; import java.util.Date; import java.util.List; +import static io.trygvis.esper.testing.Util.*; + public class GitoriousRepositoryDao { private final Connection c; @@ -38,7 +39,7 @@ public class GitoriousRepositoryDao { } public int countRepositories(String projectSlug, String name) throws SQLException { - try (PreparedStatement s = c.prepareStatement("SELECT count(*) FROM gitorious_repository WHERE project_slug=? and name=?")) { + try (PreparedStatement s = c.prepareStatement("SELECT count(*) FROM gitorious_repository WHERE project_slug=? AND name=?")) { s.setString(1, projectSlug); s.setString(2, name); try (ResultSet rs = s.executeQuery()) { @@ -55,21 +56,15 @@ public class GitoriousRepositoryDao { } } - public List select(Daos.OrderDirection order) throws SQLException { - String orderBy; - - switch (order) { - case ASC: - orderBy = "ORDER BY project_slug, name"; - break; - case DESC: - orderBy = "ORDER BY project_slug DESC, name DESC"; - break; - default: - orderBy = ""; + public List select(Boolean asc) throws SQLException { + String sql = "SELECT " + ALL_FIELDS + " FROM gitorious_repository "; + + if(asc != null) { + String[] orderBy = asc ? new String[]{"project_slug", "name"} : new String[]{"project_slug-", "name-"}; + sql += orderBy(orderBy, "project_slug", "name"); } - try (PreparedStatement s = c.prepareStatement("SELECT " + ALL_FIELDS + " FROM gitorious_repository " + orderBy)) { + try (PreparedStatement s = c.prepareStatement(sql)) { return executeQuery(s); } } diff --git a/src/main/resources/webapp/apps/buildApp/build.html b/src/main/resources/webapp/apps/buildApp/build.html index 2a24b16..fec38d2 100755 --- a/src/main/resources/webapp/apps/buildApp/build.html +++ b/src/main/resources/webapp/apps/buildApp/build.html @@ -9,7 +9,7 @@ - + diff --git a/src/main/resources/webapp/apps/frontPageApp/badge.html b/src/main/resources/webapp/apps/frontPageApp/badge.html index 48d15ce..b501f15 100755 --- a/src/main/resources/webapp/apps/frontPageApp/badge.html +++ b/src/main/resources/webapp/apps/frontPageApp/badge.html @@ -15,11 +15,16 @@

The badge was awarded for having {{badge.personalBadge.builds.length}} successful builds in a row:

- +
Date{{build.build.createdDate | date:'medium'}}{{build.build.timestamp | date:'medium'}}
Status
+ + + + +
+ {{b.timestamp | date:'medium'}} + + {{$index + 1}} +
diff --git a/src/main/resources/webapp/apps/frontPageApp/build.html b/src/main/resources/webapp/apps/frontPageApp/build.html index cbf8f8e..0972758 100755 --- a/src/main/resources/webapp/apps/frontPageApp/build.html +++ b/src/main/resources/webapp/apps/frontPageApp/build.html @@ -16,7 +16,7 @@ Duration - {{build.build.createdDate | date:'medium'}} + {{build.build.timestamp | date:'medium'}} diff --git a/src/main/resources/webapp/apps/frontPageApp/buildList.html b/src/main/resources/webapp/apps/frontPageApp/buildList.html index ddbffe2..d069736 100755 --- a/src/main/resources/webapp/apps/frontPageApp/buildList.html +++ b/src/main/resources/webapp/apps/frontPageApp/buildList.html @@ -28,7 +28,7 @@

- {{build.build.createdDate | date:'shortTime'}}: + {{build.build.timestamp | date:'shortTime'}}: {{{true: 'SUCCESS', false: 'FAILURE'}[build.build.success]}}

diff --git a/src/main/resources/webapp/apps/frontPageApp/frontPageApp.js b/src/main/resources/webapp/apps/frontPageApp/frontPageApp.js index c376f83..5623c18 100755 --- a/src/main/resources/webapp/apps/frontPageApp/frontPageApp.js +++ b/src/main/resources/webapp/apps/frontPageApp/frontPageApp.js @@ -88,11 +88,11 @@ function PersonCtrl($scope, $routeParams, Person, Build, JenkinsUser, PagingTabl $scope.mode = 'overview'; var watcher = function () { - $scope.buildGroups = groupByDay($scope.builds.rows, function(build) { return build.createdDate}); + $scope.buildGroups = groupByDay($scope.builds.rows, function(build) { return build.timestamp}); console.log("$scope.buildGroups", $scope.buildGroups); }; $scope.buildGroups = []; - $scope.builds = PagingTableService.create($scope, PagingTableService.defaultCallback(Build, {person: personUuid}), + $scope.builds = PagingTableService.create($scope, PagingTableService.defaultCallback(Build, {person: personUuid, orderBy: "timestamp-"}), {count: 50, watcher: watcher}); $scope.setMode = function(mode) { @@ -118,14 +118,14 @@ function PersonCtrl($scope, $routeParams, Person, Build, JenkinsUser, PagingTabl })}); }); - Build.query({person: personUuid}, function (builds) { + Build.query({person: personUuid, orderBy: "timestamp-"}, function (builds) { $scope.recentBuilds = builds; }); } function BuildListCtrl($scope, Build, PagingTableService) { var watcher = function () { - $scope.buildGroups = groupByDay($scope.builds.rows, function(build) { return build.build.createdDate}); + $scope.buildGroups = groupByDay($scope.builds.rows, function(build) { return build.build.timestamp}); }; $scope.buildGroups = []; diff --git a/src/main/resources/webapp/apps/frontPageApp/person.html b/src/main/resources/webapp/apps/frontPageApp/person.html index f88a7d0..11cfd0b 100755 --- a/src/main/resources/webapp/apps/frontPageApp/person.html +++ b/src/main/resources/webapp/apps/frontPageApp/person.html @@ -48,7 +48,7 @@

Recent builds

- + @@ -70,7 +70,7 @@
{{build.createdDate | date:'medium'}}{{build.timestamp | date:'medium'}} {{{true: 'Success', false: 'Failure'}[build.success]}} Details
- + diff --git a/src/main/resources/webapp/apps/jenkinsApp/build.html b/src/main/resources/webapp/apps/jenkinsApp/build.html index db07f44..7239c90 100755 --- a/src/main/resources/webapp/apps/jenkinsApp/build.html +++ b/src/main/resources/webapp/apps/jenkinsApp/build.html @@ -18,7 +18,7 @@ - + diff --git a/src/main/resources/webapp/apps/jenkinsApp/job.html b/src/main/resources/webapp/apps/jenkinsApp/job.html index e0c1a10..8942ab7 100755 --- a/src/main/resources/webapp/apps/jenkinsApp/job.html +++ b/src/main/resources/webapp/apps/jenkinsApp/job.html @@ -38,7 +38,7 @@ - + -- cgit v1.2.3
- {{build.createdDate | date:'shortTime'}}: + {{build.timestamp | date:'shortTime'}}: {{{true: 'SUCCESS', false: 'FAILURE'}[build.success]}} @@ -100,7 +100,7 @@
{{build.createdDate | date:'medium'}}{{build.timestamp | date:'medium'}}
Timestamp{{details.build.createdDate | date:'medium'}}{{details.build.timestamp | date:'medium'}}
Number
{{build.createdDate | date:'medium'}}{{build.timestamp | date:'medium'}} {{build.result}}