Search in sources :

Example 6 with Course

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

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

Example 8 with Course

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

the class PyramusWorkspaceSchoolDataBridge method listWorkspaces.

@Override
public List<Workspace> listWorkspaces() {
    List<Workspace> result = new ArrayList<Workspace>();
    Course[] courses = pyramusClient.get("/courses/courses/", Course[].class);
    if (courses != null) {
        for (Course course : courses) {
            result.add(createWorkspaceEntity(course));
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Course(fi.otavanopisto.pyramus.rest.model.Course) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace)

Example 9 with Course

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

the class PyramusWorkspaceSchoolDataBridge method updateWorkspace.

@Override
public Workspace updateWorkspace(Workspace workspace) {
    Long pyramusCourseId = identifierMapper.getPyramusCourseId(workspace.getIdentifier());
    if (pyramusCourseId == null) {
        logger.severe(String.format("Workspace identifier %s is not valid", workspace.getIdentifier()));
        return null;
    }
    Long typeId = identifierMapper.getPyramusCourseTypeId(workspace.getWorkspaceTypeId());
    Long lengthUnitId = identifierMapper.getPyramusEducationalTimeUnitId(workspace.getLengthUnitIdentifier());
    Long subjectId = identifierMapper.getPyramusSubjectId(workspace.getSubjectIdentifier());
    Course course = pyramusClient.get(String.format("/courses/courses/%d", pyramusCourseId), Course.class);
    course.setName(workspace.getName());
    course.setNameExtension(workspace.getNameExtension());
    course.setDescription(workspace.getDescription());
    course.setBeginDate(workspace.getBeginDate());
    course.setEndDate(workspace.getEndDate());
    course.setLength(workspace.getLength());
    course.setLengthUnitId(lengthUnitId);
    course.setTypeId(typeId);
    course.setSubjectId(subjectId);
    Course updatedCourse = pyramusClient.put(String.format("/courses/courses/%d", pyramusCourseId), course);
    if (updatedCourse == null) {
        logger.severe(String.format("Workspace %s updating failed", workspace.getIdentifier()));
        return null;
    }
    return createWorkspaceEntity(updatedCourse);
}
Also used : Course(fi.otavanopisto.pyramus.rest.model.Course)

Example 10 with Course

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

the class PyramusMocks method workspacePyramusMock.

public static void workspacePyramusMock(Long id, String name, String description) throws Exception {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    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, name, created, created, description, 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);
    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);
    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)));
    stubFor(put(urlEqualTo(String.format("/1/courses/courses/%d", id))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(courseJson).withStatus(200)));
    mockStudyProgrammes();
    mockCommons();
    mockCourseTypes();
    String payload = objectMapper.writeValueAsString(new WebhookCourseCreatePayload(course.getId()));
    TestUtilities.webhookCall("http://dev.muikku.fi:" + System.getProperty("it.port.http") + "/pyramus/webhook", payload);
}
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)

Aggregations

Course (fi.otavanopisto.pyramus.rest.model.Course)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 JSR310Module (com.fasterxml.jackson.datatype.jsr310.JSR310Module)5 OffsetDateTime (java.time.OffsetDateTime)5 ArrayList (java.util.ArrayList)5 WebhookCourseCreatePayload (fi.otavanopisto.pyramus.webhooks.WebhookCourseCreatePayload)4 TestEnvironments (fi.otavanopisto.muikku.TestEnvironments)3 Workspace (fi.otavanopisto.muikku.atests.Workspace)3 Builder (fi.otavanopisto.muikku.mock.PyramusMock.Builder)3 MockStaffMember (fi.otavanopisto.muikku.mock.model.MockStaffMember)3 AbstractUITest (fi.otavanopisto.muikku.ui.AbstractUITest)3 Test (org.junit.Test)3 PyramusCourseIdentifier (fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusCourseIdentifier)2 SchoolDataBridgeInternalException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException)2 CourseIdentifier (fi.otavanopisto.muikku.schooldata.entity.CourseIdentifier)2 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)2 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)1 PyramusSubject (fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusSubject)1 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)1 Subject (fi.otavanopisto.muikku.schooldata.entity.Subject)1