package controllers;

import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;

import play.libs.Json;
import play.mvc.BodyParser;
import play.mvc.Controller;
import play.mvc.Result;
import play.mvc.Security;

import views.html.search;


public class Search extends Controller {

    @Security.Authenticated(Secured.class)
    public static Result search() {
        return ok(search.render());
    }

    @Security.Authenticated(Secured.class)
    @BodyParser.Of(BodyParser.Json.class)
    public static Result doSearch() {
        ObjectNode result = Json.newObject();
        ArrayNode matchingRules = JsonNodeFactory.instance.arrayNode();
        ObjectNode dummyRule = Json.newObject();
        dummyRule.put("name", "rule1");
        dummyRule.put("description", "The first rule of fight club is...");
        matchingRules.add(dummyRule);
        result.put("matchingRules", matchingRules);
        return ok(result);
    }

}

@@ -776,16 +776,17 @@
 ummyRule
+1
  = Json.
@@ -811,24 +811,25 @@
    dummyRule
+1
 .put(%22name%22,
@@ -856,16 +856,225 @@
 ummyRule
+1.put(%22description%22, %22The second rule of fight club is...%22);%0A        matchingRules.add(dummyRule1);%0A        ObjectNode dummyRule2 = Json.newObject();%0A        dummyRule2.put(%22name%22, %22rule2%22);%0A        dummyRule2
 .put(%22de
@@ -1159,16 +1159,17 @@
 ummyRule
+2
 );%0A     

Enable sorting of search results.