Search in sources :

Example 1 with EducationSubtype

use of fi.otavanopisto.pyramus.rest.model.EducationSubtype in project muikku by otavanopisto.

the class PyramusWorkspaceSchoolDataBridge method createWorkspaceEntity.

private Workspace createWorkspaceEntity(Course course) {
    if (course == null)
        return null;
    SchoolDataIdentifier educationTypeIdentifier = null;
    SchoolDataIdentifier educationSubtypeIdentifier = null;
    if (course.getSubjectId() != null) {
        Subject subject = pyramusClient.get("/common/subjects/" + course.getSubjectId(), fi.otavanopisto.pyramus.rest.model.Subject.class);
        if (subject == null) {
            logger.severe(String.format("Subject with id %d not found", course.getSubjectId()));
        } else {
            educationTypeIdentifier = identifierMapper.getEducationTypeIdentifier(subject.getEducationTypeId());
        }
    }
    Map<String, List<String>> courseEducationTypeMap = new HashMap<String, List<String>>();
    CourseEducationType[] courseEducationTypes = pyramusClient.get(String.format("/courses/courses/%d/educationTypes", course.getId()), CourseEducationType[].class);
    if (courseEducationTypes != null) {
        for (CourseEducationType courseEducationType : courseEducationTypes) {
            // #1632: if subject didn't determine education type and course only has one education type, use that instead
            if (educationTypeIdentifier == null && courseEducationTypes.length == 1) {
                educationTypeIdentifier = identifierMapper.getEducationTypeIdentifier(courseEducationTypes[0].getEducationTypeId());
            }
            CourseEducationSubtype[] courseEducationSubtypes = pyramusClient.get(String.format("/courses/courses/%d/educationTypes/%d/educationSubtypes", course.getId(), courseEducationType.getId()), CourseEducationSubtype[].class);
            if (courseEducationSubtypes == null) {
                continue;
            }
            if (educationSubtypeIdentifier == null && courseEducationSubtypes.length == 1) {
                educationSubtypeIdentifier = identifierMapper.getEducationSubtypeIdentifier(courseEducationSubtypes[0].getEducationSubtypeId());
            }
            EducationType educationType = pyramusClient.get(String.format("/common/educationTypes/%d", courseEducationType.getEducationTypeId()), EducationType.class);
            if (educationType == null) {
                logger.severe(String.format("Could not find educationType %d", courseEducationType.getEducationTypeId()));
                continue;
            }
            String educationTypeCode = educationType.getCode();
            List<String> courseEducationSubtypeList = new ArrayList<String>();
            for (CourseEducationSubtype courseEducationSubtype : courseEducationSubtypes) {
                EducationSubtype educationSubtype = pyramusClient.get(String.format("/common/educationTypes/%d/subtypes/%d", educationType.getId(), courseEducationSubtype.getEducationSubtypeId()), EducationSubtype.class);
                if (educationSubtype != null) {
                    String educationSubtypeCode = educationSubtype.getCode();
                    courseEducationSubtypeList.add(educationSubtypeCode);
                } else {
                    logger.severe(String.format("Could not find education subtype %d from type %d", courseEducationSubtype.getEducationSubtypeId(), educationType.getId()));
                }
            }
            courseEducationTypeMap.put(educationTypeCode, courseEducationSubtypeList);
        }
    }
    return entityFactory.createEntity(course, educationTypeIdentifier, educationSubtypeIdentifier, courseEducationTypeMap);
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) CourseEducationType(fi.otavanopisto.pyramus.rest.model.CourseEducationType) EducationType(fi.otavanopisto.pyramus.rest.model.EducationType) CourseEducationType(fi.otavanopisto.pyramus.rest.model.CourseEducationType) HashMap(java.util.HashMap) CourseEducationSubtype(fi.otavanopisto.pyramus.rest.model.CourseEducationSubtype) EducationSubtype(fi.otavanopisto.pyramus.rest.model.EducationSubtype) CourseEducationSubtype(fi.otavanopisto.pyramus.rest.model.CourseEducationSubtype) ArrayList(java.util.ArrayList) Subject(fi.otavanopisto.pyramus.rest.model.Subject) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)1 CourseEducationSubtype (fi.otavanopisto.pyramus.rest.model.CourseEducationSubtype)1 CourseEducationType (fi.otavanopisto.pyramus.rest.model.CourseEducationType)1 EducationSubtype (fi.otavanopisto.pyramus.rest.model.EducationSubtype)1 EducationType (fi.otavanopisto.pyramus.rest.model.EducationType)1 Subject (fi.otavanopisto.pyramus.rest.model.Subject)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1