Search in sources :

Example 1 with WorkspaceAssessment

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

the class Evaluation2RESTService method deleteWorkspaceAssessment.

@DELETE
@Path("/workspace/{WORKSPACEENTITYID}/user/{USERENTITYID}/evaluationdata")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response deleteWorkspaceAssessment(@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();
    }
    // 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());
    // If the workspace user has been given a graded evaluation, remove that
    // 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) {
        gradingController.deleteWorkspaceAssessment(workspaceIdentifier, userIdentifier, workspaceAssessment.getIdentifier());
    }
    // If the workspace user has been given a supplementation request, remove that
    SupplementationRequest supplementationRequest = evaluationController.findSupplementationRequestByStudentAndWorkspace(userEntityId, workspaceEntityId);
    if (supplementationRequest != null) {
        evaluationController.deleteSupplementationRequest(supplementationRequest);
    }
    // If student has assessment requests, restore the latest one (issue #2716)
    gradingController.restoreLatestAssessmentRequest(workspaceIdentifier, userIdentifier);
    return Response.noContent().build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) WorkspaceAssessment(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) 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) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.security.rest.RESTPermit)

Example 2 with WorkspaceAssessment

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

the class Evaluation2RESTService method createWorkspaceSupplementationRequest.

@POST
@Path("/workspace/{WORKSPACEENTITYID}/user/{USERENTITYID}/supplementationrequest")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createWorkspaceSupplementationRequest(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("USERENTITYID") Long userEntityId, RestSupplementationRequest payload) {
    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.BAD_REQUEST).build();
    }
    // Workspace supplementation request
    SupplementationRequest supplementationRequest = evaluationController.findSupplementationRequestByStudentAndWorkspace(userEntityId, workspaceEntityId);
    if (supplementationRequest == null) {
        supplementationRequest = evaluationController.createSupplementationRequest(payload.getUserEntityId(), payload.getStudentEntityId(), payload.getWorkspaceEntityId(), null, payload.getRequestDate(), payload.getRequestText());
    } else {
        supplementationRequest = evaluationController.updateSupplementationRequest(supplementationRequest, payload.getUserEntityId(), payload.getRequestDate(), payload.getRequestText());
    }
    // Delete possible workspace assessment
    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) {
        gradingController.deleteWorkspaceAssessment(workspaceIdentifier, userIdentifier, workspaceAssessment.getIdentifier());
    }
    // 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 : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) WorkspaceAssessment(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment) 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) POST(javax.ws.rs.POST)

Example 3 with WorkspaceAssessment

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

the class VopsLister method processCourse.

