Search in sources :

Example 6 with Student

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

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

the class PyramusSchoolDataUserListener method handlePyramusUserDiscovered.

private void handlePyramusUserDiscovered(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) {
                boolean isActive = !student.getArchived() && (student.getStudyEndDate() == null || student.getStudyEndDate().isAfter(OffsetDateTime.now()));
                if (isActive) {
                    String userGroupUserIdentifier = identifierMapper.getStudyProgrammeStudentIdentifier(pyramusStudentId);
                    String userGroupIdentifier = identifierMapper.getStudyProgrammeIdentifier(pyramusStudyProgrammeId);
                    String userEntityIdentifier = identifier.getIdentifier();
                    fireUserGroupUserDiscovered(userGroupUserIdentifier, userGroupIdentifier, userEntityIdentifier);
                }
            }
        }
    }
}
Also used : Student(fi.otavanopisto.pyramus.rest.model.Student)

Example 8 with Student

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

the class PyramusUpdater method isStudentActive.

private boolean isStudentActive(Long studentId) {
    Student student = pyramusClient.get().get(String.format("/students/students/%d", studentId), Student.class);
    if (student == null || student.getArchived()) {
        logger.severe(String.format("Tried to resolve activity for non existings student (%d)", studentId));
        return false;
    }
    OffsetDateTime studyStartDate = student.getStudyStartDate();
    OffsetDateTime studyEndDate = student.getStudyEndDate();
    if (studyStartDate == null && studyEndDate == null) {
        // It's a never ending study programme
        return true;
    }
    boolean startedStudies = studyStartDate != null && studyStartDate.isBefore(OffsetDateTime.now());
    boolean finishedStudies = studyEndDate != null && studyEndDate.isBefore(OffsetDateTime.now());
    return startedStudies && !finishedStudies;
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Student(fi.otavanopisto.pyramus.rest.model.Student) StudentGroupStudent(fi.otavanopisto.pyramus.rest.model.StudentGroupStudent) CourseStudent(fi.otavanopisto.pyramus.rest.model.CourseStudent)

Example 9 with Student

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

the class PyramusUserSchoolDataBridge method getUserProperty.

@Override
public UserProperty getUserProperty(String userIdentifier, String key) {
    Long studentId = identifierMapper.getPyramusStudentId(userIdentifier);
    if (studentId != null) {
        Student student = pyramusClient.get("/students/students/" + studentId, Student.class);
        Map<String, String> variables = student.getVariables();
        String value = variables.get(key);
        if (value == null) {
            return null;
        } else {
            return new PyramusUserProperty(userIdentifier, key, value);
        }
    }
    logger.warning(String.format("PyramusUserSchoolDataBridge.getUserProperty malformed user identifier %s\n%s", userIdentifier, ExceptionUtils.getStackTrace(new Throwable())));
    throw new SchoolDataBridgeInternalException(String.format("Malformed user identifier %s", userIdentifier));
}
Also used : PyramusUserProperty(fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusUserProperty) SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) Student(fi.otavanopisto.pyramus.rest.model.Student) StudentGroupStudent(fi.otavanopisto.pyramus.rest.model.StudentGroupStudent)

Example 10 with Student

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

the class PyramusUserSchoolDataBridge method findUser.

@Override
public User findUser(String identifier) {
    Long studentId = identifierMapper.getPyramusStudentId(identifier);
    if (studentId != null) {
        Student student = findPyramusStudent(studentId);
        return createStudentEntity(student);
    }
    Long staffId = identifierMapper.getPyramusStaffId(identifier);
    if (staffId != null) {
        StaffMember staffMember = findPyramusStaffMember(staffId);
        return staffMember == null ? null : entityFactory.createEntity(staffMember);
    }
    logger.warning(String.format("PyramusUserSchoolDataBridge.findUser malformed user identifier %s\n%s", identifier, ExceptionUtils.getStackTrace(new Throwable())));
    throw new SchoolDataBridgeInternalException(String.format("Malformed user identifier %s", identifier));
}
Also used : SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) Student(fi.otavanopisto.pyramus.rest.model.Student) StudentGroupStudent(fi.otavanopisto.pyramus.rest.model.StudentGroupStudent) StaffMember(fi.otavanopisto.pyramus.rest.model.StaffMember)

Aggregations

Student (fi.otavanopisto.pyramus.rest.model.Student)21 StudentGroupStudent (fi.otavanopisto.pyramus.rest.model.StudentGroupStudent)16 StaffMember (fi.otavanopisto.pyramus.rest.model.StaffMember)9 SchoolDataBridgeInternalException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException)7 CourseStudent (fi.otavanopisto.pyramus.rest.model.CourseStudent)7 ArrayList (java.util.ArrayList)6 Person (fi.otavanopisto.pyramus.rest.model.Person)5 HashMap (java.util.HashMap)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 JSR310Module (com.fasterxml.jackson.datatype.jsr310.JSR310Module)4 PyramusUserProperty (fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusUserProperty)3 CourseStaffMember (fi.otavanopisto.pyramus.rest.model.CourseStaffMember)3 Email (fi.otavanopisto.pyramus.rest.model.Email)3 OffsetDateTime (java.time.OffsetDateTime)3 MockCourseStudent (fi.otavanopisto.muikku.mock.model.MockCourseStudent)2 UserGroupUserEntity (fi.otavanopisto.muikku.model.users.UserGroupUserEntity)2 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)2 PyramusGroupUser (fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusGroupUser)2 GroupUser (fi.otavanopisto.muikku.schooldata.entity.GroupUser)2 User (fi.otavanopisto.muikku.schooldata.entity.User)2