Search in sources :

Example 11 with GradingScaleItem

use of fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem in project muikku by otavanopisto.

the class VopsLister method findGradingScaleItemCached.

private GradingScaleItem findGradingScaleItemCached(SchoolDataIdentifier gradingScaleIdentifier, SchoolDataIdentifier gradingScaleItemIdentifier) {
    GradingScaleItemCoordinates key = new GradingScaleItemCoordinates(gradingScaleIdentifier, gradingScaleItemIdentifier);
    if (!gradingScaleCache.containsKey(key)) {
        GradingScale gradingScale = gradingController.findGradingScale(gradingScaleIdentifier);
        if (gradingScale == null) {
            logger.log(Level.SEVERE, "Grading scale not found for identifier: %s", gradingScaleIdentifier);
            return null;
        }
        for (GradingScaleItem gradingScaleItem : gradingController.listGradingScaleItems(gradingScale)) {
            GradingScaleItemCoordinates newItemKey = new GradingScaleItemCoordinates(gradingScaleIdentifier, new SchoolDataIdentifier(gradingScaleItem.getIdentifier(), gradingScaleItem.getSchoolDataSource()));
            gradingScaleCache.put(newItemKey, gradingScaleItem);
        }
    }
    return gradingScaleCache.get(key);
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) GradingScale(fi.otavanopisto.muikku.schooldata.entity.GradingScale) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem)

Example 12 with GradingScaleItem

use of fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem 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 13 with GradingScaleItem

use of fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem in project muikku by otavanopisto.

the class EvaluationRESTService method createWorkspaceAssessment.

@POST
@Path("/workspaces/{WORKSPACEENTITYID}/students/{STUDENTID}/assessments")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createWorkspaceAssessment(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("STUDENTID") String studentId, WorkspaceAssessment payload) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    SchoolDataIdentifier studentIdentifier = SchoolDataIdentifier.fromId(studentId);
    if (studentIdentifier == null) {
        return Response.status(Status.BAD_REQUEST).entity(String.format("Malformed student identifier %s", studentId)).build();
    }
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).entity(String.format("Could not find workspace entity %d", workspaceEntityId)).build();
    }
    WorkspaceUserEntity workspaceStudentEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserIdentifier(workspaceEntity, studentIdentifier);
    if (workspaceStudentEntity == null) {
        return Response.status(Status.NOT_FOUND).entity(String.format("Could not find workspace student entity %s from workspace entity %d", studentIdentifier, workspaceEntityId)).build();
    }
    if (!sessionController.hasWorkspacePermission(MuikkuPermissions.EVALUATE_USER, workspaceEntity)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    if (payload.getEvaluated() == null) {
        return Response.status(Status.BAD_REQUEST).entity("evaluated is missing").build();
    }
    if (payload.getAssessorEntityId() == null) {
        return Response.status(Status.BAD_REQUEST).entity("assessorEntityId is missing").build();
    }
    if (payload.getGradeSchoolDataSource() == null) {
        return Response.status(Status.BAD_REQUEST).entity("gradeSchoolDataSource is missing").build();
    }
    if (payload.getGradeIdentifier() == null) {
        return Response.status(Status.BAD_REQUEST).entity("gradeIdentifier is missing").build();
    }
    UserEntity assessor = userEntityController.findUserEntityById(payload.getAssessorEntityId());
    if (assessor == null) {
        return Response.status(Status.BAD_REQUEST).entity("assessor is invalid").build();
    }
    User assessingUser = userController.findUserByUserEntityDefaults(assessor);
    if (assessingUser == null) {
        return Response.status(Status.BAD_REQUEST).entity("Could not find assessor from school data source").build();
    }
    GradingScale gradingScale = gradingController.findGradingScale(payload.getGradingScaleSchoolDataSource(), payload.getGradingScaleIdentifier());
    if (gradingScale == null) {
        return Response.status(Status.BAD_REQUEST).entity("gradingScale is invalid").build();
    }
    GradingScaleItem grade = gradingController.findGradingScaleItem(gradingScale, payload.getGradeSchoolDataSource(), payload.getGradeIdentifier());
    if (grade == null) {
        return Response.status(Status.BAD_REQUEST).entity("grade is invalid").build();
    }
    fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser workspaceStudent = workspaceController.findWorkspaceUser(workspaceStudentEntity);
    if (workspaceStudent == null) {
        return Response.status(Status.INTERNAL_SERVER_ERROR).entity(String.format("Failed to get workspace student for workspace student entity %d from school data source", workspaceStudentEntity.getId())).build();
    }
    Date evaluated = payload.getEvaluated();
    UserEntity student = userEntityController.findUserEntityByUserIdentifier(workspaceStudent.getUserIdentifier());
    Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
    fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment assessment = gradingController.createWorkspaceAssessment(workspaceStudent.getSchoolDataSource(), workspaceStudent, assessingUser, grade, payload.getVerbalAssessment(), evaluated);
    if (student != null && workspace != null && assessment != null) {
        sendAssessmentNotification(workspaceEntity, payload, assessor, student, workspace, grade.getName());
    }
    return Response.ok(createRestModel(workspaceEntity, assessment)).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) GradingScale(fi.otavanopisto.muikku.schooldata.entity.GradingScale) WorkspaceGradingScale(fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale) User(fi.otavanopisto.muikku.schooldata.entity.User) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) Date(java.util.Date) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 14 with GradingScaleItem