private VopsRESTModel.VopsEntry processCourse(Subject subject, int courseNumber) {
    VopsRESTModel.VopsEntry transferCreditEntry = processTransferCredits(subject, courseNumber);
    if (transferCreditEntry != null) {
        return transferCreditEntry;
    }
    List<VopsWorkspace> workspaces = vopsController.listWorkspaceIdentifiersBySubjectIdentifierAndCourseNumber(subject.getSchoolDataSource(), subject.getIdentifier(), courseNumber);
    List<WorkspaceAssessment> workspaceAssessments = new ArrayList<>();
    if (curriculumIdentifier != null) {
        workspaces.removeIf((VopsWorkspace workspace) -> !workspace.getCurriculumIdentifiers().contains(curriculumIdentifier));
    }
    if (!workspaces.isEmpty()) {
        SchoolDataIdentifier educationSubtypeIdentifier = null;
        boolean workspaceUserExists = false;
        String name = "";
        String description = "";
        boolean canSignUp = false;
        for (VopsWorkspace workspace : workspaces) {
            WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspace.getWorkspaceIdentifier());
            WorkspaceUserEntity workspaceUser = workspaceUserEntityController.findWorkspaceUserByWorkspaceEntityAndUserIdentifier(workspaceEntity, studentIdentifier);
            WorkspaceAssessment workspaceAssesment = studentAssessments.get(workspace.getWorkspaceIdentifier());
            List<UserGroupEntity> userGroupEntities = userGroupEntityController.listUserGroupsByUserIdentifier(studentIdentifier);
            Permission permission = permissionController.findByName(MuikkuPermissions.WORKSPACE_SIGNUP);
            for (UserGroupEntity userGroupEntity : userGroupEntities) {
                if (permissionController.hasWorkspaceGroupPermission(workspaceEntity, userGroupEntity, permission)) {
                    canSignUp = true;
                    break;
                }
            }
            if (workspaceAssesment != null) {
                workspaceAssessments.add(workspaceAssesment);
            }
            if (workspaceUser != null) {
                workspaceUserExists = true;
            }
        }
        for (VopsWorkspace workspace : workspaces) {
            name = workspace.getName();
            if (name != null) {
                break;
            }
        }
        for (VopsWorkspace workspace : workspaces) {
            description = workspace.getDescription();
            if (description != null) {
                break;
            }
        }
        for (VopsWorkspace workspace : workspaces) {
            educationSubtypeIdentifier = workspace.getEducationSubtypeIdentifier();
            if (educationSubtypeIdentifier != null) {
                break;
            }
        }
        Mandatority mandatority = educationTypeMapping.getMandatority(educationSubtypeIdentifier);
        CourseCompletionState state = CourseCompletionState.NOT_ENROLLED;
        String grade = null;
        if (workspaceUserExists) {
            state = CourseCompletionState.ENROLLED;
        }
        for (WorkspaceAssessment workspaceAssessment : workspaceAssessments) {
            if (!Boolean.TRUE.equals(workspaceAssessment.getPassing())) {
                state = CourseCompletionState.FAILED;
                break;
            }
        }
        for (WorkspaceAssessment workspaceAssessment : workspaceAssessments) {
            if (Boolean.TRUE.equals(workspaceAssessment.getPassing())) {
                state = CourseCompletionState.ASSESSED;
                numCourses++;
                if (mandatority == Mandatority.MANDATORY) {
                    numMandatoryCourses++;
                }
                SchoolDataIdentifier gradingScaleIdentifier = workspaceAssessment.getGradingScaleIdentifier();
                if (gradingScaleIdentifier == null) {
                    break;
                }
                SchoolDataIdentifier gradeIdentifier = workspaceAssessment.getGradeIdentifier();
                if (gradeIdentifier == null) {
                    break;
                }
                GradingScaleItem gradingScaleItem = findGradingScaleItemCached(gradingScaleIdentifier, gradeIdentifier);
                String gradeName = gradingScaleItem.getName();
                if (!StringUtils.isBlank(gradeName)) {
                    if (gradeName.length() > 2)
                        grade = gradeName.substring(0, 2);
                    else
                        grade = gradeName;
                }
                break;
            }
        }
        if (state == CourseCompletionState.NOT_ENROLLED && !canSignUp) {
            return new VopsRESTModel.VopsPlaceholder();
        }
        StudiesViewCourseChoice courseChoice = studiesViewCourseChoiceController.find(new SchoolDataIdentifier(subject.getIdentifier(), subject.getSchoolDataSource()).toId(), courseNumber, studentIdentifierString);
        if (state == CourseCompletionState.NOT_ENROLLED && courseChoice != null) {
            state = CourseCompletionState.PLANNED;
        }
        return new VopsRESTModel.VopsItem(courseNumber, state, educationSubtypeIdentifier != null ? educationSubtypeIdentifier.toId() : null, mandatority, grade, workspaceUserExists, clean(name), clean(description));
    }
    return new VopsRESTModel.VopsPlaceholder();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) WorkspaceAssessment(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem) ArrayList(java.util.ArrayList) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) StudiesViewCourseChoice(fi.otavanopisto.muikku.plugins.transcriptofrecords.model.StudiesViewCourseChoice) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Mandatority(fi.otavanopisto.muikku.plugins.transcriptofrecords.rest.Mandatority) Permission(fi.otavanopisto.muikku.model.security.Permission) VopsRESTModel(fi.otavanopisto.muikku.plugins.transcriptofrecords.rest.VopsRESTModel) CourseCompletionState(fi.otavanopisto.muikku.plugins.transcriptofrecords.rest.CourseCompletionState)

Example 4 with WorkspaceAssessment

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

the class PyramusGradingSchoolDataBridge method createWorkspaceAssessment.

