From ddf0a4bd5961b88ec510b5da5f6051e165956257 Mon Sep 17 00:00:00 2001 From: Dima May Date: Tue, 19 Nov 2024 18:58:08 +0000 Subject: [PATCH 1/4] #56: Enhance data to support quiz grading and admin groups --- .../data/InitSkillServiceWithData.java | 50 ++++++++++++++---- .../skills/examples/data/model/Question.java | 14 ++++- .../java/skills/examples/data/model/Quiz.java | 3 ++ .../AdminGroupRequest.java | 51 +++++++++++++++++++ .../src/main/resources/quiz.json | 28 ++++++++++ 5 files changed, 134 insertions(+), 12 deletions(-) create mode 100644 java-backend-example/src/main/java/skills/examples/data/serviceRequestModel/AdminGroupRequest.java diff --git a/java-backend-example/src/main/java/skills/examples/data/InitSkillServiceWithData.java b/java-backend-example/src/main/java/skills/examples/data/InitSkillServiceWithData.java index 991933c..abc55a4 100644 --- a/java-backend-example/src/main/java/skills/examples/data/InitSkillServiceWithData.java +++ b/java-backend-example/src/main/java/skills/examples/data/InitSkillServiceWithData.java @@ -118,6 +118,8 @@ void load() throws Exception { } createQuizzesAndSurveys(rest); + + createAdminGroups(rest); } private void createQuizzesAndSurveys(RestTemplate rest) { @@ -219,7 +221,11 @@ private List loadQuizzes(RestTemplate rest) { String questionUrl = serviceUrl + "/admin/quiz-definitions/" + quizId + "/create-question"; QuizQuestionDefRequest questionDefRequest = new QuizQuestionDefRequest(); questionDefRequest.setQuestion(setDescPrefix(q.getQuestion())); - questionDefRequest.setQuestionType("SingleChoice"); + if (q.getQuestionType() != null) { + questionDefRequest.setQuestionType(q.getQuestionType()); + } else { + questionDefRequest.setQuestionType("SingleChoice"); + } List answers = new ArrayList<>(); for (Answer a : q.getAnswers()){ answers.add(new QuizAnswerDefRequest(setDescPrefix(a.getText()), a.isCorrect())); @@ -287,23 +293,45 @@ private void achieveQuizForUser(RestTemplate adminUserRest, String userId, Strin int index = 0; for (QuizQuestionInfoResponse question : quizInfoResponse.getQuestions()) { index++; - boolean failIfPassNotTrue = index % 2 == 0; - if (pass || !failIfPassNotTrue) { - List correctAnswers = question.getAnswers() - .stream().filter(answer -> answer.getIsCorrect()).collect(Collectors.toList()); - for (QuizAnswerOptionsInfoResponse correctAnswer : correctAnswers) { - post(thisUserRest, skillsConfig.getServiceUrl() + "/api/quizzes/" + quizId + "/attempt/" + quizAttemptStartResult.getId() + "/answers/" + correctAnswer.getId(), new QuizReportAnswerReq()); - } + + if (question.getQuestionType().equalsIgnoreCase("TextInput")) { + String answerText = "-Develop your pieces\n-Control Center\n-Castle"; + post(thisUserRest, skillsConfig.getServiceUrl() + "/api/quizzes/" + quizId + "/attempt/" + quizAttemptStartResult.getId() + "/answers/" + question.getAnswers().get(0).getId(), new QuizReportAnswerReq(answerText)); } else { - List wrongAnswers = question.getAnswers() - .stream().filter(answer -> !answer.getIsCorrect()).collect(Collectors.toList()); - post(thisUserRest, skillsConfig.getServiceUrl() + "/api/quizzes/" + quizId + "/attempt/" + quizAttemptStartResult.getId() + "/answers/" + wrongAnswers.get(0).getId(), new QuizReportAnswerReq()); + boolean failIfPassNotTrue = index % 2 == 0; + if (pass || !failIfPassNotTrue) { + List correctAnswers = question.getAnswers() + .stream().filter(answer -> answer.getIsCorrect()).collect(Collectors.toList()); + for (QuizAnswerOptionsInfoResponse correctAnswer : correctAnswers) { + post(thisUserRest, skillsConfig.getServiceUrl() + "/api/quizzes/" + quizId + "/attempt/" + quizAttemptStartResult.getId() + "/answers/" + correctAnswer.getId(), new QuizReportAnswerReq()); + } + } else { + List wrongAnswers = question.getAnswers() + .stream().filter(answer -> !answer.getIsCorrect()).collect(Collectors.toList()); + post(thisUserRest, skillsConfig.getServiceUrl() + "/api/quizzes/" + quizId + "/attempt/" + quizAttemptStartResult.getId() + "/answers/" + wrongAnswers.get(0).getId(), new QuizReportAnswerReq()); + } } } post(thisUserRest, skillsConfig.getServiceUrl() + "/api/quizzes/" + quizId + "/attempt/" + quizAttemptStartResult.getId() + "/complete"); } + private void createAdminGroups(RestTemplate adminUserRest) { + post(adminUserRest, skillsConfig.getServiceUrl() + "/app/admin-group-definitions/FancyGroup", + new AdminGroupRequest("FancyGroup", "Fancy Group")); + List groupMembers = Arrays.asList("groupUser1@email.org", "groupUser2@email.org"); + for (String userId: groupMembers) { + createUser(skillsConfig.getServiceUrl() + "/createAccount", userId); + post(adminUserRest, skillsConfig.getServiceUrl() + "/admin/admin-group-definitions/FancyGroup/users/" + userId + "/roles/ROLE_ADMIN_GROUP_MEMBER"); + } + + post(adminUserRest, skillsConfig.getServiceUrl() + "/admin/admin-group-definitions/FancyGroup/projects/shows"); + post(adminUserRest, skillsConfig.getServiceUrl() + "/admin/admin-group-definitions/FancyGroup/projects/movies"); + post(adminUserRest, skillsConfig.getServiceUrl() + "/admin/admin-group-definitions/FancyGroup/quizzes/ChessInsight"); + post(adminUserRest, skillsConfig.getServiceUrl() + "/admin/admin-group-definitions/FancyGroup/quizzes/TriviaChallenge1"); + post(adminUserRest, skillsConfig.getServiceUrl() + "/admin/admin-group-definitions/FancyGroup/quizzes/TriviaChallenge3"); + } + private T parseStrRes(String res, Class expectedClass) { try { return jsonMapper.readValue(res, expectedClass); diff --git a/java-backend-example/src/main/java/skills/examples/data/model/Question.java b/java-backend-example/src/main/java/skills/examples/data/model/Question.java index 4f4123e..cce7f32 100644 --- a/java-backend-example/src/main/java/skills/examples/data/model/Question.java +++ b/java-backend-example/src/main/java/skills/examples/data/model/Question.java @@ -15,11 +15,14 @@ */ package skills.examples.data.model; +import com.fasterxml.jackson.annotation.JsonInclude; + import java.util.List; +@JsonInclude(JsonInclude.Include.NON_NULL) public class Question { private String question; - + private String questionType; private List answers; public String getQuestion() { @@ -38,10 +41,19 @@ public void setAnswers(List answers) { this.answers = answers; } + public String getQuestionType() { + return questionType; + } + + public void setQuestionType(String questionType) { + this.questionType = questionType; + } + @Override public String toString() { return "Question{" + "question='" + question + '\'' + + ", questionType='" + questionType + '\'' + ", answers=" + answers + '}'; } diff --git a/java-backend-example/src/main/java/skills/examples/data/model/Quiz.java b/java-backend-example/src/main/java/skills/examples/data/model/Quiz.java index 5edbb00..84995d7 100644 --- a/java-backend-example/src/main/java/skills/examples/data/model/Quiz.java +++ b/java-backend-example/src/main/java/skills/examples/data/model/Quiz.java @@ -15,8 +15,11 @@ */ package skills.examples.data.model; +import com.fasterxml.jackson.annotation.JsonInclude; + import java.util.List; +@JsonInclude(JsonInclude.Include.NON_NULL) public class Quiz { private String quizName; private String description; diff --git a/java-backend-example/src/main/java/skills/examples/data/serviceRequestModel/AdminGroupRequest.java b/java-backend-example/src/main/java/skills/examples/data/serviceRequestModel/AdminGroupRequest.java new file mode 100644 index 0000000..dbc89b0 --- /dev/null +++ b/java-backend-example/src/main/java/skills/examples/data/serviceRequestModel/AdminGroupRequest.java @@ -0,0 +1,51 @@ +/** + * Copyright 2020 SkillTree + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package skills.examples.data.serviceRequestModel; + +public class AdminGroupRequest { + private String adminGroupId; + private String name; + private Boolean enableProtectedUserCommunity = false; + + public AdminGroupRequest(String groupId, String name) { + this.name = name; + this.adminGroupId = groupId; + } + + public String getAdminGroupId() { + return adminGroupId; + } + + public void setAdminGroupId(String adminGroupId) { + this.adminGroupId = adminGroupId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Boolean getEnableProtectedUserCommunity() { + return enableProtectedUserCommunity; + } + + public void setEnableProtectedUserCommunity(Boolean enableProtectedUserCommunity) { + this.enableProtectedUserCommunity = enableProtectedUserCommunity; + } +} diff --git a/java-backend-example/src/main/resources/quiz.json b/java-backend-example/src/main/resources/quiz.json index 6e5d768..333228b 100644 --- a/java-backend-example/src/main/resources/quiz.json +++ b/java-backend-example/src/main/resources/quiz.json @@ -564,5 +564,33 @@ ] } ] + }, + { + "quizName": "Chess Insight", + "description": "Chess questions demonstrating how `Input Text` question type works", + "questions": [ + { + "question": "Please describe 3 basic goals during the chess opening?", + "questionType": "TextInput", + "answers": [] + }, + { + "question": "What is the overall goal of a chess game?", + "answers": [ + { + "text": "Stalemate", + "correct": false + }, + { + "text": "Checkmate", + "correct": true + }, + { + "text": "En passant", + "correct": false + } + ] + } + ] } ] \ No newline at end of file From a8f46f7008266eb2ced68e81db38051760e30e85 Mon Sep 17 00:00:00 2001 From: Dima May Date: Tue, 19 Nov 2024 19:07:43 +0000 Subject: [PATCH 2/4] #56: Enhance data to support quiz grading and admin groups --- .../java/skills/examples/data/InitSkillServiceWithData.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-backend-example/src/main/java/skills/examples/data/InitSkillServiceWithData.java b/java-backend-example/src/main/java/skills/examples/data/InitSkillServiceWithData.java index abc55a4..d9608cd 100644 --- a/java-backend-example/src/main/java/skills/examples/data/InitSkillServiceWithData.java +++ b/java-backend-example/src/main/java/skills/examples/data/InitSkillServiceWithData.java @@ -319,7 +319,7 @@ private void achieveQuizForUser(RestTemplate adminUserRest, String userId, Strin private void createAdminGroups(RestTemplate adminUserRest) { post(adminUserRest, skillsConfig.getServiceUrl() + "/app/admin-group-definitions/FancyGroup", new AdminGroupRequest("FancyGroup", "Fancy Group")); - List groupMembers = Arrays.asList("groupUser1@email.org", "groupUser2@email.org"); + List groupMembers = Arrays.asList("user5@email.com", "user6@email.org"); for (String userId: groupMembers) { createUser(skillsConfig.getServiceUrl() + "/createAccount", userId); post(adminUserRest, skillsConfig.getServiceUrl() + "/admin/admin-group-definitions/FancyGroup/users/" + userId + "/roles/ROLE_ADMIN_GROUP_MEMBER"); From 0c727fde4495358bcfc0fc092beec53ce2fa07a7 Mon Sep 17 00:00:00 2001 From: Dima May Date: Tue, 19 Nov 2024 19:22:09 +0000 Subject: [PATCH 3/4] #56: upgrade github action versions --- .github/workflows/build-and-test.yml | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 41a4357..bf9a489 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -50,14 +50,15 @@ jobs: - 5432:5432 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: actions/setup-node@v2-beta + - uses: actions/setup-node@v4 with: - node-version: '12' + node-version: '20.17.0' - - uses: actions/setup-java@v1 + - uses: actions/setup-java@v4 with: + distribution: 'temurin' java-version: '19' # The JDK version to make available on the path. - name: Print Versions @@ -66,7 +67,7 @@ jobs: java -version - name: Cache local Maven repository - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} @@ -133,15 +134,16 @@ jobs: - 5432:5432 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: actions/setup-node@v2-beta + - uses: actions/setup-node@v4 with: - node-version: '12' + node-version: '20.17.0' - - uses: actions/setup-java@v1 + - uses: actions/setup-java@v4 with: - java-version: '11.X.X' # The JDK version to make available on the path. + distribution: 'temurin' + java-version: '19' # The JDK version to make available on the path. - name: Print Versions run: | From 8cae4e949561a1469dcd3b8746f2ab56317e1bbc Mon Sep 17 00:00:00 2001 From: Dima May Date: Tue, 19 Nov 2024 19:25:15 +0000 Subject: [PATCH 4/4] #56: upgrade github action versions --- .github/workflows/build-and-test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index bf9a489..562e83c 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -103,7 +103,7 @@ jobs: - name: upload result artifacts if: ${{ always() }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: result artifacts - with jar path: | @@ -151,7 +151,7 @@ jobs: java -version - name: Cache local Maven repository - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} @@ -191,7 +191,7 @@ jobs: - name: upload result artifacts if: ${{ always() }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: result artifacts - with docker path: |