aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-12-26 21:45:38 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2012-12-26 21:45:38 +0100
commit422b1caeaa9f7d069a9208ecb0d0249485b1a05e (patch)
tree90ef9e1d0b6f26178f1fae3e3df20226a1d91087 /src/main/java/io
parent348ec4e14aeaf4e98fcab96f0ae7242d178db69b (diff)
downloadesper-testing-422b1caeaa9f7d069a9208ecb0d0249485b1a05e.tar.gz
esper-testing-422b1caeaa9f7d069a9208ecb0d0249485b1a05e.tar.bz2
esper-testing-422b1caeaa9f7d069a9208ecb0d0249485b1a05e.tar.xz
esper-testing-422b1caeaa9f7d069a9208ecb0d0249485b1a05e.zip
o Adding details page for persons.
o Better front page.
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/trygvis/esper/testing/core/badge/UnbreakableBadgeProgress.java1
-rw-r--r--src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java18
-rw-r--r--src/main/java/io/trygvis/esper/testing/esper/Test1.java1
-rw-r--r--src/main/java/io/trygvis/esper/testing/esper/Test3.java1
-rw-r--r--src/main/java/io/trygvis/esper/testing/gitorious/GitoriousClient.java1
-rw-r--r--src/main/java/io/trygvis/esper/testing/gitorious/GitoriousProjectDiscovery.java1
-rw-r--r--src/main/java/io/trygvis/esper/testing/nexus/NexusFeedParser.java1
-rw-r--r--src/main/java/io/trygvis/esper/testing/nexus/NexusImporter.java1
-rw-r--r--src/main/java/io/trygvis/esper/testing/util/HttpClient.java1
-rw-r--r--src/main/java/io/trygvis/esper/testing/util/XmlParser.java1
-rw-r--r--src/main/java/io/trygvis/esper/testing/util/object/ObjectUtil.java1
-rw-r--r--src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java2
-rw-r--r--src/main/java/io/trygvis/esper/testing/web/AbstractResource.java26
-rw-r--r--src/main/java/io/trygvis/esper/testing/web/CoreResource.java66
-rw-r--r--src/main/java/io/trygvis/esper/testing/web/JenkinsResource.java19
-rw-r--r--src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java3
16 files changed, 96 insertions, 48 deletions
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 dc9a5bc..4cba611 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
@@ -80,7 +80,6 @@ public class UnbreakableBadgeProgress extends BadgeProgress {
return 1;
}
- @Override
public String toString() {
return "UnbreakableBadgeProgress{person=" + person + ", count=" + count + '}';
}
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 6605999..62c4f2b 100644
--- a/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java
+++ b/src/main/java/io/trygvis/esper/testing/core/db/PersonDao.java
@@ -1,6 +1,5 @@
package io.trygvis.esper.testing.core.db;
-import static io.trygvis.esper.testing.Util.toList;
import io.trygvis.esper.testing.core.db.PersonBadgeDto.*;
import io.trygvis.esper.testing.util.sql.*;
import org.joda.time.*;
@@ -8,6 +7,7 @@ import org.joda.time.*;
import java.sql.*;
import java.util.*;
+import static io.trygvis.esper.testing.Util.*;
import static io.trygvis.esper.testing.util.sql.SqlOption.*;
import static java.lang.System.*;
@@ -36,7 +36,7 @@ public class PersonDao {
new DateTime(rs.getTimestamp(i++).getTime()),
UUID.fromString(rs.getString(i++)),
BadgeType.valueOf(rs.getString(i++)),
- rs.getInt(i),
+ rs.getInt(i++),
rs.getInt(i));
}
};
@@ -63,16 +63,16 @@ public class PersonDao {
// Person
// -----------------------------------------------------------------------
- public SqlOption<PersonDto> selectPerson(String id) throws SQLException {
- try (PreparedStatement s = c.prepareStatement("SELECT " + PERSON + " FROM person WHERE id=?")) {
+ public SqlOption<PersonDto> selectPerson(UUID uuid) throws SQLException {
+ try (PreparedStatement s = c.prepareStatement("SELECT " + PERSON + " FROM person WHERE uuid=?")) {
int i = 1;
- s.setString(i, id);
+ s.setString(i, uuid.toString());
return fromRs(s.executeQuery()).map(person);
}
}
public List<PersonDto> selectPerson(PageRequest pageRequest) throws SQLException {
- try (PreparedStatement s = c.prepareStatement("SELECT " + PERSON + " FROM person ORDER BY created_date LIMIT ? OFFSET ?")) {
+ try (PreparedStatement s = c.prepareStatement("SELECT " + PERSON + " FROM person ORDER BY created_date, name LIMIT ? OFFSET ?")) {
int i = 1;
s.setInt(i++, pageRequest.count.orSome(10));
s.setInt(i, pageRequest.startIndex.orSome(0));
@@ -80,6 +80,12 @@ public class PersonDao {
}
}
+ public int selectPersonCount() throws SQLException {
+ try (PreparedStatement s = c.prepareStatement("SELECT count(1) FROM person")) {
+ return fromRs(s.executeQuery()).map(ResultSetF.getInt).get();
+ }
+ }
+
public SqlOption<PersonDto> selectPersonByJenkinsUuid(UUID jenkinsUser) throws SQLException {
try (PreparedStatement s = c.prepareStatement("SELECT " + PERSON + " FROM person WHERE uuid=(SELECT person FROM person_jenkins_user WHERE jenkins_user=?)")) {
int i = 1;
diff --git a/src/main/java/io/trygvis/esper/testing/esper/Test1.java b/src/main/java/io/trygvis/esper/testing/esper/Test1.java
index 842dcb3..43f857b 100644
--- a/src/main/java/io/trygvis/esper/testing/esper/Test1.java
+++ b/src/main/java/io/trygvis/esper/testing/esper/Test1.java
@@ -68,7 +68,6 @@ public class Test1 {
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
- @Override
public void run() {
logger.info("tick");
}
diff --git a/src/main/java/io/trygvis/esper/testing/esper/Test3.java b/src/main/java/io/trygvis/esper/testing/esper/Test3.java
index 70c4dc3..1c007b9 100644
--- a/src/main/java/io/trygvis/esper/testing/esper/Test3.java
+++ b/src/main/java/io/trygvis/esper/testing/esper/Test3.java
@@ -68,7 +68,6 @@ public class Test3 {
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
- @Override
public void run() {
logger.info("tick");
}
diff --git a/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousClient.java b/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousClient.java
index 0071b1f..745c36a 100644
--- a/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousClient.java
+++ b/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousClient.java
@@ -31,7 +31,6 @@ public class GitoriousClient {
private final GitoriousAtomFeedParser parser;
private final F<HTTPResponse, Option<List<GitoriousProjectXml>>> parseDocument = new F<HTTPResponse, Option<List<GitoriousProjectXml>>>() {
- @Override
public Option<List<GitoriousProjectXml>> f(HTTPResponse response) {
MIMEType mimeType = MIMEType.valueOf(trimToEmpty(response.getHeaders().getFirstHeaderValue("Content-Type")));
if (!mimeType.getPrimaryType().equals("application") || !mimeType.getSubType().equals("xml")) {
diff --git a/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousProjectDiscovery.java b/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousProjectDiscovery.java
index 1429f83..9fe809c 100644
--- a/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousProjectDiscovery.java
+++ b/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousProjectDiscovery.java
@@ -50,7 +50,6 @@ public class GitoriousProjectDiscovery {
});
ObjectUtil.scheduledActorWithFixedDelay(service, config.gitorious.projectListUpdateDelay, config.gitorious.projectListUpdateInterval, TimeUnit.MILLISECONDS, boneCp, "Gitorious", new TransactionalActor() {
- @Override
public void act(Connection c) throws Exception {
try (Daos daos = new Daos(c)) {
discoverProjects(daos);
diff --git a/src/main/java/io/trygvis/esper/testing/nexus/NexusFeedParser.java b/src/main/java/io/trygvis/esper/testing/nexus/NexusFeedParser.java
index eb89f30..fa5f2a1 100644
--- a/src/main/java/io/trygvis/esper/testing/nexus/NexusFeedParser.java
+++ b/src/main/java/io/trygvis/esper/testing/nexus/NexusFeedParser.java
@@ -50,7 +50,6 @@ public class NexusFeedParser {
Option<String> guid = Option.fromNull(item.getChildText("guid"));
Option<String> creator = Option.fromNull(item.getChildText("creator", dc));
Option<DateTime> date = Option.fromNull(item.getChildText("date", dc)).bind(new F<String, Option<DateTime>>() {
- @Override
public Option<DateTime> f(String s) {
try {
return some(ISODateTimeFormat.dateTimeNoMillis().parseDateTime(s));
diff --git a/src/main/java/io/trygvis/esper/testing/nexus/NexusImporter.java b/src/main/java/io/trygvis/esper/testing/nexus/NexusImporter.java
index 4042108..024cde2 100644
--- a/src/main/java/io/trygvis/esper/testing/nexus/NexusImporter.java
+++ b/src/main/java/io/trygvis/esper/testing/nexus/NexusImporter.java
@@ -71,7 +71,6 @@ class NexusServer implements TransactionalActor {
this.xmlParser = xmlParser;
}
- @Override
public void act(Connection c) throws Exception {
NexusDao dao = new NexusDao(c);
diff --git a/src/main/java/io/trygvis/esper/testing/util/HttpClient.java b/src/main/java/io/trygvis/esper/testing/util/HttpClient.java
index 69c74fe..1676d3f 100644
--- a/src/main/java/io/trygvis/esper/testing/util/HttpClient.java
+++ b/src/main/java/io/trygvis/esper/testing/util/HttpClient.java
@@ -34,7 +34,6 @@ public class HttpClient<A> {
public static <A> F<HTTPResponse, Option<A>> inputStreamOnly(final F<InputStream, Option<A>> f) {
return new F<HTTPResponse, Option<A>>() {
- @Override
public Option<A> f(HTTPResponse response) {
InputStream inputStream = response.getPayload().getInputStream();
try {
diff --git a/src/main/java/io/trygvis/esper/testing/util/XmlParser.java b/src/main/java/io/trygvis/esper/testing/util/XmlParser.java
index 9c585fc..624785c 100644
--- a/src/main/java/io/trygvis/esper/testing/util/XmlParser.java
+++ b/src/main/java/io/trygvis/esper/testing/util/XmlParser.java
@@ -46,7 +46,6 @@ public class XmlParser {
boolean seenStartDocument;
- @Override
public boolean accept(XMLStreamReader reader) {
if(reader.getEventType() == SPACE && !seenStartDocument) {
return false;
diff --git a/src/main/java/io/trygvis/esper/testing/util/object/ObjectUtil.java b/src/main/java/io/trygvis/esper/testing/util/object/ObjectUtil.java
index 143a181..26c9e14 100644
--- a/src/main/java/io/trygvis/esper/testing/util/object/ObjectUtil.java
+++ b/src/main/java/io/trygvis/esper/testing/util/object/ObjectUtil.java
@@ -80,7 +80,6 @@ public class ObjectUtil {
future.cancel(true);
}
- @Override
public void run() {
actor.run();
}
diff --git a/src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java b/src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java
index 2d8edfe..91a00f8 100644
--- a/src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java
+++ b/src/main/java/io/trygvis/esper/testing/util/sql/PageRequest.java
@@ -15,7 +15,7 @@ public class PageRequest {
this.count = count;
}
- public static PageRequest fromReq(HttpServletRequest req) {
+ public static PageRequest pageReq(HttpServletRequest req) {
return new PageRequest(
fromNull(req.getParameter("startIndex")).bind(Util.parseInt),
fromNull(req.getParameter("count")).bind(Util.parseInt));
diff --git a/src/main/java/io/trygvis/esper/testing/web/AbstractResource.java b/src/main/java/io/trygvis/esper/testing/web/AbstractResource.java
new file mode 100644
index 0000000..c811a2f
--- /dev/null
+++ b/src/main/java/io/trygvis/esper/testing/web/AbstractResource.java
@@ -0,0 +1,26 @@
+package io.trygvis.esper.testing.web;
+
+import fj.data.*;
+import io.trygvis.esper.testing.*;
+
+import javax.ws.rs.*;
+import javax.ws.rs.core.*;
+import java.sql.*;
+
+public class AbstractResource {
+ protected final DatabaseAccess da;
+
+ public AbstractResource(DatabaseAccess da) {
+ this.da = da;
+ }
+
+ public <T> T get(DatabaseAccess.DaosCallback<Option<T>> callback) throws SQLException {
+ Option<T> server = da.inTransaction(callback);
+
+ if(server.isNone()) {
+ throw new WebApplicationException(Response.Status.NOT_FOUND);
+ }
+
+ return server.some();
+ }
+}
diff --git a/src/main/java/io/trygvis/esper/testing/web/CoreResource.java b/src/main/java/io/trygvis/esper/testing/web/CoreResource.java
index 3132a62..f2fb12a 100644
--- a/src/main/java/io/trygvis/esper/testing/web/CoreResource.java
+++ b/src/main/java/io/trygvis/esper/testing/web/CoreResource.java
@@ -1,5 +1,6 @@
package io.trygvis.esper.testing.web;
+import fj.data.*;
import io.trygvis.esper.testing.*;
import io.trygvis.esper.testing.core.badge.*;
import io.trygvis.esper.testing.core.db.*;
@@ -10,27 +11,31 @@ import javax.ws.rs.*;
import javax.ws.rs.core.*;
import java.sql.*;
import java.util.*;
+import java.util.List;
+
+import static io.trygvis.esper.testing.util.sql.PageRequest.*;
+import static io.trygvis.esper.testing.web.JenkinsResource.*;
@Path("/resource/core")
-public class CoreResource {
+@Produces(MediaType.APPLICATION_JSON)
+public class CoreResource extends AbstractResource {
- private final DatabaseAccess da;
private final BadgeService badgeService;
public CoreResource(DatabaseAccess da, BadgeService badgeService) {
- this.da = da;
+ super(da);
this.badgeService = badgeService;
}
@GET
@Path("/person")
- @Produces(MediaType.APPLICATION_JSON)
- public List<PersonJson> getServers(@Context final HttpServletRequest req) throws Exception {
+ public List<PersonJson> getPersons(@Context final HttpServletRequest req) throws Exception {
+ final PageRequest pageRequest = pageReq(req);
+
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))) {
+ for (PersonDto person : daos.personDao.selectPerson(pageRequest)) {
list.add(getPersonJson(daos, person));
}
return list;
@@ -38,6 +43,36 @@ public class CoreResource {
});
}
+ /**
+ * This is wrong, but Angular's $resource is a bit dumb.
+ */
+ @GET
+ @Path("/person-count")
+ public int getPersonCount() throws Exception {
+ return da.inTransaction(new DatabaseAccess.DaosCallback<Integer>() {
+ public Integer run(Daos daos) throws SQLException {
+ return daos.personDao.selectPersonCount();
+ }
+ });
+ }
+
+ @GET
+ @Path("/person/{uuid}")
+ public PersonJson getPerson(@PathParam("uuid") final String s) throws Exception {
+ final UUID uuid = parseUuid(s);
+
+ return get(new DatabaseAccess.DaosCallback<Option<PersonJson>>() {
+ public Option<PersonJson> run(Daos daos) throws SQLException {
+ SqlOption<PersonDto> o = daos.personDao.selectPerson(uuid);
+ if (o.isNone()) {
+ return Option.none();
+ }
+
+ return Option.some(getPersonJson(daos, o.get()));
+ }
+ });
+ }
+
private PersonJson getPersonJson(Daos daos, PersonDto person) throws SQLException {
List<BadgeJson> badges = new ArrayList<>();
@@ -45,16 +80,19 @@ public class CoreResource {
badges.add(new BadgeJson(badge.type.name(), badge.level, badge.count, 100, 100));
}
+ List<BadgeJson> badgesInProgress = new ArrayList<>();
+
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()));
+ badgesInProgress.add(new BadgeJson(progress.type.name(), progress.progressingAgainstLevel(), 0,
+ progress.progression(), progress.goal()));
}
return new PersonJson(
- person.uuid,
- person.name,
- badges
+ person.uuid,
+ person.name,
+ badges,
+ badgesInProgress
);
}
@@ -62,11 +100,13 @@ public class CoreResource {
public final UUID uuid;
public final String name;
public final List<BadgeJson> badges;
+ public final List<BadgeJson> badgesInProgress;
- public PersonJson(UUID uuid, String name, List<BadgeJson> badges) {
+ public PersonJson(UUID uuid, String name, List<BadgeJson> badges, List<BadgeJson> badgesInProgress) {
this.uuid = uuid;
this.name = name;
this.badges = badges;
+ this.badgesInProgress = badgesInProgress;
}
}
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 6551cea..bd925b6 100644
--- a/src/main/java/io/trygvis/esper/testing/web/JenkinsResource.java
+++ b/src/main/java/io/trygvis/esper/testing/web/JenkinsResource.java
@@ -15,12 +15,10 @@ import java.util.List;
import static fj.data.Option.*;
@Path("/resource/jenkins")
-public class JenkinsResource {
-
- private final DatabaseAccess da;
+public class JenkinsResource extends AbstractResource {
public JenkinsResource(DatabaseAccess da) {
- this.da = da;
+ super(da);
}
@GET
@@ -28,7 +26,6 @@ public class JenkinsResource {
@Produces(MediaType.APPLICATION_JSON)
public List<JenkinsServerJson> getServers() throws Exception {
return da.inTransaction(new DatabaseAccess.DaosCallback<List<JenkinsServerJson>>() {
- @Override
public List<JenkinsServerJson> run(Daos daos) throws SQLException {
List<JenkinsServerJson> list = new ArrayList<>();
for (JenkinsServerDto server : daos.jenkinsDao.selectServers(false)) {
@@ -63,17 +60,7 @@ public class JenkinsResource {
return new JenkinsServerJson(server.uuid, server.createdDate, server.url, server.enabled, count);
}
- private <T> T get(DatabaseAccess.DaosCallback<Option<T>> callback) throws SQLException {
- Option<T> server = da.inTransaction(callback);
-
- if(server.isNone()) {
- throw new WebApplicationException(Response.Status.NOT_FOUND);
- }
-
- return server.some();
- }
-
- private UUID parseUuid(String s) {
+ public static UUID parseUuid(String s) {
try {
return UUID.fromString(s);
} catch (IllegalArgumentException e) {
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 67fbf74..eded64c 100644
--- a/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java
+++ b/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java
@@ -15,13 +15,12 @@ public class JerseyApplication extends Application {
BadgeService badgeService = new BadgeService();
- singletons = new HashSet<>(Arrays.asList(
+ singletons = new HashSet<Object>(Arrays.asList(
new CoreResource(da, badgeService),
new JenkinsResource(da)
));
}
- @Override
public Set<Object> getSingletons() {
return singletons;
}