Search in sources :

Example 1 with UserGroupUserEntity

use of fi.otavanopisto.muikku.model.users.UserGroupUserEntity in project muikku by otavanopisto.

the class AcceptanceTestsRESTService method deleteUserGroup.

@DELETE
@Path("/userGroups/{USERGROUPID}")
@RESTPermit(handling = Handling.UNSECURED)
public Response deleteUserGroup(@PathParam("USERGROUPID") Long userGroupId) {
    UserGroupEntity userGroup = userGroupEntityController.findUserGroupEntityById(userGroupId);
    for (UserGroupUserEntity userGroupUser : userGroupEntityController.listUserGroupUserEntitiesByUserGroupEntity(userGroup)) {
        userGroupEntityController.deleteUserGroupUserEntity(userGroupUser);
    }
    userGroupEntityController.deleteUserGroupEntity(userGroup);
    return Response.noContent().build();
}
Also used : UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.security.rest.RESTPermit)

Example 2 with UserGroupUserEntity

use of fi.otavanopisto.muikku.model.users.UserGroupUserEntity in project muikku by otavanopisto.

the class CommunicatorController method createMessage.

public CommunicatorMessage createMessage(CommunicatorMessageId communicatorMessageId, UserEntity sender, List<UserEntity> userRecipients, List<UserGroupEntity> userGroupRecipients, List<WorkspaceEntity> workspaceStudentRecipients, List<WorkspaceEntity> workspaceTeacherRecipients, CommunicatorMessageCategory category, String caption, String content, Set<Tag> tags) {
    CommunicatorMessage message = communicatorMessageDAO.create(communicatorMessageId, sender.getId(), category, caption, clean(content), new Date(), tags);
    // Clean duplicates from recipient list
    cleanDuplicateRecipients(userRecipients);
    Set<Long> recipientIds = new HashSet<Long>();
    for (UserEntity recipient : userRecipients) {
        // #3758: Only send messages to active users
        if (!isActiveUser(recipient)) {
            continue;
        }
        if (!recipientIds.contains(recipient.getId())) {
            recipientIds.add(recipient.getId());
            communicatorMessageRecipientDAO.create(message, recipient, null);
        }
    }
    if (!CollectionUtils.isEmpty(userGroupRecipients)) {
        for (UserGroupEntity userGroup : userGroupRecipients) {
            List<UserGroupUserEntity> groupUsers = userGroupEntityController.listUserGroupUserEntitiesByUserGroupEntity(userGroup);
            if (!CollectionUtils.isEmpty(groupUsers)) {
                CommunicatorMessageRecipientUserGroup groupRecipient = createUserGroupRecipient(userGroup);
                for (UserGroupUserEntity groupUser : groupUsers) {
                    UserSchoolDataIdentifier userSchoolDataIdentifier = groupUser.getUserSchoolDataIdentifier();
                    UserEntity recipient = userSchoolDataIdentifier.getUserEntity();
                    // #3758: Only send messages to active users
                    if (!isActiveUser(recipient)) {
                        continue;
                    }
                    if ((recipient != null) && !Objects.equals(sender.getId(), recipient.getId())) {
                        if (!recipientIds.contains(recipient.getId())) {
                            recipientIds.add(recipient.getId());
                            communicatorMessageRecipientDAO.create(message, recipient, groupRecipient);
                        }
                    }
                }
            }
        }
    }
    if (!CollectionUtils.isEmpty(workspaceStudentRecipients)) {
        for (WorkspaceEntity workspaceEntity : workspaceStudentRecipients) {
            List<WorkspaceUserEntity> workspaceUsers = workspaceUserEntityController.listActiveWorkspaceStudents(workspaceEntity);
            if (!CollectionUtils.isEmpty(workspaceUsers)) {
                CommunicatorMessageRecipientWorkspaceGroup groupRecipient = createWorkspaceGroupRecipient(workspaceEntity, WorkspaceRoleArchetype.STUDENT);
                for (WorkspaceUserEntity workspaceUserEntity : workspaceUsers) {
                    UserEntity recipient = workspaceUserEntity.getUserSchoolDataIdentifier().getUserEntity();
                    // #3758: Only send messages to active users
                    if (!isActiveUser(recipient)) {
                        continue;
                    }
                    if ((recipient != null) && !Objects.equals(sender.getId(), recipient.getId())) {
                        if (!recipientIds.contains(recipient.getId())) {
                            recipientIds.add(recipient.getId());
                            communicatorMessageRecipientDAO.create(message, recipient, groupRecipient);
                        }
                    }
                }
            }
        }
    }
    if (!CollectionUtils.isEmpty(workspaceTeacherRecipients)) {
        for (WorkspaceEntity workspaceEntity : workspaceTeacherRecipients) {
            List<WorkspaceUserEntity> workspaceUsers = workspaceUserEntityController.listActiveWorkspaceStaffMembers(workspaceEntity);
            if (!CollectionUtils.isEmpty(workspaceUsers)) {
                CommunicatorMessageRecipientWorkspaceGroup groupRecipient = createWorkspaceGroupRecipient(workspaceEntity, WorkspaceRoleArchetype.TEACHER);
                for (WorkspaceUserEntity wosu : workspaceUsers) {
                    UserEntity recipient = wosu.getUserSchoolDataIdentifier().getUserEntity();
                    // #3758: Workspace teachers are considered active, no need to check
                    if ((recipient != null) && !Objects.equals(sender.getId(), recipient.getId())) {
                        if (!recipientIds.contains(recipient.getId())) {
                            recipientIds.add(recipient.getId());
                            communicatorMessageRecipientDAO.create(message, recipient, groupRecipient);
                        }
                    }
                }
            }
        }
    }
    return message;
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) Date(java.util.Date) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) CommunicatorMessageRecipientUserGroup(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientUserGroup) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) CommunicatorMessageRecipientWorkspaceGroup(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientWorkspaceGroup) HashSet(java.util.HashSet)

