use of fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessmentRequest in project muikku by otavanopisto.
the class Evaluation2RESTService method listAssessmentRequests.
@GET
@Path("/compositeAssessmentRequests")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listAssessmentRequests(@QueryParam("workspaceEntityId") Long workspaceEntityId) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).build();
}
if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.ACCESS_EVALUATION)) {
return Response.status(Status.FORBIDDEN).build();
}
List<RestAssessmentRequest> restAssessmentRequests = new ArrayList<RestAssessmentRequest>();
if (workspaceEntityId == null) {
// List assessment requests by staff member
SchoolDataIdentifier loggedUser = sessionController.getLoggedUser();
List<CompositeAssessmentRequest> assessmentRequests = gradingController.listAssessmentRequestsByStaffMember(loggedUser);
for (CompositeAssessmentRequest assessmentRequest : assessmentRequests) {
restAssessmentRequests.add(toRestAssessmentRequest(assessmentRequest));
}
} else {
// List assessment requests by workspace
List<String> workspaceStudentIdentifiers = new ArrayList<String>();
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
List<WorkspaceUserEntity> workspaceUserEntities = workspaceUserEntityController.listActiveWorkspaceStudents(workspaceEntity);
for (WorkspaceUserEntity workspaceUserEntity : workspaceUserEntities) {
workspaceStudentIdentifiers.add(workspaceUserEntity.getIdentifier());
}
List<CompositeAssessmentRequest> assessmentRequests = gradingController.listAssessmentRequestsByWorkspace(workspaceIdentifier, workspaceStudentIdentifiers);
for (CompositeAssessmentRequest assessmentRequest : assessmentRequests) {
restAssessmentRequests.add(toRestAssessmentRequest(assessmentRequest));
}
}
return Response.ok(restAssessmentRequests).build();
}
use of fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessmentRequest in project muikku by otavanopisto.
the class Evaluation2RESTService method toRestAssessmentRequest.
private RestAssessmentRequest toRestAssessmentRequest(CompositeAssessmentRequest compositeAssessmentRequest) {
Long assignmentsDone = 0L;
Long assignmentsTotal = 0L;
// Assignments total
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByIdentifier(compositeAssessmentRequest.getCourseIdentifier());
if (workspaceEntity == null) {
logger.severe(String.format("WorkspaceEntity for course %s not found", compositeAssessmentRequest.getCourseIdentifier()));
} else {
List<WorkspaceMaterial> evaluatedAssignments = workspaceMaterialController.listVisibleWorkspaceMaterialsByAssignmentType(workspaceEntity, WorkspaceMaterialAssignmentType.EVALUATED);
assignmentsTotal = new Long(evaluatedAssignments.size());
// Assignments done by user
if (assignmentsTotal > 0) {
UserEntity userEntity = userEntityController.findUserEntityByUserIdentifier(compositeAssessmentRequest.getUserIdentifier());
if (userEntity == null) {
logger.severe(String.format("UserEntity not found for AssessmentRequest student %s not found", compositeAssessmentRequest.getUserIdentifier()));
} else {
List<WorkspaceMaterialReplyState> replyStates = new ArrayList<WorkspaceMaterialReplyState>();
replyStates.add(WorkspaceMaterialReplyState.FAILED);
replyStates.add(WorkspaceMaterialReplyState.PASSED);
replyStates.add(WorkspaceMaterialReplyState.SUBMITTED);
replyStates.add(WorkspaceMaterialReplyState.INCOMPLETE);
assignmentsDone = workspaceMaterialReplyController.getReplyCountByUserEntityAndReplyStatesAndWorkspaceMaterials(userEntity.getId(), replyStates, evaluatedAssignments);
}
}
}
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(compositeAssessmentRequest.getCourseStudentIdentifier());
UserEntity userEntity = userEntityController.findUserEntityByUserIdentifier(compositeAssessmentRequest.getUserIdentifier());
// An active workspace supplementation request will override graded, passing, and evaluationDate
Boolean graded = Boolean.TRUE;
Boolean passing = compositeAssessmentRequest.getPassing();
Date evaluationDate = compositeAssessmentRequest.getEvaluationDate();
if (userEntity != null) {
SupplementationRequest supplementationRequest = evaluationController.findSupplementationRequestByStudentAndWorkspaceAndArchived(userEntity.getId(), workspaceEntity.getId(), Boolean.FALSE);
if (supplementationRequest != null) {
graded = Boolean.FALSE;
passing = Boolean.FALSE;
evaluationDate = supplementationRequest.getRequestDate();
}
}
RestAssessmentRequest restAssessmentRequest = new RestAssessmentRequest();
restAssessmentRequest.setWorkspaceUserEntityId(workspaceUserEntity == null ? null : workspaceUserEntity.getId());
restAssessmentRequest.setWorkspaceUserIdentifier(compositeAssessmentRequest.getCourseStudentIdentifier().toId());
restAssessmentRequest.setUserEntityId(userEntity == null ? null : userEntity.getId());
restAssessmentRequest.setAssessmentRequestDate(compositeAssessmentRequest.getAssessmentRequestDate());
restAssessmentRequest.setEvaluationDate(evaluationDate);
restAssessmentRequest.setPassing(passing);
restAssessmentRequest.setGraded(graded);
restAssessmentRequest.setAssignmentsDone(assignmentsDone);
restAssessmentRequest.setAssignmentsTotal(assignmentsTotal);
restAssessmentRequest.setEnrollmentDate(compositeAssessmentRequest.getCourseEnrollmentDate());
restAssessmentRequest.setFirstName(compositeAssessmentRequest.getFirstName());
restAssessmentRequest.setLastName(compositeAssessmentRequest.getLastName());
restAssessmentRequest.setStudyProgramme(compositeAssessmentRequest.getStudyProgramme());
restAssessmentRequest.setWorkspaceEntityId(workspaceEntity == null ? null : workspaceEntity.getId());
restAssessmentRequest.setWorkspaceName(compositeAssessmentRequest.getCourseName());
restAssessmentRequest.setWorkspaceNameExtension(compositeAssessmentRequest.getCourseNameExtension());
restAssessmentRequest.setWorkspaceUrlName(workspaceEntity == null ? null : workspaceEntity.getUrlName());
return restAssessmentRequest;
}
Aggregations