aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/Config.java28
-rw-r--r--src/main/java/io/trygvis/esper/testing/core/badge/BadgeProgress.java2
-rw-r--r--src/main/java/io/trygvis/esper/testing/core/badge/BadgeService.java45
-rw-r--r--src/main/java/io/trygvis/esper/testing/core/badge/PersonalBadge.java13
-rw-r--r--src/main/java/io/trygvis/esper/testing/core/badge/UnbreakableBadge.java13
-rw-r--r--src/main/java/io/trygvis/esper/testing/core/badge/UnbreakableBadgeProgress.java51
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/core/badge/UnbreakablePoller.java39
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/core/db/BuildDao.java4
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/core/db/PersonDao.java44
-rw-r--r--src/main/java/io/trygvis/esper/testing/core/db/PersonalBadgeDto.java (renamed from src/main/java/io/trygvis/esper/testing/core/db/PersonBadgeDto.java)8
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/util/sql/ResultSetF.java10
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/web/JerseyApplication.java21
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/web/MyObjectMapper.java26
-rw-r--r--src/main/java/io/trygvis/esper/testing/web/resource/BadgeJson.java25
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java40
-rw-r--r--src/main/resources/logback.xml (renamed from src/main/sql/base-schema/logback.xml)2
-rw-r--r--src/main/sql/base-schema/posgresql-ddl.sql500
-rw-r--r--src/main/sql/dbdelta/1-person_badge-add-timestamps.sql27
-rwxr-xr-xsrc/main/webapp/apps/frontPageApp/frontPageApp.js6
-rwxr-xr-xsrc/main/webapp/apps/frontPageApp/person.html77
-rw-r--r--src/test/java/io/trygvis/esper/testing/core/badge/UnbreakableBadgeProgressTest.java8
21 files changed, 797 insertions, 192 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/Config.java b/src/main/java/io/trygvis/esper/testing/Config.java
index e184d46..7da14fa 100755
--- a/src/main/java/io/trygvis/esper/testing/Config.java
+++ b/src/main/java/io/trygvis/esper/testing/Config.java
@@ -3,6 +3,9 @@ package io.trygvis.esper.testing;
import com.jolbox.bonecp.*;
import fj.data.*;
import org.apache.abdera.*;
+import org.codehaus.jackson.*;
+import org.codehaus.jackson.map.*;
+import org.codehaus.jackson.map.module.*;
import org.slf4j.*;
import org.slf4j.bridge.*;
@@ -104,8 +107,8 @@ public class Config {
}
LoggerFactory.getILoggerFactory();
-// LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
-// StatusPrinter.print(lc);
+// ch.qos.logback.classic.LoggerContext lc = (ch.qos.logback.classic.LoggerContext) LoggerFactory.getILoggerFactory();
+// ch.qos.logback.core.util.StatusPrinter.print(lc);
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
@@ -130,6 +133,15 @@ public class Config {
return new Abdera();
}
+ public ObjectMapper createObjectMapper() {
+ ObjectMapper objectMapper = new ObjectMapper();
+ SimpleModule module = new SimpleModule("wat", Version.unknownVersion());
+ module.addDeserializer(Uuid.class, new UuidDeserializer());
+ module.addSerializer(Uuid.class, new UuidSerializer());
+ objectMapper.registerModule(module);
+ return objectMapper;
+ }
+
public void addShutdownHook(final Thread t, final AtomicBoolean shouldRun) {
Runtime.getRuntime().addShutdownHook(new Thread() {
{
@@ -149,4 +161,16 @@ public class Config {
private static Option<String> getProperty(Properties properties, String key) {
return fromNull(trimToNull(properties.getProperty(key)));
}
+
+ private static class UuidDeserializer extends JsonDeserializer<Uuid> {
+ public Uuid deserialize(JsonParser jp, DeserializationContext context) throws IOException {
+ return Uuid.fromString(jp.getText());
+ }
+ }
+
+ private static class UuidSerializer extends JsonSerializer<Uuid> {
+ public void serialize(Uuid value, JsonGenerator generator, SerializerProvider provider) throws IOException {
+ generator.writeString(value.toStringBase64());
+ }
+ }
}
diff --git a/src/main/java/io/trygvis/esper/testing/core/badge/BadgeProgress.java b/src/main/java/io/trygvis/esper/testing/core/badge/BadgeProgress.java
index eb8d4bd..c2fda15 100644
--- a/src/main/java/io/trygvis/esper/testing/core/badge/BadgeProgress.java
+++ b/src/main/java/io/trygvis/esper/testing/core/badge/BadgeProgress.java
@@ -1,6 +1,6 @@
package io.trygvis.esper.testing.core.badge;
-import io.trygvis.esper.testing.core.db.PersonBadgeDto.*;
+import io.trygvis.esper.testing.core.db.PersonalBadgeDto.*;
public abstract class BadgeProgress {
public final BadgeType type;
diff --git a/src/main/java/io/trygvis/esper/testing/core/badge/BadgeService.java b/src/main/java/io/trygvis/esper/testing/core/badge/BadgeService.java
index ea0c0dc..bf06fbb 100644
--- a/src/main/java/io/trygvis/esper/testing/core/badge/BadgeService.java
+++ b/src/main/java/io/trygvis/esper/testing/core/badge/BadgeService.java
@@ -9,20 +9,38 @@ import java.io.*;
public class BadgeService {
private final Logger logger = LoggerFactory.getLogger(getClass());
- private static final ObjectMapper objectMapper = new ObjectMapper();
+ private final ObjectMapper objectMapper;
- public UnbreakableBadgeProgress unbreakable(PersonBadgeProgressDto dto) {
- String state = dto.state;
+ public BadgeService(ObjectMapper objectMapper) {
+ this.objectMapper = objectMapper;
+ }
- try {
- return objectMapper.readValue(state, UnbreakableBadgeProgress.class);
- } catch (IOException e) {
- logger.error("Could not de-serialize badge state: {}", state);
- throw new RuntimeException(e);
+ public BadgeProgress badgeProgress(PersonBadgeProgressDto dto) {
+ switch (PersonalBadgeDto.BadgeType.valueOf(dto.badge)) {
+ case UNBREAKABLE:
+ return getProgress(dto.state, UnbreakableBadgeProgress.class);
}
+
+ throw new RuntimeException("Unknown badge type: " + dto.badge);
+ }
+
+ public <T extends BadgeProgress> T badgeProgress(PersonBadgeProgressDto dto, Class<T> klass) {
+ switch (PersonalBadgeDto.BadgeType.valueOf(dto.badge)) {
+ case UNBREAKABLE:
+ if(!klass.equals(UnbreakableBadgeProgress.class)) {
+ throw new RuntimeException("Badge is not of the expected type: UNBREAKABLE.");
+ }
+ return getProgress(dto.state, klass);
+ }
+
+ throw new RuntimeException("Unknown badge type: " + dto.badge);
}
- public String serialize(UnbreakableBadgeProgress badge) {
+ public UnbreakableBadge unbreakable(PersonalBadgeDto dto) {
+ return getProgress(dto.state, UnbreakableBadge.class);
+ }
+
+ public String serialize(Object badge) {
try {
CharArrayWriter writer = new CharArrayWriter();
objectMapper.writeValue(writer, badge);
@@ -32,4 +50,13 @@ public class BadgeService {
throw new RuntimeException(e);
}
}
+
+ private <T> T getProgress(String state, Class<T> klass) {
+ try {
+ return objectMapper.readValue(state, klass);
+ } catch (IOException e) {
+ logger.error("Could not de-serialize badge state: {}", state);
+ throw new RuntimeException(e);
+ }
+ }
}
diff --git a/src/main/java/io/trygvis/esper/testing/core/badge/PersonalBadge.java b/src/main/java/io/trygvis/esper/testing/core/badge/PersonalBadge.java
new file mode 100644
index 0000000..c34c35c
--- /dev/null
+++ b/src/main/java/io/trygvis/esper/testing/core/badge/PersonalBadge.java
@@ -0,0 +1,13 @@
+package io.trygvis.esper.testing.core.badge;
+
+import io.trygvis.esper.testing.*;
+
+public class PersonalBadge {
+ public final Uuid person;
+ public final int level;
+
+ public PersonalBadge(Uuid person, int level) {
+ this.person = person;
+ this.level = level;
+ }
+}
diff --git a/src/main/java/io/trygvis/esper/testing/core/badge/UnbreakableBadge.java b/src/main/java/io/trygvis/esper/testing/core/badge/UnbreakableBadge.java
index a4f1e54..6b1c78d 100644
--- a/src/main/java/io/trygvis/esper/testing/core/badge/UnbreakableBadge.java
+++ b/src/main/java/io/trygvis/esper/testing/core/badge/UnbreakableBadge.java
@@ -1,14 +1,19 @@
package io.trygvis.esper.testing.core.badge;
-class UnbreakableBadge {
+import io.trygvis.esper.testing.*;
+
+import java.util.*;
+
+class UnbreakableBadge extends PersonalBadge {
// Configuration for this badge
public static final int LEVEL_1_COUNT = 10;
public static final int LEVEL_2_COUNT = 20;
public static final int LEVEL_3_COUNT = 50;
- public final int level;
+ public final List<UUID> builds;
- UnbreakableBadge(int level) {
- this.level = level;
+ UnbreakableBadge(Uuid person, int level, List<UUID> builds) {
+ super(person, level);
+ this.builds = builds;
}
}
diff --git a/src/main/java/io/trygvis/esper/testing/core/badge/UnbreakableBadgeProgress.java b/src/main/java/io/trygvis/esper/testing/core/badge/UnbreakableBadgeProgress.java
index 4cba611..f43ec94 100644
--- a/src/main/java/io/trygvis/esper/testing/core/badge/UnbreakableBadgeProgress.java
+++ b/src/main/java/io/trygvis/esper/testing/core/badge/UnbreakableBadgeProgress.java
@@ -4,30 +4,34 @@ import static fj.P.*;
import fj.*;
import fj.data.*;
import static fj.data.Option.*;
+import static java.util.Collections.singletonList;
+
+import io.trygvis.esper.testing.*;
import io.trygvis.esper.testing.core.db.*;
-import io.trygvis.esper.testing.core.db.PersonBadgeDto.*;
+import io.trygvis.esper.testing.core.db.PersonalBadgeDto.*;
import java.util.*;
+import java.util.List;
public class UnbreakableBadgeProgress extends BadgeProgress {
- public final UUID person;
- public final int count;
+ public final Uuid person;
+ public final List<UUID> builds;
- private UnbreakableBadgeProgress(UUID person, int count) {
+ private UnbreakableBadgeProgress(Uuid person, List<UUID> builds) {
super(BadgeType.UNBREAKABLE);
this.person = person;
- this.count = count;
+ this.builds = Collections.unmodifiableList(builds);
}
@SuppressWarnings("UnusedDeclaration")
private UnbreakableBadgeProgress() {
super(BadgeType.UNBREAKABLE);
person = null;
- count = -1;
+ builds = null;
}
- public static UnbreakableBadgeProgress initial(UUID person) {
- return new UnbreakableBadgeProgress(person, 0);
+ public static UnbreakableBadgeProgress initial(Uuid person) {
+ return new UnbreakableBadgeProgress(person, Collections.<UUID>emptyList());
}
public P2<UnbreakableBadgeProgress, Option<UnbreakableBadge>> onBuild(BuildDto build) {
@@ -35,33 +39,36 @@ public class UnbreakableBadgeProgress extends BadgeProgress {
return p(initial(person), Option.<UnbreakableBadge>none());
}
- int count = this.count + 1;
+ List<UUID> builds = new ArrayList<>(this.builds);
+ builds.add(build.uuid);
- if (count == UnbreakableBadge.LEVEL_3_COUNT) {
- return p(initial(person), some(new UnbreakableBadge(3)));
+ if (progression() == UnbreakableBadge.LEVEL_3_COUNT) {
+ // You have to start from scratch now.
+ builds = singletonList(build.uuid);
+ return p(new UnbreakableBadgeProgress(person, builds), some(new UnbreakableBadge(person, 3, builds)));
}
- if (count == UnbreakableBadge.LEVEL_2_COUNT) {
- return p(new UnbreakableBadgeProgress(person, count), some(new UnbreakableBadge(2)));
+ if (progression() == UnbreakableBadge.LEVEL_2_COUNT) {
+ return p(new UnbreakableBadgeProgress(person, builds), some(new UnbreakableBadge(person, 2, builds)));
}
- if (count == UnbreakableBadge.LEVEL_1_COUNT) {
- return p(new UnbreakableBadgeProgress(person, count), some(new UnbreakableBadge(1)));
+ if (progression() == UnbreakableBadge.LEVEL_1_COUNT) {
+ return p(new UnbreakableBadgeProgress(person, builds), some(new UnbreakableBadge(person, 1, builds)));
}
- return p(new UnbreakableBadgeProgress(person, count), Option.<UnbreakableBadge>none());
+ return p(new UnbreakableBadgeProgress(person, builds), Option.<UnbreakableBadge>none());
}
public int progression() {
- return count;
+ return builds.size();
}
public int goal() {
- if (count > UnbreakableBadge.LEVEL_2_COUNT) {
+ if (progression() > UnbreakableBadge.LEVEL_2_COUNT) {
return UnbreakableBadge.LEVEL_3_COUNT;
}
- if (count > UnbreakableBadge.LEVEL_1_COUNT) {
+ if (progression() > UnbreakableBadge.LEVEL_1_COUNT) {
return UnbreakableBadge.LEVEL_2_COUNT;
}
@@ -69,11 +76,11 @@ public class UnbreakableBadgeProgress extends BadgeProgress {
}
public int progressingAgainstLevel() {
- if (count > UnbreakableBadge.LEVEL_2_COUNT) {
+ if (progression() > UnbreakableBadge.LEVEL_2_COUNT) {
return 3;
}
- if (count > UnbreakableBadge.LEVEL_1_COUNT) {
+ if (progression() > UnbreakableBadge.LEVEL_1_COUNT) {
return 2;
}
@@ -81,6 +88,6 @@ public class UnbreakableBadgeProgress extends BadgeProgress {
}
public String toString() {
- return "UnbreakableBadgeProgress{person=" + person + ", count=" + count + '}';
+ return "UnbreakableBadgeProgress{person=" + person + ", #builds=" + builds.size() + '}';
}
}
diff --git a/src/main/java/io/trygvis/esper/testing/core/badge/UnbreakablePoller.java b/src/main/java/io/trygvis/esper/testing/core/badge/UnbreakablePoller.java
index ab0abd8..76dee02 100755
--- a/src/main/java/io/trygvis/esper/testing/core/badge/UnbreakablePoller.java
+++ b/src/main/java/io/trygvis/esper/testing/core/badge/UnbreakablePoller.java
@@ -11,25 +11,28 @@ import org.slf4j.*;
import java.sql.*;
import java.util.List;
-import java.util.*;
-import static fj.data.Option.some;
import static io.trygvis.esper.testing.Config.*;
-import static io.trygvis.esper.testing.core.db.PersonBadgeDto.BadgeType.*;
+import static io.trygvis.esper.testing.core.db.PersonalBadgeDto.BadgeType.*;
public class UnbreakablePoller implements TablePoller.NewRowCallback<BuildDto> {
private final Logger logger = LoggerFactory.getLogger(getClass());
- private final BadgeService badgeService = new BadgeService();
+ private final BadgeService badgeService;
+
+ public UnbreakablePoller(BadgeService badgeService) {
+ this.badgeService = badgeService;
+ }
public static void main(String[] args) throws Exception {
String pollerName = "unbreakable";
String tableName = "build";
String columnNames = BuildDao.BUILD;
SqlF<ResultSet, BuildDto> f = BuildDao.build;
- TablePoller.NewRowCallback<BuildDto> callback = new UnbreakablePoller();
Config config = loadFromDisk("unbreakable-poller");
+ BadgeService badgeService = new BadgeService(config.createObjectMapper());
+ TablePoller.NewRowCallback<BuildDto> callback = new UnbreakablePoller(badgeService);
BoneCPDataSource dataSource = config.createBoneCp();
@@ -41,11 +44,11 @@ public class UnbreakablePoller implements TablePoller.NewRowCallback<BuildDto> {
public void process(Connection c, BuildDto build) throws SQLException {
Daos daos = new Daos(c);
- List<UUID> persons = daos.buildDao.selectBuildParticipantByBuild(build.uuid);
+ List<Uuid> persons = daos.buildDao.selectBuildParticipantByBuild(build.uuid);
logger.info("Processing build={}, success={}, #persons={}", build.uuid, build.success, persons.size());
- for (UUID person : persons) {
- logger.info("person={}", person);
+ for (Uuid person : persons) {
+ logger.info("person={}", person.toUuidString());
SqlOption<PersonBadgeProgressDto> o = daos.personDao.selectBadgeProgress(person, UNBREAKABLE);
@@ -53,37 +56,31 @@ public class UnbreakablePoller implements TablePoller.NewRowCallback<BuildDto> {
UnbreakableBadgeProgress badge = UnbreakableBadgeProgress.initial(person);
logger.info("New badge progress");
String state = badgeService.serialize(badge);
- daos.personDao.insertBadgeProgress(new Uuid(person), UNBREAKABLE, state);
+ daos.personDao.insertBadgeProgress(person, UNBREAKABLE, state);
continue;
}
- UnbreakableBadgeProgress badge = badgeService.unbreakable(o.get());
+ UnbreakableBadgeProgress badge = badgeService.badgeProgress(o.get(), UnbreakableBadgeProgress.class);
- logger.info("Existing badge progress: count={}", badge.count);
+ logger.info("Existing badge progress: progression={}", badge.progression());
P2<UnbreakableBadgeProgress, Option<UnbreakableBadge>> p = badge.onBuild(build);
badge = p._1();
- logger.info("New badge progress: count={}", badge.count);
+ logger.info("New badge progress: progression={}", badge.progression());
if (p._2().isSome()) {
UnbreakableBadge b = p._2().some();
- logger.info("New unbreakable badge: person={}, level={}", person, b.level);
-
- SqlOption<PersonBadgeDto> option = daos.personDao.selectBadge(person, UNBREAKABLE, b.level);
+ logger.info("New unbreakable badge: person={}, level={}", person.toUuidString(), b.level);
- if (option.isNone()) {
- daos.personDao.insertBadge(person, UNBREAKABLE, b.level, 1);
- } else {
- daos.personDao.incrementBadgeCount(person, UNBREAKABLE, b.level);
- }
+ daos.personDao.insertBadge(build.createdDate, person, UNBREAKABLE, b.level, badgeService.serialize(b));
}
String state = badgeService.serialize(badge);
- daos.personDao.updateBadgeProgress(new Uuid(person), UNBREAKABLE, state);
+ daos.personDao.updateBadgeProgress(person, UNBREAKABLE, state);
}
}
}
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 cd103d6..32afe42 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
@@ -57,7 +57,7 @@ public class BuildDao {
}
}
- public List<UUID> selectBuildParticipantByBuild(UUID build) throws SQLException {
+ public List<Uuid> selectBuildParticipantByBuild(UUID build) throws SQLException {
try (PreparedStatement s = c.prepareStatement("SELECT person FROM build_participant WHERE build=?")) {
int i = 1;
s.setString(i, build.toString());
@@ -86,7 +86,7 @@ public class BuildDao {
int i = 1;
s.setString(i++, ref.type);
s.setString(i, ref.uuid.toString());
- return fromRs(s.executeQuery()).map(getUuid);
+ return fromRs(s.executeQuery()).map(getUUID);
}
}
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 0f80219..7a682dc 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
@@ -2,7 +2,7 @@ package io.trygvis.esper.testing.core.db;
import fj.data.*;
import io.trygvis.esper.testing.*;
-import io.trygvis.esper.testing.core.db.PersonBadgeDto.*;
+import io.trygvis.esper.testing.core.db.PersonalBadgeDto.*;
import io.trygvis.esper.testing.util.sql.*;
import org.joda.time.*;
@@ -30,18 +30,18 @@ public class PersonDao {
}
};
- public static final String PERSON_BADGE = "uuid, created_date, person, name, level, count";
+ public static final String PERSON_BADGE = "uuid, created_date, person, name, level, state";
- public static final SqlF<ResultSet, PersonBadgeDto> personBadge = new SqlF<ResultSet, PersonBadgeDto>() {
- public PersonBadgeDto apply(ResultSet rs) throws SQLException {
+ public static final SqlF<ResultSet, PersonalBadgeDto> personBadge = new SqlF<ResultSet, PersonalBadgeDto>() {
+ public PersonalBadgeDto apply(ResultSet rs) throws SQLException {
int i = 1;
- return new PersonBadgeDto(
+ return new PersonalBadgeDto(
UUID.fromString(rs.getString(i++)),
new DateTime(rs.getTimestamp(i++).getTime()),
Uuid.fromString(rs.getString(i++)),
BadgeType.valueOf(rs.getString(i++)),
rs.getInt(i++),
- rs.getInt(i));
+ rs.getString(i));
}
};
@@ -146,41 +146,31 @@ public class PersonDao {
// Badge
// -----------------------------------------------------------------------
- public UUID insertBadge(UUID person, BadgeType type, int level, int count) throws SQLException {
+ public UUID insertBadge(DateTime createdDate, Uuid person, BadgeType type, int level, String state) throws SQLException {
try (PreparedStatement s = c.prepareStatement("INSERT INTO person_badge(" + PERSON_BADGE + ") VALUES(?, ?, ?, ?, ?, ?)")) {
UUID uuid = UUID.randomUUID();
int i = 1;
s.setString(i++, uuid.toString());
- s.setTimestamp(i++, new Timestamp(currentTimeMillis()));
- s.setString(i++, person.toString());
+ s.setTimestamp(i++, new Timestamp(createdDate.getMillis()));
+ s.setString(i++, person.toUuidString());
s.setString(i++, type.toString());
s.setInt(i++, level);
- s.setInt(i, count);
+ s.setString(i, state);
s.executeUpdate();
return uuid;
}
}
- public void incrementBadgeCount(UUID person, BadgeType type, int level) throws SQLException {
- try (PreparedStatement s = c.prepareStatement("UPDATE person_badge SET count=count+1 WHERE person=? AND name=? AND level=?")) {
- int i = 1;
- s.setString(i++, person.toString());
- s.setString(i++, type.toString());
- s.setInt(i, level);
- s.executeUpdate();
- }
- }
-
- public List<PersonBadgeDto> selectBadges(Uuid person) throws SQLException {
- try (PreparedStatement s = c.prepareStatement("SELECT " + PERSON_BADGE + " FROM person_badge WHERE person=? ORDER BY name, level DESC")) {
+ public List<PersonalBadgeDto> selectBadges(Uuid person) throws SQLException {
+ try (PreparedStatement s = c.prepareStatement("SELECT " + PERSON_BADGE + " FROM person_badge WHERE person=? ORDER BY created_date DESC")) {
int i = 1;
s.setString(i, person.toUuidString());
return toList(s, personBadge);
}
}
- public SqlOption<PersonBadgeDto> selectBadge(UUID person, BadgeType type, int level) throws SQLException {
- try (PreparedStatement s = c.prepareStatement("SELECT " + PERSON_BADGE + " FROM person_badge WHERE person=? AND name=? AND level=?")) {
+ public SqlOption<PersonalBadgeDto> selectBadge(UUID person, BadgeType type, int level) throws SQLException {
+ try (PreparedStatement s = c.prepareStatement("SELECT " + PERSON_BADGE + " FROM person_badge WHERE person=? AND name=? AND level=? LIMIT 1")) {
int i = 1;
s.setString(i++, person.toString());
s.setString(i++, type.toString());
@@ -189,7 +179,7 @@ public class PersonDao {
}
}
- public List<PersonBadgeDto> selectBadges(Option<Uuid> person, Option<BadgeType> type, Option<Integer> level, PageRequest page) throws SQLException {
+ public List<PersonalBadgeDto> selectBadges(Option<Uuid> person, Option<BadgeType> type, Option<Integer> level, PageRequest page) throws SQLException {
String sql = "SELECT " + PERSON_BADGE + " FROM person_badge WHERE 1=1";
if (person.isSome()) {
@@ -227,10 +217,10 @@ public class PersonDao {
// Badge Progress
// -----------------------------------------------------------------------
- public SqlOption<PersonBadgeProgressDto> selectBadgeProgress(UUID person, BadgeType type) throws SQLException {
+ public SqlOption<PersonBadgeProgressDto> selectBadgeProgress(Uuid person, BadgeType type) throws SQLException {
try (PreparedStatement s = c.prepareStatement("SELECT " + PERSON_BADGE_PROGRESS + " FROM person_badge_progress WHERE person=? AND badge=?")) {
int i = 1;
- s.setString(i++, person.toString());
+ s.setString(i++, person.toUuidString());
s.setString(i, type.toString());
return fromRs(s.executeQuery()).map(personBadgeProgress);
}
diff --git a/src/main/java/io/trygvis/esper/testing/core/db/PersonBadgeDto.java b/src/main/java/io/trygvis/esper/testing/core/db/PersonalBadgeDto.java
index 0f34347..cc2a739 100644
--- a/src/main/java/io/trygvis/esper/testing/core/db/PersonBadgeDto.java
+++ b/src/main/java/io/trygvis/esper/testing/core/db/PersonalBadgeDto.java
@@ -5,7 +5,7 @@ import org.joda.time.*;
import java.util.*;
-public class PersonBadgeDto extends AbstractEntity {
+public class PersonalBadgeDto extends AbstractEntity {
public enum BadgeType {
UNBREAKABLE
}
@@ -13,13 +13,13 @@ public class PersonBadgeDto extends AbstractEntity {
public final Uuid person;
public final BadgeType type;
public final int level;
- public final int count;
+ public final String state;
- public PersonBadgeDto(UUID uuid, DateTime createdDate, Uuid person, BadgeType type, int level, int count) {
+ public PersonalBadgeDto(UUID uuid, DateTime createdDate, Uuid person, BadgeType type, int level, String state) {
super(uuid, createdDate);
this.person = person;
this.type = type;
this.level = level;
- this.count = count;
+ this.state = state;
}
}
diff --git a/src/main/java/io/trygvis/esper/testing/util/sql/ResultSetF.java b/src/main/java/io/trygvis/esper/testing/util/sql/ResultSetF.java
index 7169372..5c51e6f 100755
--- a/src/main/java/io/trygvis/esper/testing/util/sql/ResultSetF.java
+++ b/src/main/java/io/trygvis/esper/testing/util/sql/ResultSetF.java
@@ -1,5 +1,7 @@
package io.trygvis.esper.testing.util.sql;
+import io.trygvis.esper.testing.*;
+
import java.sql.*;
import java.util.*;
@@ -17,9 +19,15 @@ public class ResultSetF {
}
};
- public static final SqlF<ResultSet, UUID> getUuid = new SqlF<ResultSet, UUID>() {
+ public static final SqlF<ResultSet, UUID> getUUID = new SqlF<ResultSet, UUID>() {
public UUID apply(ResultSet rs) throws SQLException {
return UUID.fromString(rs.getString(1));
}
};
+
+ public static final SqlF<ResultSet, Uuid> getUuid = new SqlF<ResultSet, Uuid>() {
+ public Uuid apply(ResultSet rs) throws SQLException {
+ return Uuid.fromString(rs.getString(1));
+ }
+ };
}
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 8f66548..3c86581 100755
--- a/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java
+++ b/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java
@@ -8,6 +8,7 @@ import io.trygvis.esper.testing.*;
import io.trygvis.esper.testing.core.badge.*;
import io.trygvis.esper.testing.util.sql.*;
import io.trygvis.esper.testing.web.resource.*;
+import org.codehaus.jackson.map.*;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
@@ -23,18 +24,22 @@ public class JerseyApplication extends Application {
private final HashSet<Object> singletons;
public JerseyApplication() throws Exception {
- DatabaseAccess da = new DatabaseAccess(WebConfig.config.createBoneCp());
+ Config config = WebConfig.config;
- BadgeService badgeService = new BadgeService();
+ DatabaseAccess da = new DatabaseAccess(config.createBoneCp());
+ ObjectMapper objectMapper = config.createObjectMapper();
- singletons = new HashSet<Object>(Arrays.asList(
+ BadgeService badgeService = new BadgeService(objectMapper);
+
+ singletons = new HashSet<>(Arrays.asList(
new CoreResource(da, badgeService),
- new JenkinsResource(da)
+ new JenkinsResource(da),
+ new MyObjectMapper(objectMapper)
));
}
public Set<Class<?>> getClasses() {
- return new HashSet<>(Arrays.<Class<?>>asList(ResourceParamInjector.class, MyObjectMapper.class));
+ return new HashSet<>(Arrays.<Class<?>>asList(ResourceParamInjector.class));
}
public Set<Object> getSingletons() {
@@ -44,12 +49,6 @@ public class JerseyApplication extends Application {
@Provider
public static class ResourceParamInjector implements InjectableProvider<MagicParam, Type> {
- private final ResourceContext rc;
-
- public ResourceParamInjector(@Context ResourceContext rc) {
- this.rc = rc;
- }
-
public ComponentScope getScope() {
return ComponentScope.PerRequest;
}
diff --git a/src/main/java/io/trygvis/esper/testing/web/MyObjectMapper.java b/src/main/java/io/trygvis/esper/testing/web/MyObjectMapper.java
index bfbd6eb..c684010 100755
--- a/src/main/java/io/trygvis/esper/testing/web/MyObjectMapper.java
+++ b/src/main/java/io/trygvis/esper/testing/web/MyObjectMapper.java
@@ -1,37 +1,17 @@
package io.trygvis.esper.testing.web;
-import io.trygvis.esper.testing.*;
-import org.codehaus.jackson.*;
import org.codehaus.jackson.map.*;
-import org.codehaus.jackson.map.module.*;
-import java.io.*;
import javax.ws.rs.ext.*;
public class MyObjectMapper implements ContextResolver<ObjectMapper> {
- private ObjectMapper objectMapper;
+ private final ObjectMapper objectMapper;
- public MyObjectMapper() throws Exception {
- objectMapper = new ObjectMapper();
- SimpleModule module = new SimpleModule("wat", Version.unknownVersion());
- module.addDeserializer(Uuid.class, new UuidDeserializer());
- module.addSerializer(Uuid.class, new UuidSerializer());
- objectMapper.registerModule(module);
+ public MyObjectMapper(ObjectMapper objectMapper) throws Exception {
+ this.objectMapper = objectMapper;
}
public ObjectMapper getContext(Class<?> type) {
return objectMapper;
}
-
- private static class UuidDeserializer extends JsonDeserializer<Uuid> {
- public Uuid deserialize(JsonParser jp, DeserializationContext context) throws IOException {
- return Uuid.fromString(jp.getText());
- }
- }
-
- private static class UuidSerializer extends JsonSerializer<Uuid> {
- public void serialize(Uuid value, JsonGenerator generator, SerializerProvider provider) throws IOException {
- generator.writeString(value.toStringBase64());
- }
- }
}
diff --git a/src/main/java/io/trygvis/esper/testing/web/resource/BadgeJson.java b/src/main/java/io/trygvis/esper/testing/web/resource/BadgeJson.java
index 8eea335..ded97ae 100644
--- a/src/main/java/io/trygvis/esper/testing/web/resource/BadgeJson.java
+++ b/src/main/java/io/trygvis/esper/testing/web/resource/BadgeJson.java
@@ -1,20 +1,33 @@
package io.trygvis.esper.testing.web.resource;
+import org.joda.time.*;
+
public class BadgeJson {
+ public final DateTime createdDate;
public final String name;
public final int level;
+ public final Integer progress;
+ public final Integer goal;
+
/**
- * Number of times this badge has been received.
+ * For completed badges.
*/
- public final int count;
- public final int progress;
- public final int goal;
+ public BadgeJson(DateTime createdDate, String name, int level) {
+ this.createdDate = createdDate;
+ this.name = name;
+ this.level = level;
+ this.progress = null;
+ this.goal = null;
+ }
- public BadgeJson(String name, int level, int count, int progress, int goal) {
+ /**
+ * For badges in progress.
+ */
+ public BadgeJson(DateTime createdDate, String name, int level, int progress, int goal) {
+ this.createdDate = createdDate;
this.name = name;
this.level = level;
- this.count = count;
this.progress = progress;
this.goal = goal;
}
diff --git a/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java b/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java
index f68d6ec..a129cf3 100755
--- a/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java
+++ b/src/main/java/io/trygvis/esper/testing/web/resource/CoreResource.java
@@ -124,14 +124,14 @@ public class CoreResource extends AbstractResource {
@GET
@Path("/badge")
- public List<BadgeDetailJson> getBadges(@MagicParam final PageRequest page, @MagicParam(query = "person") final Uuid person) throws Exception {
- return da.inTransaction(new CoreDaosCallback<List<BadgeDetailJson>>() {
- protected List<BadgeDetailJson> run() throws SQLException {
- List<PersonBadgeDto> badgeDtos = daos.personDao.selectBadges(fromNull(person), Option.<PersonBadgeDto.BadgeType>none(), Option.<Integer>none(), page);
-
- List<BadgeDetailJson> list = new ArrayList<>();
- for (PersonBadgeDto badge : badgeDtos) {
- list.add(getBadgeDetailJson.apply(badge));
+ public List<BadgeJson> getBadges(@MagicParam final PageRequest page, @MagicParam(query = "person") final Uuid person) throws Exception {
+ return da.inTransaction(new CoreDaosCallback<List<BadgeJson>>() {
+ protected List<BadgeJson> run() throws SQLException {
+ List<PersonalBadgeDto> badgeDtos = daos.personDao.selectBadges(fromNull(person), Option.<PersonalBadgeDto.BadgeType>none(), Option.<Integer>none(), page);
+
+ List<BadgeJson> list = new ArrayList<>();
+ for (PersonalBadgeDto badge : badgeDtos) {
+ list.add(getBadgeJson.apply(badge));
}
return list;
}
@@ -157,15 +157,13 @@ public class CoreResource extends AbstractResource {
protected final SqlF<PersonDto, PersonDetailJson> getPersonDetailJson = new SqlF<PersonDto, PersonDetailJson>() {
public PersonDetailJson apply(PersonDto person) throws SQLException {
List<BadgeJson> badges = new ArrayList<>();
-
- for (PersonBadgeDto badge : daos.personDao.selectBadges(person.uuid)) {
- badges.add(getBadge(badge));
+ for (PersonalBadgeDto badge : daos.personDao.selectBadges(person.uuid)) {
+ badges.add(getBadgeJson.apply(badge));
}
List<BadgeJson> badgesInProgress = new ArrayList<>();
-
for (PersonBadgeProgressDto badgeProgressDto : daos.personDao.selectBadgeProgresses(person.uuid)) {
- UnbreakableBadgeProgress progress = badgeService.unbreakable(badgeProgressDto);
+ BadgeProgress progress = badgeService.badgeProgress(badgeProgressDto);
badgesInProgress.add(getBadge(progress));
}
@@ -177,17 +175,19 @@ public class CoreResource extends AbstractResource {
}
};
- private BadgeJson getBadge(PersonBadgeDto badge) {
- return new BadgeJson(badge.type.name(), badge.level, badge.count, 100, 100);
- }
+ protected SqlF<PersonalBadgeDto, BadgeJson> getBadgeJson = new SqlF<PersonalBadgeDto, BadgeJson>() {
+ public BadgeJson apply(PersonalBadgeDto badge) throws SQLException {
+ return new BadgeJson(badge.createdDate, badge.type.name(), badge.level);
+ }
+ };
private BadgeJson getBadge(BadgeProgress progress) {
- return new BadgeJson(progress.type.name(), progress.progressingAgainstLevel(), 0, progress.progression(), progress.goal());
+ return new BadgeJson(null, progress.type.name(), progress.progressingAgainstLevel(), progress.progression(), progress.goal());
}
- protected final SqlF<PersonBadgeDto, BadgeDetailJson> getBadgeDetailJson = new SqlF<PersonBadgeDto, BadgeDetailJson>() {
- public BadgeDetailJson apply(PersonBadgeDto badgeDto) throws SQLException {
- return new BadgeDetailJson(getBadge(badgeDto),
+ protected final SqlF<PersonalBadgeDto, BadgeDetailJson> getBadgeDetailJson = new SqlF<PersonalBadgeDto, BadgeDetailJson>() {
+ public BadgeDetailJson apply(PersonalBadgeDto badgeDto) throws SQLException {
+ return new BadgeDetailJson(getBadgeJson.apply(badgeDto),
daos.personDao.selectPerson(badgeDto.person).map(getPersonJson).get());
}
};
diff --git a/src/main/sql/base-schema/logback.xml b/src/main/resources/logback.xml
index 460df3a..b502003 100644
--- a/src/main/sql/base-schema/logback.xml
+++ b/src/main/resources/logback.xml
@@ -26,6 +26,8 @@
<!-- Gitorious spews out a few invalid cookies -->
<logger name="org.apache.http.client.protocol.ResponseProcessCookies" level="ERROR"/>
+ <logger name="org.eclipse.jetty" level="INFO"/>
+
<logger name="io.trygvis.esper.testing.util.HttpClient" level="INFO"/>
<logger name="org.apache.shiro" level="DEBUG"/>
diff --git a/src/main/sql/base-schema/posgresql-ddl.sql b/src/main/sql/base-schema/posgresql-ddl.sql
new file mode 100644
index 0000000..4a274a8
--- /dev/null
+++ b/src/main/sql/base-schema/posgresql-ddl.sql
@@ -0,0 +1,500 @@
+--
+-- PostgreSQL database dump
+--
+
+SET statement_timeout = 0;
+SET client_encoding = 'UTF8';
+SET standard_conforming_strings = on;
+SET check_function_bodies = false;
+SET client_min_messages = warning;
+
+SET search_path = public, pg_catalog;
+
+SET default_tablespace = '';
+
+SET default_with_oids = false;
+
+--
+-- Name: apache_user; Type: TABLE; Schema: public; Owner: esper; Tablespace:
+--
+
+CREATE TABLE apache_user (
+ id character varying(100),
+ name character varying(100)
+);
+
+
+ALTER TABLE public.apache_user OWNER TO esper;
+
+--
+-- Name: build_seq; Type: SEQUENCE; Schema: public; Owner: esper
+--
+
+CREATE SEQUENCE build_seq
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+
+ALTER TABLE public.build_seq OWNER TO esper;
+
+--
+-- Name: build; Type: TABLE; Schema: public; Owner: esper; Tablespace:
+--
+
+CREATE TABLE build (
+ uuid character(36) NOT NULL,
+ created_date timestamp without time zone NOT NULL,
+ seq integer DEFAULT nextval('build_seq'::regclass) NOT NULL,
+ "timestamp" timestamp without time zone NOT NULL,
+ success boolean NOT NULL,
+ reference_type character varying(100) NOT NULL,
+ reference_uuid character(36) NOT NULL
+);
+
+
+ALTER TABLE public.build OWNER TO esper;
+
+--
+-- Name: build_participant; Type: TABLE; Schema: public; Owner: esper; Tablespace:
+--
+
+CREATE TABLE build_participant (
+ build character(36) NOT NULL,
+ person character(36) NOT NULL
+);
+
+
+ALTER TABLE public.build_participant OWNER TO esper;
+
+--
+-- Name: file; Type: TABLE; Schema: public; Owner: esper; Tablespace:
+--
+
+CREATE TABLE file (
+ uuid character(36) NOT NULL,
+ created_date timestamp without time zone NOT NULL,
+ url character varying(1000) NOT NULL,
+ content_type character varying(100) NOT NULL,
+ data bytea
+);
+
+
+ALTER TABLE public.file OWNER TO esper;
+
+--
+-- Name: jenkins_build_seq; Type: SEQUENCE; Schema: public; Owner: esper
+--
+
+CREATE SEQUENCE jenkins_build_seq
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+
+ALTER TABLE public.jenkins_build_seq OWNER TO esper;
+
+--
+-- Name: jenkins_build; Type: TABLE; Schema: public; Owner: esper; Tablespace:
+--
+
+CREATE TABLE jenkins_build (
+ uuid character(36) NOT NULL,
+ created_date timestamp without time zone NOT NULL,
+ seq integer DEFAULT nextval('jenkins_build_seq'::regclass) NOT NULL,
+ job character(36) NOT NULL,
+ file character(36) NOT NULL,
+ entry_id character varying(1000) NOT NULL,
+ url character varying(1000) NOT NULL,
+ result character varying(100),
+ number integer,
+ duration integer,
+ "timestamp" timestamp without time zone,
+ users character(36)[]
+);
+
+
+ALTER TABLE public.jenkins_build OWNER TO esper;
+
+--
+-- Name: jenkins_job; Type: TABLE; Schema: public; Owner: esper; Tablespace:
+--
+
+CREATE TABLE jenkins_job (
+ uuid character(36) NOT NULL,
+ created_date timestamp without time zone NOT NULL,
+ server character(36) NOT NULL,
+ file character(36) NOT NULL,
+ url character varying(1000) NOT NULL,
+ job_type character varying(100) NOT NULL,
+ display_name character varying(100)
+);
+
+
+ALTER TABLE public.jenkins_job OWNER TO esper;
+
+--
+-- Name: jenkins_server; Type: TABLE; Schema: public; Owner: esper; Tablespace:
+--
+
+CREATE TABLE jenkins_server (
+ uuid character(36) NOT NULL,
+ created_date timestamp without time zone NOT NULL,
+ url character varying(1000) NOT NULL,
+ enabled boolean NOT NULL
+);
+
+
+ALTER TABLE public.jenkins_server OWNER TO esper;
+
+--
+-- Name: jenkins_user; Type: TABLE; Schema: public; Owner: esper; Tablespace:
+--
+
+CREATE TABLE jenkins_user (
+ uuid character(36) NOT NULL,
+ created_date timestamp without time zone NOT NULL,
+ server character(36) NOT NULL,
+ absolute_url character varying(1000) NOT NULL
+);
+
+
+ALTER TABLE public.jenkins_user OWNER TO esper;
+
+--
+-- Name: person; Type: TABLE; Schema: public; Owner: esper; Tablespace:
+--
+
+CREATE TABLE person (
+ uuid character(36) NOT NULL,
+ created_date timestamp without time zone NOT NULL,
+ name character varying(100),
+ mail character varying(100)
+);
+
+
+ALTER TABLE public.person OWNER TO esper;
+
+--
+-- Name: person_badge; Type: TABLE; Schema: public; Owner: esper; Tablespace:
+--
+
+CREATE TABLE person_badge (
+ uuid character(36) NOT NULL,
+ created_date timestamp without time zone NOT NULL,
+ person character(36) NOT NULL,
+ name character varying(100) NOT NULL,
+ level integer NOT NULL,
+ count integer NOT NULL
+);
+
+
+ALTER TABLE public.person_badge OWNER TO esper;
+
+--
+-- Name: person_badge_progress; Type: TABLE; Schema: public; Owner: esper; Tablespace:
+--
+
+CREATE TABLE person_badge_progress (
+ uuid character(36) NOT NULL,
+ created_date timestamp without time zone NOT NULL,
+ person character(36) NOT NULL,
+ badge character varying(100) NOT NULL,
+ state character varying(8000) NOT NULL
+);
+
+
+ALTER TABLE public.person_badge_progress OWNER TO esper;
+
+--
+-- Name: person_jenkins_user; Type: TABLE; Schema: public; Owner: esper; Tablespace:
+--
+
+CREATE TABLE person_jenkins_user (
+ person character(36) NOT NULL,
+ jenkins_user character(36) NOT NULL
+);
+
+
+ALTER TABLE public.person_jenkins_user OWNER TO esper;
+
+--
+-- Name: table_poller_status; Type: TABLE; Schema: public; Owner: esper; Tablespace:
+--
+
+CREATE TABLE table_poller_status (
+ poller_name character varying(100) NOT NULL,
+ last_seq integer NOT NULL,
+ last_run timestamp without time zone,
+ duration integer,
+ status character varying(1000)
+);
+
+
+ALTER TABLE public.table_poller_status OWNER TO esper;
+
+--
+-- Name: pk_build; Type: CONSTRAINT; Schema: public; Owner: esper; Tablespace:
+--
+
+ALTER TABLE ONLY build
+ ADD CONSTRAINT pk_build PRIMARY KEY (uuid);
+
+
+--
+-- Name: pk_build_participant; Type: CONSTRAINT; Schema: public; Owner: esper; Tablespace:
+--
+
+ALTER TABLE ONLY build_participant
+ ADD CONSTRAINT pk_build_participant PRIMARY KEY (build, person);
+
+
+--
+-- Name: pk_file; Type: CONSTRAINT; Schema: public; Owner: esper; Tablespace:
+--
+
+ALTER TABLE ONLY file
+ ADD CONSTRAINT pk_file PRIMARY KEY (uuid);
+
+
+--
+-- Name: pk_jenkins_build; Type: CONSTRAINT; Schema: public; Owner: esper; Tablespace:
+--
+
+ALTER TABLE ONLY jenkins_build
+ ADD CONSTRAINT pk_jenkins_build PRIMARY KEY (uuid);
+
+
+--
+-- Name: pk_jenkins_job; Type: CONSTRAINT; Schema: public; Owner: esper; Tablespace:
+--
+
+ALTER TABLE ONLY jenkins_job
+ ADD CONSTRAINT pk_jenkins_job PRIMARY KEY (uuid);
+
+
+--
+-- Name: pk_jenkins_server; Type: CONSTRAINT; Schema: public; Owner: esper; Tablespace:
+--
+
+ALTER TABLE ONLY jenkins_server
+ ADD CONSTRAINT pk_jenkins_server PRIMARY KEY (uuid);
+
+
+--
+-- Name: pk_jenkins_user; Type: CONSTRAINT; Schema: public; Owner: esper; Tablespace:
+--
+
+ALTER TABLE ONLY jenkins_user
+ ADD CONSTRAINT pk_jenkins_user PRIMARY KEY (uuid);
+
+
+--
+-- Name: pk_job_status; Type: CONSTRAINT; Schema: public; Owner: esper; Tablespace:
+--
+
+ALTER TABLE ONLY table_poller_status
+ ADD CONSTRAINT pk_job_status PRIMARY KEY (poller_name);
+
+
+--
+-- Name: pk_person; Type: CONSTRAINT; Schema: public; Owner: esper; Tablespace:
+--
+
+ALTER TABLE ONLY person
+ ADD CONSTRAINT pk_person PRIMARY KEY (uuid);
+
+
+--
+-- Name: pk_person_badge; Type: CONSTRAINT; Schema: public; Owner: esper; Tablespace:
+--
+
+ALTER TABLE ONLY person_badge
+ ADD CONSTRAINT pk_person_badge PRIMARY KEY (uuid);
+
+
+--
+-- Name: pk_person_badge_progress; Type: CONSTRAINT; Schema: public; Owner: esper; Tablespace:
+--
+
+ALTER TABLE ONLY person_badge_progress
+ ADD CONSTRAINT pk_person_badge_progress PRIMARY KEY (uuid);
+
+
+--
+-- Name: pk_person_jenkins_user; Type: CONSTRAINT; Schema: public; Owner: esper; Tablespace:
+--
+
+ALTER TABLE ONLY person_jenkins_user
+ ADD CONSTRAINT pk_person_jenkins_user PRIMARY KEY (person, jenkins_user);
+
+
+--
+-- Name: uq_jenkins_build__id; Type: CONSTRAINT; Schema: public; Owner: esper; Tablespace:
+--
+
+ALTER TABLE ONLY jenkins_build
+ ADD CONSTRAINT uq_jenkins_build__id UNIQUE (entry_id);
+
+
+--
+-- Name: uq_jenkins_build__seq; Type: CONSTRAINT; Schema: public; Owner: esper; Tablespace:
+--
+
+ALTER TABLE ONLY jenkins_build
+ ADD CONSTRAINT uq_jenkins_build__seq UNIQUE (seq);
+
+
+--
+-- Name: uq_jenkins_job__url; Type: CONSTRAINT; Schema: public; Owner: esper; Tablespace:
+--
+
+ALTER TABLE ONLY jenkins_job
+ ADD CONSTRAINT uq_jenkins_job__url UNIQUE (url);
+
+
+--
+-- Name: uq_jenkins_server__url; Type: CONSTRAINT; Schema: public; Owner: esper; Tablespace:
+--
+
+ALTER TABLE ONLY jenkins_server
+ ADD CONSTRAINT uq_jenkins_server__url UNIQUE (url);
+
+
+--
+-- Name: uq_jenkins_user__absolute_url; Type: CONSTRAINT; Schema: public; Owner: esper; Tablespace:
+--
+
+ALTER TABLE ONLY jenkins_user
+ ADD CONSTRAINT uq_jenkins_user__absolute_url UNIQUE (absolute_url);
+
+
+--
+-- Name: uq_person_badge__person__name__level; Type: CONSTRAINT; Schema: public; Owner: esper; Tablespace:
+--
+
+ALTER TABLE ONLY person_badge
+ ADD CONSTRAINT uq_person_badge__person__name__level UNIQUE (person, name, level);
+
+
+--
+-- Name: uq_person_badge_progress__person_badge; Type: CONSTRAINT; Schema: public; Owner: esper; Tablespace:
+--
+
+ALTER TABLE ONLY person_badge_progress
+ ADD CONSTRAINT uq_person_badge_progress__person_badge UNIQUE (person, badge);
+
+
+--
+-- Name: ix_jenkins_build__created_date; Type: INDEX; Schema: public; Owner: esper; Tablespace:
+--
+
+CREATE INDEX ix_jenkins_build__created_date ON jenkins_build USING btree (created_date);
+
+
+--
+-- Name: fk_build_participant__build; Type: FK CONSTRAINT; Schema: public; Owner: esper
+--
+
+ALTER TABLE ONLY build_participant
+ ADD CONSTRAINT fk_build_participant__build FOREIGN KEY (build) REFERENCES build(uuid);
+
+
+--
+-- Name: fk_build_participant__person; Type: FK CONSTRAINT; Schema: public; Owner: esper
+--
+
+ALTER TABLE ONLY build_participant
+ ADD CONSTRAINT fk_build_participant__person FOREIGN KEY (person) REFERENCES person(uuid);
+
+
+--
+-- Name: fk_jenkins_build__file; Type: FK CONSTRAINT; Schema: public; Owner: esper
+--
+
+ALTER TABLE ONLY jenkins_build
+ ADD CONSTRAINT fk_jenkins_build__file FOREIGN KEY (file) REFERENCES file(uuid);
+
+
+--
+-- Name: fk_jenkins_build__job; Type: FK CONSTRAINT; Schema: public; Owner: esper
+--
+
+ALTER TABLE ONLY jenkins_build
+ ADD CONSTRAINT fk_jenkins_build__job FOREIGN KEY (job) REFERENCES jenkins_job(uuid);
+
+
+--
+-- Name: fk_jenkins_job__file; Type: FK CONSTRAINT; Schema: public; Owner: esper
+--
+
+ALTER TABLE ONLY jenkins_job
+ ADD CONSTRAINT fk_jenkins_job__file FOREIGN KEY (file) REFERENCES file(uuid);
+
+
+--
+-- Name: fk_jenkins_job__server; Type: FK CONSTRAINT; Schema: public; Owner: esper
+--
+
+ALTER TABLE ONLY jenkins_job
+ ADD CONSTRAINT fk_jenkins_job__server FOREIGN KEY (server) REFERENCES jenkins_server(uuid);
+
+
+--
+-- Name: fk_jenkins_user__server; Type: FK CONSTRAINT; Schema: public; Owner: esper
+--
+
+ALTER TABLE ONLY jenkins_user
+ ADD CONSTRAINT fk_jenkins_user__server FOREIGN KEY (server) REFERENCES jenkins_server(uuid);
+
+
+--
+-- Name: fk_person_badge__person; Type: FK CONSTRAINT; Schema: public; Owner: esper
+--
+
+ALTER TABLE ONLY person_badge
+ ADD CONSTRAINT fk_person_badge__person FOREIGN KEY (person) REFERENCES person(uuid);
+
+
+--
+-- Name: fk_person_badge_progress__person; Type: FK CONSTRAINT; Schema: public; Owner: esper
+--
+
+ALTER TABLE ONLY person_badge_progress
+ ADD CONSTRAINT fk_person_badge_progress__person FOREIGN KEY (person) REFERENCES person(uuid);
+
+
+--
+-- Name: fk_person_jenkins_user__jenkins_user; Type: FK CONSTRAINT; Schema: public; Owner: esper
+--
+
+ALTER TABLE ONLY person_jenkins_user
+ ADD CONSTRAINT fk_person_jenkins_user__jenkins_user FOREIGN KEY (jenkins_user) REFERENCES jenkins_user(uuid);
+
+
+--
+-- Name: fk_person_jenkins_user__person; Type: FK CONSTRAINT; Schema: public; Owner: esper
+--
+
+ALTER TABLE ONLY person_jenkins_user
+ ADD CONSTRAINT fk_person_jenkins_user__person FOREIGN KEY (person) REFERENCES person(uuid);
+
+
+--
+-- Name: public; Type: ACL; Schema: -; Owner: postgres
+--
+
+REVOKE ALL ON SCHEMA public FROM PUBLIC;
+REVOKE ALL ON SCHEMA public FROM postgres;
+GRANT ALL ON SCHEMA public TO postgres;
+GRANT ALL ON SCHEMA public TO PUBLIC;
+
+
+--
+-- PostgreSQL database dump complete
+--
+
diff --git a/src/main/sql/dbdelta/1-person_badge-add-timestamps.sql b/src/main/sql/dbdelta/1-person_badge-add-timestamps.sql
index 5b53145..3c8162c 100644
--- a/src/main/sql/dbdelta/1-person_badge-add-timestamps.sql
+++ b/src/main/sql/dbdelta/1-person_badge-add-timestamps.sql
@@ -1,21 +1,34 @@
-ALTER TABLE person_badge ADD timestamps TIMESTAMP[];
+ALTER TABLE person_badge ADD state VARCHAR(8000);
+
+ALTER TABLE person_badge DROP CONSTRAINT uq_person_badge__person__name__level;
DO $$
DECLARE r RECORD;
-DECLARE ts TIMESTAMP[];
BEGIN
- FOR r IN SELECT uuid, count FROM person_badge
+ FOR r IN SELECT uuid, created_date, person, count FROM person_badge
LOOP
- SELECT array_agg(x) FROM (SELECT current_timestamp FROM generate_series(1, r.count)) AS x INTO ts;
- UPDATE person_badge SET timestamps=ts WHERE uuid=r.uuid;
+ FOR x IN SELECT x FROM generate_series(1, r.count)
+ LOOP
+ INSERT INTO person_badge(uuid, created_date, person, name, level, state) VALUES(
+ uuid_generate_v1(), r.created_date, r.person, r.name, r.level,
+ '{"type":"' || r.name || '","person":"' || r.person || '","builds":[]}');
+ END LOOP;
+
+ DELETE FROM person_badge WHERE uuid=r.uuid;
END LOOP;
END$$;
ALTER TABLE person_badge DROP count;
+ALTER TABLE person_badge ALTER state SET NOT NULL;
+
--//@UNDO
ALTER TABLE person_badge ADD count INT;
-UPDATE person_badge SET count=array_length(timestamps, 1);
+
+INSERT into person_badge(uuid, created_date, name, person, level, count)
+ SELECT uuid_generate_v1(), min(created_date) as "created_date", name, person, level, count(level) from person_badge group by name, person, level;
+
ALTER TABLE person_badge ALTER count SET NOT NULL;
-ALTER TABLE person_badge DROP timestamps;
+
+ALTER TABLE person_badge DROP state;
diff --git a/src/main/webapp/apps/frontPageApp/frontPageApp.js b/src/main/webapp/apps/frontPageApp/frontPageApp.js
index 7678f0d..ef0de81 100755
--- a/src/main/webapp/apps/frontPageApp/frontPageApp.js
+++ b/src/main/webapp/apps/frontPageApp/frontPageApp.js
@@ -40,7 +40,7 @@ function PersonCtrl($scope, $routeParams, Person, Badge, Build, PagingTableServi
$scope.recentBuilds = builds;
});
- Badge.query({person: personUuid}, function (badges) {
- $scope.badges = badges;
- });
+// Badge.query({person: personUuid}, function (badges) {
+// $scope.badges = badges;
+// });
}
diff --git a/src/main/webapp/apps/frontPageApp/person.html b/src/main/webapp/apps/frontPageApp/person.html
index 3544221..8573afe 100755
--- a/src/main/webapp/apps/frontPageApp/person.html
+++ b/src/main/webapp/apps/frontPageApp/person.html
@@ -3,7 +3,7 @@
<navbar/>
<div class="page-header">
- <h1>{{person.name}}</h1>
+ <h1>{{person.person.name}}</h1>
</div>
<ul class="nav nav-tabs">
@@ -12,35 +12,60 @@
</ul>
<div id="overview" ng-show="mode == 'overview'">
- <h3>Badges</h3>
+ <div class="row">
+ <div class="span6">
+ <h3>Upcoming</h3>
+ <table>
+ <tr ng-repeat="badge in person.badgesInProgress">
+ <td style="padding-right: 1em">{{badge.name}}</td>
+ <td style="width: 100%">
+ <div class="progress" style="margin-bottom: 0;" title="Progress: {{badge.progress}} of {{badge.goal}}">
+ <div class="bar" style="width: {{badge.progress / badge.goal * 100}}%;"></div>
+ </div>
+ </td>
+ </tr>
+ </table>
- <p ng-repeat="badge in person.badges">
- <span class="badge-level-{{badge.level}} badge">{{badge.name}}</span><span ng-show="badge.count > 1"> x {{badge.count}}</span>
- </p>
+ <h3>Badges</h3>
+ <ul class="unstyled">
+ <li ng-repeat="badge in person.badges">
+<!--
+ <span class="badge-level-{{badge.level}} badge">{{badge.name}}</span>
+-->
+ <strong>{{badge.name}}</strong>
+<!--
+ <i class="icon-user ng-class: {{{1: 'badge-level-1', 2: 'badge-level-2', 3: 'badge-level-3'}[badge.level]}}"></i>
+-->
+ <span class="badge-level-{{badge.level}} badge">
+ <i class="icon-user"></i>
+ </span>
- <div ng-repeat="badge in person.badgesInProgress">
- <div class="progress">
- <div class="bar" style="width: {{badge.progress / badge.goal * 100}}%;">{{badge.name}}</div>
+ {{badge.createdDate | date:'medium'}}
+ </li>
+ </ul>
+ </div>
+ <div class="span6">
+ <h3>Recent builds</h3>
+ <table class="table">
+ <thead>
+<!--
+ <tr>
+ <th>Date</th>
+ <th>Success</th>
+ <th></th>
+ </tr>
+-->
+ </thead>
+ <tbody>
+ <tr ng-repeat="build in recentBuilds" class="{{{true: 'success', false: 'error'}[build.success]}}">
+ <td>{{build.timestamp | date:'medium'}}</td>
+ <td>{{{true: 'Success', false: 'Failure'}[build.success]}}</td>
+ <td><a href="/build/{{build.uuid}}">Details</a></td>
+ </tr>
+ </tbody>
+ </table>
</div>
</div>
-
- <h3>Recent builds</h3>
- <table class="table">
- <thead>
- <tr>
- <th>Date</th>
- <th>Success</th>
- <th></th>
- </tr>
- </thead>
- <tbody>
- <tr ng-repeat="build in recentBuilds" class="{{{true: 'success', false: 'error'}[build.success]}}">
- <td>{{build.timestamp | date:'medium'}}</td>
- <td>{{build.success}}</td>
- <td><a href="/build/{{build.uuid}}">Details</a></td>
- </tr>
- </tbody>
- </table>
</div>
<div id="builds" ng-show="mode == 'builds'">
diff --git a/src/test/java/io/trygvis/esper/testing/core/badge/UnbreakableBadgeProgressTest.java b/src/test/java/io/trygvis/esper/testing/core/badge/UnbreakableBadgeProgressTest.java
index b50693d..3ee0c05 100644
--- a/src/test/java/io/trygvis/esper/testing/core/badge/UnbreakableBadgeProgressTest.java
+++ b/src/test/java/io/trygvis/esper/testing/core/badge/UnbreakableBadgeProgressTest.java
@@ -2,6 +2,7 @@ package io.trygvis.esper.testing.core.badge;
import fj.*;
import fj.data.*;
+import io.trygvis.esper.testing.*;
import io.trygvis.esper.testing.core.db.*;
import junit.framework.*;
import org.joda.time.*;
@@ -9,6 +10,7 @@ import org.joda.time.*;
import java.util.*;
import java.util.List;
+import static io.trygvis.esper.testing.Uuid.randomUuid;
import static java.util.UUID.*;
public class UnbreakableBadgeProgressTest extends TestCase {
@@ -18,7 +20,7 @@ public class UnbreakableBadgeProgressTest extends TestCase {
BuildDto success = new BuildDto(uuid, new DateTime(), new DateTime(), true, null);
BuildDto failure = new BuildDto(uuid, new DateTime(), new DateTime(), false, null);
- UUID person = randomUUID();
+ Uuid person = randomUuid();
UnbreakableBadgeProgress p = UnbreakableBadgeProgress.initial(person);
@@ -34,7 +36,7 @@ public class UnbreakableBadgeProgressTest extends TestCase {
p = p2._1();
}
- assertEquals(5, p.count);
+ assertEquals(5, p.builds.size());
assertEquals(3, badges.size());
assertEquals(1, badges.get(0).level);
assertEquals(2, badges.get(1).level);
@@ -42,7 +44,7 @@ public class UnbreakableBadgeProgressTest extends TestCase {
P2<UnbreakableBadgeProgress, Option<UnbreakableBadge>> p2 = p.onBuild(failure);
- assertEquals(0, p2._1().count);
+ assertEquals(0, p2._1().builds.size());
assertFalse(p2._2().isSome());
}
}