Skip to content

Commit

Permalink
securing indexSync method, moving to new controller as part of issue #9
Browse files Browse the repository at this point in the history
  • Loading branch information
monitorjbl authored and leocwolter committed Aug 25, 2014
1 parent 5d85144 commit 8d058eb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
43 changes: 43 additions & 0 deletions src/main/java/org/mamute/controllers/IndexController.java
@@ -0,0 +1,43 @@
package org.mamute.controllers;

import br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import org.mamute.brutauth.auth.rules.ModeratorOnlyRule;
import org.mamute.dao.QuestionDAO;
import org.mamute.model.Question;
import org.mamute.search.QuestionIndex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.util.List;

@Controller
public class IndexController {
private static final Logger LOGGER = LoggerFactory.getLogger(IndexController.class);

@Inject
private Result result;
@Inject
private QuestionIndex index;
@Inject
private QuestionDAO dao;

@CustomBrutauthRules(ModeratorOnlyRule.class)
@Post("/msdf0fhq924pqpsdl")
public void indexSync() {
long pages = dao.numberOfPages();
long total = 0;
for (int i = 0; i < pages; i++) {
List<Question> q = dao.allVisible(i);
index.indexQuestionBatch(q);
total += q.size();
}

LOGGER.info("Synced " + total + " questions");
result.nothing();
}

}
19 changes: 3 additions & 16 deletions src/main/java/org/mamute/controllers/SearchController.java
Expand Up @@ -2,13 +2,13 @@

import javax.inject.Inject;

import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Result;
import org.mamute.dao.QuestionDAO;
import org.mamute.model.Question;
import org.mamute.sanitizer.HtmlSanitizer;

import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.environment.Environment;
import br.com.caelum.vraptor.routes.annotation.Routed;
import org.mamute.search.QuestionIndex;
Expand Down Expand Up @@ -48,17 +48,4 @@ public void indexSearch(String query) {
result.include("results", questions);
result.include("query", sanitized);
}

@Get
public void indexSync() {
long pages = dao.numberOfPages();
long total = 0;
for (int i = 0; i < pages; i++) {
List<Question> q = dao.allVisible(i);
index.indexQuestionBatch(q);
total += q.size();
}

result.include("total", total);
}
}
1 change: 0 additions & 1 deletion src/main/resources/routes.properties
Expand Up @@ -67,7 +67,6 @@ RssController.newsRss = /news/rss

SearchController.search = /search
SearchController.indexSearch = /indexSearch
SearchController.indexSync = /indexSync

SignupController.signupForm = /sign-up
SignupController.signup = /sign-up
Expand Down

0 comments on commit 8d058eb

Please sign in to comment.