Example 3 with UserGroupUserEntity

use of fi.otavanopisto.muikku.model.users.UserGroupUserEntity in project muikku by otavanopisto.

the class UserGroupEntityDAO method listByUserIdentifierExcludeArchived.

public List<UserGroupEntity> listByUserIdentifierExcludeArchived(UserSchoolDataIdentifier userSchoolDataIdentifier) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<UserGroupEntity> criteria = criteriaBuilder.createQuery(UserGroupEntity.class);
    Root<UserGroupUserEntity> root = criteria.from(UserGroupUserEntity.class);
    Join<UserGroupUserEntity, UserGroupEntity> groupJoin = root.join(UserGroupUserEntity_.userGroupEntity);
    criteria.select(root.get(UserGroupUserEntity_.userGroupEntity));
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(UserGroupUserEntity_.userSchoolDataIdentifier), userSchoolDataIdentifier), criteriaBuilder.equal(groupJoin.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) EntityManager(javax.persistence.EntityManager) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity)

Example 4 with UserGroupUserEntity

use of fi.otavanopisto.muikku.model.users.UserGroupUserEntity in project muikku by otavanopisto.

the class UserGroupUserEntityDAO method create.

public UserGroupUserEntity create(UserGroupEntity userGroupEntity, SchoolDataSource schoolDataSource, String identifier, UserSchoolDataIdentifier userSchoolDataIdentifier, boolean archived) {
    UserGroupUserEntity userGroupUser = new UserGroupUserEntity();
    userGroupUser.setArchived(archived);
    userGroupUser.setSchoolDataSource(schoolDataSource);
    userGroupUser.setIdentifier(identifier);
    userGroupUser.setUserGroupEntity(userGroupEntity);
    userGroupUser.setUserSchoolDataIdentifier(userSchoolDataIdentifier);
    getEntityManager().persist(userGroupUser);
    return userGroupUser;
}
Also used : UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity)

Example 5 with UserGroupUserEntity

use of fi.otavanopisto.muikku.model.users.UserGroupUserEntity in project muikku by otavanopisto.

the class UserGroupUserEntityDAO method findByDataSourceAndIdentifier.

public UserGroupUserEntity findByDataSourceAndIdentifier(SchoolDataSource schoolDataSource, String identifier) {
    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_.schoolDataSource), schoolDataSource), criteriaBuilder.equal(root.get(UserGroupUserEntity_.identifier), identifier)));
    return getSingleResult(entityManager.createQuery(criteria));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity)

Aggregations

UserGroupUserEntity (fi.otavanopisto.muikku.model.users.UserGroupUserEntity)22 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)11 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)8 EntityManager (javax.persistence.EntityManager)8 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)8 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)3 Path (javax.ws.rs.Path)3 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)2 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)2 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)2 StudentGroupType (fi.otavanopisto.muikku.plugins.schooldatapyramus.PyramusIdentifierMapper.StudentGroupType)2 StudentGroupStudent (fi.otavanopisto.pyramus.rest.model.StudentGroupStudent)2 StudentGroupUser (fi.otavanopisto.pyramus.rest.model.StudentGroupUser)2 ArrayList (java.util.ArrayList)2 DELETE (javax.ws.rs.DELETE)2 Tag (fi.otavanopisto.muikku.model.base.Tag)1 CommunicatorMessage (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)1 CommunicatorMessageCategory (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageCategory)1 CommunicatorMessageId (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId)1 CommunicatorMessageRecipientUserGroup (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientUserGroup)1