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();
}
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();
}
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();
}
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();
}
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;
}
Aggregations