private String getResponseSummary(Response response) { String responseSummary; if (response.getContent() == null) { responseSummary = null; } else { responseSummary = response.getContent().renderAsText(); if (responseSummary.length() > 128) { responseSummary = new NekoHTMLFilter().filter(responseSummary); if (responseSummary.length() > 128) { responseSummary = responseSummary.substring(0, 125) + "..."; } } } return StringHelper.containsNonWhitespace(responseSummary) ? responseSummary : null; }
private void setKPrimCorrectResponses(List<Response> responses, FormLayoutContainer layoutCont) { List<ResponseAndPoints> responsesPoints = new ArrayList<>(); if (responses != null && responses.size() > 0) { for (Response response : responses) { String responseSummary = getResponseSummary(response); if (responseSummary != null) { boolean correct = response.isCorrect(); String points = Float.toString(response.getPoints()); ResponseAndPoints responseInfos = new ResponseAndPoints(responseSummary, points, correct); responsesPoints.add(responseInfos); } } } layoutCont.contextPut("kprimResponsesAndPoints", responsesPoints); }
private void setMCAndSCCorrectResponses( Question question, List<Response> responses, FormLayoutContainer layoutCont) { List<String> correctResponseNames = new ArrayList<>(); List<ResponseAndPoints> responsesPoints = new ArrayList<>(); if (responses != null && responses.size() > 0) { if (question.isSingleCorrect()) { for (Response response : responses) { if (response.isCorrect()) { String responseSummary = getResponseSummary(response); if (responseSummary != null) { correctResponseNames.add(responseSummary); } } } } else { boolean hasNegative = false; for (Response response : responses) { if (response.getPoints() < 0.0f) { hasNegative = true; } } for (Response response : responses) { String responseSummary = getResponseSummary(response); if (responseSummary != null && ((hasNegative && response.getPoints() >= 0.0f) || (!hasNegative && response.getPoints() > 0.0f))) { boolean correct = response.getPoints() > 0.0f; String points = Float.toString(response.getPoints()); ResponseAndPoints responseInfos = new ResponseAndPoints(responseSummary, points, correct); responsesPoints.add(responseInfos); } } } } layoutCont.contextPut("responses", correctResponseNames); layoutCont.contextPut("responsesAndPoints", responsesPoints); }