Search in sources :

Example 1 with WorkspaceMaterialEvaluation

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);
}
Also used : GradingScale(fi.otavanopisto.muikku.schooldata.entity.GradingScale) WorkspaceGradingScale(fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem) WorkspaceMaterialEvaluation(fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceMaterialEvaluation)

Example 2 with WorkspaceMaterialEvaluation

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();
}
Also used : ArrayList(java.util.ArrayList) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceMaterialEvaluation(fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceMaterialEvaluation) WorkspaceRootFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Aggregations

WorkspaceMaterialEvaluation (fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceMaterialEvaluation)2 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)1 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)1 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)1 WorkspaceGradingScale (fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale)1 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)1 WorkspaceRootFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder)1 GradingScale (fi.otavanopisto.muikku.schooldata.entity.GradingScale)1 GradingScaleItem (fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem)1 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)1 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1