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();
}
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;
}
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();
}
}
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();
}
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));
}
Aggregations