Search in sources :

Example 16 with Student

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

the class PyramusUserSchoolDataBridge method updateUser.

@Override
public User updateUser(User user) {
    Long studentId = identifierMapper.getPyramusStudentId(user.getIdentifier());
    if (studentId == null) {
        throw new SchoolDataBridgeInternalException("User is not a Pyramus student");
    }
    Student student = pyramusClient.get(String.format("/students/students/%d", studentId), Student.class);
    Municipality[] municipalities = pyramusClient.get("/students/municipalities", Municipality[].class);
    // There's no search endpoint in Pyramus REST, and the municipality field is text, so we need to do this
    boolean municipalityFound = false;
    for (Municipality municipality : Arrays.asList(municipalities)) {
        if (StringUtils.equalsIgnoreCase(municipality.getName(), user.getMunicipality())) {
            student.setMunicipalityId(municipality.getId());
            municipalityFound = true;
            break;
        }
    }
    if (!municipalityFound) {
        throw new SchoolDataBridgeInternalException("Municipality not found");
    }
    pyramusClient.put(String.format("/students/students/%d", studentId), student);
    return user;
}
Also used : Municipality(fi.otavanopisto.pyramus.rest.model.Municipality) SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) Student(fi.otavanopisto.pyramus.rest.model.Student) StudentGroupStudent(fi.otavanopisto.pyramus.rest.model.StudentGroupStudent)

Example 17 with Student

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

the class PyramusUserSchoolDataBridge method listUserPropertiesByUser.