use of fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem in project muikku by otavanopisto.

the class EvaluationRESTService method updateWorkspaceMaterialEvaluation.

@PUT
@Path("/workspaces/{WORKSPACEENTITYID}/materials/{WORKSPACEMATERIALID}/evaluations/{ID}")
@RESTPermit(handling = Handling.INLINE)
public Response updateWorkspaceMaterialEvaluation(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("WORKSPACEMATERIALID") Long workspaceMaterialId, @PathParam("ID") Long workspaceMaterialEvaluationId, WorkspaceMaterialEvaluation payload) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!sessionController.hasWorkspacePermission(EvaluationResourcePermissionCollection.EVALUATION_UPDATEWORKSPACEMATERIALEVALUATION, 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.INTERNAL_SERVER_ERROR).build();
    }
    if (!workspaceEntity.getId().equals(rootFolder.getWorkspaceEntityId())) {
        return Response.status(Status.NOT_FOUND).build();
    }
    fi.otavanopisto.muikku.plugins.evaluation.model.WorkspaceMaterialEvaluation workspaceMaterialEvaluation = evaluationController.findWorkspaceMaterialEvaluation(workspaceMaterialEvaluationId);
    if (workspaceMaterialEvaluation == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!workspaceMaterialEvaluation.getWorkspaceMaterialId().equals(workspaceMaterial.getId())) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (payload.getEvaluated() == null) {
        return Response.status(Status.BAD_REQUEST).entity("evaluated is missing").build();
    }
    if (payload.getAssessorEntityId() == null) {
        return Response.status(Status.BAD_REQUEST).entity("assessorEntityId is missing").build();
    }
    if (payload.getGradingScaleSchoolDataSource() == null) {
        return Response.status(Status.BAD_REQUEST).entity("gradingScaleSchoolDataSource is missing").build();
    }
    if (payload.getGradingScaleIdentifier() == null) {
        return Response.status(Status.BAD_REQUEST).entity("gradingScaleIdentifier is missing").build();
    }
    if (payload.getGradeSchoolDataSource() == null) {
        return Response.status(Status.BAD_REQUEST).entity("gradeSchoolDataSource is missing").build();
    }
    if (payload.getGradeIdentifier() == null) {
        return Response.status(Status.BAD_REQUEST).entity("gradeIdentifier is missing").build();
    }
    UserEntity assessor = userEntityController.findUserEntityById(payload.getAssessorEntityId());
    UserEntity student = userEntityController.findUserEntityById(payload.getStudentEntityId());
    GradingScale gradingScale = gradingController.findGradingScale(payload.getGradingScaleSchoolDataSource(), payload.getGradingScaleIdentifier());
    GradingScaleItem grade = gradingController.findGradingScaleItem(gradingScale, payload.getGradeSchoolDataSource(), payload.getGradeIdentifier());
    if (assessor == null) {
        return Response.status(Status.BAD_REQUEST).entity("assessor is invalid").build();
    }
    if (student == null) {
        return Response.status(Status.BAD_REQUEST).entity("student is invalid").build();
    }
    if (gradingScale == null) {
        return Response.status(Status.BAD_REQUEST).entity("gradingScale is invalid").build();
    }
    if (grade == null) {
        return Response.status(Status.BAD_REQUEST).entity("grade is invalid").build();
    }
    Date evaluated = payload.getEvaluated();
    workspaceMaterialEvaluation = evaluationController.updateWorkspaceMaterialEvaluation(workspaceMaterialEvaluation, gradingScale, grade, assessor, evaluated, payload.getVerbalAssessment());
    return Response.ok(createRestModel(workspaceMaterialEvaluation)).build();
}
Also used : GradingScale(fi.otavanopisto.muikku.schooldata.entity.GradingScale) WorkspaceGradingScale(fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) Date(java.util.Date) WorkspaceRootFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) PUT(javax.ws.rs.PUT)

