Search in sources :

Example 1 with TransferCredit

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

the class UserRESTService method searchStudentTransferCredits.

@GET
@Path("/students/{ID}/transferCredits")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response searchStudentTransferCredits(@PathParam("ID") String id, @QueryParam("curriculumEmpty") @DefaultValue("true") Boolean curriculumEmpty, @QueryParam("curriculumIdentifier") String curriculumIdentifier) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    SchoolDataIdentifier studentIdentifier = SchoolDataIdentifier.fromId(id);
    if (studentIdentifier == null) {
        return Response.status(Response.Status.BAD_REQUEST).entity(String.format("Invalid studentIdentifier %s", id)).build();
    }
    UserEntity studentEntity = userEntityController.findUserEntityByUserIdentifier(studentIdentifier);
    if (studentEntity == null) {
        return Response.status(Response.Status.BAD_REQUEST).entity(String.format("Could not find user entity for identifier %s", id)).build();
    }
    if (!studentEntity.getId().equals(sessionController.getLoggedUserEntity().getId())) {
        if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.LIST_STUDENT_TRANSFER_CREDITS)) {
            return Response.status(Status.FORBIDDEN).build();
        }
    }
    List<TransferCredit> transferCredits = new ArrayList<TransferCredit>(gradingController.listStudentTransferCredits(studentIdentifier));
    for (int i = transferCredits.size() - 1; i >= 0; i--) {
        TransferCredit tc = transferCredits.get(i);
        SchoolDataIdentifier tcCurriculum = tc.getCurriculumIdentifier();
        if (tcCurriculum != null) {
            if (!StringUtils.isEmpty(curriculumIdentifier) && !Objects.equals(tcCurriculum.toId(), curriculumIdentifier)) {
                transferCredits.remove(i);
            }
        } else {
            if (!curriculumEmpty)
                transferCredits.remove(i);
        }
    }
    return Response.ok(createRestModel(transferCredits.toArray(new TransferCredit[0]))).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) ArrayList(java.util.ArrayList) TransferCredit(fi.otavanopisto.muikku.schooldata.entity.TransferCredit) 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 2 with TransferCredit

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

the class VopsLister method processTransferCredits.

private VopsRESTModel.VopsEntry processTransferCredits(Subject subject, int courseNumber) {
    for (TransferCredit transferCredit : transferCredits) {
        boolean subjectsMatch = Objects.equals(transferCredit.getSubjectIdentifier(), new SchoolDataIdentifier(subject.getIdentifier(), subject.getSchoolDataSource()));
        boolean courseNumbersMatch = Objects.equals(transferCredit.getCourseNumber(), courseNumber);
        if (subjectsMatch && courseNumbersMatch) {
            String grade = "";
            GradingScaleItem gradingScaleItem = null;
            Mandatority mandatority = Mandatority.MANDATORY;
            if (transferCredit.getOptionality() == Optionality.OPTIONAL) {
                mandatority = Mandatority.UNSPECIFIED_OPTIONAL;
            }
            if (transferCredit.getGradeIdentifier() != null && transferCredit.getGradingScaleIdentifier() != null) {
                gradingScaleItem = findGradingScaleItemCached(transferCredit.getGradingScaleIdentifier(), transferCredit.getGradeIdentifier());
                String gradeName = gradingScaleItem.getName();
                if (!StringUtils.isBlank(gradeName)) {
                    if (gradeName.length() > 2)
                        grade = gradeName.substring(0, 2);
                    else
                        grade = gradeName;
                }
            }
            numCourses++;
            if (mandatority == Mandatority.MANDATORY) {
                numMandatoryCourses++;
            }
            return new VopsRESTModel.VopsItem(courseNumber, CourseCompletionState.ASSESSED, (String) null, mandatority, grade, false, transferCredit.getCourseName(), "");
        }
    }
    return null;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) Mandatority(fi.otavanopisto.muikku.plugins.transcriptofrecords.rest.Mandatority) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem) TransferCredit(fi.otavanopisto.muikku.schooldata.entity.TransferCredit)

Example 3 with TransferCredit

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

SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)3 TransferCredit (fi.otavanopisto.muikku.schooldata.entity.TransferCredit)3 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 EnvironmentUser (fi.otavanopisto.muikku.model.users.EnvironmentUser)1 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)1 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)1 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)1 VopsLister (fi.otavanopisto.muikku.plugins.transcriptofrecords.VopsLister)1 Mandatority (fi.otavanopisto.muikku.plugins.transcriptofrecords.rest.Mandatority)1 GradingScaleItem (fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem)1 Subject (fi.otavanopisto.muikku.schooldata.entity.Subject)1 User (fi.otavanopisto.muikku.schooldata.entity.User)1 WorkspaceAssessment (fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment)1 IOException (java.io.IOException)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1