use of fi.otavanopisto.pyramus.koski.CreditStubCredit in project pyramus by otavanopisto.
the class KoskiInternetixLukioStudentHandler method findCourseType.
private LukionKurssinTyyppi findCourseType(Student student, CreditStub courseCredit, boolean national, LukionKurssinTyyppi... allowedValues) {
Set<LukionKurssinTyyppi> resolvedTypes = new HashSet<>();
for (CreditStubCredit credit : courseCredit.getCredits()) {
if (credit.getCredit() instanceof CourseAssessment) {
CourseAssessment courseAssessment = (CourseAssessment) credit.getCredit();
if (courseAssessment.getCourseStudent() != null && courseAssessment.getCourseStudent().getCourse() != null) {
Course course = courseAssessment.getCourseStudent().getCourse();
Set<Long> educationSubTypeIds = course.getCourseEducationTypes().stream().flatMap(educationType -> educationType.getCourseEducationSubtypes().stream().map(subType -> subType.getEducationSubtype().getId())).collect(Collectors.toSet());
for (Long educationSubTypeId : educationSubTypeIds) {
String mappedValue = settings.getCourseTypeMapping(educationSubTypeId);
if (mappedValue != null && EnumUtils.isValidEnum(LukionKurssinTyyppi.class, mappedValue)) {
resolvedTypes.add(LukionKurssinTyyppi.valueOf(mappedValue));
}
}
} else
logger.warning(String.format("CourseAssessment %d has no courseStudent or Course", courseAssessment.getId()));
} else if (credit.getCredit() instanceof TransferCredit) {
TransferCredit transferCredit = (TransferCredit) credit.getCredit();
if (national && transferCredit.getOptionality() == CourseOptionality.MANDATORY) {
resolvedTypes.add(LukionKurssinTyyppi.pakollinen);
} else {
resolvedTypes.add(LukionKurssinTyyppi.syventava);
}
} else {
logger.warning(String.format("Unknown credit type %s", credit.getClass().getSimpleName()));
}
}
Set<LukionKurssinTyyppi> allowedSet = new HashSet<>(Arrays.asList(allowedValues));
allowedSet.removeIf(element -> !resolvedTypes.contains(element));
if (allowedSet.size() == 0) {
logger.warning(String.format("Course %s has no feasible subtypes.", courseCredit.getCourseCode()));
koskiPersonLogDAO.create(student.getPerson(), student, KoskiPersonState.UNRESOLVABLE_SUBTYPES, new Date(), courseCredit.getCourseCode());
return allowedValues[0];
} else if (allowedSet.size() == 1) {
return allowedSet.iterator().next();
} else {
for (LukionKurssinTyyppi type : allowedValues) {
if (allowedSet.contains(type)) {
logger.warning(String.format("Course %s has several matching subtypes.", courseCredit.getCourseCode()));
koskiPersonLogDAO.create(student.getPerson(), student, KoskiPersonState.UNRESOLVABLE_SUBTYPES, new Date(), courseCredit.getCourseCode());
return type;
}
}
}
return allowedValues[0];
}
use of fi.otavanopisto.pyramus.koski.CreditStubCredit in project pyramus by otavanopisto.
the class AbstractKoskiLukioStudentHandler2019 method findCourseType.
private LukionKurssinTyyppi findCourseType(Student student, CreditStub courseCredit, boolean national, LukionKurssinTyyppi... allowedValues) {
Set<LukionKurssinTyyppi> resolvedTypes = new HashSet<>();
for (CreditStubCredit credit : courseCredit.getCredits()) {
if (credit.getCredit() instanceof CourseAssessment) {
CourseAssessment courseAssessment = (CourseAssessment) credit.getCredit();
if (courseAssessment.getCourseStudent() != null && courseAssessment.getCourseStudent().getCourse() != null) {
Course course = courseAssessment.getCourseStudent().getCourse();
Set<Long> educationSubTypeIds = course.getCourseEducationTypes().stream().flatMap(educationType -> educationType.getCourseEducationSubtypes().stream().map(subType -> subType.getEducationSubtype().getId())).collect(Collectors.toSet());
for (Long educationSubTypeId : educationSubTypeIds) {
String mappedValue = settings.getCourseTypeMapping2019(educationSubTypeId);
if (mappedValue != null && EnumUtils.isValidEnum(LukionKurssinTyyppi.class, mappedValue)) {
resolvedTypes.add(LukionKurssinTyyppi.valueOf(mappedValue));
}
}
} else {
logger.warning(String.format("CourseAssessment %d has no courseStudent or Course", courseAssessment.getId()));
}
} else if (credit.getCredit() instanceof TransferCredit) {
TransferCredit transferCredit = (TransferCredit) credit.getCredit();
if (national && transferCredit.getOptionality() == CourseOptionality.MANDATORY) {
resolvedTypes.add(LukionKurssinTyyppi.pakollinen);
} else {
// TODO Is this correct?
resolvedTypes.add(LukionKurssinTyyppi.syventava);
}
} else {
logger.warning(String.format("Unknown credit type %s", credit.getClass().getSimpleName()));
}
}
Set<LukionKurssinTyyppi> allowedSet = new HashSet<>(Arrays.asList(allowedValues));
allowedSet.removeIf(element -> !resolvedTypes.contains(element));
if (allowedSet.size() == 0) {
logger.warning(String.format("Course %s has no feasible subtypes.", courseCredit.getCourseCode()));
koskiPersonLogDAO.create(student.getPerson(), student, KoskiPersonState.UNRESOLVABLE_SUBTYPES, new Date(), courseCredit.getCourseCode());
return allowedValues[0];
} else if (allowedSet.size() == 1) {
return allowedSet.iterator().next();
} else {
for (LukionKurssinTyyppi type : allowedValues) {
if (allowedSet.contains(type)) {
logger.warning(String.format("Course %s has several matching subtypes.", courseCredit.getCourseCode()));
koskiPersonLogDAO.create(student.getPerson(), student, KoskiPersonState.UNRESOLVABLE_SUBTYPES, new Date(), courseCredit.getCourseCode());
return type;
}
}
}
return allowedValues[0];
}
use of fi.otavanopisto.pyramus.koski.CreditStubCredit in project pyramus by otavanopisto.
the class KoskiLukioStudentHandler method findCourseType.
private LukionKurssinTyyppi findCourseType(Student student, CreditStub courseCredit, boolean national, LukionKurssinTyyppi... allowedValues) {
Set<LukionKurssinTyyppi> resolvedTypes = new HashSet<>();
for (CreditStubCredit credit : courseCredit.getCredits()) {
if (credit.getCredit() instanceof CourseAssessment) {
CourseAssessment courseAssessment = (CourseAssessment) credit.getCredit();
if (courseAssessment.getCourseStudent() != null && courseAssessment.getCourseStudent().getCourse() != null) {
Course course = courseAssessment.getCourseStudent().getCourse();
Set<Long> educationSubTypeIds = course.getCourseEducationTypes().stream().flatMap(educationType -> educationType.getCourseEducationSubtypes().stream().map(subType -> subType.getEducationSubtype().getId())).collect(Collectors.toSet());
for (Long educationSubTypeId : educationSubTypeIds) {
String mappedValue = settings.getCourseTypeMapping(educationSubTypeId);
if (mappedValue != null && EnumUtils.isValidEnum(LukionKurssinTyyppi.class, mappedValue)) {
resolvedTypes.add(LukionKurssinTyyppi.valueOf(mappedValue));
}
}
} else
logger.warning(String.format("CourseAssessment %d has no courseStudent or Course", courseAssessment.getId()));
} else if (credit.getCredit() instanceof TransferCredit) {
TransferCredit transferCredit = (TransferCredit) credit.getCredit();
if (national && transferCredit.getOptionality() == CourseOptionality.MANDATORY) {
resolvedTypes.add(LukionKurssinTyyppi.pakollinen);
} else {
resolvedTypes.add(LukionKurssinTyyppi.syventava);
}
} else {
logger.warning(String.format("Unknown credit type %s", credit.getClass().getSimpleName()));
}
}
Set<LukionKurssinTyyppi> allowedSet = new HashSet<>(Arrays.asList(allowedValues));
allowedSet.removeIf(element -> !resolvedTypes.contains(element));
if (allowedSet.size() == 0) {
logger.warning(String.format("Course %s has no feasible subtypes.", courseCredit.getCourseCode()));
koskiPersonLogDAO.create(student.getPerson(), student, KoskiPersonState.UNRESOLVABLE_SUBTYPES, new Date(), courseCredit.getCourseCode());
return allowedValues[0];
} else if (allowedSet.size() == 1) {
return allowedSet.iterator().next();
} else {
for (LukionKurssinTyyppi type : allowedValues) {
if (allowedSet.contains(type)) {
logger.warning(String.format("Course %s has several matching subtypes.", courseCredit.getCourseCode()));
koskiPersonLogDAO.create(student.getPerson(), student, KoskiPersonState.UNRESOLVABLE_SUBTYPES, new Date(), courseCredit.getCourseCode());
return type;
}
}
}
return allowedValues[0];
}
Aggregations