Search in sources :

Example 6 with RestAssessment

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();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) WorkspaceAssessment(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) RestAssessment(fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessment) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Aggregations

UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)6 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)6 RestAssessment (fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessment)6 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)6 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)6 Path (javax.ws.rs.Path)6 WorkspaceGradingScale (fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale)4 CompositeGradingScale (fi.otavanopisto.muikku.schooldata.entity.CompositeGradingScale)4 GradingScale (fi.otavanopisto.muikku.schooldata.entity.GradingScale)4 GradingScaleItem (fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem)4 User (fi.otavanopisto.muikku.schooldata.entity.User)4 WorkspaceUser (fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser)4 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)3 WorkspaceMaterialEvaluation (fi.otavanopisto.muikku.plugins.evaluation.model.WorkspaceMaterialEvaluation)3 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)3 WorkspaceAssessment (fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment)3 SupplementationRequest (fi.otavanopisto.muikku.plugins.evaluation.model.SupplementationRequest)2 RestSupplementationRequest (fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestSupplementationRequest)2 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)2 GET (javax.ws.rs.GET)2