diff --git a/Source/Server/src/ca/uqac/lif/cornipickle/server/DummyImage.java b/Source/Server/src/ca/uqac/lif/cornipickle/server/DummyImage.java index a552ef6..f99ffe2 100755 --- a/Source/Server/src/ca/uqac/lif/cornipickle/server/DummyImage.java +++ b/Source/Server/src/ca/uqac/lif/cornipickle/server/DummyImage.java @@ -174,7 +174,7 @@ public CallbackResponse process(HttpExchange t) if (j != null) { m_interpreter.evaluateAll(j); - //m_server.setLastProbeContact(); + m_server.setLastProbeContact(); } // Select the dummy image to send back verdicts = m_interpreter.getVerdicts(); diff --git a/Source/Server/src/ca/uqac/lif/cornipickle/server/DummyImageMobile.java b/Source/Server/src/ca/uqac/lif/cornipickle/server/DummyImageMobile.java index 426edfc..d33c84c 100644 --- a/Source/Server/src/ca/uqac/lif/cornipickle/server/DummyImageMobile.java +++ b/Source/Server/src/ca/uqac/lif/cornipickle/server/DummyImageMobile.java @@ -146,7 +146,7 @@ public CallbackResponse process(HttpExchange t) if (j != null) { m_interpreter.evaluateAll(j); - //m_server.setLastProbeContact(); + m_server.setLastProbeContact(); } // System.out.println(j.toString()); // Select the dummy image to send back diff --git a/Source/Server/src/ca/uqac/lif/cornipickle/server/PreEvaluation.java b/Source/Server/src/ca/uqac/lif/cornipickle/server/PreEvaluation.java index 50cb23c..1be0ebb 100644 --- a/Source/Server/src/ca/uqac/lif/cornipickle/server/PreEvaluation.java +++ b/Source/Server/src/ca/uqac/lif/cornipickle/server/PreEvaluation.java @@ -82,7 +82,7 @@ public CallbackResponse process(HttpExchange t) if (j != null) { m_interpreter.evaluateAll(j); - //m_server.setLastProbeContact(); + m_server.setLastProbeContact(); } // Select the dummy image to send back diff --git a/Source/Server/src/ca/uqac/lif/cornipickle/server/StatusPageCallback.java b/Source/Server/src/ca/uqac/lif/cornipickle/server/StatusPageCallback.java index 866bca0..5c42675 100755 --- a/Source/Server/src/ca/uqac/lif/cornipickle/server/StatusPageCallback.java +++ b/Source/Server/src/ca/uqac/lif/cornipickle/server/StatusPageCallback.java @@ -39,195 +39,194 @@ class StatusPageCallback extends InterpreterCallback * queries information about the server's state. */ protected CornipickleServer m_server; - - public StatusPageCallback(Interpreter i, CornipickleServer s) - { - super(i, RequestCallback.Method.GET, "/status"); - m_server = s; - } - - @Override - public CallbackResponse process(HttpExchange t) - { - StringBuilder page = new StringBuilder(); - page.append(pageHead("Cornipickle status")); - page.append("

Cornipickle Status

"); - - // Show last contact with probe - createProbeContactMessage(m_server.getLastProbeContact(), page); - - // Compute verdicts - Map verdicts = m_interpreter.getVerdicts(); - createStatusMessage(verdicts, page); - - //page.append("
\n"); - - // Show properties - page.append("

Properties

\n"); - page.append("

Reset history

\n"); - //page.append("
\n"); - createPropertyList(verdicts, page); - //page.append("
\n"); - page.append("
\n"); - - // Show predicates - page.append("

Predicates

\n"); - //page.append("
\n"); - createPredicateList(m_interpreter.getPredicates(), page); - //page.append("
\n"); - page.append("
\n"); - - // Show sets - page.append("

Sets

\n"); - //page.append("
\n"); - createSetList(m_interpreter.getSetDefinitions(), page); - //page.append("
\n"); - page.append("
\n"); - - //page.append("
\n"); - - // Show box to add new properties - page.append("\n
\n"); - page.append("

Add properties

\n\n"); - page.append("

Type here the Cornipickle properties you want to add.

\n"); - page.append("
\n"); - page.append("
\n"); - page.append("\n"); - page.append("
\n"); - page.append("
\n"); - page.append(pageFoot()); - String page_string = page.toString(); - CallbackResponse out = new CallbackResponse(t, CallbackResponse.HTTP_OK, page_string, CallbackResponse.ContentType.HTML); - out.disableCaching(); - return out; - } - - protected void createSetList(List sets, StringBuilder page) - { - page.append(""); - } - - protected void createPredicateList(List preds, StringBuilder page) - { - page.append("
    \n"); - for (PredicateDefinition pd : preds) - { - page.append("
  • "); - page.append(HtmlFormatter.format(pd)).append("
  • \n"); - } - page.append("
"); - } - - protected static void createProbeContactMessage(Date last_contact, StringBuilder page) - { - // TODO: the refactoring is such that this callback no longer has access to the - // server - if (last_contact == null) - { - page.append("

No contact with probe so far.

\n"); - } - else - { - page.append("

Last contact with probe just now"); - //page.append(last_contact) - page.append("

\n"); - } - } - - protected static void createStatusMessage(Map verdicts, StringBuilder page) - { - int num_errors = 0; - for (StatementMetadata key : verdicts.keySet()) - { - Verdict v = verdicts.get(key); - if (v.is(Verdict.Value.FALSE)) - { - num_errors++; - } - } - if (num_errors == 0) - { - if (verdicts.isEmpty()) - { - page.append("

Cornipickle has no property to evaluate.

"); - } - else - { - page.append("

All's well! All properties evaluate to true.

"); - } - } - else if (num_errors == 1) - { - page.append("

Oops! There is a problem with some property.

"); - } - else - { - page.append("

Oops! There is a problem with ").append(num_errors).append(" properties.

"); - } - } - - protected void createPropertyList(Map verdicts, StringBuilder verdict_string) - { - // Ignore unique ID given by interpreter to each statement - HashSet ignored_attributes = new HashSet(); - ignored_attributes.add("uniqueid"); - verdict_string.append("
    \n"); - for (StatementMetadata key : verdicts.keySet()) - { - Verdict v = verdicts.get(key); - String class_name = "inconclusive"; - if (v.is(Verdict.Value.TRUE)) - { - class_name = "true"; - } - else if (v.is(Verdict.Value.FALSE)) - { - class_name = "false"; - } - verdict_string.append("
  • "); - verdict_string.append("
    ").append(HtmlFormatter.format(key, ignored_attributes)).append("
    \n"); - verdict_string.append("
    \n"); - verdict_string.append(HtmlFormatter.format(m_interpreter.getProperty(key))); - verdict_string.append("
    \n"); - verdict_string.append("
  • "); - } - verdict_string.append("
\n"); - } - - protected StringBuilder pageHead(String title) - { - StringBuilder page = new StringBuilder(); - page.append("\n"); - page.append("\n"); - page.append("\n"); - page.append("").append(title).append("\n"); - page.append("\n"); - page.append("\n"); - page.append("\n"); - page.append("\n"); - page.append("\n"); - page.append("\n"); - page.append("\n"); - //page.append("\n"); - page.append("\n\n"); - return page; - } - - protected StringBuilder pageFoot() - { - StringBuilder page = new StringBuilder(); - page.append("
\n"); - page.append("
\n"); - Date d = new Date(); - page.append(d); - page.append("
\n"); - page.append("\n\n"); - return page; - } + + public StatusPageCallback(Interpreter i, CornipickleServer s) + { + super(i, RequestCallback.Method.GET, "/status"); + m_server = s; + } + + @Override + public CallbackResponse process(HttpExchange t) + { + StringBuilder page = new StringBuilder(); + page.append(pageHead("Cornipickle status")); + page.append("

Cornipickle Status

"); + if (m_server.getLastProbeContact() != null) + page.append(""); + + // Show last contact with probe + createProbeContactMessage(m_server.getLastProbeContact(), page); + + // Compute verdicts + Map verdicts = m_interpreter.getVerdicts(); + createStatusMessage(verdicts, page); + + //page.append("
\n"); + + // Show properties + page.append("

Properties

\n"); + page.append("

Reset history

\n"); + //page.append("
\n"); + createPropertyList(verdicts, page); + //page.append("
\n"); + page.append("
\n"); + + // Show predicates + page.append("

Predicates

\n"); + //page.append("
\n"); + createPredicateList(m_interpreter.getPredicates(), page); + //page.append("
\n"); + page.append("
\n"); + + // Show sets + page.append("

Sets

\n"); + //page.append("
\n"); + createSetList(m_interpreter.getSetDefinitions(), page); + //page.append("
\n"); + page.append("
\n"); + + //page.append("
\n"); + + // Show box to add new properties + page.append("\n
\n"); + page.append("

Add properties

\n\n"); + page.append("

Type here the Cornipickle properties you want to add.

\n"); + page.append("
\n"); + page.append("
\n"); + page.append("\n"); + page.append("
\n"); + page.append("
\n"); + page.append(pageFoot()); + String page_string = page.toString(); + CallbackResponse out = new CallbackResponse(t, CallbackResponse.HTTP_OK, page_string, CallbackResponse.ContentType.HTML); + out.disableCaching(); + return out; + } + + protected void createSetList(List sets, StringBuilder page) + { + page.append("
    \n"); + for (SetDefinition sd : sets) + { + page.append("
  • ").append(HtmlFormatter.format(sd)).append("
  • \n"); + } + page.append("
"); + } + + protected void createPredicateList(List preds, StringBuilder page) + { + page.append("
    \n"); + for (PredicateDefinition pd : preds) + { + page.append("
  • "); + page.append(HtmlFormatter.format(pd)).append("
  • \n"); + } + page.append("
"); + } + + protected void createProbeContactMessage(Date last_contact, StringBuilder page) + { + if (last_contact == null) + { + page.append("

No contact with probe so far.

\n"); + } + else + { + page.append("

Last contact with probe just now"); + page.append("

\n"); + } + } + + protected static void createStatusMessage(Map verdicts, StringBuilder page) + { + int num_errors = 0; + for (StatementMetadata key : verdicts.keySet()) + { + Verdict v = verdicts.get(key); + if (v.is(Verdict.Value.FALSE)) + { + num_errors++; + } + } + if (num_errors == 0) + { + if (verdicts.isEmpty()) + { + page.append("

Cornipickle has no property to evaluate.

"); + } + else + { + page.append("

All's well! All properties evaluate to true.

"); + } + } + else if (num_errors == 1) + { + page.append("

Oops! There is a problem with some property.

"); + } + else + { + page.append("

Oops! There is a problem with ").append(num_errors).append(" properties.

"); + } + } + + protected void createPropertyList(Map verdicts, StringBuilder verdict_string) + { + // Ignore unique ID given by interpreter to each statement + HashSet ignored_attributes = new HashSet(); + ignored_attributes.add("uniqueid"); + verdict_string.append("
    \n"); + for (StatementMetadata key : verdicts.keySet()) + { + Verdict v = verdicts.get(key); + String class_name = "inconclusive"; + if (v.is(Verdict.Value.TRUE)) + { + class_name = "true"; + } + else if (v.is(Verdict.Value.FALSE)) + { + class_name = "false"; + } + verdict_string.append("
  • "); + verdict_string.append("
    ").append(HtmlFormatter.format(key, ignored_attributes)).append("
    \n"); + verdict_string.append("
    \n"); + verdict_string.append(HtmlFormatter.format(m_interpreter.getProperty(key))); + verdict_string.append("
    \n"); + verdict_string.append("
  • "); + } + verdict_string.append("
\n"); + } + + protected StringBuilder pageHead(String title) + { + StringBuilder page = new StringBuilder(); + page.append("\n"); + page.append("\n"); + page.append("\n"); + page.append("").append(title).append("\n"); + page.append("\n"); + page.append("\n"); + page.append("\n"); + page.append("\n"); + page.append("\n"); + page.append("\n"); + page.append("\n"); + //page.append("\n"); + page.append("\n\n"); + return page; + } + + protected StringBuilder pageFoot() + { + StringBuilder page = new StringBuilder(); + page.append("
\n"); + page.append("
\n"); + Date d = new Date(); + page.append(d); + page.append("
\n"); + page.append("\n\n"); + return page; + } } \ No newline at end of file diff --git a/Source/Server/src/ca/uqac/lif/cornipickle/server/resource/highlight.js b/Source/Server/src/ca/uqac/lif/cornipickle/server/resource/highlight.js index b8bb647..a58b6f7 100644 --- a/Source/Server/src/ca/uqac/lif/cornipickle/server/resource/highlight.js +++ b/Source/Server/src/ca/uqac/lif/cornipickle/server/resource/highlight.js @@ -17,7 +17,7 @@ highlight_predicate = function(predicate_name) time_since = function(ts) { now = new Date(); - //ts = new Date(ts*1000); + ts = new Date(ts*1000); var delta = now.getTime() - ts.getTime(); delta = delta/1000; //us to s var ps, pm, ph, pd, min, hou, sec, days; diff --git a/Source/ServerTest/src/ca/uqac/lif/cornipickle/server/StatusPageCallbackTest.java b/Source/ServerTest/src/ca/uqac/lif/cornipickle/server/StatusPageCallbackTest.java index 1776cb7..2a7b58b 100644 --- a/Source/ServerTest/src/ca/uqac/lif/cornipickle/server/StatusPageCallbackTest.java +++ b/Source/ServerTest/src/ca/uqac/lif/cornipickle/server/StatusPageCallbackTest.java @@ -144,36 +144,6 @@ public void testStatusPageCallbackTestCreatePredicateList(){ }*/ - - @Test - public void TestStatusPageCallbackCreateProbeContactMessageNull(){ - - - - StringBuilder result = new StringBuilder(); - - StatusPageCallback.createProbeContactMessage(null, result); - - String expected = "

No contact with probe so far.

\n"; - - assertTrue(expected.equals(result.toString())); - - } - - - @Test - public void TestStatusPageCallbackCreateProbeContactMessageOk(){ - - StringBuilder result = new StringBuilder(); - - StatusPageCallback.createProbeContactMessage(new Date(), result); - - String expected = "

Last contact with probe just now

\n"; - - assertTrue(expected.equals(result.toString())); - - } - @Test public void TestStatusPageCallBackFooter(){