use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageCategory in project muikku by otavanopisto.
the class CommunicatorRESTService method postMessage.
@POST
@Path("/messages")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response postMessage(CommunicatorNewMessageRESTModel newMessage) throws AuthorizationException {
UserEntity userEntity = sessionController.getLoggedUserEntity();
CommunicatorMessageId communicatorMessageId = communicatorController.createMessageId();
Set<Tag> tagList = parseTags(newMessage.getTags());
List<UserEntity> recipients = new ArrayList<UserEntity>();
for (Long recipientId : newMessage.getRecipientIds()) {
UserEntity recipient = userEntityController.findUserEntityById(recipientId);
if (recipient != null)
recipients.add(recipient);
}
List<UserGroupEntity> userGroupRecipients = null;
List<WorkspaceEntity> workspaceStudentRecipients = null;
List<WorkspaceEntity> workspaceTeacherRecipients = null;
if (!CollectionUtils.isEmpty(newMessage.getRecipientGroupIds())) {
if (sessionController.hasEnvironmentPermission(CommunicatorPermissionCollection.COMMUNICATOR_GROUP_MESSAGING)) {
userGroupRecipients = new ArrayList<UserGroupEntity>();
for (Long groupId : newMessage.getRecipientGroupIds()) {
UserGroupEntity group = userGroupEntityController.findUserGroupEntityById(groupId);
userGroupRecipients.add(group);
}
} else {
// Trying to feed group ids when you don't have permission greets you with bad request
return Response.status(Status.BAD_REQUEST).build();
}
}
if (!CollectionUtils.isEmpty(newMessage.getRecipientStudentsWorkspaceIds())) {
workspaceStudentRecipients = new ArrayList<WorkspaceEntity>();
for (Long workspaceId : newMessage.getRecipientStudentsWorkspaceIds()) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceId);
if (sessionController.hasPermission(CommunicatorPermissionCollection.COMMUNICATOR_WORKSPACE_MESSAGING, workspaceEntity))
workspaceStudentRecipients.add(workspaceEntity);
else
return Response.status(Status.BAD_REQUEST).build();
}
}
if (!CollectionUtils.isEmpty(newMessage.getRecipientTeachersWorkspaceIds())) {
workspaceTeacherRecipients = new ArrayList<WorkspaceEntity>();
for (Long workspaceId : newMessage.getRecipientTeachersWorkspaceIds()) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceId);
if (sessionController.hasPermission(CommunicatorPermissionCollection.COMMUNICATOR_WORKSPACE_MESSAGING, workspaceEntity))
workspaceTeacherRecipients.add(workspaceEntity);
else
return Response.status(Status.BAD_REQUEST).build();
}
}
if (StringUtils.isBlank(newMessage.getCategoryName())) {
return Response.status(Status.BAD_REQUEST).entity("CategoryName missing").build();
}
// TODO Category not existing at this point would technically indicate an invalid state
CommunicatorMessageCategory categoryEntity = communicatorController.persistCategory(newMessage.getCategoryName());
CommunicatorMessage message = communicatorController.createMessage(communicatorMessageId, userEntity, recipients, userGroupRecipients, workspaceStudentRecipients, workspaceTeacherRecipients, categoryEntity, newMessage.getCaption(), newMessage.getContent(), tagList);
sendNewMessageNotifications(message);
return Response.ok(restModels.restFullMessage(message)).build();
}
use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageCategory in project muikku by otavanopisto.
the class CommunicatorRESTService method postMessageReply.
@POST
@Path("/messages/{COMMUNICATORMESSAGEID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response postMessageReply(@PathParam("COMMUNICATORMESSAGEID") Long communicatorMessageId, CommunicatorNewMessageRESTModel newMessage) throws AuthorizationException {
UserEntity userEntity = sessionController.getLoggedUserEntity();
CommunicatorMessageId communicatorMessageId2 = communicatorController.findCommunicatorMessageId(communicatorMessageId);
Set<Tag> tagList = parseTags(newMessage.getTags());
List<UserEntity> recipients = new ArrayList<UserEntity>();
for (Long recipientId : newMessage.getRecipientIds()) {
UserEntity recipient = userEntityController.findUserEntityById(recipientId);
if (recipient != null)
recipients.add(recipient);
}
List<UserGroupEntity> userGroupRecipients = null;
List<WorkspaceEntity> workspaceStudentRecipients = null;
List<WorkspaceEntity> workspaceTeacherRecipients = null;
if (!CollectionUtils.isEmpty(newMessage.getRecipientGroupIds())) {
if (sessionController.hasEnvironmentPermission(CommunicatorPermissionCollection.COMMUNICATOR_GROUP_MESSAGING)) {
userGroupRecipients = new ArrayList<UserGroupEntity>();
for (Long groupId : newMessage.getRecipientGroupIds()) {
UserGroupEntity group = userGroupEntityController.findUserGroupEntityById(groupId);
userGroupRecipients.add(group);
}
} else {
// Trying to feed group ids when you don't have permission greets you with bad request
return Response.status(Status.BAD_REQUEST).build();
}
}
if (!CollectionUtils.isEmpty(newMessage.getRecipientStudentsWorkspaceIds())) {
workspaceStudentRecipients = new ArrayList<WorkspaceEntity>();
for (Long workspaceId : newMessage.getRecipientStudentsWorkspaceIds()) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceId);
if (sessionController.hasPermission(CommunicatorPermissionCollection.COMMUNICATOR_WORKSPACE_MESSAGING, workspaceEntity))
workspaceStudentRecipients.add(workspaceEntity);
else
return Response.status(Status.BAD_REQUEST).build();
}
}
if (!CollectionUtils.isEmpty(newMessage.getRecipientTeachersWorkspaceIds())) {
workspaceTeacherRecipients = new ArrayList<WorkspaceEntity>();
for (Long workspaceId : newMessage.getRecipientTeachersWorkspaceIds()) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceId);
if (sessionController.hasPermission(CommunicatorPermissionCollection.COMMUNICATOR_WORKSPACE_MESSAGING, workspaceEntity))
workspaceTeacherRecipients.add(workspaceEntity);
else
return Response.status(Status.BAD_REQUEST).build();
}
}
// TODO Category not existing at this point would technically indicate an invalid state
CommunicatorMessageCategory categoryEntity = communicatorController.persistCategory(newMessage.getCategoryName());
CommunicatorMessage message = communicatorController.createMessage(communicatorMessageId2, userEntity, recipients, userGroupRecipients, workspaceStudentRecipients, workspaceTeacherRecipients, categoryEntity, newMessage.getCaption(), newMessage.getContent(), tagList);
sendNewMessageNotifications(message);
return Response.ok(restModels.restFullMessage(message)).build();
}
use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageCategory in project muikku by otavanopisto.
the class EvaluationController method notifyOfIncompleteWorkspace.
private void notifyOfIncompleteWorkspace(UserEntity teacher, UserEntity student, WorkspaceEntity workspaceEntity, String verbalAssessment) {
// Workspace
Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
String workspaceUrl = String.format("%s/workspace/%s/materials", baseUrl, workspaceEntity.getUrlName());
String workspaceName = workspace.getName();
if (!StringUtils.isBlank(workspace.getNameExtension())) {
workspaceName = String.format("%s (%s)", workspaceName, workspace.getNameExtension());
}
Locale locale = userEntityController.getLocale(student);
CommunicatorMessageCategory category = communicatorController.persistCategory("assessments");
communicatorController.createMessage(communicatorController.createMessageId(), teacher, Arrays.asList(student), null, null, null, category, localeController.getText(locale, "plugin.evaluation.workspaceIncomplete.notificationCaption"), localeController.getText(locale, "plugin.evaluation.workspaceIncomplete.notificationText", new Object[] { workspaceUrl, workspaceName, verbalAssessment }), Collections.<Tag>emptySet());
}
use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageCategory 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();
}
Aggregations