use of fi.otavanopisto.muikku.plugins.transcriptofrecords.VopsLister 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();
}
Aggregations