use of fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessment in project muikku by otavanopisto.
the class Evaluation2RESTService method findWorkspaceAssessment.
@GET
@Path("/workspace/{WORKSPACEENTITYID}/user/{USERENTITYID}/assessment")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response findWorkspaceAssessment(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("USERENTITYID") Long userEntityId) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).build();
}
if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.ACCESS_EVALUATION)) {
// Allow students to access their own assessments
if (!sessionController.getLoggedUserEntity().getId().equals(userEntityId)) {
return Response.status(Status.FORBIDDEN).build();
}
return Response.status(Status.FORBIDDEN).build();
}
// Entities and identifiers
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
UserEntity userEntity = userEntityController.findUserEntityById(userEntityId);
if (workspaceEntity == null || userEntity == null) {
return Response.status(Status.BAD_REQUEST).build();
}
SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
SchoolDataIdentifier userIdentifier = new SchoolDataIdentifier(userEntity.getDefaultIdentifier(), userEntity.getDefaultSchoolDataSource().getIdentifier());
// TODO listWorkspaceAssessments is incorrect; one student in one workspace should have one assessment at most
List<WorkspaceAssessment> workspaceAssessments = gradingController.listWorkspaceAssessments(workspaceIdentifier, userIdentifier);
WorkspaceAssessment workspaceAssessment = workspaceAssessments.isEmpty() ? null : workspaceAssessments.get(0);
if (workspaceAssessment == null) {
return Response.status(Status.NOT_FOUND).build();
}
RestAssessment restAssessment = new RestAssessment(workspaceAssessment.getIdentifier().toId(), workspaceAssessment.getAssessingUserIdentifier().toId(), workspaceAssessment.getGradingScaleIdentifier().toId(), workspaceAssessment.getGradeIdentifier().toId(), workspaceAssessment.getVerbalAssessment(), workspaceAssessment.getDate(), workspaceAssessment.getPassing());
return Response.ok(restAssessment).build();
}
Aggregations