Some refactoring in SimpleReasonerRecomputeController to reduce clutter in the controller and template.

This commit is contained in:
ryounes 2011-08-29 21:21:39 +00:00
parent 315aac425c
commit 6b5ec3efda
2 changed files with 22 additions and 27 deletions

View file

@ -33,31 +33,27 @@ public class SimpleReasonerRecomputeController extends FreemarkerHttpServlet {
String messageStr = ""; String messageStr = "";
try { try {
Object simpleReasoner = vreq.getSession().getServletContext().getAttribute(SimpleReasoner.class.getName()); Object sr = getServletContext().getAttribute(SimpleReasoner.class.getName());
if (!(simpleReasoner instanceof SimpleReasoner)) { if (!(sr instanceof SimpleReasoner)) {
messageStr = "No SimpleReasoner has been set up."; messageStr = "No SimpleReasoner has been set up.";
} else if ( ((SimpleReasoner)simpleReasoner).isABoxReasoningAsynchronous() ) {
messageStr = "SimpleReasoner is currently in asynchronous mode so a recompute cannot be started. Please try again later.";
} else { } else {
String signal = (String) vreq.getParameter("signal"); SimpleReasoner simpleReasoner = (SimpleReasoner) sr;
if (simpleReasoner.isABoxReasoningAsynchronous()) {
if (((SimpleReasoner)simpleReasoner).isRecomputing()) { messageStr = "SimpleReasoner is currently in asynchronous mode so a recompute cannot be started. Please try again later.";
messageStr = } else if (simpleReasoner.isRecomputing()) {
"The SimpleReasoner is currently in the process of " + messageStr =
"recomputing inferences."; "The SimpleReasoner is currently in the process of " +
} else{ "recomputing inferences.";
String restart = (String)getServletContext().getAttribute("restart"); } else {
if(restart == null || restart.equals("showButton") || signal == null){ String submit = (String)vreq.getParameter("submit");
body.put("link", "show"); if (submit != null) {
messageStr = null; new Thread(new Recomputer((simpleReasoner))).start();
getServletContext().setAttribute("restart", "yes"); messageStr = "Recompute of inferences started. See vivo log for further details.";
} } else {
else if(signal!=null && signal.equals("Recompute")){ body.put("formAction", UrlBuilder.getUrl("/RecomputeInferences"));
new Thread(new Recomputer(((SimpleReasoner)simpleReasoner))).start(); }
messageStr = "Recomputation of inferences started";
getServletContext().setAttribute("restart", "showButton");
}
} }
} }
@ -71,7 +67,6 @@ public class SimpleReasonerRecomputeController extends FreemarkerHttpServlet {
} }
body.put("message", messageStr); body.put("message", messageStr);
body.put("redirecturl",vreq.getContextPath()+"/RecomputeInferences");
return new TemplateResponseValues(RECOMPUTE_INFERENCES_FTL, body); return new TemplateResponseValues(RECOMPUTE_INFERENCES_FTL, body);
} }

View file

@ -1,11 +1,11 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> <#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#if link??> <#if formAction?has_content>
<form method="post" action="RecomputeInferences"> <form method="post" action="${formAction}">
<input type="submit" value="Recompute Inferences" name="submit"/> <input type="submit" value="Recompute Inferences" name="submit"/>
<input type="hidden" value="Recompute" name="signal">
</form> </form>
</#if> </#if>
<#if message??>
<#if message?has_content>
<p>${message}</p> <p>${message}</p>
</#if> </#if>