Search in sources :

Example 16 with UserGroupUserEntity

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

the class AcceptanceTestsRESTService method deleteUserGroupUser.

@DELETE
@Path("/userGroups/{USERGROUPID}/{USERID}")
@RESTPermit(handling = Handling.UNSECURED)
public Response deleteUserGroupUser(@PathParam("USERGROUPID") Long userGroupId, @PathParam("USERID") Long userId) {
    UserGroupUserEntity userGroupUser = userGroupEntityController.findUserGroupUserEntityById(userId);
    userGroupEntityController.deleteUserGroupUserEntity(userGroupUser);
    return Response.noContent().build();
}
Also used : UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.security.rest.RESTPermit)

Example 17 with UserGroupUserEntity

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

the class AcceptanceTestsRESTService method createCommunicatorMessage.

@POST
@Path("/communicator/messages")
@RESTPermit(handling = Handling.UNSECURED)
public Response createCommunicatorMessage(fi.otavanopisto.muikku.atests.CommunicatorMessage payload) {
    UserEntity user = userEntityController.findUserEntityById(payload.getSenderId());
    CommunicatorMessageId communicatorMessageId = communicatorController.createMessageId();
    Set<Tag> tagList = parseTags(payload.getTags());
    List<UserEntity> recipients = new ArrayList<UserEntity>();
    for (Long recipientId : payload.getRecipientIds()) {
        UserEntity recipient = userEntityController.findUserEntityById(recipientId);
        if (recipient != null)
            recipients.add(recipient);
    }
    for (Long groupId : payload.getRecipientGroupIds()) {
        UserGroupEntity group = userGroupEntityController.findUserGroupEntityById(groupId);
        List<UserGroupUserEntity> groupUsers = userGroupEntityController.listUserGroupUserEntitiesByUserGroupEntity(group);
        for (UserGroupUserEntity groupUser : groupUsers) {
            UserSchoolDataIdentifier userSchoolDataIdentifier = groupUser.getUserSchoolDataIdentifier();
            UserEntity userEntity = userSchoolDataIdentifier.getUserEntity();
            recipients.add(userEntity);
        }
    }
    for (Long workspaceId : payload.getRecipientStudentsWorkspaceIds()) {
        WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceId);
        List<WorkspaceUserEntity> workspaceUsers = workspaceUserEntityController.listActiveWorkspaceStudents(workspaceEntity);
        for (WorkspaceUserEntity wosu : workspaceUsers) {
            recipients.add(wosu.getUserSchoolDataIdentifier().getUserEntity());
        }
    }
    for (Long workspaceId : payload.getRecipientTeachersWorkspaceIds()) {
        WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceId);
        List<WorkspaceUserEntity> workspaceUsers = workspaceUserEntityController.listActiveWorkspaceStaffMembers(workspaceEntity);
        for (WorkspaceUserEntity wosu : workspaceUsers) {
            recipients.add(wosu.getUserSchoolDataIdentifier().getUserEntity());
        }
    }
    CommunicatorMessageCategory categoryEntity = communicatorController.persistCategory(payload.getCategoryName());
    fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage message = communicatorController.createMessage(communicatorMessageId, user, recipients, null, null, null, categoryEntity, payload.getCaption(), payload.getContent(), tagList);
    Long communicatorMessageId2 = message.getCommunicatorMessageId().getId();
    fi.otavanopisto.muikku.atests.CommunicatorMessage result = new fi.otavanopisto.muikku.atests.CommunicatorMessage(message.getId(), communicatorMessageId2, message.getSender(), payload.getCategoryName(), message.getCaption(), message.getContent(), message.getCreated(), payload.getTags(), payload.getRecipientIds(), payload.getRecipientGroupIds(), payload.getRecipientStudentsWorkspaceIds(), payload.getRecipientTeachersWorkspaceIds());
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("sender", "Admin User");
    params.put("subject", message.getCaption());
    params.put("content", message.getContent());
    params.put("url", "https://dev.muikku.fi/communicator");
    notifierController.sendNotification(communicatorNewInboxMessageNotification, user, recipients, params);
    return Response.ok(result).build();
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) CommunicatorMessageId(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CommunicatorMessageCategory(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageCategory) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Tag(fi.otavanopisto.muikku.model.base.Tag) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 18 with UserGroupUserEntity

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

the class UserGroupEntityDAO method countGroupUsers.

public Long countGroupUsers(UserGroupEntity userGroupEntity) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Long> criteria = criteriaBuilder.createQuery(Long.class);
    Root<UserGroupUserEntity> root = criteria.from(UserGroupUserEntity.class);
    criteria.select(criteriaBuilder.count(root));
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(UserGroupUserEntity_.userGroupEntity), userGroupEntity), criteriaBuilder.equal(root.get(UserGroupUserEntity_.archived), Boolean.FALSE)));
    return entityManager.createQuery(criteria).getSingleResult();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity)

Example 19 with UserGroupUserEntity

use of fi.otavanopisto.muikku.model.users.UserGroupUserEntity 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 20 with UserGroupUserEntity

use of fi.otavanopisto.muikku.model.users.UserGroupUserEntity 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)

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