use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit in project pyramus by otavanopisto.
the class KoskiStudentHandler method listCredits.
protected Map<OpiskelijanOPS, List<CreditStub>> listCredits(Student student, boolean listTransferCredits, boolean listCreditLinks, List<OpiskelijanOPS> orderedOPSs, OpiskelijanOPS defaultOPS, Predicate<Credit> filter) {
// Map of OPS -> CourseCode -> CreditStub
Map<OpiskelijanOPS, Map<String, CreditStub>> map = new HashMap<>();
Set<Long> filteredGrades = settings.getSettings().getKoski().getFilteredGrades();
List<CourseAssessment> courseAssessments = courseAssessmentDAO.listByStudent(student);
courseAssessments.stream().filter(filter).filter(credit -> !isFilteredGrade(credit, filteredGrades)).forEach(ca -> {
Course course = ca.getCourseStudent() != null ? ca.getCourseStudent().getCourse() : null;
Subject subject = course != null ? course.getSubject() : null;
OpiskelijanOPS creditOPS = resolveSingleOPSFromCredit(ca, orderedOPSs, defaultOPS);
if (creditOPS != null) {
Map<String, CreditStub> stubs = map.get(creditOPS);
if (stubs == null) {
map.put(creditOPS, stubs = new HashMap<>());
}
String courseCode = courseCode(subject, course.getCourseNumber(), ca.getId());
CreditStub stub;
if (!stubs.containsKey(courseCode)) {
stub = new CreditStub(courseCode, course.getCourseNumber(), course.getName(), subject);
stubs.put(courseCode, stub);
} else {
stub = stubs.get(courseCode);
}
Laajuus laajuus = kurssinLaajuus(course);
stub.addCredit(new CreditStubCredit(ca, Type.CREDIT, laajuus != null ? laajuus.getArvo() : 0, laajuus != null ? laajuus.getYksikko().getValue() : null));
} else {
logger.log(Level.WARNING, String.format("Couldn't resolve OPS for CourseAssessment %d", ca.getId()));
koskiPersonLogDAO.create(student.getPerson(), student, KoskiPersonState.UNRESOLVED_CREDIT_CURRICULUM, new Date(), course.getName());
}
});
if (listTransferCredits) {
List<TransferCredit> transferCredits = transferCreditDAO.listByStudent(student);
transferCredits.stream().filter(filter).filter(credit -> !isFilteredGrade(credit, filteredGrades)).forEach(tc -> {
OpiskelijanOPS creditOPS = resolveSingleOPSFromCredit(tc, orderedOPSs, defaultOPS);
if (creditOPS != null) {
Map<String, CreditStub> stubs = map.get(creditOPS);
if (stubs == null) {
map.put(creditOPS, stubs = new HashMap<>());
}
String courseCode = courseCode(tc.getSubject(), tc.getCourseNumber(), tc.getId());
CreditStub stub;
if (!stubs.containsKey(courseCode)) {
stub = new CreditStub(courseCode, tc.getCourseNumber(), tc.getCourseName(), tc.getSubject());
stubs.put(courseCode, stub);
} else {
stub = stubs.get(courseCode);
}
Laajuus laajuus = kurssinLaajuus(tc);
stub.addCredit(new CreditStubCredit(tc, Type.RECOGNIZED, laajuus != null ? laajuus.getArvo() : 0, laajuus != null ? laajuus.getYksikko().getValue() : null));
} else {
logger.log(Level.WARNING, String.format("Couldn't resolve OPS for TransferCredit %d", tc.getId()));
koskiPersonLogDAO.create(student.getPerson(), student, KoskiPersonState.UNRESOLVED_CREDIT_CURRICULUM, new Date(), tc.getCourseName());
}
});
}
if (listCreditLinks) {
List<CreditLink> creditLinks = creditLinkDAO.listByStudent(student);
creditLinks.stream().map(creditLink -> creditLink.getCredit()).filter(filter).filter(credit -> !isFilteredGrade(credit, filteredGrades)).forEach(credit -> {
Subject subject = null;
Integer courseNumber = null;
String courseName = null;
OpiskelijanOPS creditOPS = null;
Laajuus laajuus = null;
switch(credit.getCreditType()) {
case CourseAssessment:
CourseAssessment ca = (CourseAssessment) credit;
Course course = ca.getCourseStudent() != null ? ca.getCourseStudent().getCourse() : null;
subject = course != null ? course.getSubject() : null;
courseNumber = course.getCourseNumber();
courseName = course.getName();
laajuus = kurssinLaajuus(course);
creditOPS = resolveSingleOPSFromCredit(ca, orderedOPSs, defaultOPS);
break;
case TransferCredit:
TransferCredit tc = (TransferCredit) credit;
subject = tc.getSubject();
courseNumber = tc.getCourseNumber();
courseName = tc.getCourseName();
laajuus = kurssinLaajuus(tc);
creditOPS = resolveSingleOPSFromCredit(tc, orderedOPSs, defaultOPS);
break;
case ProjectAssessment:
break;
}
if (allNotNull(subject, courseNumber, courseName, creditOPS)) {
String courseCode = courseCode(subject, courseNumber, credit.getId());
CreditStub stub;
Map<String, CreditStub> stubs = map.get(creditOPS);
if (stubs == null) {
map.put(creditOPS, stubs = new HashMap<>());
}
if (!stubs.containsKey(courseCode)) {
stub = new CreditStub(courseCode, courseNumber, courseName, subject);
stubs.put(courseCode, stub);
} else {
stub = stubs.get(courseCode);
}
stub.addCredit(new CreditStubCredit(credit, Type.RECOGNIZED, laajuus != null ? laajuus.getArvo() : 0, laajuus != null ? laajuus.getYksikko().getValue() : null));
}
});
}
Map<OpiskelijanOPS, List<CreditStub>> result = new HashMap<>();
for (OpiskelijanOPS ops : map.keySet()) {
Map<String, CreditStub> stubs = map.get(ops);
List<CreditStub> stubList = new ArrayList<>(stubs.values());
stubList.sort((a, b) -> ObjectUtils.compare(a.getCourseNumber(), b.getCourseNumber()));
result.put(ops, stubList);
}
return result;
}
use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit in project pyramus by otavanopisto.
the class StudentTORController method constructStudentTOR.
public static StudentTOR constructStudentTOR(Student student) throws Exception {
CourseAssessmentDAO courseAssessmentDAO = DAOFactory.getInstance().getCourseAssessmentDAO();
TransferCreditDAO transferCreditDAO = DAOFactory.getInstance().getTransferCreditDAO();
CreditLinkDAO creditLinkDAO = DAOFactory.getInstance().getCreditLinkDAO();
List<CourseAssessment> courseAssessmentsByStudent = courseAssessmentDAO.listByStudent(student);
List<TransferCredit> transferCreditsByStudent = transferCreditDAO.listByStudent(student);
List<CreditLink> linkedCourseAssessmentByStudent = creditLinkDAO.listByStudentAndType(student, CreditType.CourseAssessment);
List<CreditLink> linkedTransferCreditsByStudent = creditLinkDAO.listByStudentAndType(student, CreditType.TransferCredit);
StudentTOR tor = new StudentTOR();
TORProblems problems = tor.getProblems();
for (CourseAssessment courseAssessment : courseAssessmentsByStudent) {
if (courseAssessment.getCourseStudent() != null && courseAssessment.getCourseStudent().getCourse() != null) {
Subject subject = courseAssessment.getCourseStudent().getCourse().getSubject();
Integer courseNumber = courseAssessment.getCourseStudent().getCourse().getCourseNumber();
Set<Curriculum> creditCurriculums = courseAssessment.getCourseStudent().getCourse().getCurriculums();
EducationalLength courseEducationalLength = courseAssessment.getCourseStudent().getCourse().getCourseLength();
Double courseLength = courseEducationalLength != null ? courseEducationalLength.getUnits() : null;
TORCourseLengthUnit courseLengthUnit = courseEducationalLength != null ? getCourseLengthUnit(courseEducationalLength.getUnit(), problems) : null;
addTORCredit(tor, student, subject, courseAssessment, courseNumber, creditCurriculums, courseLength, courseLengthUnit, problems);
}
}
for (TransferCredit transferCredit : transferCreditsByStudent) {
Subject subject = transferCredit.getSubject();
Integer courseNumber = transferCredit.getCourseNumber();
Set<Curriculum> creditCurriculums = transferCredit.getCurriculum() != null ? new HashSet<>(Arrays.asList(transferCredit.getCurriculum())) : Collections.emptySet();
EducationalLength courseEducationalLength = transferCredit.getCourseLength();
Double courseLength = courseEducationalLength != null ? courseEducationalLength.getUnits() : null;
TORCourseLengthUnit courseLengthUnit = courseEducationalLength != null ? getCourseLengthUnit(courseEducationalLength.getUnit(), problems) : null;
addTORCredit(tor, student, subject, transferCredit, courseNumber, creditCurriculums, courseLength, courseLengthUnit, problems);
}
for (CreditLink linkedCourseAssessment : linkedCourseAssessmentByStudent) {
CourseAssessment courseAssessment = (CourseAssessment) linkedCourseAssessment.getCredit();
if (courseAssessment != null && courseAssessment.getCourseStudent() != null && courseAssessment.getCourseStudent().getCourse() != null) {
Subject subject = courseAssessment.getCourseStudent().getCourse().getSubject();
Integer courseNumber = courseAssessment.getCourseStudent().getCourse().getCourseNumber();
Set<Curriculum> creditCurriculums = courseAssessment.getCourseStudent().getCourse().getCurriculums();
EducationalLength courseEducationalLength = courseAssessment.getCourseStudent().getCourse().getCourseLength();
Double courseLength = courseEducationalLength != null ? courseEducationalLength.getUnits() : null;
TORCourseLengthUnit courseLengthUnit = courseEducationalLength != null ? getCourseLengthUnit(courseEducationalLength.getUnit(), problems) : null;
addTORCredit(tor, student, subject, courseAssessment, courseNumber, creditCurriculums, courseLength, courseLengthUnit, problems);
}
}
for (CreditLink linkedTransferCredit : linkedTransferCreditsByStudent) {
TransferCredit transferCredit = (TransferCredit) linkedTransferCredit.getCredit();
if (transferCredit != null) {
Subject subject = transferCredit.getSubject();
Integer courseNumber = transferCredit.getCourseNumber();
Set<Curriculum> creditCurriculums = transferCredit.getCurriculum() != null ? new HashSet<>(Arrays.asList(transferCredit.getCurriculum())) : Collections.emptySet();
EducationalLength courseEducationalLength = transferCredit.getCourseLength();
Double courseLength = courseEducationalLength != null ? courseEducationalLength.getUnits() : null;
TORCourseLengthUnit courseLengthUnit = courseEducationalLength != null ? getCourseLengthUnit(courseEducationalLength.getUnit(), problems) : null;
addTORCredit(tor, student, subject, transferCredit, courseNumber, creditCurriculums, courseLength, courseLengthUnit, problems);
}
}
tor.postProcess();
return tor;
}
use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit in project pyramus by otavanopisto.
the class TransferCreditDAO method listByStudentAndSubjectAndCurriculumAndOptionality.
/**
* Lists student's transfer credits by student, subject, curriculum and optionality.
*
* Method exludes archived transfer credits
*
* @param student student
* @param subject subject
* @param curriculum curriculum if null, curriculum is ignored
* @param optionality optionality if null, optionality is ignored
* @return list of student's transfer credits
*/
public List<TransferCredit> listByStudentAndSubjectAndCurriculumAndOptionality(Student student, Subject subject, Curriculum curriculum, CourseOptionality optionality) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<TransferCredit> criteria = criteriaBuilder.createQuery(TransferCredit.class);
Root<TransferCredit> root = criteria.from(TransferCredit.class);
criteria.select(root);
List<Predicate> predicates = new ArrayList<>();
if (optionality != null) {
predicates.add(criteriaBuilder.equal(root.get(TransferCredit_.optionality), optionality));
}
if (curriculum != null) {
predicates.add(criteriaBuilder.equal(root.get(TransferCredit_.curriculum), curriculum));
}
predicates.add(criteriaBuilder.equal(root.get(TransferCredit_.archived), Boolean.FALSE));
predicates.add(criteriaBuilder.equal(root.get(TransferCredit_.student), student));
predicates.add(criteriaBuilder.equal(root.get(TransferCredit_.subject), subject));
criteria.where(criteriaBuilder.and(predicates.toArray(new Predicate[0])));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit in project pyramus by otavanopisto.
the class TransferCreditDAO method countByStudent.
public Long countByStudent(Student student) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> criteria = criteriaBuilder.createQuery(Long.class);
Root<TransferCredit> root = criteria.from(TransferCredit.class);
criteria.select(criteriaBuilder.count(root));
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(TransferCredit_.student), student), criteriaBuilder.equal(root.get(TransferCredit_.archived), Boolean.FALSE)));
return entityManager.createQuery(criteria).getSingleResult();
}
use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit in project pyramus by otavanopisto.
the class TransferCreditDAO method listByStudentAndCurriculumAndOptionality.
public List<TransferCredit> listByStudentAndCurriculumAndOptionality(Student student, Curriculum curriculum, CourseOptionality optionality) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<TransferCredit> criteria = criteriaBuilder.createQuery(TransferCredit.class);
Root<TransferCredit> root = criteria.from(TransferCredit.class);
criteria.select(root);
List<Predicate> predicates = new ArrayList<>();
if (optionality != null) {
predicates.add(criteriaBuilder.equal(root.get(TransferCredit_.optionality), optionality));
}
if (curriculum != null) {
predicates.add(criteriaBuilder.equal(root.get(TransferCredit_.curriculum), curriculum));
}
predicates.add(criteriaBuilder.equal(root.get(TransferCredit_.archived), Boolean.FALSE));
predicates.add(criteriaBuilder.equal(root.get(TransferCredit_.student), student));
criteria.where(criteriaBuilder.and(predicates.toArray(new Predicate[0])));
return entityManager.createQuery(criteria).getResultList();
}
Aggregations