Search in sources :

Example 26 with WorkspaceEntity

use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.

the class Evaluation2RESTService method findWorkspaceSupplementationRequest.

@GET
@Path("/workspace/{WORKSPACEENTITYID}/user/{USERENTITYID}/supplementationrequest")
@RESTPermit(handling = Handling.INLINE)
public Response findWorkspaceSupplementationRequest(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("USERENTITYID") Long userEntityId) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.ACCESS_EVALUATION)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    // User entity
    UserEntity userEntity = userEntityController.findUserEntityById(userEntityId);
    if (userEntity == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    // Workspace entity
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).entity("workspaceEntity not found").build();
    }
    // Workspace supplementation request
    SupplementationRequest supplementationRequest = evaluationController.findSupplementationRequestByStudentAndWorkspace(userEntityId, workspaceEntityId);
    if (supplementationRequest == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    // SupplementationRequest to RestSupplementationRequest
    RestSupplementationRequest restSupplementationRequest = new RestSupplementationRequest(supplementationRequest.getId(), supplementationRequest.getUserEntityId(), supplementationRequest.getStudentEntityId(), supplementationRequest.getWorkspaceEntityId(), supplementationRequest.getWorkspaceMaterialId(), supplementationRequest.getRequestDate(), supplementationRequest.getRequestText());
    return Response.ok(restSupplementationRequest).build();
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) RestSupplementationRequest(fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestSupplementationRequest) SupplementationRequest(fi.otavanopisto.muikku.plugins.evaluation.model.SupplementationRequest) RestSupplementationRequest(fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestSupplementationRequest) 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)

Example 27 with WorkspaceEntity

use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.

the class EvaluationController method handleSupplementationNotifications.

/**
 * Handles all notification messages related to the given supplementation request.
 *
 * @param supplementationRequest Supplementation request
 */
private void handleSupplementationNotifications(SupplementationRequest supplementationRequest) {
    Long teacherEntityId = supplementationRequest.getUserEntityId();
    Long studentEntityId = supplementationRequest.getStudentEntityId();
    Long workspaceEntityId = supplementationRequest.getWorkspaceEntityId();
    Long workspaceMaterialId = supplementationRequest.getWorkspaceMaterialId();
    String requestText = supplementationRequest.getRequestText();
    if (studentEntityId != null && workspaceMaterialId != null) {
        UserEntity student = userEntityController.findUserEntityById(studentEntityId);
        WorkspaceMaterial workspaceMaterial = workspaceMaterialController.findWorkspaceMaterialById(workspaceMaterialId);
        if (student != null && workspaceMaterial != null) {
            WorkspaceMaterialReply reply = workspaceMaterialReplyController.findWorkspaceMaterialReplyByWorkspaceMaterialAndUserEntity(workspaceMaterial, student);
            if (reply == null) {
                workspaceMaterialReplyController.createWorkspaceMaterialReply(workspaceMaterial, WorkspaceMaterialReplyState.INCOMPLETE, student);
            } else {
                workspaceMaterialReplyController.updateWorkspaceMaterialReply(reply, WorkspaceMaterialReplyState.INCOMPLETE);
            }
        }
    } else if (studentEntityId != null && workspaceEntityId != null) {
        // Send notification of an incomplete workspace
        UserEntity teacher = userEntityController.findUserEntityById(teacherEntityId);
        UserEntity student = userEntityController.findUserEntityById(studentEntityId);
        WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
        notifyOfIncompleteWorkspace(teacher, student, workspaceEntity, requestText);
    }
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceMaterialReply(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialReply) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)

Example 28 with WorkspaceEntity

use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.

the class EvaluationMainViewBackingBean method init.

