use of fi.otavanopisto.muikku.model.users.UserGroupUserEntity in project muikku by otavanopisto.
the class UserGroupUserEntityDAO method listByUserGroupEntityAndArchived.
public List<UserGroupUserEntity> listByUserGroupEntityAndArchived(UserGroupEntity userGroupEntity, Boolean archived) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<UserGroupUserEntity> criteria = criteriaBuilder.createQuery(UserGroupUserEntity.class);
Root<UserGroupUserEntity> root = criteria.from(UserGroupUserEntity.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(UserGroupUserEntity_.userGroupEntity), userGroupEntity), criteriaBuilder.equal(root.get(UserGroupUserEntity_.archived), archived)));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.model.users.UserGroupUserEntity 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.UserGroupUserEntity in project muikku by otavanopisto.
the class PyramusUpdater method updateStudentGroupStaffMember.
public void updateStudentGroupStaffMember(Long studentGroupId, Long studentGroupStaffMemberId) {
StudentGroupUser studentGroupStaffMember = pyramusClient.get().get(String.format("/students/studentGroups/%d/staffmembers/%d", studentGroupId, studentGroupStaffMemberId), StudentGroupUser.class);
String identifier = identifierMapper.getStudentGroupStaffMemberIdentifier(studentGroupStaffMemberId);
UserGroupUserEntity userGroupUserEntity = userGroupEntityController.findUserGroupUserEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, identifier);
String userGroupIdentifier = identifierMapper.getStudentGroupIdentifier(studentGroupId);
if (studentGroupStaffMember == null) {
if (userGroupUserEntity != null)
fireUserGroupUserRemoved(identifier, userGroupIdentifier, userGroupUserEntity.getUserSchoolDataIdentifier().getIdentifier());
} else {
if (userGroupUserEntity == null) {
String staffMemberIdentifier = identifierMapper.getStaffIdentifier(studentGroupStaffMember.getStaffMemberId());
fireUserGroupUserDiscovered(identifier, userGroupIdentifier, staffMemberIdentifier);
} else {
fireUserGroupUserUpdated(identifier, userGroupIdentifier, userGroupUserEntity.getUserSchoolDataIdentifier().getIdentifier());
}
}
}
use of fi.otavanopisto.muikku.model.users.UserGroupUserEntity in project muikku by otavanopisto.
the class DefaultSchoolDataUserGroupListener method onSchoolDataUserGroupUserRemovedEvent.
public void onSchoolDataUserGroupUserRemovedEvent(@Observes SchoolDataUserGroupUserRemovedEvent event) {
String discoverId = getUserGroupUserDiscoveryId(event.getDataSource(), event.getIdentifier());
discoveredUserGroupUsers.remove(discoverId);
UserGroupUserEntity userGroupUserEntity = userGroupEntityController.findUserGroupUserEntityByDataSourceAndIdentifier(event.getDataSource(), event.getIdentifier());
if (userGroupUserEntity != null) {
userGroupEntityController.archiveUserGroupUserEntity(userGroupUserEntity);
}
}
use of fi.otavanopisto.muikku.model.users.UserGroupUserEntity 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()));
}
Aggregations