Search in sources :

Example 36 with UserGroupEntity

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity)

Example 37 with UserGroupEntity

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) EntityManager(javax.persistence.EntityManager) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity)

Example 38 with UserGroupEntity

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;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) EntityManager(javax.persistence.EntityManager) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity)

Example 39 with UserGroupEntity

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;
    }
}
Also used : UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) UserGroup(fi.otavanopisto.muikku.schooldata.entity.UserGroup)

Example 40 with UserGroupEntity

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));
    }
}
Also used : UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity)

Aggregations

UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)40 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)14 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)12 UserGroupUserEntity (fi.otavanopisto.muikku.model.users.UserGroupUserEntity)12 Path (javax.ws.rs.Path)12 ArrayList (java.util.ArrayList)11 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)10 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)9 EntityManager (javax.persistence.EntityManager)8 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)8 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)7 UserGroup (fi.otavanopisto.muikku.schooldata.entity.UserGroup)6 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)5 HashMap (java.util.HashMap)5 POST (javax.ws.rs.POST)5 Permission (fi.otavanopisto.muikku.model.security.Permission)4 Announcement (fi.otavanopisto.muikku.plugins.announcer.model.Announcement)4 Tag (fi.otavanopisto.muikku.model.base.Tag)3 EnvironmentRoleArchetype (fi.otavanopisto.muikku.model.users.EnvironmentRoleArchetype)3 CommunicatorMessage (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)3