@Override
public List<UserProperty> listUserPropertiesByUser(String userIdentifier) {
    Long studentId = identifierMapper.getPyramusStudentId(userIdentifier);
    if (studentId != null) {
        Student student = pyramusClient.get("/students/students/" + studentId, Student.class);
        Map<String, String> variables = student.getVariables();
        List<UserProperty> userProperties = new ArrayList<>();
        for (String key : variables.keySet()) {
            String value = variables.get(key);
            if (value != null) {
                userProperties.add(new PyramusUserProperty(userIdentifier, key, value));
            }
        }
        return userProperties;
    }
    logger.warning(String.format("PyramusUserSchoolDataBridge.listUserPropertiesByUser 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) UserProperty(fi.otavanopisto.muikku.schooldata.entity.UserProperty) PyramusUserProperty(fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusUserProperty) SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) ArrayList(java.util.ArrayList) Student(fi.otavanopisto.pyramus.rest.model.Student) StudentGroupStudent(fi.otavanopisto.pyramus.rest.model.StudentGroupStudent)

Example 18 with Student

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

the class PyramusUserSchoolDataBridge method findUserByPyramusUser.

private User findUserByPyramusUser(Long userId) {
    Student student = findPyramusStudent(userId);
    if (student != null) {
        return createStudentEntity(student);
    }
    StaffMember staffMember = findPyramusStaffMember(userId);
    return entityFactory.createEntity(staffMember);
}
Also used : Student(fi.otavanopisto.pyramus.rest.model.Student) StudentGroupStudent(fi.otavanopisto.pyramus.rest.model.StudentGroupStudent) StaffMember(fi.otavanopisto.pyramus.rest.model.StaffMember)

Example 19 with Student

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

the class PyramusUserSchoolDataBridge method listUsersByEmail.

@Override
public List<User> listUsersByEmail(String email) {
    Map<Long, User> userMap = new HashMap<Long, User>();
    Long personId = null;
    for (Student student : pyramusClient.get("/students/students?email=" + email, Student[].class)) {
        userMap.put(student.getId(), createStudentEntity(student));
        personId = student.getPersonId();
    }
    for (StaffMember staffMember : pyramusClient.get("/staff/members?email=" + email, StaffMember[].class)) {
        userMap.put(staffMember.getId(), entityFactory.createEntity(staffMember));
        personId = staffMember.getPersonId();
    }
    List<User> result = new ArrayList<User>();
    if (personId != null) {
        Person person = findPyramusPerson(personId);
        if (userMap.containsKey(person.getDefaultUserId())) {
            result.add(userMap.remove(person.getDefaultUserId()));
        }
    }
    result.addAll(userMap.values());
    return result;
}
Also used : User(fi.otavanopisto.muikku.schooldata.entity.User) PyramusGroupUser(fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusGroupUser) StudentGroupUser(fi.otavanopisto.pyramus.rest.model.StudentGroupUser) GroupUser(fi.otavanopisto.muikku.schooldata.entity.GroupUser) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Student(fi.otavanopisto.pyramus.rest.model.Student) StudentGroupStudent(fi.otavanopisto.pyramus.rest.model.StudentGroupStudent) StaffMember(fi.otavanopisto.pyramus.rest.model.StaffMember) Person(fi.otavanopisto.pyramus.rest.model.Person)

Example 20 with Student

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

the class PyramusUserSchoolDataBridge method createStudentEntities.

private List<User> createStudentEntities(Student... students) {
    Map<Long, StudyProgramme> studyProgrammeMap = new HashMap<Long, StudyProgramme>();
    List<User> users = new ArrayList<User>();
    for (Student student : students) {
        StudyProgramme studyProgramme;
        String nationality = null;
        String language = null;
        String municipality = null;
        String school = null;
        boolean hidden = false;
        if (student.getStudyProgrammeId() != null) {
            if (!studyProgrammeMap.containsKey(student.getStudyProgrammeId())) {
                StudyProgramme studyProgrammeO = pyramusClient.get("/students/studyProgrammes/" + student.getStudyProgrammeId(), StudyProgramme.class);
                if (studyProgrammeO != null)
                    studyProgrammeMap.put(student.getStudyProgrammeId(), studyProgrammeO);
            }
            studyProgramme = studyProgrammeMap.get(student.getStudyProgrammeId());
        } else {
            studyProgramme = null;
        }
        if (student.getNationalityId() != null) {
            Nationality nationalityO = pyramusClient.get("/students/nationalities/" + student.getNationalityId(), Nationality.class);
            if (nationalityO != null)
                nationality = nationalityO.getName();
        }
        if (student.getLanguageId() != null) {
            Language languageO = pyramusClient.get("/students/languages/" + student.getLanguageId(), Language.class);
            if (languageO != null)
                language = languageO.getName();
        }
        if (student.getMunicipalityId() != null) {
            Municipality municipalityO = pyramusClient.get("/students/municipalities/" + student.getMunicipalityId(), Municipality.class);
            if (municipalityO != null)
                municipality = municipalityO.getName();
        }
        if (student.getSchoolId() != null) {
            School schoolO = pyramusClient.get("/schools/schools/" + student.getSchoolId(), School.class);
            if (schoolO != null)
                school = schoolO.getName();
        }
        if (student.getPersonId() != null) {
            Person person = pyramusClient.get("/persons/persons/" + student.getPersonId(), Person.class);
            if (person != null)
                hidden = person.getSecureInfo() != null ? person.getSecureInfo() : false;
        }
        String curriculumIdentifier = student.getCurriculumId() != null ? identifierMapper.getCurriculumIdentifier(student.getCurriculumId()).toId() : null;
        // #3069: User has evaluation fees if their study program begins with Internetix/
        boolean evaluationFees = studyProgramme != null && StringUtils.startsWith(studyProgramme.getName(), "Internetix/");
        users.add(entityFactory.createEntity(student, studyProgramme, nationality, language, municipality, school, student.getStudyStartDate(), student.getStudyEndDate(), student.getStudyTimeEnd(), evaluationFees, hidden, curriculumIdentifier));
    }
    return users;
}
Also used : User(fi.otavanopisto.muikku.schooldata.entity.User) PyramusGroupUser(fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusGroupUser) StudentGroupUser(fi.otavanopisto.pyramus.rest.model.StudentGroupUser) GroupUser(fi.otavanopisto.muikku.schooldata.entity.GroupUser) Municipality(fi.otavanopisto.pyramus.rest.model.Municipality) StudyProgramme(fi.otavanopisto.pyramus.rest.model.StudyProgramme) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Student(fi.otavanopisto.pyramus.rest.model.Student) StudentGroupStudent(fi.otavanopisto.pyramus.rest.model.StudentGroupStudent) Nationality(fi.otavanopisto.pyramus.rest.model.Nationality) School(fi.otavanopisto.pyramus.rest.model.School) Language(fi.otavanopisto.pyramus.rest.model.Language) Person(fi.otavanopisto.pyramus.rest.model.Person)

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