Search in sources :

Example 1 with StudentGroupUser

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

the class PyramusUpdater method updateStudentGroupStaffMember.

public void updateStudentGroupStaffMember(Long studentGroupId, Long studentGroupStaffMemberId) {
    StudentGroupUser studentGroupStaffMember = pyramusClient.get().get(String.format("/students/studentGroups/%d/staffmembers/%d", studentGroupId, studentGroupStaffMemberId), StudentGroupUser.class);
    String identifier = identifierMapper.getStudentGroupStaffMemberIdentifier(studentGroupStaffMemberId);
    UserGroupUserEntity userGroupUserEntity = userGroupEntityController.findUserGroupUserEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, identifier);
    String userGroupIdentifier = identifierMapper.getStudentGroupIdentifier(studentGroupId);
    if (studentGroupStaffMember == null) {
        if (userGroupUserEntity != null)
            fireUserGroupUserRemoved(identifier, userGroupIdentifier, userGroupUserEntity.getUserSchoolDataIdentifier().getIdentifier());
    } else {
        if (userGroupUserEntity == null) {
            String staffMemberIdentifier = identifierMapper.getStaffIdentifier(studentGroupStaffMember.getStaffMemberId());
            fireUserGroupUserDiscovered(identifier, userGroupIdentifier, staffMemberIdentifier);
        } else {
            fireUserGroupUserUpdated(identifier, userGroupIdentifier, userGroupUserEntity.getUserSchoolDataIdentifier().getIdentifier());
        }
    }
}
Also used : UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) StudentGroupUser(fi.otavanopisto.pyramus.rest.model.StudentGroupUser)

Example 2 with StudentGroupUser

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

the class PyramusUpdater method updateStudentGroupUsers.

public int updateStudentGroupUsers(Long studentGroupId) {
    String userGroupIdentifier = identifierMapper.getStudentGroupIdentifier(studentGroupId);
    UserGroupEntity userGroupEntity = userGroupEntityController.findUserGroupEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, userGroupIdentifier, true);
    if (userGroupEntity != null) {
        if (userGroupEntity.getArchived()) {
            // Just skip archived user groups
            return 0;
        }
        List<UserGroupUserEntity> existingUsers = userGroupEntityController.listUserGroupUserEntitiesByUserGroupEntity(userGroupEntity);
        List<String> existingGroupUserIds = new ArrayList<String>();
        for (UserGroupUserEntity existingUser : existingUsers) {
            existingGroupUserIds.add(existingUser.getIdentifier());
        }
        List<String> foundGroupUserIds = new ArrayList<String>();
        int count = 0;
        StudentGroupUser[] userGroupStaffMembers = pyramusClient.get().get(String.format("/students/studentGroups/%d/staffmembers", studentGroupId), StudentGroupUser[].class);
        if (userGroupStaffMembers != null) {
            for (StudentGroupUser sgStaffMember : userGroupStaffMembers) {
                String identifier = identifierMapper.getStudentGroupStaffMemberIdentifier(sgStaffMember.getId());
                foundGroupUserIds.add(identifier);
                // If not existing, then it's a new one
                if (!existingGroupUserIds.contains(identifier)) {
                    String staffMemberIdentifier = identifierMapper.getStaffIdentifier(sgStaffMember.getStaffMemberId());
                    fireUserGroupUserDiscovered(identifier, userGroupIdentifier, staffMemberIdentifier);
                }
            }
            count += userGroupStaffMembers.length;
        }
        StudentGroupStudent[] userGroupStudents = pyramusClient.get().get(String.format("/students/studentGroups/%d/students", studentGroupId), StudentGroupStudent[].class);
        if (userGroupStudents != null) {
            for (StudentGroupStudent sgs : userGroupStudents) {
                String identifier = identifierMapper.getStudentGroupStudentIdentifier(sgs.getId());
                foundGroupUserIds.add(identifier);
                // If not existing, then it's a new one
                if (!existingGroupUserIds.contains(identifier)) {
                    String studentIdentifier = identifierMapper.getStudentIdentifier(sgs.getStudentId());
                    fireUserGroupUserDiscovered(identifier, userGroupIdentifier, studentIdentifier);
                }
            }
            count += userGroupStudents.length;
        }
        // Remove found ids from existing and we'll get the ones to remove
        existingGroupUserIds.removeAll(foundGroupUserIds);
        for (String identifier : existingGroupUserIds) {
            UserGroupUserEntity ugu = userGroupEntityController.findUserGroupUserEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, identifier);
            if (ugu != null)
                fireUserGroupUserRemoved(identifier, userGroupIdentifier, ugu.getUserSchoolDataIdentifier().getIdentifier());
        }
        return count;
    } else {
        logger.log(Level.WARNING, String.format("UserGroup is null for id %d - update of users is skipped", studentGroupId));
    }
    return 0;
}
Also used : StudentGroupStudent(fi.otavanopisto.pyramus.rest.model.StudentGroupStudent) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) ArrayList(java.util.ArrayList) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) StudentGroupUser(fi.otavanopisto.pyramus.rest.model.StudentGroupUser)

Example 3 with StudentGroupUser

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

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