use of fi.otavanopisto.muikku.model.users.UserGroupEntity in project muikku by otavanopisto.
the class AcceptanceTestsRESTService method createAnnouncement.
@POST
@Path("/announcements")
@RESTPermit(handling = Handling.UNSECURED)
public Response createAnnouncement(fi.otavanopisto.muikku.atests.Announcement payload) {
UserEntity user = userEntityController.findUserEntityById(payload.getPublisherUserEntityId());
Announcement announcement = announcementController.createAnnouncement(user, payload.getCaption(), payload.getContent(), payload.getStartDate(), payload.getEndDate(), payload.getPubliclyVisible());
if (payload.getUserGroupEntityIds() != null) {
List<Long> userGroups = payload.getUserGroupEntityIds();
for (Long userGroupId : userGroups) {
UserGroupEntity userGroup = userGroupEntityController.findUserGroupEntityById(userGroupId);
announcementController.addAnnouncementTargetGroup(announcement, userGroup);
}
}
return Response.ok(announcement.getId()).build();
}
use of fi.otavanopisto.muikku.model.users.UserGroupEntity 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.UserGroupEntity in project muikku by otavanopisto.
the class AnnouncerRESTService method createAnnouncement.
@POST
@Path("/announcements")
@RESTPermit(handling = Handling.INLINE)
public Response createAnnouncement(AnnouncementRESTModel restModel) {
UserEntity userEntity = sessionController.getLoggedUserEntity();
List<Long> workspaceEntityIds = restModel.getWorkspaceEntityIds();
if (workspaceEntityIds == null) {
workspaceEntityIds = Collections.emptyList();
}
List<Long> userGroupEntityIds = restModel.getUserGroupEntityIds();
if (userGroupEntityIds == null) {
userGroupEntityIds = Collections.emptyList();
}
if (workspaceEntityIds.isEmpty() && !sessionController.hasEnvironmentPermission(AnnouncerPermissions.CREATE_ANNOUNCEMENT)) {
return Response.status(Status.FORBIDDEN).entity("You don't have the permission to create environment announcements").build();
}
for (Long workspaceEntityId : workspaceEntityIds) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid workspaceEntityId").build();
}
if (!sessionController.hasWorkspacePermission(AnnouncerPermissions.CREATE_WORKSPACE_ANNOUNCEMENT, workspaceEntity)) {
return Response.status(Status.FORBIDDEN).entity("You don't have the permission to create workspace announcement").build();
}
}
Announcement announcement = announcementController.createAnnouncement(userEntity, restModel.getCaption(), restModel.getContent(), restModel.getStartDate(), restModel.getEndDate(), restModel.getPubliclyVisible());
for (Long userGroupEntityId : userGroupEntityIds) {
UserGroupEntity userGroupEntity = userGroupEntityController.findUserGroupEntityById(userGroupEntityId);
if (userGroupEntity == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid userGroupEntityId").build();
}
announcementController.addAnnouncementTargetGroup(announcement, userGroupEntity);
}
for (Long workspaceEntityId : workspaceEntityIds) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid workspaceEntityId").build();
}
announcementController.addAnnouncementWorkspace(announcement, workspaceEntity);
}
return Response.noContent().build();
}
use of fi.otavanopisto.muikku.model.users.UserGroupEntity in project muikku by otavanopisto.
the class UserGroupEntityDAO method create.
public UserGroupEntity create(SchoolDataSource defaultSchoolDataSource, String defaultIdentifier, boolean archived) {
UserGroupEntity userGroup = new UserGroupEntity();
userGroup.setArchived(archived);
userGroup.setSchoolDataSource(defaultSchoolDataSource);
userGroup.setIdentifier(defaultIdentifier);
getEntityManager().persist(userGroup);
return userGroup;
}
use of fi.otavanopisto.muikku.model.users.UserGroupEntity in project muikku by otavanopisto.
the class UserGroupEntityDAO method findByDataSourceAndIdentifier.
public UserGroupEntity findByDataSourceAndIdentifier(SchoolDataSource schoolDataSource, String identifier) {
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.and(criteriaBuilder.equal(root.get(UserGroupEntity_.schoolDataSource), schoolDataSource), criteriaBuilder.equal(root.get(UserGroupEntity_.identifier), identifier)));
return getSingleResult(entityManager.createQuery(criteria));
}
Aggregations