use of fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceMaterialEvaluation in project muikku by otavanopisto.
the class EvaluationRESTService method createRestModel.
private WorkspaceMaterialEvaluation createRestModel(fi.otavanopisto.muikku.plugins.evaluation.model.WorkspaceMaterialEvaluation evaluation) {
Boolean passingGrade = null;
String grade = null;
if (evaluation.getGradingScaleSchoolDataSource() != null && evaluation.getGradingScaleIdentifier() != null && evaluation.getGradeSchoolDataSource() != null && evaluation.getGradeIdentifier() != null) {
GradingScale gradingScale = gradingController.findGradingScale(evaluation.getGradingScaleSchoolDataSource(), evaluation.getGradingScaleIdentifier());
if (gradingScale == null) {
logger.severe(String.format("Grading scale %s-%s not found for evaluation %d", evaluation.getGradingScaleSchoolDataSource(), evaluation.getGradingScaleIdentifier(), evaluation.getId()));
} else {
GradingScaleItem gradingScaleItem = gradingController.findGradingScaleItem(gradingScale, evaluation.getGradeSchoolDataSource(), evaluation.getGradeIdentifier());
if (gradingScaleItem == null) {
logger.severe(String.format("Grading scale item %s-%s not found for evaluation %d", evaluation.getGradeSchoolDataSource(), evaluation.getGradeIdentifier(), evaluation.getId()));
} else {
grade = gradingScaleItem.getName();
passingGrade = gradingScaleItem.isPassingGrade();
}
}
}
return new WorkspaceMaterialEvaluation(evaluation.getId(), evaluation.getEvaluated(), evaluation.getAssessorEntityId(), evaluation.getStudentEntityId(), evaluation.getWorkspaceMaterialId(), evaluation.getGradingScaleIdentifier(), evaluation.getGradingScaleSchoolDataSource(), grade, evaluation.getGradeIdentifier(), evaluation.getGradeSchoolDataSource(), evaluation.getVerbalAssessment(), passingGrade);
}
use of fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceMaterialEvaluation in project muikku by otavanopisto.
the class EvaluationRESTService method listWorkspaceMaterialEvaluations.
@GET
@Path("/workspaces/{WORKSPACEENTITYID}/materials/{WORKSPACEMATERIALID}/evaluations/")
@RESTPermit(handling = Handling.INLINE)
public Response listWorkspaceMaterialEvaluations(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("WORKSPACEMATERIALID") Long workspaceMaterialId, @QueryParam("userEntityId") Long userEntityId) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).build();
}
if (userEntityId == null) {
return Response.status(Status.NOT_IMPLEMENTED).entity("Listing workspace material evaluations without userEntityId is not implemented yet").build();
}
UserEntity userEntity = userEntityController.findUserEntityById(userEntityId);
if (userEntity == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid user entity id").build();
}
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).build();
}
if (!sessionController.getLoggedUserEntity().getId().equals(userEntity.getId())) {
if (!sessionController.hasWorkspacePermission(EvaluationResourcePermissionCollection.EVALUATION_LISTWORKSPACEMATERIALEVALUATIONS, workspaceEntity)) {
return Response.status(Status.FORBIDDEN).build();
}
}
WorkspaceMaterial workspaceMaterial = workspaceMaterialController.findWorkspaceMaterialById(workspaceMaterialId);
if (workspaceMaterial == null) {
return Response.status(Status.NOT_FOUND).entity("workspaceMaterial not found").build();
}
WorkspaceRootFolder rootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceNode(workspaceMaterial);
if (rootFolder == null) {
return Response.status(Status.NOT_FOUND).build();
}
if (!workspaceEntity.getId().equals(rootFolder.getWorkspaceEntityId())) {
return Response.status(Status.NOT_FOUND).build();
}
List<fi.otavanopisto.muikku.plugins.evaluation.model.WorkspaceMaterialEvaluation> result = new ArrayList<>();
fi.otavanopisto.muikku.plugins.evaluation.model.WorkspaceMaterialEvaluation workspaceMaterialEvaluation = evaluationController.findWorkspaceMaterialEvaluationByWorkspaceMaterialAndStudent(workspaceMaterial, userEntity);
if (workspaceMaterialEvaluation != null) {
result.add(workspaceMaterialEvaluation);
}
if (result.isEmpty()) {
return Response.ok(Collections.emptyList()).build();
}
if (!workspaceMaterialEvaluation.getWorkspaceMaterialId().equals(workspaceMaterial.getId())) {
return Response.status(Status.NOT_FOUND).build();
}
return Response.ok(createRestModel(result.toArray(new fi.otavanopisto.muikku.plugins.evaluation.model.WorkspaceMaterialEvaluation[0]))).build();
}
Aggregations