@Override
public WorkspaceAssessment createWorkspaceAssessment(String workspaceUserIdentifier, String workspaceUserSchoolDataSource, String workspaceIdentifier, String studentIdentifier, String assessingUserIdentifier, String assessingUserSchoolDataSource, String gradeIdentifier, String gradeSchoolDataSource, String gradingScaleIdentifier, String gradingScaleSchoolDataSource, String verbalAssessment, Date date) {
    Long courseStudentId = identifierMapper.getPyramusCourseStudentId(workspaceUserIdentifier);
    Long assessingUserId = identifierMapper.getPyramusStaffId(assessingUserIdentifier);
    Long courseId = identifierMapper.getPyramusCourseId(workspaceIdentifier);
    Long studentId = identifierMapper.getPyramusStudentId(studentIdentifier);
    Long gradeId = identifierMapper.getPyramusGradeId(gradeIdentifier);
    Long gradingScaleId = identifierMapper.getPyramusGradingScaleId(gradingScaleIdentifier);
    if (courseStudentId == null) {
        logger.severe(String.format("Could not translate %s to Pyramus course student", workspaceUserIdentifier));
        return null;
    }
    if (assessingUserId == null) {
        logger.severe(String.format("Could not translate %s to Pyramus staff member", assessingUserIdentifier));
        return null;
    }
    if (courseId == null) {
        logger.severe(String.format("Could not translate %s to Pyramus course", workspaceIdentifier));
        return null;
    }
    if (studentId == null) {
        logger.severe(String.format("Could not translate %s to Pyramus student", studentIdentifier));
        return null;
    }
    if (gradeId == null) {
        logger.severe(String.format("Could not translate %s to Pyramus grade", gradeIdentifier));
        return null;
    }
    if (gradingScaleId == null) {
        logger.severe(String.format("Could not translate %s to Pyramus grading scale", gradingScaleIdentifier));
        return null;
    }
    Grade grade = pyramusClient.get(String.format("/common/gradingScales/%d/grades/%d", gradingScaleId, gradeId), fi.otavanopisto.pyramus.rest.model.Grade.class);
    if (grade == null) {
        logger.severe(String.format("Could not create workspace assessment because grade %d could not be found from Pyramus", gradeId));
        return null;
    }
    CourseAssessment courseAssessment = new CourseAssessment(null, courseStudentId, gradeId, gradingScaleId, assessingUserId, fromDateToOffsetDateTime(date), verbalAssessment, grade.getPassingGrade());
    WorkspaceAssessment workspaceAssessment = entityFactory.createEntity(pyramusClient.post(String.format("/students/students/%d/courses/%d/assessments/", studentId, courseId), courseAssessment));
    updateParticipationTypeByGrade(courseStudentId, courseId, grade);
    return workspaceAssessment;
}
Also used : WorkspaceAssessment(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment) CompositeGrade(fi.otavanopisto.muikku.schooldata.entity.CompositeGrade) PyramusCompositeGrade(fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusCompositeGrade) Grade(fi.otavanopisto.pyramus.rest.model.Grade) CourseAssessment(fi.otavanopisto.pyramus.rest.model.CourseAssessment)

Example 5 with WorkspaceAssessment

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

the class TranscriptofRecordsRESTService method getVops.

