use of fi.otavanopisto.muikku.model.users.UserGroupUserEntity 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");
}
}
use of fi.otavanopisto.muikku.model.users.UserGroupUserEntity in project muikku by otavanopisto.
the class PyramusSchoolDataUserListener method handlePyramusUserRemoved.
private void handlePyramusUserRemoved(SchoolDataIdentifier identifier) {
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) {
fireUserGroupUserRemoved(userGroupUser.getIdentifier(), userGroup.getIdentifier(), identifier.getIdentifier());
}
}
}
use of fi.otavanopisto.muikku.model.users.UserGroupUserEntity in project muikku by otavanopisto.
the class PyramusUpdater method updateStudyProgrammeMember.
public void updateStudyProgrammeMember(Student student) {
if (student.getStudyProgrammeId() != null) {
String studyProgrammeIdentifier = identifierMapper.getStudyProgrammeIdentifier(student.getStudyProgrammeId());
String studyProgrammeStudentIdentifier = identifierMapper.getStudyProgrammeStudentIdentifier(student.getId());
UserGroupUserEntity userGroupUserEntity = userGroupEntityController.findUserGroupUserEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, studyProgrammeStudentIdentifier);
boolean isActive = !student.getArchived() && (student.getStudyEndDate() == null || student.getStudyEndDate().isAfter(OffsetDateTime.now()));
if (isActive) {
if (userGroupUserEntity == null) {
String userEntityIdentifier = identifierMapper.getStudentIdentifier(student.getId());
fireUserGroupUserDiscovered(studyProgrammeStudentIdentifier, studyProgrammeIdentifier, userEntityIdentifier);
} else
fireUserGroupUserUpdated(studyProgrammeStudentIdentifier, studyProgrammeIdentifier, userGroupUserEntity.getUserSchoolDataIdentifier().getIdentifier());
} else {
if (userGroupUserEntity != null)
fireUserGroupUserRemoved(studyProgrammeStudentIdentifier, studyProgrammeIdentifier, userGroupUserEntity.getUserSchoolDataIdentifier().getIdentifier());
}
}
}
use of fi.otavanopisto.muikku.model.users.UserGroupUserEntity in project muikku by otavanopisto.
the class PyramusUpdater method updateStudentGroupUsers.
public int updateStudentGroupUsers(Long studentGroupId) {
String userGroupIdentifier = identifierMapper.getStudentGroupIdentifier(studentGroupId);
UserGroupEntity userGroupEntity = userGroupEntityController.findUserGroupEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, userGroupIdentifier, true);
if (userGroupEntity != null) {
if (userGroupEntity.getArchived()) {
// Just skip archived user groups
return 0;
}
List<UserGroupUserEntity> existingUsers = userGroupEntityController.listUserGroupUserEntitiesByUserGroupEntity(userGroupEntity);
List<String> existingGroupUserIds = new ArrayList<String>();
for (UserGroupUserEntity existingUser : existingUsers) {
existingGroupUserIds.add(existingUser.getIdentifier());
}
List<String> foundGroupUserIds = new ArrayList<String>();
int count = 0;
StudentGroupUser[] userGroupStaffMembers = pyramusClient.get().get(String.format("/students/studentGroups/%d/staffmembers", studentGroupId), StudentGroupUser[].class);
if (userGroupStaffMembers != null) {
for (StudentGroupUser sgStaffMember : userGroupStaffMembers) {
String identifier = identifierMapper.getStudentGroupStaffMemberIdentifier(sgStaffMember.getId());
foundGroupUserIds.add(identifier);
// If not existing, then it's a new one
if (!existingGroupUserIds.contains(identifier)) {
String staffMemberIdentifier = identifierMapper.getStaffIdentifier(sgStaffMember.getStaffMemberId());
fireUserGroupUserDiscovered(identifier, userGroupIdentifier, staffMemberIdentifier);
}
}
count += userGroupStaffMembers.length;
}
StudentGroupStudent[] userGroupStudents = pyramusClient.get().get(String.format("/students/studentGroups/%d/students", studentGroupId), StudentGroupStudent[].class);
if (userGroupStudents != null) {
for (StudentGroupStudent sgs : userGroupStudents) {
String identifier = identifierMapper.getStudentGroupStudentIdentifier(sgs.getId());
foundGroupUserIds.add(identifier);
// If not existing, then it's a new one
if (!existingGroupUserIds.contains(identifier)) {
String studentIdentifier = identifierMapper.getStudentIdentifier(sgs.getStudentId());
fireUserGroupUserDiscovered(identifier, userGroupIdentifier, studentIdentifier);
}
}
count += userGroupStudents.length;
}
// Remove found ids from existing and we'll get the ones to remove
existingGroupUserIds.removeAll(foundGroupUserIds);
for (String identifier : existingGroupUserIds) {
UserGroupUserEntity ugu = userGroupEntityController.findUserGroupUserEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, identifier);
if (ugu != null)
fireUserGroupUserRemoved(identifier, userGroupIdentifier, ugu.getUserSchoolDataIdentifier().getIdentifier());
}
return count;
} else {
logger.log(Level.WARNING, String.format("UserGroup is null for id %d - update of users is skipped", studentGroupId));
}
return 0;
}
use of fi.otavanopisto.muikku.model.users.UserGroupUserEntity in project muikku by otavanopisto.
the class PyramusUpdater method updateStudentGroupStudent.
public void updateStudentGroupStudent(Long studentGroupId, Long studentGroupStudentId) {
StudentGroupStudent studentGroupStudent = pyramusClient.get().get(String.format("/students/studentGroups/%d/students/%d", studentGroupId, studentGroupStudentId), StudentGroupStudent.class);
String identifier = identifierMapper.getStudentGroupStudentIdentifier(studentGroupStudentId);
UserGroupUserEntity userGroupUserEntity = userGroupEntityController.findUserGroupUserEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, identifier);
String userGroupIdentifier = identifierMapper.getStudentGroupIdentifier(studentGroupId);
if (studentGroupStudent == null) {
if (userGroupUserEntity != null)
fireUserGroupUserRemoved(identifier, userGroupIdentifier, userGroupUserEntity.getUserSchoolDataIdentifier().getIdentifier());
} else {
String studentIdentifier = identifierMapper.getStudentIdentifier(studentGroupStudent.getStudentId());
if (userGroupUserEntity == null) {
fireUserGroupUserDiscovered(identifier, userGroupIdentifier, studentIdentifier);
} else {
fireUserGroupUserUpdated(identifier, userGroupIdentifier, studentIdentifier);
}
}
}
Aggregations