@RequestAction
public String init() {
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    if (userEntity == null) {
        return NavigationRules.ACCESS_DENIED;
    }
    WorkspaceEntity workspaceEntity = null;
    if (workspaceEntityId != null) {
        workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
        if (workspaceEntity == null) {
            return NavigationRules.NOT_FOUND;
        }
        Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
        if (workspace == null) {
            return NavigationRules.NOT_FOUND;
        }
        setWorkspaceName(workspace.getName());
        if (!StringUtils.isEmpty(workspace.getNameExtension())) {
            setWorkspaceName(getWorkspaceName() + String.format(" (%s)", workspace.getNameExtension()));
        }
    }
    if (workspaceEntity == null) {
        if (!sessionController.hasEnvironmentPermission(EvaluationResourcePermissionCollection.EVALUATION_VIEW_INDEX)) {
            return NavigationRules.ACCESS_DENIED;
        }
    } else {
        if (!sessionController.hasWorkspacePermission(EvaluationResourcePermissionCollection.EVALUATION_VIEW_INDEX, workspaceEntity)) {
            return NavigationRules.ACCESS_DENIED;
        }
    }
    return null;
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Example 29 with WorkspaceEntity

use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.

the class EvaluationRESTService method listWorkspaceGrades.

@GET
@Path("/workspaces/{WORKSPACEENTITYID}/gradingScales")
@RESTPermit(handling = Handling.INLINE)
public Response listWorkspaceGrades(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId) {
    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_LISTGRADINGSCALES, workspaceEntity)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    List<WorkspaceGradingScale> result = new ArrayList<>();
    List<GradingScale> gradingScales = gradingController.listGradingScales();
    for (GradingScale gradingScale : gradingScales) {
        List<GradingScaleItem> gradingScaleItems = gradingController.listGradingScaleItems(gradingScale);
        List<WorkspaceGrade> workspaceGrades = new ArrayList<>();
        for (GradingScaleItem gradingScaleItem : gradingScaleItems) {
            workspaceGrades.add(new WorkspaceGrade(gradingScaleItem.getName(), gradingScaleItem.getIdentifier(), gradingScaleItem.getSchoolDataSource()));
        }
        result.add(new WorkspaceGradingScale(gradingScale.getName(), gradingScale.getIdentifier(), gradingScale.getSchoolDataSource(), workspaceGrades));
    }
    return Response.ok(result).build();
}
Also used : WorkspaceGrade(fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGrade) 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) ArrayList(java.util.ArrayList) WorkspaceGradingScale(fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 30 with WorkspaceEntity

use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.

the class EvaluationRESTService method updateWorkspaceAssessment.

@PUT
@Path("/workspaces/{WORKSPACEENTITYID}/students/{STUDENTID}/assessments/{EVALUATIONID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response updateWorkspaceAssessment(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("STUDENTID") String studentId, @PathParam("EVALUATIONID") String workspaceAssesmentId, 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();
    }
    SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
    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();
    }
    SchoolDataIdentifier workspaceAssesmentIdentifier = SchoolDataIdentifier.fromId(workspaceAssesmentId);
    if (workspaceAssesmentIdentifier == null) {
        return Response.status(Status.BAD_REQUEST).entity(String.format("Malformed workspace assessment identifier %s", workspaceAssesmentIdentifier)).build();
    }
    fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment workspaceAssessment = gradingController.findWorkspaceAssessment(workspaceIdentifier, studentIdentifier, workspaceAssesmentIdentifier);
    if (workspaceAssessment == null) {
        return Response.status(Status.NOT_FOUND).entity(String.format("Could not find workspace assessment %s from workspace entity %d, student identifer %s", workspaceAssesmentId, workspaceEntityId, studentIdentifier)).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();
    }
    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();
    }
    if (payload.getGradeSchoolDataSource() == null) {
        return Response.status(Status.BAD_REQUEST).entity("gradeSchoolDataSource is missing").build();
    }
    GradingScale gradingScale = gradingController.findGradingScale(payload.getGradingScaleSchoolDataSource(), payload.getGradingScaleIdentifier());
    if (gradingScale == null) {
        return Response.status(Status.BAD_REQUEST).entity("gradingScale is invalid").build();
    }
    if (payload.getGradeIdentifier() == null) {
        return Response.status(Status.BAD_REQUEST).entity("gradeIdentifier is missing").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.updateWorkspaceAssessment(workspaceAssesmentIdentifier, 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) PUT(javax.ws.rs.PUT)

Aggregations

WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)190 Path (javax.ws.rs.Path)102 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)82 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)65 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)51 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)49 GET (javax.ws.rs.GET)46 ArrayList (java.util.ArrayList)38 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)29 POST (javax.ws.rs.POST)26 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)25 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)21 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)21 WorkspaceForumArea (fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea)20 RequestAction (org.ocpsoft.rewrite.annotation.RequestAction)19 ForumArea (fi.otavanopisto.muikku.plugins.forum.model.ForumArea)17 Date (java.util.Date)17 DELETE (javax.ws.rs.DELETE)17 PUT (javax.ws.rs.PUT)16 WorkspaceRootFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder)15