From 7f94968bb9a9bf0095b84e22028ce57b8300c216 Mon Sep 17 00:00:00 2001 From: Riccardo De Benedictis Date: Mon, 25 Jun 2018 18:52:27 +0200 Subject: [PATCH] solved back-end issue with going back in time and not deleting consequences of taken actions.. --- .../cnr/istc/lecture/webapp/LECTurEBean.java | 53 ++++++++++--------- .../lecture/webapp/solver/LessonManager.java | 4 +- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/LECTurE-WebApp/src/main/java/it/cnr/istc/lecture/webapp/LECTurEBean.java b/LECTurE-WebApp/src/main/java/it/cnr/istc/lecture/webapp/LECTurEBean.java index 5fd353a..334a037 100644 --- a/LECTurE-WebApp/src/main/java/it/cnr/istc/lecture/webapp/LECTurEBean.java +++ b/LECTurE-WebApp/src/main/java/it/cnr/istc/lecture/webapp/LECTurEBean.java @@ -37,6 +37,7 @@ import it.cnr.istc.lecture.api.messages.Token; import it.cnr.istc.lecture.api.messages.TokenUpdate; import it.cnr.istc.lecture.api.messages.URLEvent; +import it.cnr.istc.lecture.api.model.EventTemplate; import it.cnr.istc.lecture.api.model.LessonModel; import it.cnr.istc.lecture.api.model.QuestionEventTemplate; import it.cnr.istc.lecture.api.model.TextEventTemplate; @@ -362,31 +363,33 @@ public void movedToken(SolverToken tk) { @Override public void executeToken(SolverToken tk) { - String tk_json = null; - switch (tk.template.type) { - case TextEventTemplate: - TextEvent te = new TextEvent(lesson.id, tk.tp, tk.template.role, System.currentTimeMillis(), ((TextEventTemplate) tk.template).content); - lesson.events.add(te); - tk_json = JSONB.toJson(te); - break; - case URLEventTemplate: - URLEvent ue = new URLEvent(lesson.id, tk.tp, tk.template.role, System.currentTimeMillis(), ((URLEventTemplate) tk.template).content, ((URLEventTemplate) tk.template).url); - lesson.events.add(ue); - tk_json = JSONB.toJson(ue); - break; - case QuestionEventTemplate: - QuestionEvent qe = new QuestionEvent(lesson.id, tk.tp, tk.template.role, System.currentTimeMillis(), ((QuestionEventTemplate) tk.template).question, ((QuestionEventTemplate) tk.template).answers.stream().map(ans -> ans.answer).collect(Collectors.toList()), null); - lesson.events.add(qe); - tk_json = JSONB.toJson(qe); - break; - default: - throw new AssertionError(tk.template.type.name()); - } - try { - // we notify the student associated to the token's role that a token has to be executed.. - mqtt.publish(lesson.roles.get(tk.template.role) + "/input", tk_json.getBytes(), 1, false); - } catch (MqttException ex) { - LOG.log(Level.SEVERE, null, ex); + if (tk.template.type != EventTemplate.EventTemplateType.EventTemplate) { + String tk_json = null; + switch (tk.template.type) { + case TextEventTemplate: + TextEvent te = new TextEvent(lesson.id, tk.tp, tk.template.role, System.currentTimeMillis(), ((TextEventTemplate) tk.template).content); + lesson.events.add(te); + tk_json = JSONB.toJson(te); + break; + case URLEventTemplate: + URLEvent ue = new URLEvent(lesson.id, tk.tp, tk.template.role, System.currentTimeMillis(), ((URLEventTemplate) tk.template).content, ((URLEventTemplate) tk.template).url); + lesson.events.add(ue); + tk_json = JSONB.toJson(ue); + break; + case QuestionEventTemplate: + QuestionEvent qe = new QuestionEvent(lesson.id, tk.tp, tk.template.role, System.currentTimeMillis(), ((QuestionEventTemplate) tk.template).question, ((QuestionEventTemplate) tk.template).answers.stream().map(ans -> ans.answer).collect(Collectors.toList()), null); + lesson.events.add(qe); + tk_json = JSONB.toJson(qe); + break; + default: + throw new AssertionError(tk.template.type.name()); + } + try { + // we notify the student associated to the token's role that a token has to be executed.. + mqtt.publish(lesson.roles.get(tk.template.role) + "/input", tk_json.getBytes(), 1, false); + } catch (MqttException ex) { + LOG.log(Level.SEVERE, null, ex); + } } } diff --git a/LECTurE-WebApp/src/main/java/it/cnr/istc/lecture/webapp/solver/LessonManager.java b/LECTurE-WebApp/src/main/java/it/cnr/istc/lecture/webapp/solver/LessonManager.java index 5f00e8b..7183948 100644 --- a/LECTurE-WebApp/src/main/java/it/cnr/istc/lecture/webapp/solver/LessonManager.java +++ b/LECTurE-WebApp/src/main/java/it/cnr/istc/lecture/webapp/solver/LessonManager.java @@ -173,9 +173,7 @@ private void extract_timeline() { tks = new ArrayList<>(); at.put(pulse, tks); } - if (tk.template.type != EventTemplate.EventTemplateType.EventTemplate) { - tks.add(tk); - } + tks.add(tk); }); Long[] c_arr_pulses = c_pulses.toArray(new Long[c_pulses.size()]); Arrays.sort(c_arr_pulses);