use of fi.otavanopisto.muikku.model.users.UserGroupEntity in project muikku by otavanopisto.
the class UserGroupEntityDAO method listByArchived.
public List<UserGroupEntity> listByArchived(Boolean archived) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<UserGroupEntity> criteria = criteriaBuilder.createQuery(UserGroupEntity.class);
Root<UserGroupEntity> root = criteria.from(UserGroupEntity.class);
criteria.select(root);
criteria.where(criteriaBuilder.equal(root.get(UserGroupEntity_.archived), archived));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.model.users.UserGroupEntity in project muikku by otavanopisto.
the class UserGroupEntityDAO method listByUserEntityExcludeArchived.
public List<UserGroupEntity> listByUserEntityExcludeArchived(UserEntity userEntity) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<UserGroupEntity> criteria = criteriaBuilder.createQuery(UserGroupEntity.class);
Root<UserGroupUserEntity> root = criteria.from(UserGroupUserEntity.class);
Join<UserGroupUserEntity, UserSchoolDataIdentifier> join = root.join(UserGroupUserEntity_.userSchoolDataIdentifier);
Join<UserGroupUserEntity, UserGroupEntity> join2 = root.join(UserGroupUserEntity_.userGroupEntity);
criteria.select(root.get(UserGroupUserEntity_.userGroupEntity));
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(join.get(UserSchoolDataIdentifier_.userEntity), userEntity), criteriaBuilder.equal(join.get(UserSchoolDataIdentifier_.archived), Boolean.FALSE), criteriaBuilder.equal(join2.get(UserGroupEntity_.archived), Boolean.FALSE), criteriaBuilder.equal(root.get(UserGroupUserEntity_.archived), Boolean.FALSE)));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.model.users.UserGroupEntity in project muikku by otavanopisto.
the class UserGroupUserEntityDAO method haveSharedUserGroups.
public boolean haveSharedUserGroups(UserEntity user1, UserEntity user2) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> criteria = criteriaBuilder.createQuery(Long.class);
Root<UserGroupEntity> root = criteria.from(UserGroupEntity.class);
Subquery<UserGroupEntity> user1Groups = criteria.subquery(UserGroupEntity.class);
Subquery<UserGroupEntity> user2Groups = criteria.subquery(UserGroupEntity.class);
Root<UserGroupUserEntity> user1Root = user1Groups.from(UserGroupUserEntity.class);
Join<UserGroupUserEntity, UserSchoolDataIdentifier> user1Identifier = user1Root.join(UserGroupUserEntity_.userSchoolDataIdentifier);
Root<UserGroupUserEntity> user2Root = user2Groups.from(UserGroupUserEntity.class);
Join<UserGroupUserEntity, UserSchoolDataIdentifier> user2Identifier = user2Root.join(UserGroupUserEntity_.userSchoolDataIdentifier);
user1Groups.select(user1Root.get(UserGroupUserEntity_.userGroupEntity));
user2Groups.select(user2Root.get(UserGroupUserEntity_.userGroupEntity));
user1Groups.where(criteriaBuilder.and(criteriaBuilder.equal(user1Identifier.get(UserSchoolDataIdentifier_.userEntity), user1), criteriaBuilder.equal(user1Root.get(UserGroupUserEntity_.archived), Boolean.FALSE)));
user2Groups.where(criteriaBuilder.and(criteriaBuilder.equal(user2Identifier.get(UserSchoolDataIdentifier_.userEntity), user2), criteriaBuilder.equal(user2Root.get(UserGroupUserEntity_.archived), Boolean.FALSE)));
criteria.select(criteriaBuilder.count(root));
criteria.where(criteriaBuilder.and(root.in(user1Groups), root.in(user2Groups), criteriaBuilder.equal(root.get(UserGroupEntity_.archived), Boolean.FALSE)));
return entityManager.createQuery(criteria).getSingleResult() > 0;
}
use of fi.otavanopisto.muikku.model.users.UserGroupEntity in project muikku by otavanopisto.
the class SchoolDataSearchReindexListener method reindexUserGroups.
private boolean reindexUserGroups() {
try {
List<UserGroupEntity> userGroups = userGroupEntityController.listUserGroupEntities();
int groupIndex = getOffset("groupIndex");
if (groupIndex < userGroups.size()) {
int last = Math.min(userGroups.size(), groupIndex + getBatchSize());
for (int i = groupIndex; i < last; i++) {
UserGroupEntity groupEntity = userGroups.get(i);
UserGroup userGroup = userGroupController.findUserGroup(groupEntity.getSchoolDataSource(), groupEntity.getIdentifier());
try {
indexer.index(UserGroup.class.getSimpleName(), userGroup);
} catch (Exception e) {
logger.log(Level.WARNING, "could not index UserGroup #" + groupEntity.getSchoolDataSource() + '/' + groupEntity.getIdentifier(), e);
}
}
logger.log(Level.INFO, "Reindexed batch of usergroups (" + groupIndex + "-" + last + ")");
setOffset("groupIndex", groupIndex + getBatchSize());
return false;
} else
return true;
} catch (Exception ex) {
logger.log(Level.SEVERE, "Could not finish indexing usergroup entities.", ex);
return true;
}
}
use of fi.otavanopisto.muikku.model.users.UserGroupEntity in project muikku by otavanopisto.
the class PyramusSchoolDataUserGroupUsersUpdateScheduler method synchronize.
public void synchronize() {
int currentOffset = getAndUpdateCurrentOffset(BATCH_SIZE);
int count = 0;
try {
logger.fine("Synchronizing Pyramus user group users");
List<UserGroupEntity> userGroupEntities = userGroupEntityController.listUserGroupEntitiesByDataSource(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, currentOffset, BATCH_SIZE);
if (userGroupEntities.size() == 0) {
resetCurrentOffset();
} else {
for (UserGroupEntity userGroupEntity : userGroupEntities) {
switch(identityMapper.getStudentGroupType(userGroupEntity.getIdentifier())) {
case STUDENTGROUP:
Long userGroupId = identityMapper.getPyramusStudentGroupId(userGroupEntity.getIdentifier());
count += pyramusUpdater.updateStudentGroupUsers(userGroupId);
break;
case STUDYPROGRAMME:
Long studyProgrammeId = identityMapper.getPyramusStudyProgrammeId(userGroupEntity.getIdentifier());
count += pyramusUpdater.updateStudyProgrammeGroupUsers(studyProgrammeId);
break;
}
}
}
} finally {
logger.fine(String.format("Synchronized %d Pyramus user group users", count));
}
}
Aggregations