Index: lams_common/src/java/org/lamsfoundation/lams/etherpad/service/EtherpadService.java =================================================================== diff -u -rffc3401f0b164d7bc2aff097a633e22bef241874 -r6e27c5c2349b310d7259708c2b49314c91c01605 --- lams_common/src/java/org/lamsfoundation/lams/etherpad/service/EtherpadService.java (.../EtherpadService.java) (revision ffc3401f0b164d7bc2aff097a633e22bef241874) +++ lams_common/src/java/org/lamsfoundation/lams/etherpad/service/EtherpadService.java (.../EtherpadService.java) (revision 6e27c5c2349b310d7259708c2b49314c91c01605) @@ -69,6 +69,16 @@ } @Override + public String getPadText(String padId) throws EtherpadException { + EPLiteClient client = getClient(); + Map response = client.getText(padId); + if (response == null) { + return null; + } + return response.get("text"); + } + + @Override public EPLiteClient getClient() throws EtherpadException { // get the API key from the configuration and create EPLiteClient using it String etherpadServerUrl = Configuration.get(ConfigurationKeys.ETHERPAD_SERVER_URL); @@ -107,7 +117,7 @@ if (!topLevelDomain.equals("localhost")) { cookieHeaderValue.append("Domain=").append(topLevelDomain).append("; "); } - + cookieHeaderValue.append("Secure; SameSite=None"); response.setHeader("Set-Cookie", cookieHeaderValue.toString()); @@ -146,8 +156,8 @@ String etherpadSessionId = null; Set otherEtherpadSessionIds = new HashSet<>(); for (String etherpadSessionIdIter : etherpadSessions.keySet()) { - Map sessessionAttributes = (Map) etherpadSessions - .get(etherpadSessionIdIter); + Map sessessionAttributes = (Map) etherpadSessions.get( + etherpadSessionIdIter); String groupIdIter = (String) sessessionAttributes.get("groupID"); boolean isTargetGroup = groupIdIter.equals(etherpadGroupId); if (includeAllGroups || isTargetGroup) { Index: lams_common/src/java/org/lamsfoundation/lams/etherpad/service/IEtherpadService.java =================================================================== diff -u -rc364f48d3f1a5d354f6fce9a3063a8f6963e7a62 -r6e27c5c2349b310d7259708c2b49314c91c01605 --- lams_common/src/java/org/lamsfoundation/lams/etherpad/service/IEtherpadService.java (.../IEtherpadService.java) (revision c364f48d3f1a5d354f6fce9a3063a8f6963e7a62) +++ lams_common/src/java/org/lamsfoundation/lams/etherpad/service/IEtherpadService.java (.../IEtherpadService.java) (revision 6e27c5c2349b310d7259708c2b49314c91c01605) @@ -18,22 +18,26 @@ * Creates EPLiteClient that will make calls to Etherpad server * * @throws EtherpadException - * if the Etherpad is not configured appropriately (either server URL or API key). + * if the Etherpad is not configured appropriately (either server URL or API key). */ EPLiteClient getClient() throws EtherpadException; /** * Using API client creates/fetches Etherpad Pad. * * @param groupIdentifier - * LAMS-specific group ID (just any identifier); do not confuse with Etherpad groupId, readOnlyId or - * padId + * LAMS-specific group ID (just any identifier); do not confuse with Etherpad groupId, readOnlyId or padId * @param content - * initial content of Etherpad; ignored if null or Etherpad already exists + * initial content of Etherpad; ignored if null or Etherpad already exists */ Map createPad(String groupIdentifier, String content) throws EtherpadException; /** + * Using API client fetches Pad text + */ + String getPadText(String padId) throws EtherpadException; + + /** * Constructs cookie to be stored at a client side browser. */ void createCookie(String etherpadSessionIds, HttpServletResponse response) throws EtherpadException; Index: lams_tool_doku/conf/language/lams/ApplicationResources.properties =================================================================== diff -u -r4c8a81c2d65a0fd8be399d6e7e13935b7e796401 -r6e27c5c2349b310d7259708c2b49314c91c01605 --- lams_tool_doku/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 4c8a81c2d65a0fd8be399d6e7e13935b7e796401) +++ lams_tool_doku/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 6e27c5c2349b310d7259708c2b49314c91c01605) @@ -181,4 +181,5 @@ label.minimum.number.words = Minimum number of words in a comment {0} label.monitoring.ai.review = AI review label.monitoring.ai.review.all = AI review all -label.monitoring.ai.review.tooltip = Have AI compare the given task and students' submissions. \ No newline at end of file +label.monitoring.ai.review.tooltip = Have AI compare the given task and students' submissions. +label.monitoring.ai.review.error = Error while requesting AI review \ No newline at end of file Index: lams_tool_doku/src/java/org/lamsfoundation/lams/tool/dokumaran/service/DokumaranService.java =================================================================== diff -u -r0356b71a54403d2a4f45a3b90e5fab4fc3c11dd7 -r6e27c5c2349b310d7259708c2b49314c91c01605 --- lams_tool_doku/src/java/org/lamsfoundation/lams/tool/dokumaran/service/DokumaranService.java (.../DokumaranService.java) (revision 0356b71a54403d2a4f45a3b90e5fab4fc3c11dd7) +++ lams_tool_doku/src/java/org/lamsfoundation/lams/tool/dokumaran/service/DokumaranService.java (.../DokumaranService.java) (revision 6e27c5c2349b310d7259708c2b49314c91c01605) @@ -1098,6 +1098,16 @@ etherpadService.createCookie(etherpadSessionIds, response); } + @Override + public String getPadText(long toolSessionId) throws EtherpadException { + DokumaranSession session = dokumaranSessionDao.getSessionBySessionId(toolSessionId); + if (session == null) { + return null; + } + String padId = EtherpadUtil.getPadId(session.getEtherpadGroupId()); + return etherpadService.getPadText(padId); + } + private ObjectNode getTimeLimitSettingsJson(long toolContentId) { ObjectNode timeLimitSettings = JsonNodeFactory.instance.objectNode(); Dokumaran dokumaran = getDokumaranByContentId(toolContentId); Index: lams_tool_doku/src/java/org/lamsfoundation/lams/tool/dokumaran/service/IDokumaranService.java =================================================================== diff -u -r52a6369ce66a2ea70d38bfa2e627dfcde6354b10 -r6e27c5c2349b310d7259708c2b49314c91c01605 --- lams_tool_doku/src/java/org/lamsfoundation/lams/tool/dokumaran/service/IDokumaranService.java (.../IDokumaranService.java) (revision 52a6369ce66a2ea70d38bfa2e627dfcde6354b10) +++ lams_tool_doku/src/java/org/lamsfoundation/lams/tool/dokumaran/service/IDokumaranService.java (.../IDokumaranService.java) (revision 6e27c5c2349b310d7259708c2b49314c91c01605) @@ -129,6 +129,9 @@ */ void createPad(Dokumaran dokumaran, DokumaranSession session) throws DokumaranApplicationException; + // fetches pad content from Etherpad server side + String getPadText(long toolSessionId) throws EtherpadException; + // ********** for user methods ************* /** Index: lams_tool_doku/src/java/org/lamsfoundation/lams/tool/dokumaran/web/controller/MonitoringController.java =================================================================== diff -u -r4c8a81c2d65a0fd8be399d6e7e13935b7e796401 -r6e27c5c2349b310d7259708c2b49314c91c01605 --- lams_tool_doku/src/java/org/lamsfoundation/lams/tool/dokumaran/web/controller/MonitoringController.java (.../MonitoringController.java) (revision 4c8a81c2d65a0fd8be399d6e7e13935b7e796401) +++ lams_tool_doku/src/java/org/lamsfoundation/lams/tool/dokumaran/web/controller/MonitoringController.java (.../MonitoringController.java) (revision 6e27c5c2349b310d7259708c2b49314c91c01605) @@ -103,6 +103,9 @@ public static final int LEARNER_MARKS_SORTING_LAST_NAME_ASC = 2; public static final int LEARNER_MARKS_SORTING_LAST_NAME_DESC = 3; + private static final String AI_REVIEW_TEMPLATE_INSTRUCTIONS = "The instructions are:"; + private static final String AI_REVIEW_TEMPLATE_DESCRIPTION = "The essay they are writing should address the following:"; + private static final Comparator USER_NAME_COMPARATOR = Comparator.comparing(User::getFirstName) .thenComparing(User::getLastName).thenComparing(User::getLogin); @@ -576,6 +579,38 @@ return formattedDate; } + @RequestMapping(path = "/aiReview", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) + @ResponseBody + public String aiReview(@RequestParam Long toolSessionId) { + boolean isAiEnabled = Configuration.isLamsModuleAvailable(Configuration.AI_MODULE_CLASS); + if (!isAiEnabled) { + throw new UnsupportedOperationException("AI module is not enabled"); + } + DokumaranSession session = dokumaranService.getDokumaranSessionBySessionId(toolSessionId); + Dokumaran dokumaran = session.getDokumaran(); + ObjectNode responseJSON = JsonNodeFactory.instance.objectNode(); + if (StringUtils.isNotBlank(dokumaran.getInstructions())) { + responseJSON.put("instructions", + new StringBuilder("\n").append(AI_REVIEW_TEMPLATE_INSTRUCTIONS).append("\n") + .append(dokumaran.getInstructions()).append("\n\n").toString()); + } + if (StringUtils.isNotBlank(dokumaran.getDescription())) { + responseJSON.put("description", + new StringBuilder("\n").append(AI_REVIEW_TEMPLATE_DESCRIPTION).append("\n").append(dokumaran.getDescription()) + .append("\n\n").toString()); + } + try { + String padContent = dokumaranService.getPadText(toolSessionId); + if (StringUtils.isNotBlank(padContent)) { + responseJSON.put("content", "\n" + padContent); + } + } catch (EtherpadException e) { + log.error("Failed to get pad content for session " + toolSessionId, e); + return null; + } + return responseJSON.toString(); + } + private Integer getUserId() { HttpSession ss = SessionManager.getSession(); UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); Index: lams_tool_doku/web/pages/monitoring/summary.jsp =================================================================== diff -u -r4c8a81c2d65a0fd8be399d6e7e13935b7e796401 -r6e27c5c2349b310d7259708c2b49314c91c01605 --- lams_tool_doku/web/pages/monitoring/summary.jsp (.../summary.jsp) (revision 4c8a81c2d65a0fd8be399d6e7e13935b7e796401) +++ lams_tool_doku/web/pages/monitoring/summary.jsp (.../summary.jsp) (revision 6e27c5c2349b310d7259708c2b49314c91c01605) @@ -113,6 +113,13 @@ .doku-monitoring-summary .marks-container .marks-header { line-height: 1.7; } + + .doku-monitoring-summary .ai-review-content { + padding: 1rem; + margin: 1rem; + border: 1px #EEEEEE solid; + border-radius: 5px; + }