use of fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier in project muikku by otavanopisto.
the class WorkspaceSystemRESTService method ensureCorrectWorkspaceStudent.
private void ensureCorrectWorkspaceStudent(WorkspaceUserEntity muikkuWorkspaceStudent, SchoolDataIdentifier muikkuStudentIdentifier, SchoolDataIdentifier pyramusStudentIdentifier) {
if (!pyramusStudentIdentifier.equals(muikkuStudentIdentifier)) {
logger.warning(String.format("Muikku workspace student points to student %s and Pyramus to student %s", muikkuStudentIdentifier, pyramusStudentIdentifier));
UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierBySchoolDataIdentifier(pyramusStudentIdentifier);
if (userSchoolDataIdentifier == null) {
logger.severe(String.format("Unable to fix: UserSchoolDataIdentifier for Pyramus student %s not found", pyramusStudentIdentifier));
} else if (!userSchoolDataIdentifier.getUserEntity().getId().equals(muikkuWorkspaceStudent.getUserSchoolDataIdentifier().getUserEntity().getId())) {
logger.severe("Unable to fix: UserSchoolDataIdentifiers in Muikku and Pyramus point to different users");
} else {
// Muikku and Pyramus students are not the same. Let's see if we can find a workspace student with workspace + student combo
WorkspaceUserEntity existingStudent = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceAndUserIdentifierIncludeArchived(muikkuWorkspaceStudent.getWorkspaceEntity(), pyramusStudentIdentifier);
if (existingStudent != null && !existingStudent.getId().equals(muikkuWorkspaceStudent.getId())) {
// We can, so delete the workspace student we had and use the one we found instead, unarchiving it if needed
if (existingStudent.getArchived()) {
workspaceUserEntityController.unarchiveWorkspaceUserEntity(existingStudent);
}
workspaceUserEntityController.updateIdentifier(existingStudent, muikkuWorkspaceStudent.getIdentifier());
workspaceUserEntityController.archiveWorkspaceUserEntity(muikkuWorkspaceStudent);
muikkuWorkspaceStudent = existingStudent;
}
// Set workspace student to point at the same student as in Pyramus
workspaceUserEntityController.updateUserSchoolDataIdentifier(muikkuWorkspaceStudent, userSchoolDataIdentifier);
logger.info("Muikku workspace student UserSchoolDataIdentifier updated");
}
}
}
use of fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier in project muikku by otavanopisto.
the class UserSchoolDataController method findUserEntity.
/* User Entity */
public UserEntity findUserEntity(User user) {
SchoolDataSource schoolDataSource = schoolDataSourceDAO.findByIdentifier(user.getSchoolDataSource());
UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierDAO.findByDataSourceAndIdentifierAndArchived(schoolDataSource, user.getIdentifier(), Boolean.FALSE);
return userSchoolDataIdentifier == null ? null : userSchoolDataIdentifier.getUserEntity();
}
use of fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier 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.muikku.model.users.UserSchoolDataIdentifier in project muikku by otavanopisto.
the class DefaultSchoolDataUserGroupListener method onSchoolDataUserGroupUserUpdatedEvent.
public void onSchoolDataUserGroupUserUpdatedEvent(@Observes SchoolDataUserGroupUserUpdatedEvent event) {
UserGroupUserEntity userGroupUserEntity = userGroupEntityController.findUserGroupUserEntityByDataSourceAndIdentifier(event.getDataSource(), event.getIdentifier());
UserGroupEntity userGroupEntity = userGroupEntityController.findUserGroupEntityByDataSourceAndIdentifier(event.getUserGroupDataSource(), event.getUserGroupIdentifier());
UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierByDataSourceAndIdentifier(event.getUserDataSource(), event.getUserIdentifier());
if ((userGroupUserEntity != null) && (userGroupEntity != null) && (userSchoolDataIdentifier != null)) {
userGroupEntityController.updateUserGroupEntity(userGroupUserEntity, userGroupEntity);
userGroupEntityController.updateUserSchoolDataIdentifier(userGroupUserEntity, userSchoolDataIdentifier);
} else
logger.warning(String.format("Couldn't find userGroupUserEntity (%s) or userGroupEntity (%s)", event.getIdentifier(), event.getUserGroupIdentifier()));
}
use of fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier in project muikku by otavanopisto.
the class DefaultSchoolDataUserGroupListener method onSchoolDataUserGroupUserDiscoveredEvent.
public void onSchoolDataUserGroupUserDiscoveredEvent(@Observes SchoolDataUserGroupUserDiscoveredEvent event) {
String discoverId = getUserGroupUserDiscoveryId(event.getDataSource(), event.getIdentifier());
if (discoveredUserGroupUsers.containsKey(discoverId)) {
event.setDiscoveredUserGroupUserEntityId(discoveredUserGroupUsers.get(discoverId));
return;
}
UserGroupEntity userGroupEntity = userGroupEntityController.findUserGroupEntityByDataSourceAndIdentifier(event.getUserGroupDataSource(), event.getUserGroupIdentifier(), true);
if (userGroupEntity != null) {
if (!userGroupEntity.getArchived()) {
UserGroupUserEntity userGroupUserEntity = userGroupEntityController.findUserGroupUserEntityByDataSourceAndIdentifier(event.getDataSource(), event.getIdentifier(), true);
if ((userGroupUserEntity == null) || (userGroupUserEntity.getArchived())) {
UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierByDataSourceAndIdentifier(event.getUserDataSource(), event.getUserIdentifier());
if (userSchoolDataIdentifier != null) {
if (userGroupUserEntity == null) {
userGroupUserEntity = userGroupEntityController.createUserGroupUserEntity(userGroupEntity, event.getDataSource(), event.getIdentifier(), userSchoolDataIdentifier);
} else {
userGroupEntityController.unarchiveUserGroupUserEntity(userGroupUserEntity);
userGroupEntityController.updateUserSchoolDataIdentifier(userGroupUserEntity, userSchoolDataIdentifier);
}
discoveredUserGroupUsers.put(discoverId, userGroupUserEntity.getId());
event.setDiscoveredUserGroupUserEntityId(userGroupUserEntity.getId());
} else {
logger.warning("could not add group user because UserSchoolDataIdentifier for " + event.getUserIdentifier() + "/" + event.getUserDataSource() + " wasn't found");
}
} else {
logger.warning("UserGroupUserEntity for " + event.getIdentifier() + "/" + event.getDataSource() + " already exists");
}
}
} else {
logger.warning("could not init user group user because usergroup #" + event.getUserGroupIdentifier() + '/' + event.getUserGroupDataSource() + " could not be found");
}
}
Aggregations