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;
}
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));
}
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);
}
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;
}
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;
}
Aggregations