aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/trygvis/esper/testing/web
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-12-26 13:30:42 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2012-12-26 13:30:42 +0100
commit348ec4e14aeaf4e98fcab96f0ae7242d178db69b (patch)
tree642b16e2fa6ffcfaf1429571d2f4771acc620e2e /src/main/java/io/trygvis/esper/testing/web
parent97b1b1eeacd72845cc7065c86d68444881370275 (diff)
downloadesper-testing-348ec4e14aeaf4e98fcab96f0ae7242d178db69b.tar.gz
esper-testing-348ec4e14aeaf4e98fcab96f0ae7242d178db69b.tar.bz2
esper-testing-348ec4e14aeaf4e98fcab96f0ae7242d178db69b.tar.xz
esper-testing-348ec4e14aeaf4e98fcab96f0ae7242d178db69b.zip
o Starting on a better front page.
Diffstat (limited to 'src/main/java/io/trygvis/esper/testing/web')
-rw-r--r--src/main/java/io/trygvis/esper/testing/web/CoreResource.java92
-rw-r--r--src/main/java/io/trygvis/esper/testing/web/JenkinsResource.java6
-rw-r--r--src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java16
3 files changed, 106 insertions, 8 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/web/CoreResource.java b/src/main/java/io/trygvis/esper/testing/web/CoreResource.java
new file mode 100644
index 0000000..3132a62
--- /dev/null
+++ b/src/main/java/io/trygvis/esper/testing/web/CoreResource.java
@@ -0,0 +1,92 @@
+package io.trygvis.esper.testing.web;
+
+import io.trygvis.esper.testing.*;
+import io.trygvis.esper.testing.core.badge.*;
+import io.trygvis.esper.testing.core.db.*;
+import io.trygvis.esper.testing.util.sql.*;
+
+import javax.servlet.http.*;
+import javax.ws.rs.*;
+import javax.ws.rs.core.*;
+import java.sql.*;
+import java.util.*;
+
+@Path("/resource/core")
+public class CoreResource {
+
+ private final DatabaseAccess da;
+ private final BadgeService badgeService;
+
+ public CoreResource(DatabaseAccess da, BadgeService badgeService) {
+ this.da = da;
+ this.badgeService = badgeService;
+ }
+
+ @GET
+ @Path("/person")
+ @Produces(MediaType.APPLICATION_JSON)
+ public List<PersonJson> getServers(@Context final HttpServletRequest req) throws Exception {
+ return da.inTransaction(new DatabaseAccess.DaosCallback<List<PersonJson>>() {
+ @Override
+ public List<PersonJson> run(Daos daos) throws SQLException {
+ List<PersonJson> list = new ArrayList<>();
+ for (PersonDto person : daos.personDao.selectPerson(PageRequest.fromReq(req))) {
+ list.add(getPersonJson(daos, person));
+ }
+ return list;
+ }
+ });
+ }
+
+ private PersonJson getPersonJson(Daos daos, PersonDto person) throws SQLException {
+ List<BadgeJson> badges = new ArrayList<>();
+
+ for (PersonBadgeDto badge : daos.personDao.selectBadges(person.uuid)) {
+ badges.add(new BadgeJson(badge.type.name(), badge.level, badge.count, 100, 100));
+ }
+
+ for (PersonBadgeProgressDto badgeProgressDto : daos.personDao.selectBadgeProgresses(person.uuid)) {
+ UnbreakableBadgeProgress progress = badgeService.unbreakable(badgeProgressDto);
+ badges.add(new BadgeJson(progress.type.name(), progress.progressingAgainstLevel(), 0,
+ progress.progression(), progress.goal()));
+ }
+
+ return new PersonJson(
+ person.uuid,
+ person.name,
+ badges
+ );
+ }
+
+ public static class PersonJson {
+ public final UUID uuid;
+ public final String name;
+ public final List<BadgeJson> badges;
+
+ public PersonJson(UUID uuid, String name, List<BadgeJson> badges) {
+ this.uuid = uuid;
+ this.name = name;
+ this.badges = badges;
+ }
+ }
+
+ public static class BadgeJson {
+ public final String name;
+ public final int level;
+
+ /**
+ * Number of times this badge has been received.
+ */
+ public final int count;
+ public final int progress;
+ public final int goal;
+
+ public BadgeJson(String name, int level, int count, int progress, int goal) {
+ 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/JenkinsResource.java b/src/main/java/io/trygvis/esper/testing/web/JenkinsResource.java
index b9e997f..6551cea 100644
--- a/src/main/java/io/trygvis/esper/testing/web/JenkinsResource.java
+++ b/src/main/java/io/trygvis/esper/testing/web/JenkinsResource.java
@@ -14,7 +14,7 @@ import java.util.List;
import static fj.data.Option.*;
-@Path("/")
+@Path("/resource/jenkins")
public class JenkinsResource {
private final DatabaseAccess da;
@@ -24,7 +24,7 @@ public class JenkinsResource {
}
@GET
- @Path("/resource/jenkins/server")
+ @Path("/server")
@Produces(MediaType.APPLICATION_JSON)
public List<JenkinsServerJson> getServers() throws Exception {
return da.inTransaction(new DatabaseAccess.DaosCallback<List<JenkinsServerJson>>() {
@@ -40,7 +40,7 @@ public class JenkinsResource {
}
@GET
- @Path("/resource/jenkins/server/{uuid}")
+ @Path("/server/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
public JenkinsServerJson getServer(@PathParam("uuid") String s) throws Exception {
final UUID uuid = parseUuid(s);
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 6937804..67fbf74 100644
--- a/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java
+++ b/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java
@@ -1,22 +1,28 @@
package io.trygvis.esper.testing.web;
import io.trygvis.esper.testing.*;
+import io.trygvis.esper.testing.core.badge.*;
import javax.ws.rs.core.*;
import java.util.*;
public class JerseyApplication extends Application {
- private final DatabaseAccess da;
+ private final HashSet<Object> singletons;
public JerseyApplication() throws Exception {
- this.da = new DatabaseAccess(WebConfig.config.createBoneCp());
+ DatabaseAccess da = new DatabaseAccess(WebConfig.config.createBoneCp());
+
+ BadgeService badgeService = new BadgeService();
+
+ singletons = new HashSet<>(Arrays.asList(
+ new CoreResource(da, badgeService),
+ new JenkinsResource(da)
+ ));
}
@Override
public Set<Object> getSingletons() {
- return new HashSet<Object>(Arrays.asList(
- new JenkinsResource(da)
- ));
+ return singletons;
}
}