Example 15 with GradingScaleItem

use of fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem in project muikku by otavanopisto.

the class EvaluationRESTService method createOrUpdateWorkspaceMaterialEvaluation.

@POST
@Path("/workspaces/{WORKSPACEENTITYID}/materials/{WORKSPACEMATERIALID}/evaluations/")
@RESTPermit(handling = Handling.INLINE)
public Response createOrUpdateWorkspaceMaterialEvaluation(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("WORKSPACEMATERIALID") Long workspaceMaterialId, WorkspaceMaterialEvaluation payload) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!sessionController.hasWorkspacePermission(EvaluationResourcePermissionCollection.EVALUATION_CREATEWORKSPACEMATERIALEVALUATION, 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.INTERNAL_SERVER_ERROR).build();
    }
    if (!workspaceEntity.getId().equals(rootFolder.getWorkspaceEntityId())) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (payload.getEvaluated() == null) {
        return Response.status(Status.BAD_REQUEST).entity("evaluated is missing").build();
    }
    if (payload.getAssessorEntityId() == null) {
        return Response.status(Status.BAD_REQUEST).entity("assessorEntityId is missing").build();
    }
    if (payload.getStudentEntityId() == null) {
        return Response.status(Status.BAD_REQUEST).entity("studentEntityId is missing").build();
    }
    if (payload.getGradingScaleSchoolDataSource() == null) {
        return Response.status(Status.BAD_REQUEST).entity("gradingScaleSchoolDataSource is missing").build();
    }
    if (payload.getGradingScaleIdentifier() == null) {
        return Response.status(Status.BAD_REQUEST).entity("gradingScaleIdentifier is missing").build();
    }
    if (payload.getGradeSchoolDataSource() == null) {
        return Response.status(Status.BAD_REQUEST).entity("gradeSchoolDataSource is missing").build();
    }
    if (payload.getGradeIdentifier() == null) {
        return Response.status(Status.BAD_REQUEST).entity("gradeIdentifier is missing").build();
    }
    UserEntity assessor = userEntityController.findUserEntityById(payload.getAssessorEntityId());
    UserEntity student = userEntityController.findUserEntityById(payload.getStudentEntityId());
    GradingScale gradingScale = gradingController.findGradingScale(payload.getGradingScaleSchoolDataSource(), payload.getGradingScaleIdentifier());
    GradingScaleItem grade = gradingController.findGradingScaleItem(gradingScale, payload.getGradeSchoolDataSource(), payload.getGradeIdentifier());
    if (assessor == null) {
        return Response.status(Status.BAD_REQUEST).entity("assessor is invalid").build();
    }
    if (student == null) {
        return Response.status(Status.BAD_REQUEST).entity("student is invalid").build();
    }
    if (gradingScale == null) {
        return Response.status(Status.BAD_REQUEST).entity("gradingScale is invalid").build();
    }
    if (grade == null) {
        return Response.status(Status.BAD_REQUEST).entity("grade is invalid").build();
    }
    if (evaluationController.findWorkspaceMaterialEvaluationByWorkspaceMaterialAndStudent(workspaceMaterial, student) != null) {
        return Response.status(Status.BAD_REQUEST).entity("material already evaluated").build();
    }
    Date evaluated = payload.getEvaluated();
    return Response.ok(createRestModel(evaluationController.createWorkspaceMaterialEvaluation(student, workspaceMaterial, gradingScale, grade, assessor, evaluated, payload.getVerbalAssessment()))).build();
}
Also used : GradingScale(fi.otavanopisto.muikku.schooldata.entity.GradingScale) WorkspaceGradingScale(fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) Date(java.util.Date) WorkspaceRootFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Aggregations

GradingScaleItem (fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem)17 GradingScale (fi.otavanopisto.muikku.schooldata.entity.GradingScale)15 WorkspaceGradingScale (fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale)12 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)11 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)11 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)10 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)10 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)10 Path (javax.ws.rs.Path)10 User (fi.otavanopisto.muikku.schooldata.entity.User)7 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)5 CompositeGradingScale (fi.otavanopisto.muikku.schooldata.entity.CompositeGradingScale)5 Date (java.util.Date)5 RestAssessment (fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessment)4 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)4 WorkspaceAssessment (fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment)4 WorkspaceUser (fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser)4 PUT (javax.ws.rs.PUT)4 SupplementationRequest (fi.otavanopisto.muikku.plugins.evaluation.model.SupplementationRequest)3 WorkspaceMaterialEvaluation (fi.otavanopisto.muikku.plugins.evaluation.model.WorkspaceMaterialEvaluation)3