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