aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java4
-rw-r--r--src/main/java/io/trygvis/esper/testing/web/JenkinsResource.java74
-rw-r--r--src/main/webapp/apps/jenkinsApp/jenkinsApp.js16
-rw-r--r--src/main/webapp/apps/jenkinsApp/server-list.html5
-rw-r--r--src/main/webapp/apps/jenkinsApp/server.html11
5 files changed, 89 insertions, 21 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 ab4b515..bf1954e 100644
--- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java
+++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java
@@ -112,11 +112,11 @@ public class JenkinsDao {
}
}
- public Integer selectJobCountForServer(UUID uuid) throws SQLException {
+ public int selectJobCountForServer(UUID uuid) throws SQLException {
try (PreparedStatement s = c.prepareStatement("SELECT count(1) FROM jenkins_job WHERE server=?")) {
s.setString(1, uuid.toString());
ResultSet rs = s.executeQuery();
-
+ rs.next();
return rs.getInt(1);
}
}
diff --git a/src/main/java/io/trygvis/esper/testing/web/JenkinsResource.java b/src/main/java/io/trygvis/esper/testing/web/JenkinsResource.java
index a1e2f51..24ed367 100644
--- a/src/main/java/io/trygvis/esper/testing/web/JenkinsResource.java
+++ b/src/main/java/io/trygvis/esper/testing/web/JenkinsResource.java
@@ -3,13 +3,17 @@ package io.trygvis.esper.testing.web;
import fj.data.*;
import io.trygvis.esper.testing.*;
import io.trygvis.esper.testing.jenkins.*;
+import org.joda.time.*;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
+import java.net.*;
import java.sql.*;
import java.util.*;
import java.util.List;
+import static fj.data.Option.*;
+
@Path("/")
public class JenkinsResource {
@@ -22,12 +26,15 @@ public class JenkinsResource {
@GET
@Path("/resource/jenkins/server")
@Produces(MediaType.APPLICATION_JSON)
- public List<JenkinsServerDto> getServers() throws Exception {
- System.out.println("JenkinsResource.getServers");
- return da.inTransaction(new DatabaseAccess.DaosCallback<List<JenkinsServerDto>>() {
+ public List<JenkinsServerJson> getServers() throws Exception {
+ return da.inTransaction(new DatabaseAccess.DaosCallback<List<JenkinsServerJson>>() {
@Override
- public List<JenkinsServerDto> run(Daos daos) throws SQLException {
- return daos.jenkinsDao.selectServers(false);
+ public List<JenkinsServerJson> run(Daos daos) throws SQLException {
+ List<JenkinsServerJson> list = new ArrayList<>();
+ for (JenkinsServerDto server : daos.jenkinsDao.selectServers(false)) {
+ list.add(getJenkinsServerJson(daos, server));
+ }
+ return list;
}
});
}
@@ -35,23 +42,58 @@ public class JenkinsResource {
@GET
@Path("/resource/jenkins/server/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
- public JenkinsServerDto getServer(@PathParam("uuid") String s) throws Exception {
- try {
- final UUID uuid = UUID.fromString(s);
- System.out.println("JenkinsResource.getServers");
- Option<JenkinsServerDto> server = da.inTransaction(new DatabaseAccess.DaosCallback<Option<JenkinsServerDto>>() {
- public Option<JenkinsServerDto> run(Daos daos) throws SQLException {
- return daos.jenkinsDao.selectServer(uuid);
+ public JenkinsServerJson getServer(@PathParam("uuid") String s) throws Exception {
+ final UUID uuid = parseUuid(s);
+
+ return get(new DatabaseAccess.DaosCallback<Option<JenkinsServerJson>>() {
+ public Option<JenkinsServerJson> run(final Daos daos) throws SQLException {
+ Option<JenkinsServerDto> o = daos.jenkinsDao.selectServer(uuid);
+
+ if (o.isNone()) {
+ return Option.none();
}
- });
- if(server.isNone()) {
- throw new WebApplicationException(Response.Status.NOT_FOUND);
+ return some(getJenkinsServerJson(daos, o.some()));
}
+ });
+ }
+
+ private JenkinsServerJson getJenkinsServerJson(Daos daos, JenkinsServerDto server) throws SQLException {
+ int count = daos.jenkinsDao.selectJobCountForServer(server.uuid);
+ return new JenkinsServerJson(server.uuid, server.created_date, server.url, server.enabled, count);
+ }
+
+ private <T> T get(DatabaseAccess.DaosCallback<Option<T>> callback) throws SQLException {
+ Option<T> server = da.inTransaction(callback);
- return server.some();
+ if(server.isNone()) {
+ throw new WebApplicationException(Response.Status.NOT_FOUND);
+ }
+
+ return server.some();
+ }
+
+ private UUID parseUuid(String s) {
+ try {
+ return UUID.fromString(s);
} catch (IllegalArgumentException e) {
throw new WebApplicationException(Response.Status.BAD_REQUEST);
}
}
}
+
+class JenkinsServerJson {
+ public final UUID uuid;
+ public final DateTime createdDate;
+ public final URI url;
+ public final boolean enabled;
+ public final int jobCount;
+
+ JenkinsServerJson(UUID uuid, DateTime createdDate, URI url, boolean enabled, int jobCount) {
+ this.uuid = uuid;
+ this.createdDate = createdDate;
+ this.url = url;
+ this.enabled = enabled;
+ this.jobCount = jobCount;
+ }
+}
diff --git a/src/main/webapp/apps/jenkinsApp/jenkinsApp.js b/src/main/webapp/apps/jenkinsApp/jenkinsApp.js
index 5370496..5477039 100644
--- a/src/main/webapp/apps/jenkinsApp/jenkinsApp.js
+++ b/src/main/webapp/apps/jenkinsApp/jenkinsApp.js
@@ -11,19 +11,31 @@ var jenkinsApp = angular.module('jenkinsApp', ['jenkinsServerService']).config(f
// $locationProvider.html5Mode(true);
});
-function ServerListCtrl($scope, $route, $routeParams, $location, JenkinsServerService) {
+function ServerListCtrl($scope, $location, JenkinsServerService) {
JenkinsServerService.query(function (servers) {
$scope.servers = servers;
});
+ $scope.showServers = function (uuid) {
+ $location.path('/');
+ };
+
$scope.showServer = function (uuid) {
$location.path('/server/' + uuid);
};
}
-function ServerCtrl($scope, $routeParams, JenkinsServerService) {
+function ServerCtrl($scope, $location, $routeParams, JenkinsServerService) {
window.x = $routeParams;
JenkinsServerService.get({uuid: $routeParams.uuid}, function (server) {
$scope.server = server;
});
+
+ $scope.showServers = function (uuid) {
+ $location.path('/');
+ };
+
+ $scope.showServer = function (uuid) {
+ $location.path('/server/' + uuid);
+ };
}
diff --git a/src/main/webapp/apps/jenkinsApp/server-list.html b/src/main/webapp/apps/jenkinsApp/server-list.html
index 0ca65d6..f335c1f 100644
--- a/src/main/webapp/apps/jenkinsApp/server-list.html
+++ b/src/main/webapp/apps/jenkinsApp/server-list.html
@@ -1,6 +1,11 @@
<div class="page-header">
<h1>Jenkins Servers</h1>
</div>
+
+<ul class="breadcrumb">
+ <li class="active">All Servers</li>
+</ul>
+
<table class="table table-condensed">
<thead>
<tr>
diff --git a/src/main/webapp/apps/jenkinsApp/server.html b/src/main/webapp/apps/jenkinsApp/server.html
index e15f43e..9213c73 100644
--- a/src/main/webapp/apps/jenkinsApp/server.html
+++ b/src/main/webapp/apps/jenkinsApp/server.html
@@ -2,6 +2,11 @@
<h1>Jenkins Server</h1>
</div>
+<ul class="breadcrumb">
+ <li><a ng-click="showServers()">All Servers</a> <span class="divider">/</span></li>
+ <li class="active">Server</li>
+</ul>
+
<table class="table">
<tbody>
<tr>
@@ -14,7 +19,11 @@
</tr>
<tr>
<th>Visit</th>
- <td>{{server.visit}}</td>
+ <td><a href="{{server.url}}">{{server.url}}</a></td>
+ </tr>
+ <tr>
+ <th>Job Count</th>
+ <td>{{server.jobCount}}</td>
</tr>
</tbody>
</table>