Search in sources :

Example 1 with PyramusCourseIdentifier

use of fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusCourseIdentifier in project muikku by otavanopisto.

the class PyramusCourseMetaSchoolDataBridge method findCourseIdentifier.

@Override
public CourseIdentifier findCourseIdentifier(String identifier) {
    if (StringUtils.isBlank(identifier)) {
        return null;
    }
    if (identifier.indexOf("/") == -1)
        throw new SchoolDataBridgeInternalException("Invalid CourseIdentifierId");
    String[] idParts = identifier.split("/");
    fi.otavanopisto.pyramus.rest.model.Subject subject = pyramusClient.get("/common/subjects/" + idParts[0], fi.otavanopisto.pyramus.rest.model.Subject.class);
    return new PyramusCourseIdentifier(identifier, subject.getCode() + idParts[1], subject.getId().toString());
}
Also used : PyramusCourseIdentifier(fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusCourseIdentifier) SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException)

Example 2 with PyramusCourseIdentifier

use of fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusCourseIdentifier in project muikku by otavanopisto.

the class PyramusCourseMetaSchoolDataBridge method listCourseIdentifiers.

@Override
public List<CourseIdentifier> listCourseIdentifiers() {
    List<CourseIdentifier> result = new ArrayList<>();
    fi.otavanopisto.pyramus.rest.model.Subject[] subjects = pyramusClient.get("/common/subjects/", fi.otavanopisto.pyramus.rest.model.Subject[].class);
    if (subjects != null) {
        for (fi.otavanopisto.pyramus.rest.model.Subject subject : subjects) {
            List<String> courseNumbers = new ArrayList<String>();
            String identifier = subject.getId().toString();
            Course[] courses = pyramusClient.get("/common/subjects/" + identifier + "/courses", fi.otavanopisto.pyramus.rest.model.Course[].class);
            if (courses != null) {
                for (Course course : courses) {
                    String courseNumber = course.getCourseNumber() != null ? course.getCourseNumber().toString() : "null";
                    if (!courseNumbers.contains(courseNumber))
                        courseNumbers.add(courseNumber);
                }
                for (String cn : courseNumbers) {
                    result.add(new PyramusCourseIdentifier(subject.getId().toString() + "/" + cn, subject.getCode(), subject.getId().toString()));
                }
            }
        }
    }
    return result;
}
Also used : PyramusCourseIdentifier(fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusCourseIdentifier) ArrayList(java.util.ArrayList) PyramusCourseIdentifier(fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusCourseIdentifier) CourseIdentifier(fi.otavanopisto.muikku.schooldata.entity.CourseIdentifier) Subject(fi.otavanopisto.muikku.schooldata.entity.Subject) PyramusSubject(fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusSubject) Course(fi.otavanopisto.pyramus.rest.model.Course)

Example 3 with PyramusCourseIdentifier

use of fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusCourseIdentifier in project muikku by otavanopisto.

the class PyramusCourseMetaSchoolDataBridge method listCourseIdentifiersBySubject.

@Override
public List<CourseIdentifier> listCourseIdentifiersBySubject(String subjectIdentifier) {
    if (!StringUtils.isNumeric(subjectIdentifier)) {
        throw new SchoolDataBridgeInternalException("Identifier has to be numeric");
    }
    // TODO Fix workaround
    fi.otavanopisto.pyramus.rest.model.Subject subject = pyramusClient.get("/common/subjects/" + subjectIdentifier, fi.otavanopisto.pyramus.rest.model.Subject.class);
    List<CourseIdentifier> result = new ArrayList<>();
    List<String> courseNumbers = new ArrayList<String>();
    String identifier = subject.getId().toString();
    Course[] courses = pyramusClient.get("/common/subjects/" + identifier + "/courses", fi.otavanopisto.pyramus.rest.model.Course[].class);
    for (Course course : courses) {
        String courseNumber = course.getCourseNumber() != null ? course.getCourseNumber().toString() : "null";
        if (!courseNumbers.contains(courseNumber))
            courseNumbers.add(courseNumber);
    }
    for (String cn : courseNumbers) {
        result.add(new PyramusCourseIdentifier(subject.getId().toString() + "/" + cn, subject.getCode(), subject.getId().toString()));
    }
    return result;
}
Also used : PyramusCourseIdentifier(fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusCourseIdentifier) ArrayList(java.util.ArrayList) PyramusCourseIdentifier(fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusCourseIdentifier) CourseIdentifier(fi.otavanopisto.muikku.schooldata.entity.CourseIdentifier) SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) Course(fi.otavanopisto.pyramus.rest.model.Course)

Aggregations

PyramusCourseIdentifier (fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusCourseIdentifier)3 SchoolDataBridgeInternalException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException)2 CourseIdentifier (fi.otavanopisto.muikku.schooldata.entity.CourseIdentifier)2 Course (fi.otavanopisto.pyramus.rest.model.Course)2 ArrayList (java.util.ArrayList)2 PyramusSubject (fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusSubject)1 Subject (fi.otavanopisto.muikku.schooldata.entity.Subject)1