Search in sources :

Example 1 with StudentGroup

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

the class PyramusUpdater method updateStudentGroup.

public void updateStudentGroup(Long pyramusId) {
    StudentGroup studentGroup = pyramusClient.get().get(String.format("/students/studentGroups/%d", pyramusId), StudentGroup.class);
    String identifier = identifierMapper.getStudentGroupIdentifier(pyramusId);
    UserGroupEntity userGroupEntity = userGroupEntityController.findUserGroupEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, identifier, true);
    if (studentGroup == null) {
        if (userGroupEntity != null)
            fireUserGroupRemoved(identifier);
    } else {
        if (userGroupEntity == null) {
            fireUserGroupDiscovered(identifier);
        } else {
            fireUserGroupUpdated(identifier);
        }
    }
}
Also used : UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) StudentGroup(fi.otavanopisto.pyramus.rest.model.StudentGroup)

Example 2 with StudentGroup

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

the class PyramusMocks method studentGroupsMocks.

public static void studentGroupsMocks() throws JsonProcessingException {
    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 lastmodified = OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
    StudentGroup studentGroupStudents = new StudentGroup((long) 1, "Opiskelijat", "Spring 2015 Students", begin, (long) 1, created, (long) 1, lastmodified, null, false, false);
    StudentGroup studentGroupAnother = new StudentGroup((long) 2, "Opiskelijat 2", "Spring 2015 Students 2", begin, (long) 1, created, (long) 1, lastmodified, null, false, false);
    StudentGroup[] studentGroupArray = { studentGroupStudents, studentGroupAnother };
    String studentGroupsJson = objectMapper.writeValueAsString(studentGroupArray);
    stubFor(get(urlMatching("/1/students/studentGroups")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(studentGroupsJson).withStatus(200)));
}
Also used : OffsetDateTime(java.time.OffsetDateTime) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StudentGroup(fi.otavanopisto.pyramus.rest.model.StudentGroup)

Example 3 with StudentGroup

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

the class PyramusMocksRest method mockUserGroups.

public static void mockUserGroups(List<String> payloads) throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    OffsetDateTime begin = OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
    Long creatorId = 1l;
    Long groupId = 2l;
    StudentGroup studentGroup = new StudentGroup(groupId, "Group1", "", begin, creatorId, begin, creatorId, begin, null, false, false);
    StudentGroup[] studentGroups = new StudentGroup[] { studentGroup };
    stubFor(get(urlEqualTo("/1/students/studentGroups")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(studentGroups)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/students/studentGroups/%d", groupId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(studentGroup)).withStatus(200)));
    addPayload(payloads, objectMapper.writeValueAsString(new WebhookStudentGroupCreatePayload(groupId)));
    StudentGroupUser studentGroupStaffMember = new StudentGroupUser(1l, 4l);
    StudentGroupUser[] studentGroupStaffMembers = { studentGroupStaffMember };
    stubFor(get(urlEqualTo(String.format("/1/students/studentGroups/%d/staffmembers", groupId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(studentGroupStaffMembers)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/students/studentGroups/%d/staffmembers/%d", groupId, studentGroupStaffMember.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(studentGroupStaffMember)).withStatus(200)));
    addPayload(payloads, objectMapper.writeValueAsString(new WebhookStudentGroupStaffMemberCreatePayload(studentGroupStaffMember.getId(), groupId, studentGroupStaffMember.getStaffMemberId())));
    StudentGroupStudent studentGroupStudent = new StudentGroupStudent(2l, 1l);
    StudentGroupStudent[] studentGroupStudents = { studentGroupStudent };
    stubFor(get(urlEqualTo(String.format("/1/students/studentGroups/%d/students", groupId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(studentGroupStudents)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/students/studentGroups/%d/students/%d", groupId, studentGroupStudent.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(studentGroupStudent)).withStatus(200)));
    addPayload(payloads, objectMapper.writeValueAsString(new WebhookStudentGroupStudentCreatePayload(studentGroupStudent.getId(), groupId, studentGroupStudent.getStudentId())));
}
Also used : WebhookStudentGroupCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookStudentGroupCreatePayload) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) WebhookStudentGroupStudentCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookStudentGroupStudentCreatePayload) StudentGroupStudent(fi.otavanopisto.pyramus.rest.model.StudentGroupStudent) OffsetDateTime(java.time.OffsetDateTime) StudentGroupUser(fi.otavanopisto.pyramus.rest.model.StudentGroupUser) WebhookStudentGroupStaffMemberCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookStudentGroupStaffMemberCreatePayload) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StudentGroup(fi.otavanopisto.pyramus.rest.model.StudentGroup)

Aggregations

StudentGroup (fi.otavanopisto.pyramus.rest.model.StudentGroup)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JSR310Module (com.fasterxml.jackson.datatype.jsr310.JSR310Module)2 OffsetDateTime (java.time.OffsetDateTime)2 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)1 StudentGroupStudent (fi.otavanopisto.pyramus.rest.model.StudentGroupStudent)1 StudentGroupUser (fi.otavanopisto.pyramus.rest.model.StudentGroupUser)1 WebhookStudentGroupCreatePayload (fi.otavanopisto.pyramus.webhooks.WebhookStudentGroupCreatePayload)1 WebhookStudentGroupStaffMemberCreatePayload (fi.otavanopisto.pyramus.webhooks.WebhookStudentGroupStaffMemberCreatePayload)1 WebhookStudentGroupStudentCreatePayload (fi.otavanopisto.pyramus.webhooks.WebhookStudentGroupStudentCreatePayload)1