Search in sources :

Example 16 with Result

use of play.mvc.Result in project modules.playframework.org by playframework.

the class Application method createAccount.

public static Result createAccount() {
    Form<Register> registerForm = form(Register.class).bindFromRequest();
    Result result;
    if (registerForm.hasErrors()) {
        result = badRequest(register.render(registerForm));
    } else {
        Register register = registerForm.get();
        new UserServices().createUser(register.userName, register.displayName, register.password);
        session("userName", register.userName);
        result = redirect(routes.Application.index());
    }
    return result;
}
Also used : UserServices(services.UserServices) Register(forms.login.Register) Result(play.mvc.Result)

Example 17 with Result

use of play.mvc.Result in project play2-elasticsearch by cleverage.

the class Application method async.

public static F.Promise<Result> async() {
    // ElasticSearch HelloWorld
    IndexTest indexTest = new IndexTest();
    // "id" is mandatory if you want to update your document or to get by id else "id" is not mandatory
    indexTest.id = "1";
    indexTest.name = "hello World";
    indexTest.index();
    // ElasticSearch HelloWorld
    IndexTest indexTest2 = new IndexTest();
    // "id" is mandatory if you want to update your document or to get by id else "id" is not mandatory
    indexTest.id = "2";
    indexTest.name = "hello Bob";
    indexTest.index();
    IndexService.refresh();
    IndexQuery<IndexTest> query1 = IndexTest.find.query();
    query1.setBuilder(QueryBuilders.matchQuery("name", "hello"));
    IndexQuery<IndexTest> query2 = IndexTest.find.query();
    query2.setBuilder(QueryBuilders.matchQuery("name", "bob"));
    F.Promise<IndexResults<IndexTest>> indexResultsPromise1 = IndexTest.find.searchAsync(query1);
    F.Promise<IndexResults<IndexTest>> indexResultsPromise2 = IndexTest.find.searchAsync(query2);
    F.Promise<List<IndexResults<IndexTest>>> combinedPromise = F.Promise.sequence(indexResultsPromise1, indexResultsPromise2);
    return combinedPromise.map(new F.Function<List<IndexResults<IndexTest>>, Result>() {

        @Override
        public Result apply(List<IndexResults<IndexTest>> indexResultsList) throws Throwable {
            return ok(indexResultsList.get(0).totalCount + " - " + indexResultsList.get(1).totalCount);
        }
    });
}
Also used : IndexTest(indexing.IndexTest) F(play.libs.F) IndexResults(com.github.cleverage.elasticsearch.IndexResults) List(java.util.List) Result(play.mvc.Result)

Aggregations

Result (play.mvc.Result)17 CurrentUser (actions.CurrentUser)7 CurrentUser.currentUser (actions.CurrentUser.currentUser)7 User (models.User)7 Module (models.Module)6 RoleHolderPresent (be.objectify.deadbolt.actions.RoleHolderPresent)5 PlayVersion (models.PlayVersion)4 FeaturedModule (models.FeaturedModule)3 Vote (models.Vote)3 VoteResponseForm (forms.modules.VoteResponseForm)2 Date (java.util.Date)2 Category (models.Category)2 ModuleVersion (models.ModuleVersion)2 Rate (models.Rate)2 ObjectNode (org.codehaus.jackson.node.ObjectNode)2 Filter (utils.Filter)2 IndexResults (com.github.cleverage.elasticsearch.IndexResults)1 Login (forms.login.Login)1 Register (forms.login.Register)1 RatingForm (forms.modules.RatingForm)1