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