-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from NationalSecurityAgency/t#56/grading_and_g…
…roups T#56/grading and groups
- Loading branch information
Showing
6 changed files
with
149 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,8 @@ void load() throws Exception { | |
} | ||
|
||
createQuizzesAndSurveys(rest); | ||
|
||
createAdminGroups(rest); | ||
} | ||
|
||
private void createQuizzesAndSurveys(RestTemplate rest) { | ||
|
@@ -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())); | ||
|
@@ -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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...end-example/src/main/java/skills/examples/data/serviceRequestModel/AdminGroupRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters