Search in sources :

Example 1 with SchoolDataUserInactiveEvent

use of fi.otavanopisto.muikku.schooldata.events.SchoolDataUserInactiveEvent 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)

Aggregations

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