diff options
Diffstat (limited to 'src/main/java')
4 files changed, 20 insertions, 13 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/core/db/FileDao.java b/src/main/java/io/trygvis/esper/testing/core/db/FileDao.java index 0878f63..c418970 100644 --- a/src/main/java/io/trygvis/esper/testing/core/db/FileDao.java +++ b/src/main/java/io/trygvis/esper/testing/core/db/FileDao.java @@ -14,7 +14,7 @@ public class FileDao { this.c = c; } - public void store(URI url, String contentType, byte[] data) throws SQLException { + public UUID store(URI url, String contentType, byte[] data) throws SQLException { try (PreparedStatement s = c.prepareStatement("INSERT INTO file(uuid, created_date, url, content_type, data) VALUES(?, ?, ?, ?, ?)")) { UUID uuid = UUID.randomUUID(); int i = 1; @@ -24,6 +24,7 @@ public class FileDao { s.setString(i++, contentType); s.setBinaryStream(i, new ByteArrayInputStream(data), data.length); s.executeUpdate(); + return uuid; } } } diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsBuildDto.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsBuildDto.java index 41d90ae..5c7249f 100644 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsBuildDto.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsBuildDto.java @@ -8,6 +8,7 @@ import java.util.*; public class JenkinsBuildDto extends AbstractEntity { public final UUID job; + public final UUID file; public final String entryId; public final URI url; public final String result; @@ -16,9 +17,10 @@ public class JenkinsBuildDto extends AbstractEntity { public final DateTime timestamp; public final UUID[] users; - public JenkinsBuildDto(UUID uuid, DateTime createdDate, UUID job, String entryId, URI url, String result, int number, int duration, DateTime timestamp, UUID[] users) { + public JenkinsBuildDto(UUID uuid, DateTime createdDate, UUID job, UUID file, String entryId, URI url, String result, int number, int duration, DateTime timestamp, UUID[] users) { super(uuid, createdDate); this.job = job; + this.file = file; this.entryId = entryId; this.url = url; this.result = result; 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 a31c6a0..8d32dbe 100644 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsDao.java @@ -20,9 +20,7 @@ public class JenkinsDao { public static final String JENKINS_SERVER = "uuid, created_date, url, enabled"; - public static final String JENKINS_JOB = "uuid, created_date, server, url, job_type, display_name"; - - public static final String JENKINS_BUILD = "uuid, created_date, job, entry_id, url, result, number, duration, timestamp, users"; + 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"; @@ -67,6 +65,8 @@ public class JenkinsDao { return list; } + public static final String JENKINS_BUILD = "uuid, created_date, job, file, entry_id, url, result, number, duration, timestamp, users"; + public static final SqlF<ResultSet, JenkinsBuildDto> jenkinsBuild = new SqlF<ResultSet, JenkinsBuildDto>() { public JenkinsBuildDto apply(ResultSet rs) throws SQLException { int i = 1; @@ -74,6 +74,7 @@ public class JenkinsDao { UUID.fromString(rs.getString(i++)), new DateTime(rs.getTimestamp(i++).getTime()), UUID.fromString(rs.getString(i++)), + UUID.fromString(rs.getString(i++)), rs.getString(i++), URI.create(rs.getString(i++)), rs.getString(i++), @@ -143,13 +144,14 @@ public class JenkinsDao { } } - public UUID insertJob(UUID server, URI url, JenkinsJobXml.JenkinsJobType type, Option<String> displayName) throws SQLException { - try (PreparedStatement s = c.prepareStatement("INSERT INTO jenkins_job(" + JENKINS_JOB + ") VALUES(?, ?, ?, ?, ?, ?)")) { + public UUID insertJob(UUID server, UUID file, URI url, JenkinsJobXml.JenkinsJobType type, Option<String> displayName) throws SQLException { + try (PreparedStatement s = c.prepareStatement("INSERT INTO jenkins_job(" + JENKINS_JOB + ") VALUES(?, ?, ?, ?, ?, ?, ?)")) { UUID uuid = UUID.randomUUID(); int i = 1; s.setString(i++, uuid.toString()); s.setTimestamp(i++, new Timestamp(currentTimeMillis())); s.setString(i++, server.toString()); + s.setString(i++, file.toString()); s.setString(i++, url.toASCIIString()); s.setString(i++, type.name()); s.setString(i, displayName.toNull()); @@ -167,13 +169,14 @@ public class JenkinsDao { } } - public UUID insertBuild(UUID server, String entryId, URI url, String result, int number, int duration, long timestamp, UUID[] users) throws SQLException { - try (PreparedStatement s = c.prepareStatement("INSERT INTO jenkins_build(" + JENKINS_BUILD + ") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) { + public UUID insertBuild(UUID job, UUID file, String entryId, URI url, String result, int number, int duration, long timestamp, UUID[] users) throws SQLException { + try (PreparedStatement s = c.prepareStatement("INSERT INTO jenkins_build(" + JENKINS_BUILD + ") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) { UUID uuid = UUID.randomUUID(); int i = 1; s.setString(i++, uuid.toString()); s.setTimestamp(i++, new Timestamp(currentTimeMillis())); - s.setString(i++, server.toString()); + s.setString(i++, job.toString()); + s.setString(i++, file.toString()); s.setString(i++, entryId); s.setString(i++, url.toASCIIString()); s.setString(i++, result); 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 32728a6..c34f422 100644 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServerActor.java @@ -76,7 +76,7 @@ public class JenkinsServerActor implements TransactionalActor { continue; } - fileDao.store(buildUrl, "application/xml", buildXmlOption.some()._2()); + UUID buildXmlFile = fileDao.store(buildUrl, "application/xml", buildXmlOption.some()._2()); String result = build.result.some(); @@ -137,11 +137,11 @@ public class JenkinsServerActor implements TransactionalActor { continue; } - fileDao.store(uri, "application/xml", jobXmlOption.some()._2()); + UUID jobXmlFile = fileDao.store(uri, "application/xml", jobXmlOption.some()._2()); JenkinsJobXml xml = jobXmlOption.some()._1(); - job = dao.insertJob(server.uuid, xml.url, xml.type, xml.displayName); + job = dao.insertJob(server.uuid, jobXmlFile, xml.url, xml.type, xml.displayName); logger.info("New job: {}, uuid={}", xml.displayName.orSome(xml.url.toASCIIString()), job); } @@ -150,6 +150,7 @@ public class JenkinsServerActor implements TransactionalActor { UUID uuid = dao.insertBuild( job, + buildXmlFile, entry.id, build.url, result, |