use of uk.ac.cam.cl.dtg.isaac.dto.UserGroupDTO in project isaac-api by isaacphysics.
the class IsaacTest method initializeIsaacObjects.
protected void initializeIsaacObjects() {
long id = 0L;
studentQuizSummary = new QuizSummaryDTO();
teacherQuizSummary = new QuizSummaryDTO();
questionPageQuestion = new IsaacQuestionBaseDTO();
questionPageQuestion.setId("questionPage|question1");
questionPageQuestionDO = new IsaacQuestionBase();
questionPageQuestionDO.setId(questionPageQuestion.getId());
question = new IsaacQuestionBaseDTO();
question.setId("studentQuiz|section1|question1");
question2 = new IsaacQuestionBaseDTO();
question2.setId("studentQuiz|section2|question2");
question3 = new IsaacQuestionBaseDTO();
question3.setId("studentQuiz|section2|question3");
questionDO = new IsaacQuestionBase();
questionDO.setId(question.getId());
quizSection1 = new IsaacQuizSectionDTO();
quizSection1.setId("studentQuiz|section1");
quizSection1.setChildren(Collections.singletonList(question));
quizSection2 = new IsaacQuizSectionDTO();
quizSection2.setId("studentQuiz|section2");
quizSection2.setChildren(ImmutableList.of(question2, question3));
studentQuiz = new IsaacQuizDTO("studentQuiz", null, null, null, null, null, null, null, ImmutableList.of(quizSection1, quizSection2), null, null, null, false, null, null, null, true, null, QuizFeedbackMode.OVERALL_MARK, null);
teacherQuiz = new IsaacQuizDTO("teacherQuiz", null, null, null, null, null, null, null, null, null, null, null, false, null, null, null, false, ImmutableList.of("STUDENT"), null, null);
otherQuiz = new IsaacQuizDTO("otherQuiz", null, null, null, null, null, null, null, Collections.singletonList(quizSection1), null, null, null, false, null, null, null, true, null, QuizFeedbackMode.DETAILED_FEEDBACK, null);
// A bit scrappy, but hopefully sufficient.
studentQuizDO = new IsaacQuiz("studentQuiz", null, null, null, null, null, null, null, null, null, null, null, false, null, null, null, true, null, null);
student = new RegisteredUserDTO("Some", "Student", "test-student@test.com", EmailVerificationStatus.VERIFIED, somePastDate, Gender.MALE, somePastDate, "");
student.setRole(Role.STUDENT);
student.setId(++id);
teacher = new RegisteredUserDTO("Some", "Teacher", "test-teacher@test.com", EmailVerificationStatus.VERIFIED, somePastDate, Gender.FEMALE, somePastDate, "");
teacher.setRole(Role.TEACHER);
teacher.setId(++id);
secondTeacher = new RegisteredUserDTO("Second", "Teacher", "second-teacher@test.com", EmailVerificationStatus.VERIFIED, somePastDate, Gender.PREFER_NOT_TO_SAY, somePastDate, "");
secondTeacher.setRole(Role.TEACHER);
secondTeacher.setId(++id);
otherTeacher = new RegisteredUserDTO("Other", "Teacher", "other-teacher@test.com", EmailVerificationStatus.VERIFIED, somePastDate, Gender.OTHER, somePastDate, "");
otherTeacher.setRole(Role.TEACHER);
otherTeacher.setId(++id);
noone = null;
secondStudent = new RegisteredUserDTO("Second", "Student", "second-student@test.com", EmailVerificationStatus.VERIFIED, somePastDate, Gender.FEMALE, somePastDate, "");
secondStudent.setRole(Role.STUDENT);
secondStudent.setId(++id);
otherStudent = new RegisteredUserDTO("Other", "Student", "other-student@test.com", EmailVerificationStatus.VERIFIED, somePastDate, Gender.MALE, somePastDate, "");
otherStudent.setRole(Role.STUDENT);
otherStudent.setId(++id);
adminUser = new RegisteredUserDTO("Test", "Admin", "test-admin@test.com", EmailVerificationStatus.VERIFIED, somePastDate, Gender.UNKNOWN, somePastDate, "");
adminUser.setRole(Role.ADMIN);
adminUser.setId(++id);
everyone = anyOf(student, teacher, secondTeacher, otherTeacher, secondStudent, otherStudent, adminUser);
studentGroup = new UserGroupDTO();
studentGroup.setId(++id);
studentGroup.setOwnerId(teacher.getId());
UserSummaryWithEmailAddressDTO secondTeacherSummary = new UserSummaryWithEmailAddressDTO();
secondTeacherSummary.setId(secondTeacher.getId());
secondTeacherSummary.setEmail(secondTeacher.getEmail());
secondTeacherSummary.setEmailVerificationStatus(secondTeacher.getEmailVerificationStatus());
secondTeacherSummary.setRole(secondTeacher.getRole());
secondTeacherSummary.setFamilyName(secondTeacher.getFamilyName());
secondTeacherSummary.setGivenName(secondTeacher.getGivenName());
studentGroup.setAdditionalManagers(Collections.singleton(secondTeacherSummary));
studentInactiveGroup = new UserGroupDTO(++id, "studentInactiveGroup", teacher.getId(), somePastDate, somePastDate, false);
studentGroups = ImmutableList.of(studentGroup.getId(), studentInactiveGroup.getId());
completedAssignment = new QuizAssignmentDTO(++id, studentQuiz.getId(), teacher.getId(), studentGroup.getId(), someFurtherPastDate, somePastDate, QuizFeedbackMode.OVERALL_MARK);
studentAssignment = new QuizAssignmentDTO(++id, studentQuiz.getId(), teacher.getId(), studentGroup.getId(), somePastDate, someFutureDate, QuizFeedbackMode.DETAILED_FEEDBACK);
overdueAssignment = new QuizAssignmentDTO(++id, studentQuiz.getId(), teacher.getId(), studentGroup.getId(), someFurtherPastDate, somePastDate, QuizFeedbackMode.SECTION_MARKS);
otherAssignment = new QuizAssignmentDTO(++id, teacherQuiz.getId(), teacher.getId(), studentGroup.getId(), somePastDate, someFutureDate, QuizFeedbackMode.OVERALL_MARK);
studentInactiveIgnoredAssignment = new QuizAssignmentDTO(++id, teacherQuiz.getId(), teacher.getId(), studentInactiveGroup.getId(), somePastDate, someFutureDate, QuizFeedbackMode.OVERALL_MARK);
studentInactiveAssignment = new QuizAssignmentDTO(++id, teacherQuiz.getId(), teacher.getId(), studentInactiveGroup.getId(), someFurtherPastDate, someFutureDate, QuizFeedbackMode.OVERALL_MARK);
studentAssignments = ImmutableList.of(completedAssignment, studentAssignment, overdueAssignment, otherAssignment, studentInactiveAssignment);
teacherAssignmentsToTheirGroups = ImmutableList.<QuizAssignmentDTO>builder().addAll(studentAssignments).add(studentInactiveIgnoredAssignment).build();
studentAttempt = new QuizAttemptDTO(++id, student.getId(), studentQuiz.getId(), studentAssignment.getId(), somePastDate, null);
overdueAttempt = new QuizAttemptDTO(++id, student.getId(), studentQuiz.getId(), overdueAssignment.getId(), somePastDate, null);
completedAttempt = new QuizAttemptDTO(++id, student.getId(), studentQuiz.getId(), studentAssignment.getId(), somePastDate, new Date());
overdueCompletedAttempt = new QuizAttemptDTO(++id, student.getId(), studentQuiz.getId(), overdueAssignment.getId(), somePastDate, new Date());
otherAttempt = new QuizAttemptDTO(++id, student.getId(), teacherQuiz.getId(), otherAssignment.getId(), somePastDate, null);
ownCompletedAttempt = new QuizAttemptDTO(++id, student.getId(), otherQuiz.getId(), null, somePastDate, somePastDate);
ownAttempt = new QuizAttemptDTO(++id, student.getId(), otherQuiz.getId(), null, somePastDate, null);
attemptOnNullFeedbackModeQuiz = new QuizAttemptDTO(101L, student.getId(), teacherQuiz.getId(), null, somePastDate, somePastDate);
studentAttempts = ImmutableList.of(studentAttempt, overdueAttempt, completedAttempt, overdueCompletedAttempt, otherAttempt, ownAttempt, ownCompletedAttempt, attemptOnNullFeedbackModeQuiz);
}
use of uk.ac.cam.cl.dtg.isaac.dto.UserGroupDTO in project isaac-api by isaacphysics.
the class EventBookingManagerTest method isUserAbleToManageEvent_checkUsersWithDifferentRoles_success.
@Test
public void isUserAbleToManageEvent_checkUsersWithDifferentRoles_success() throws Exception {
EventBookingManager eventBookingManager = this.buildEventBookingManager();
// Users to test
RegisteredUserDTO teacher = new RegisteredUserDTO();
teacher.setId(1L);
teacher.setRole(Role.TEACHER);
RegisteredUserDTO unassociatedEventLeader = new RegisteredUserDTO();
unassociatedEventLeader.setId(2L);
unassociatedEventLeader.setRole(Role.EVENT_LEADER);
RegisteredUserDTO associatedEventLeader = new RegisteredUserDTO();
associatedEventLeader.setId(3L);
associatedEventLeader.setRole(Role.EVENT_LEADER);
RegisteredUserDTO eventManager = new RegisteredUserDTO();
eventManager.setId(4L);
eventManager.setRole(Role.EVENT_MANAGER);
RegisteredUserDTO admin = new RegisteredUserDTO();
admin.setId(5L);
admin.setRole(Role.ADMIN);
// Event and associated group
UserGroupDTO testEventGroup = new UserGroupDTO();
testEventGroup.setId(0L);
testEventGroup.setOwnerId(associatedEventLeader.getId());
AssociationToken testAssociationToken = new AssociationToken();
testAssociationToken.setToken("EVENT_GROUP_TOKEN");
testAssociationToken.setOwnerUserId(testEventGroup.getOwnerId());
testAssociationToken.setGroupId(testEventGroup.getId());
IsaacEventPageDTO testEvent = new IsaacEventPageDTO();
testEvent.setId("someEventId");
testEvent.setIsaacGroupToken(testAssociationToken.getToken());
// Expected mocked method calls
expect(dummyUserAssociationManager.lookupTokenDetails(unassociatedEventLeader, testEvent.getIsaacGroupToken())).andReturn(testAssociationToken);
expect(dummyGroupManager.getGroupById(testAssociationToken.getGroupId())).andReturn(testEventGroup);
expect(dummyUserAssociationManager.lookupTokenDetails(associatedEventLeader, testEvent.getIsaacGroupToken())).andReturn(testAssociationToken);
expect(dummyGroupManager.getGroupById(testAssociationToken.getGroupId())).andReturn(testEventGroup);
replay(mockedObjects);
// Expected results
Map<RegisteredUserDTO, Boolean> expectedResults = ImmutableMap.of(teacher, false, unassociatedEventLeader, false, associatedEventLeader, true, eventManager, true, admin, true);
for (RegisteredUserDTO user : expectedResults.keySet()) {
assertEquals(String.format("Test case: %s", user.getRole()), expectedResults.get(user), eventBookingManager.isUserAbleToManageEvent(user, testEvent));
}
verify(mockedObjects);
}
use of uk.ac.cam.cl.dtg.isaac.dto.UserGroupDTO in project isaac-api by isaacphysics.
the class AssignmentFacade method getAssignmentProgress.
/**
* Allows the user to view results of an assignment they have set.
*
* @param assignmentId
* - the id of the assignment to be looked up.
* @param request
* - so that we can identify the current user.
* @return the assignment object.
*/
@GET
@Path("/assign/{assignment_id}/progress")
@Produces(MediaType.APPLICATION_JSON)
@GZIP
@ApiOperation(value = "View the progress of a specific assignment.")
public Response getAssignmentProgress(@Context final HttpServletRequest request, @PathParam("assignment_id") final Long assignmentId) {
try {
RegisteredUserDTO currentlyLoggedInUser = userManager.getCurrentRegisteredUser(request);
AssignmentDTO assignment = this.assignmentManager.getAssignmentById(assignmentId);
if (null == assignment) {
return SegueErrorResponse.getResourceNotFoundResponse("The assignment requested cannot be found");
}
UserGroupDTO group = this.groupManager.getGroupById(assignment.getGroupId());
if (!GroupManager.isOwnerOrAdditionalManager(group, currentlyLoggedInUser.getId()) && !isUserAnAdmin(userManager, currentlyLoggedInUser)) {
return new SegueErrorResponse(Status.FORBIDDEN, "You can only view the results of assignments that you own.").toResponse();
}
GameboardDTO gameboard = this.gameManager.getGameboard(assignment.getGameboardId());
List<RegisteredUserDTO> groupMembers = this.groupManager.getUsersInGroup(group);
List<ImmutableMap<String, Object>> result = Lists.newArrayList();
final String userString = "user";
final String resultsString = "results";
final String correctPartString = "correctPartResults";
final String incorrectPartString = "incorrectPartResults";
for (ImmutablePair<RegisteredUserDTO, List<GameboardItem>> userGameboardItems : this.gameManager.gatherGameProgressData(groupMembers, gameboard)) {
UserSummaryDTO userSummary = associationManager.enforceAuthorisationPrivacy(currentlyLoggedInUser, userManager.convertToUserSummaryObject(userGameboardItems.getLeft()));
// can the user access the data?
if (userSummary.isAuthorisedFullAccess()) {
ArrayList<GameboardItemState> states = Lists.newArrayList();
ArrayList<Integer> correctQuestionParts = Lists.newArrayList();
ArrayList<Integer> incorrectQuestionParts = Lists.newArrayList();
for (GameboardItem questionResult : userGameboardItems.getRight()) {
states.add(questionResult.getState());
correctQuestionParts.add(questionResult.getQuestionPartsCorrect());
incorrectQuestionParts.add(questionResult.getQuestionPartsIncorrect());
}
result.add(ImmutableMap.of(userString, userSummary, resultsString, states, correctPartString, correctQuestionParts, incorrectPartString, incorrectQuestionParts));
} else {
result.add(ImmutableMap.of(userString, userSummary, resultsString, Lists.newArrayList(), correctPartString, Lists.newArrayList(), incorrectPartString, Lists.newArrayList()));
}
}
this.getLogManager().logEvent(currentlyLoggedInUser, request, IsaacServerLogType.VIEW_ASSIGNMENT_PROGRESS, ImmutableMap.of(ASSIGNMENT_FK, assignment.getId()));
// get game manager completion information for this assignment.
return Response.ok(result).cacheControl(getCacheControl(NEVER_CACHE_WITHOUT_ETAG_CHECK, false)).build();
} catch (NoUserLoggedInException e) {
return SegueErrorResponse.getNotLoggedInResponse();
} catch (SegueDatabaseException e) {
log.error("Database error while trying to view assignment progress", e);
return new SegueErrorResponse(Status.INTERNAL_SERVER_ERROR, "Unknown database error.").toResponse();
} catch (ContentManagerException e) {
return new SegueErrorResponse(Status.INTERNAL_SERVER_ERROR, "Unknown content database error.").toResponse();
}
}
use of uk.ac.cam.cl.dtg.isaac.dto.UserGroupDTO in project isaac-api by isaacphysics.
the class QuizFacade method getQuizAssignments.
/**
* Get quizzes assigned by this user.
*
* Optionally filtered by a particular group.
*
* @param groupIdOfInterest An optional ID of a group to look up.
* @return a Response containing a list of QuizAssignmentDTO for the quizzes they have assigned.
*/
@GET
@Path("/assigned")
@Produces(MediaType.APPLICATION_JSON)
@GZIP
@ApiOperation(value = "Get tests assigned by this user.")
public Response getQuizAssignments(@Context HttpServletRequest request, @QueryParam("groupId") Long groupIdOfInterest) {
try {
RegisteredUserDTO user = userManager.getCurrentRegisteredUser(request);
if (!(isUserTeacherOrAbove(userManager, user))) {
return SegueErrorResponse.getIncorrectRoleResponse();
}
List<UserGroupDTO> groups;
if (groupIdOfInterest != null) {
UserGroupDTO group = this.groupManager.getGroupById(groupIdOfInterest);
if (null == group) {
return new SegueErrorResponse(Status.NOT_FOUND, "The group specified cannot be located.").toResponse();
}
if (!canManageGroup(user, group)) {
return new SegueErrorResponse(Status.FORBIDDEN, "You are not the owner or manager of that group").toResponse();
}
groups = Collections.singletonList(group);
} else {
groups = this.groupManager.getAllGroupsOwnedAndManagedByUser(user, false);
}
List<QuizAssignmentDTO> assignments = this.quizAssignmentManager.getAssignmentsForGroups(groups);
quizManager.augmentWithQuizSummary(assignments);
return Response.ok(assignments).cacheControl(getCacheControl(NEVER_CACHE_WITHOUT_ETAG_CHECK, false)).build();
} catch (NoUserLoggedInException e) {
return SegueErrorResponse.getNotLoggedInResponse();
} catch (SegueDatabaseException e) {
String message = "Database error whilst getting assigned tests";
log.error(message, e);
return new SegueErrorResponse(Status.INTERNAL_SERVER_ERROR, message).toResponse();
}
}
use of uk.ac.cam.cl.dtg.isaac.dto.UserGroupDTO in project isaac-api by isaacphysics.
the class AssignmentManager method findGroupsByGameboard.
/**
* findGroupsByGameboard.
*
* @param user
* - owner of assignments (teacher)
* @param gameboardId
* - the gameboard id to query
* @return Empty List if none or a List or groups.
* @throws SegueDatabaseException
* - If something goes wrong with database access.
*/
public List<UserGroupDTO> findGroupsByGameboard(final RegisteredUserDTO user, final String gameboardId) throws SegueDatabaseException {
Validate.notNull(user);
Validate.notBlank(gameboardId);
List<UserGroupDTO> allGroupsForUser = this.groupManager.getAllGroupsOwnedAndManagedByUser(user, false);
List<AssignmentDTO> allAssignmentsForMyGroups = this.getAllAssignmentsForSpecificGroups(allGroupsForUser);
List<UserGroupDTO> groups = Lists.newArrayList();
for (AssignmentDTO assignment : allAssignmentsForMyGroups) {
if (assignment.getGameboardId().equals(gameboardId)) {
groups.add(groupManager.getGroupById(assignment.getGroupId()));
}
}
return groups;
}
Aggregations