use of fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssignment in project muikku by otavanopisto.
the class Evaluation2RESTService method listWorkspaceAssignments.
@GET
@Path("/workspace/{WORKSPACEENTITYID}/assignments")
@RESTPermit(handling = Handling.INLINE)
public Response listWorkspaceAssignments(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @QueryParam("userEntityId") Long userEntityId) {
// Workspace entity
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).build();
}
// User entity (optional)
UserEntity userEntity = null;
if (userEntityId != null) {
userEntity = userEntityController.findUserEntityById(userEntityId);
if (userEntity == null) {
return Response.status(Status.NOT_FOUND).build();
}
}
// Workspace materials...
List<WorkspaceMaterial> workspaceMaterials = workspaceMaterialController.listWorkspaceMaterialsByAssignmentType(workspaceEntity, WorkspaceMaterialAssignmentType.EVALUATED, BooleanPredicate.IGNORE);
workspaceMaterials.addAll(workspaceMaterialController.listWorkspaceMaterialsByAssignmentType(workspaceEntity, WorkspaceMaterialAssignmentType.EXERCISE, BooleanPredicate.IGNORE));
// ...to RestAssignments
List<RestAssignment> assignments = new ArrayList<RestAssignment>();
for (WorkspaceMaterial workspaceMaterial : workspaceMaterials) {
Long workspaceMaterialEvaluationId = null;
Long workspaceMaterialId = workspaceMaterial.getId();
Long materialId = workspaceMaterial.getMaterialId();
String path = workspaceMaterial.getPath();
String title = workspaceMaterial.getTitle();
Boolean evaluable = workspaceMaterial.getAssignmentType() == WorkspaceMaterialAssignmentType.EVALUATED;
Date submitted = null;
Date evaluated = null;
String grade = null;
String literalEvaluation = null;
if (userEntity != null) {
WorkspaceMaterialReply workspaceMaterialReply = workspaceMaterialReplyController.findWorkspaceMaterialReplyByWorkspaceMaterialAndUserEntity(workspaceMaterial, userEntity);
if (workspaceMaterialReply != null) {
WorkspaceMaterialReplyState replyState = workspaceMaterialReply.getState();
if (replyState == WorkspaceMaterialReplyState.SUBMITTED || replyState == WorkspaceMaterialReplyState.PASSED || replyState == WorkspaceMaterialReplyState.FAILED || replyState == WorkspaceMaterialReplyState.INCOMPLETE) {
submitted = workspaceMaterialReply.getLastModified();
}
} else if (workspaceMaterial.getHidden()) {
// Skip hidden material which has no reply
continue;
}
WorkspaceMaterialEvaluation workspaceMaterialEvaluation = evaluationController.findWorkspaceMaterialEvaluationByWorkspaceMaterialAndStudent(workspaceMaterial, userEntity);
if (workspaceMaterialEvaluation != null) {
workspaceMaterialEvaluationId = workspaceMaterialEvaluation.getId();
evaluated = workspaceMaterialEvaluation.getEvaluated();
GradingScale gradingScale = gradingController.findGradingScale(workspaceMaterialEvaluation.getGradingScaleSchoolDataSource(), workspaceMaterialEvaluation.getGradingScaleIdentifier());
if (gradingScale != null) {
GradingScaleItem gradingScaleItem = gradingController.findGradingScaleItem(gradingScale, workspaceMaterialEvaluation.getGradeSchoolDataSource(), workspaceMaterialEvaluation.getGradeIdentifier());
if (gradingScaleItem != null) {
grade = gradingScaleItem.getName();
}
}
literalEvaluation = workspaceMaterialEvaluation.getVerbalAssessment();
} else {
SupplementationRequest supplementationRequest = evaluationController.findSupplementationRequestByStudentAndWorkspaceMaterialAndArchived(userEntity.getId(), workspaceMaterial.getId(), Boolean.FALSE);
if (supplementationRequest != null) {
evaluated = supplementationRequest.getRequestDate();
literalEvaluation = supplementationRequest.getRequestText();
}
}
}
if (!(workspaceMaterial.getHidden() && submitted == null)) {
assignments.add(new RestAssignment(workspaceMaterialEvaluationId, workspaceMaterialId, materialId, path, title, evaluable, submitted, evaluated, grade, literalEvaluation));
}
}
return Response.ok(assignments).build();
}
Aggregations