Search in sources :

Example 16 with GradingScaleItem

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

the class Evaluation2RESTService method updateWorkspaceAssessment.

@PUT
@Path("/workspace/{WORKSPACEENTITYID}/user/{USERENTITYID}/assessment")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response updateWorkspaceAssessment(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("USERENTITYID") Long userEntityId, RestAssessment payload) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.ACCESS_EVALUATION)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    // Entities and identifiers
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    UserEntity userEntity = userEntityController.findUserEntityById(userEntityId);
    Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
    if (workspaceEntity == null || userEntity == null || workspace == 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();
    }
    // Workspace user
    WorkspaceUser workspaceUser = workspaceController.findWorkspaceUserByWorkspaceAndUser(workspaceIdentifier, userIdentifier);
    // Assessor
    SchoolDataIdentifier assessorIdentifier = SchoolDataIdentifier.fromId(payload.getAssessorIdentifier());
    User assessingUser = userController.findUserByIdentifier(assessorIdentifier);
    UserEntity assessingUserEntity = userEntityController.findUserEntityByUser(assessingUser);
    // Grade
    SchoolDataIdentifier gradingScaleIdentifier = SchoolDataIdentifier.fromId(payload.getGradingScaleIdentifier());
    GradingScale gradingScale = gradingController.findGradingScale(gradingScaleIdentifier);
    SchoolDataIdentifier gradeIdentifier = SchoolDataIdentifier.fromId(payload.getGradeIdentifier());
    GradingScaleItem gradingScaleItem = gradingController.findGradingScaleItem(gradingScale, gradeIdentifier);
    // Update
    workspaceAssessment = gradingController.updateWorkspaceAssessment(workspaceAssessment.getIdentifier(), workspaceUser, assessingUser, gradingScaleItem, payload.getVerbalAssessment(), payload.getAssessmentDate());
    // Notification
    sendAssessmentNotification(workspaceEntity, workspaceAssessment, assessingUserEntity, userEntity, workspace, gradingScaleItem.getName());
    // Back to rest
    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) CompositeGradingScale(fi.otavanopisto.muikku.schooldata.entity.CompositeGradingScale) GradingScale(fi.otavanopisto.muikku.schooldata.entity.GradingScale) WorkspaceGradingScale(fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale) WorkspaceAssessment(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment) User(fi.otavanopisto.muikku.schooldata.entity.User) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem) RestAssessment(fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessment) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) PUT(javax.ws.rs.PUT)

Example 17 with GradingScaleItem

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

the class Evaluation2RESTService method createWorkspaceAssessment.

@POST
@Path("/workspace/{WORKSPACEENTITYID}/user/{USERENTITYID}/assessment")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createWorkspaceAssessment(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("USERENTITYID") Long userEntityId, RestAssessment payload) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.ACCESS_EVALUATION)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    // Entities and identifiers
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    UserEntity userEntity = userEntityController.findUserEntityById(userEntityId);
    Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
    if (workspaceEntity == null || userEntity == null || workspace == 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);
    // Workspace user
    WorkspaceUser workspaceUser = workspaceController.findWorkspaceUserByWorkspaceAndUser(workspaceIdentifier, userIdentifier);
    // Assessor
    SchoolDataIdentifier assessorIdentifier = SchoolDataIdentifier.fromId(payload.getAssessorIdentifier());
    User assessingUser = userController.findUserByIdentifier(assessorIdentifier);
    UserEntity assessingUserEntity = assessingUser == null ? null : userEntityController.findUserEntityByUser(assessingUser);
    // Grade
    SchoolDataIdentifier gradingScaleIdentifier = SchoolDataIdentifier.fromId(payload.getGradingScaleIdentifier());
    GradingScale gradingScale = gradingController.findGradingScale(gradingScaleIdentifier);
    SchoolDataIdentifier gradeIdentifier = SchoolDataIdentifier.fromId(payload.getGradeIdentifier());
    GradingScaleItem gradingScaleItem = gradingController.findGradingScaleItem(gradingScale, gradeIdentifier);
    if (workspaceAssessment == null) {
        workspaceAssessment = gradingController.createWorkspaceAssessment(workspaceIdentifier.getDataSource(), workspaceUser, assessingUser, gradingScaleItem, payload.getVerbalAssessment(), payload.getAssessmentDate());
    } else {
        workspaceAssessment = gradingController.updateWorkspaceAssessment(workspaceAssessment.getIdentifier(), workspaceUser, assessingUser, gradingScaleItem, payload.getVerbalAssessment(), payload.getAssessmentDate());
    }
    // Delete workspace supplementation request (if any)
    SupplementationRequest supplementationRequest = evaluationController.findSupplementationRequestByStudentAndWorkspace(userEntity.getId(), workspaceEntity.getId());
    if (supplementationRequest != null) {
        evaluationController.deleteSupplementationRequest(supplementationRequest);
    }
    // Notification
    sendAssessmentNotification(workspaceEntity, workspaceAssessment, assessingUserEntity, userEntity, workspace, gradingScaleItem.getName());
    // Back to rest
    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) CompositeGradingScale(fi.otavanopisto.muikku.schooldata.entity.CompositeGradingScale) GradingScale(fi.otavanopisto.muikku.schooldata.entity.GradingScale) WorkspaceGradingScale(fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale) WorkspaceAssessment(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment) User(fi.otavanopisto.muikku.schooldata.entity.User) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem) RestAssessment(fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessment) SupplementationRequest(fi.otavanopisto.muikku.plugins.evaluation.model.SupplementationRequest) RestSupplementationRequest(fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestSupplementationRequest) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) 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