Skip to content

Commit

Permalink
Merge pull request #57 from NationalSecurityAgency/t#56/grading_and_g…
Browse files Browse the repository at this point in the history
…roups

T#56/grading and groups
  • Loading branch information
rmmayo authored Nov 20, 2024
2 parents 744d3ab + 8cae4e9 commit 8fb89ee
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 25 deletions.
28 changes: 15 additions & 13 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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') }}
Expand Down Expand Up @@ -102,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: |
Expand Down Expand Up @@ -133,23 +134,24 @@ 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: |
mvn --version
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') }}
Expand Down Expand Up @@ -189,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: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ void load() throws Exception {
}

createQuizzesAndSurveys(rest);

createAdminGroups(rest);
}

private void createQuizzesAndSurveys(RestTemplate rest) {
Expand Down Expand Up @@ -219,7 +221,11 @@ private List<String> 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<QuizAnswerDefRequest> answers = new ArrayList<>();
for (Answer a : q.getAnswers()){
answers.add(new QuizAnswerDefRequest(setDescPrefix(a.getText()), a.isCorrect()));
Expand Down Expand Up @@ -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<QuizAnswerOptionsInfoResponse> 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<QuizAnswerOptionsInfoResponse> 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<QuizAnswerOptionsInfoResponse> 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<QuizAnswerOptionsInfoResponse> 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<String> groupMembers = Arrays.asList("[email protected]", "[email protected]");
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> T parseStrRes(String res, Class<T> expectedClass) {
try {
return jsonMapper.readValue(res, expectedClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Answer> answers;

public String getQuestion() {
Expand All @@ -38,10 +41,19 @@ public void setAnswers(List<Answer> 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 +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
28 changes: 28 additions & 0 deletions java-backend-example/src/main/resources/quiz.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
]
}
]

0 comments on commit 8fb89ee

Please sign in to comment.