Child: [14c0cf] (diff)

Download this file

ClientAPIController.java    51 lines (39 with data), 1.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package controllers;
import java.net.UnknownHostException;
import org.codehaus.jackson.JsonNode;
import play.libs.Json;
import play.mvc.Controller;
import play.mvc.Result;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.Mongo;
public class ClientAPIController extends Controller {
public static Result projects() {
try {
String projectsJson = "[";
Mongo mongo = new Mongo();
DB db = mongo.getDB("ossmeter");
DBCollection projects = db.getCollection("projects");
DBCursor cursor = projects.find();
while (cursor.hasNext()) {
DBObject obj = cursor.next();
projectsJson += obj.toString();
if (cursor.hasNext()) projectsJson += ",";
}
projectsJson += "]";
JsonNode response = Json.parse(projectsJson);
return ok(response);
} catch (UnknownHostException e) {
e.printStackTrace();
return badRequest(e.getMessage()).as("application/json");// TODO: more detail / as Json
}
}
public static Result getProject(String name) {
return TODO;
}
public static Result getMetric(String proj, String id) {
return TODO;
}
}