Search in sources :

Example 1 with StudentGroupType

use of fi.otavanopisto.muikku.plugins.schooldatapyramus.PyramusIdentifierMapper.StudentGroupType in project muikku by otavanopisto.

the class PyramusSchoolDataUserListener method handlePyramusUserUpdated.

private void handlePyramusUserUpdated(SchoolDataIdentifier identifier) {
    Long pyramusStudentId = identifierMapper.getPyramusStudentId(identifier.getIdentifier());
    if (pyramusStudentId != null) {
        Student student = pyramusClient.get().get(String.format("/students/students/%d", pyramusStudentId), Student.class);
        if (student != null) {
            Long pyramusStudyProgrammeId = student.getStudyProgrammeId();
            if (pyramusStudyProgrammeId != null) {
                String userGroupIdentifier = identifierMapper.getStudyProgrammeIdentifier(pyramusStudyProgrammeId);
                boolean found = false;
                boolean isActive = !student.getArchived() && (student.getStudyEndDate() == null || student.getStudyEndDate().isAfter(OffsetDateTime.now()));
                if (!isActive) {
                    schoolDataUserInactiveEvent.fire(new SchoolDataUserInactiveEvent(identifier.getDataSource(), identifier.getIdentifier()));
                }
                // Remove StudyProgrammeGroups
                UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierByDataSourceAndIdentifier(identifier.getDataSource(), identifier.getIdentifier());
                List<UserGroupUserEntity> userGroupUsers = userGroupEntityController.listUserGroupUsersByUserSchoolDataIdentifier(userSchoolDataIdentifier);
                for (UserGroupUserEntity userGroupUser : userGroupUsers) {
                    UserGroupEntity userGroup = userGroupUser.getUserGroupEntity();
                    StudentGroupType studentGroupType = identifierMapper.getStudentGroupType(userGroup.getIdentifier());
                    if (studentGroupType == StudentGroupType.STUDYPROGRAMME) {
                        boolean archived = Boolean.TRUE.equals(userGroupUser.getArchived());
                        if (!archived && !isActive) {
                            fireUserGroupUserRemoved(userGroupUser.getIdentifier(), userGroup.getIdentifier(), identifier.getIdentifier());
                        } else {
                            found = !archived;
                        }
                    }
                }
                if (!found && isActive) {
                    String userGroupUserIdentifier = identifierMapper.getStudyProgrammeStudentIdentifier(pyramusStudentId);
                    fireUserGroupUserDiscovered(userGroupUserIdentifier, userGroupIdentifier, identifier.getIdentifier());
                }
            }
        }
    }
}
Also used : SchoolDataUserInactiveEvent(fi.otavanopisto.muikku.schooldata.events.SchoolDataUserInactiveEvent) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) Student(fi.otavanopisto.pyramus.rest.model.Student) StudentGroupType(fi.otavanopisto.muikku.plugins.schooldatapyramus.PyramusIdentifierMapper.StudentGroupType)

Example 2 with StudentGroupType

use of fi.otavanopisto.muikku.plugins.schooldatapyramus.PyramusIdentifierMapper.StudentGroupType in project muikku by otavanopisto.

the class PyramusSchoolDataUserListener method handlePyramusUserRemoved.

private void handlePyramusUserRemoved(SchoolDataIdentifier identifier) {
    UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierByDataSourceAndIdentifier(identifier.getDataSource(), identifier.getIdentifier());
    List<UserGroupUserEntity> userGroupUsers = userGroupEntityController.listUserGroupUsersByUserSchoolDataIdentifier(userSchoolDataIdentifier);
    for (UserGroupUserEntity userGroupUser : userGroupUsers) {
        UserGroupEntity userGroup = userGroupUser.getUserGroupEntity();
        StudentGroupType studentGroupType = identifierMapper.getStudentGroupType(userGroup.getIdentifier());
        if (studentGroupType == StudentGroupType.STUDYPROGRAMME) {
            fireUserGroupUserRemoved(userGroupUser.getIdentifier(), userGroup.getIdentifier(), identifier.getIdentifier());
        }
    }
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) StudentGroupType(fi.otavanopisto.muikku.plugins.schooldatapyramus.PyramusIdentifierMapper.StudentGroupType)

Aggregations

UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)2 UserGroupUserEntity (fi.otavanopisto.muikku.model.users.UserGroupUserEntity)2 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)2 StudentGroupType (fi.otavanopisto.muikku.plugins.schooldatapyramus.PyramusIdentifierMapper.StudentGroupType)2 SchoolDataUserInactiveEvent (fi.otavanopisto.muikku.schooldata.events.SchoolDataUserInactiveEvent)1 Student (fi.otavanopisto.pyramus.rest.model.Student)1