Search in sources :

Example 1 with Subject

use of fi.otavanopisto.pyramus.rest.model.Subject 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)

Example 2 with Subject

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

the class PyramusMocks method mockCommons.

public static void mockCommons() throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    Subject subject = new Subject((long) 1, "tc_11", "Test course", (long) 1, false);
    String subjectJson = objectMapper.writeValueAsString(subject);
    stubFor(get(urlMatching("/1/common/subjects/.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(subjectJson).withStatus(200)));
    Subject[] subjectArray = { subject };
    String subjectArrayJson = objectMapper.writeValueAsString(subjectArray);
    stubFor(get(urlEqualTo("/1/common/subjects")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(subjectArrayJson).withStatus(200)));
    EducationType educationType = new EducationType((long) 1, "testEduType", "ET", false);
    String educationTypeJson = objectMapper.writeValueAsString(educationType);
    stubFor(get(urlEqualTo("/1/common/educationTypes/1")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(educationTypeJson).withStatus(200)));
    EducationType[] educationTypeArray = { educationType };
    String educationTypeArrayJson = objectMapper.writeValueAsString(educationTypeArray);
    stubFor(get(urlEqualTo("/1/common/educationTypes")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(educationTypeArrayJson).withStatus(200)));
    EducationalTimeUnit educationalTimeUnit = new EducationalTimeUnit((long) 1, "test time unit", "h", (double) 1, false);
    String eduTimeUnitJson = objectMapper.writeValueAsString(educationalTimeUnit);
    stubFor(get(urlEqualTo("/1/common/educationalTimeUnits/1")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(eduTimeUnitJson).withStatus(200)));
    EducationalTimeUnit[] eduTimeUnitArray = { educationalTimeUnit };
    String eduTimeUnitArrayJson = objectMapper.writeValueAsString(eduTimeUnitArray);
    stubFor(get(urlEqualTo("/1/common/educationalTimeUnits")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(eduTimeUnitArrayJson).withStatus(200)));
    List<GradingScale> gradingScales = new ArrayList<GradingScale>();
    GradingScale gs = new GradingScale(1l, "Pass/Fail", "Passed or failed scale", false);
    gradingScales.add(gs);
    stubFor(get(urlEqualTo("/1/common/gradingScales")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(gradingScales)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/common/gradingScales/%d", gs.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(gs)).withStatus(200)));
    Grade grade1 = new Grade(1l, "Excellent", "Excellent answer showing expertise in area of study", 1l, true, "0", null, false);
    Grade grade2 = new Grade(2l, "Failed", "Failed answer. Not proving any expertise in the matter.", 1l, false, "1", null, false);
    List<Grade> grades = new ArrayList<Grade>();
    grades.add(grade1);
    grades.add(grade2);
    stubFor(get(urlEqualTo(String.format("/1/common/gradingScales/%d/grades", gs.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(grades)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/common/gradingScales/%d/grades/%d", gs.getId(), grade1.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(grade1)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/common/gradingScales/%d/grades/%d", gs.getId(), grade2.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(grade2)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/common/gradingScales/?filterArchived=true"))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(gradingScales)).withStatus(200)));
}
Also used : GradingScale(fi.otavanopisto.pyramus.rest.model.GradingScale) EducationType(fi.otavanopisto.pyramus.rest.model.EducationType) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) ArrayList(java.util.ArrayList) Grade(fi.otavanopisto.pyramus.rest.model.Grade) Subject(fi.otavanopisto.pyramus.rest.model.Subject) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EducationalTimeUnit(fi.otavanopisto.pyramus.rest.model.EducationalTimeUnit)

Example 3 with Subject

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

the class PyramusMocksRest method mockWorkspace.

public static void mockWorkspace(Long id, List<String> payloads) throws JsonProcessingException {
    OffsetDateTime created = OffsetDateTime.of(1990, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC);
    OffsetDateTime begin = OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
    OffsetDateTime end = OffsetDateTime.of(2050, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
    Course course = new Course(id, "testCourse", created, created, "test course for testing", false, 1, (long) 25, begin, end, "test extension", (double) 15, (double) 45, (double) 45, (double) 15, (double) 45, (double) 45, end, (long) 1, (long) 1, (long) 1, null, (double) 45, (long) 1, (long) 1, (long) 1, (long) 1, null, null);
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    String courseJson = objectMapper.writeValueAsString(course);
    stubFor(get(urlEqualTo(String.format("/1/courses/courses/%d", id))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseJson).withStatus(200)));
    Course[] courseArray = { course };
    String courseArrayJson = objectMapper.writeValueAsString(courseArray);
    addPayload(payloads, new WebhookCourseCreatePayload(id));
    stubFor(get(urlEqualTo("/1/courses/courses")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseArrayJson).withStatus(200)));
    stubFor(get(urlMatching("/1/courses/courses?filterArchived=false&firstResult=.*&maxResults=.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseArrayJson).withStatus(200)));
    Subject subject = new Subject((long) 1, "tc_11", "Test course", (long) 1, false);
    String subjectJson = objectMapper.writeValueAsString(subject);
    stubFor(get(urlMatching("/1/common/subjects/.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(subjectJson).withStatus(200)));
    Subject[] subjectArray = { subject };
    String subjectArrayJson = objectMapper.writeValueAsString(subjectArray);
    stubFor(get(urlEqualTo("/1/common/subjects")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(subjectArrayJson).withStatus(200)));
}
Also used : OffsetDateTime(java.time.OffsetDateTime) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) Course(fi.otavanopisto.pyramus.rest.model.Course) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WebhookCourseCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookCourseCreatePayload) Subject(fi.otavanopisto.pyramus.rest.model.Subject)

Aggregations

Subject (fi.otavanopisto.pyramus.rest.model.Subject)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JSR310Module (com.fasterxml.jackson.datatype.jsr310.JSR310Module)2 EducationType (fi.otavanopisto.pyramus.rest.model.EducationType)2 ArrayList (java.util.ArrayList)2 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)1 Course (fi.otavanopisto.pyramus.rest.model.Course)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 EducationalTimeUnit (fi.otavanopisto.pyramus.rest.model.EducationalTimeUnit)1 Grade (fi.otavanopisto.pyramus.rest.model.Grade)1 GradingScale (fi.otavanopisto.pyramus.rest.model.GradingScale)1 WebhookCourseCreatePayload (fi.otavanopisto.pyramus.webhooks.WebhookCourseCreatePayload)1 OffsetDateTime (java.time.OffsetDateTime)1 HashMap (java.util.HashMap)1 List (java.util.List)1