@GET
@Path("/vops/{IDENTIFIER}")
@RESTPermit(handling = Handling.INLINE)
public Response getVops(@PathParam("IDENTIFIER") String studentIdentifierString) {
    String educationTypeMappingString = pluginSettingsController.getPluginSetting("transcriptofrecords", "educationTypeMapping");
    EducationTypeMapping educationTypeMapping = new EducationTypeMapping();
    if (educationTypeMappingString != null) {
        try {
            educationTypeMapping = new ObjectMapper().readValue(educationTypeMappingString, EducationTypeMapping.class);
        } catch (IOException e) {
            return Response.status(Status.INTERNAL_SERVER_ERROR).entity("Education type mapping not set").build();
        }
    }
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.FORBIDDEN).entity("Must be logged in").build();
    }
    SchoolDataIdentifier studentIdentifier = SchoolDataIdentifier.fromId(studentIdentifierString);
    if (studentIdentifier == null) {
        return Response.status(Status.NOT_FOUND).entity("Student identifier not found").build();
    }
    if (!sessionController.hasEnvironmentPermission(TranscriptofRecordsPermissions.TRANSCRIPT_OF_RECORDS_VIEW_ANY_STUDENT_STUDIES) && !Objects.equals(sessionController.getLoggedUser(), studentIdentifier)) {
        return Response.status(Status.FORBIDDEN).entity("Can only look at own information").build();
    }
    User student = userController.findUserByIdentifier(studentIdentifier);
    if (!vopsController.shouldShowStudies(student)) {
        VopsRESTModel result = new VopsRESTModel(null, 0, 0, false);
        return Response.ok(result).build();
    }
    List<TransferCredit> transferCredits = new ArrayList<>(gradingController.listStudentTransferCredits(studentIdentifier));
    List<Subject> subjects = courseMetaController.listSubjects();
    Map<SchoolDataIdentifier, WorkspaceAssessment> studentAssessments = vopsController.listStudentAssessments(studentIdentifier);
    String curriculum = pluginSettingsController.getPluginSetting("transcriptofrecords", "curriculum");
    SchoolDataIdentifier curriculumIdentifier = null;
    if (curriculum != null) {
        curriculumIdentifier = SchoolDataIdentifier.fromId(curriculum);
    }
    final List<String> subjectList = new ArrayList<String>();
    String commaSeparatedSubjectsOrder = pluginSettingsController.getPluginSetting("transcriptofrecords", "subjectsOrder");
    if (!StringUtils.isBlank(commaSeparatedSubjectsOrder)) {
        subjectList.addAll(Arrays.asList(commaSeparatedSubjectsOrder.split(",")));
    }
    subjects.sort(new Comparator<Subject>() {

        public int compare(Subject o1, Subject o2) {
            int i1 = subjectList.indexOf(o1.getCode());
            int i2 = subjectList.indexOf(o2.getCode());
            i1 = i1 == -1 ? Integer.MAX_VALUE : i1;
            i2 = i2 == -1 ? Integer.MAX_VALUE : i2;
            return i1 < i2 ? -1 : i1 == i2 ? 0 : 1;
        }
    });
    VopsLister lister = new VopsLister(subjects, vopsController, student, transferCredits, curriculumIdentifier, workspaceController, workspaceUserEntityController, studentIdentifier, studentAssessments, userGroupEntityController, permissionController, studiesViewCourseChoiceController, studentIdentifierString, gradingController, educationTypeMapping);
    lister.performListing();
    VopsRESTModel result = new VopsRESTModel(lister.getRows(), lister.getNumCourses(), lister.getNumMandatoryCourses(), lister.isOptedIn());
    return Response.ok(result).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) WorkspaceAssessment(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment) User(fi.otavanopisto.muikku.schooldata.entity.User) EnvironmentUser(fi.otavanopisto.muikku.model.users.EnvironmentUser) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Subject(fi.otavanopisto.muikku.schooldata.entity.Subject) VopsLister(fi.otavanopisto.muikku.plugins.transcriptofrecords.VopsLister) TransferCredit(fi.otavanopisto.muikku.schooldata.entity.TransferCredit) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Aggregations

WorkspaceAssessment (fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment)12 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)10 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)9 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)7 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)6 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)6 Path (javax.ws.rs.Path)6 SupplementationRequest (fi.otavanopisto.muikku.plugins.evaluation.model.SupplementationRequest)4 GradingScaleItem (fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem)4 User (fi.otavanopisto.muikku.schooldata.entity.User)4 RestAssessment (fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessment)3 RestSupplementationRequest (fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestSupplementationRequest)3 GradingScale (fi.otavanopisto.muikku.schooldata.entity.GradingScale)3 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)3 WorkspaceAssessmentRequest (fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest)3 ArrayList (java.util.ArrayList)3 WorkspaceGradingScale (fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale)2 CompositeGradingScale (fi.otavanopisto.muikku.schooldata.entity.CompositeGradingScale)2 WorkspaceUser (fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser)2 HashMap (java.util.HashMap)2