Search in sources :

Example 1 with StudiesViewCourseChoice

use of fi.otavanopisto.muikku.plugins.transcriptofrecords.model.StudiesViewCourseChoice 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 2 with StudiesViewCourseChoice

use of fi.otavanopisto.muikku.plugins.transcriptofrecords.model.StudiesViewCourseChoice in project muikku by otavanopisto.

the class StudiesViewCourseChoiceDAO method create.

public StudiesViewCourseChoice create(String subjectSchoolDataIdentifier, int courseNumber, String studentSchoolDataIdentifier) {
    EntityManager entityManager = getEntityManager();
    StudiesViewCourseChoice studiesViewCourseChoice = new StudiesViewCourseChoice(subjectSchoolDataIdentifier, courseNumber, studentSchoolDataIdentifier);
    entityManager.persist(studiesViewCourseChoice);
    return studiesViewCourseChoice;
}
Also used : EntityManager(javax.persistence.EntityManager) StudiesViewCourseChoice(fi.otavanopisto.muikku.plugins.transcriptofrecords.model.StudiesViewCourseChoice)

Example 3 with StudiesViewCourseChoice

use of fi.otavanopisto.muikku.plugins.transcriptofrecords.model.StudiesViewCourseChoice in project muikku by otavanopisto.

the class TranscriptofRecordsRESTService method unplanCourse.

@DELETE
@Path("/plannedCourses/")
@RESTPermit(handling = Handling.INLINE)
public Response unplanCourse(VopsPlannedCourseRESTModel model) {
    SchoolDataIdentifier loggedUserIdentifier = sessionController.getLoggedUser();
    boolean hasPermission = Objects.equals(loggedUserIdentifier.toId(), model.getStudentIdentifier());
    if (!hasPermission) {
        return Response.status(Status.FORBIDDEN).entity("You don't have the permission to access this").build();
    }
    StudiesViewCourseChoice choice = studiesViewCourseChoiceController.find(model.getSubjectIdentifier(), model.getCourseNumber(), model.getStudentIdentifier());
    if (choice != null) {
        studiesViewCourseChoiceController.delete(choice);
        return Response.ok().build();
    } else {
        return Response.status(Status.NOT_FOUND).build();
    }
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) StudiesViewCourseChoice(fi.otavanopisto.muikku.plugins.transcriptofrecords.model.StudiesViewCourseChoice) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.security.rest.RESTPermit)

Example 4 with StudiesViewCourseChoice

use of fi.otavanopisto.muikku.plugins.transcriptofrecords.model.StudiesViewCourseChoice in project muikku by otavanopisto.

the class TranscriptofRecordsRESTService method planCourse.

@POST
@Path("/plannedCourses/")
@RESTPermit(handling = Handling.INLINE)
public Response planCourse(VopsPlannedCourseRESTModel model) {
    SchoolDataIdentifier loggedUserIdentifier = sessionController.getLoggedUser();
    boolean hasPermission = Objects.equals(loggedUserIdentifier.toId(), model.getStudentIdentifier());
    if (!hasPermission) {
        return Response.status(Status.FORBIDDEN).entity("You don't have the permission to access this").build();
    }
    StudiesViewCourseChoice choice = studiesViewCourseChoiceController.find(model.getSubjectIdentifier(), model.getCourseNumber(), model.getStudentIdentifier());
    if (choice == null) {
        studiesViewCourseChoiceController.create(model.getSubjectIdentifier(), model.getCourseNumber(), model.getStudentIdentifier());
    }
    return Response.ok(model).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) StudiesViewCourseChoice(fi.otavanopisto.muikku.plugins.transcriptofrecords.model.StudiesViewCourseChoice) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 5 with StudiesViewCourseChoice

use of fi.otavanopisto.muikku.plugins.transcriptofrecords.model.StudiesViewCourseChoice in project muikku by otavanopisto.

the class StudiesViewCourseChoiceDAO method find.

public StudiesViewCourseChoice find(String subjectSchoolDataIdentifier, int courseNumber, String studentSchoolDataIdentifier) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<StudiesViewCourseChoice> criteria = criteriaBuilder.createQuery(StudiesViewCourseChoice.class);
    Root<StudiesViewCourseChoice> root = criteria.from(StudiesViewCourseChoice.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(StudiesViewCourseChoice_.subjectSchoolDataIdentifier), subjectSchoolDataIdentifier), criteriaBuilder.equal(root.get(StudiesViewCourseChoice_.courseNumber), courseNumber), criteriaBuilder.equal(root.get(StudiesViewCourseChoice_.studentSchoolDataIdentifier), studentSchoolDataIdentifier)));
    return getSingleResult(entityManager.createQuery(criteria));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) StudiesViewCourseChoice(fi.otavanopisto.muikku.plugins.transcriptofrecords.model.StudiesViewCourseChoice)

Aggregations

StudiesViewCourseChoice (fi.otavanopisto.muikku.plugins.transcriptofrecords.model.StudiesViewCourseChoice)5 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)3 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)2 EntityManager (javax.persistence.EntityManager)2 Path (javax.ws.rs.Path)2 Permission (fi.otavanopisto.muikku.model.security.Permission)1 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)1 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)1 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)1 CourseCompletionState (fi.otavanopisto.muikku.plugins.transcriptofrecords.rest.CourseCompletionState)1 Mandatority (fi.otavanopisto.muikku.plugins.transcriptofrecords.rest.Mandatority)1 VopsRESTModel (fi.otavanopisto.muikku.plugins.transcriptofrecords.rest.VopsRESTModel)1 GradingScaleItem (fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem)1 WorkspaceAssessment (fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment)1 ArrayList (java.util.ArrayList)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1