use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId in project muikku by otavanopisto.
the class CommunicatorRESTService method getCommunicatorMessageMessageCount.
@GET
@Path("/messages/{COMMUNICATORMESSAGEID}/messagecount")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response getCommunicatorMessageMessageCount(@PathParam("COMMUNICATORMESSAGEID") Long communicatorMessageId) {
UserEntity user = sessionController.getLoggedUserEntity();
CommunicatorMessageId messageId = communicatorController.findCommunicatorMessageId(communicatorMessageId);
Long result = communicatorController.countMessagesByUserAndMessageId(user, messageId, false);
return Response.ok(result).build();
}
use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId 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.CommunicatorMessageId in project muikku by otavanopisto.
the class CommunicatorRESTService method markInboxAsRead.
@POST
@Path("/items/{COMMUNICATORMESSAGEID}/markasread")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response markInboxAsRead(@PathParam("COMMUNICATORMESSAGEID") Long communicatorMessageId) {
UserEntity user = sessionController.getLoggedUserEntity();
CommunicatorMessageId messageId = communicatorController.findCommunicatorMessageId(communicatorMessageId);
List<CommunicatorMessageRecipient> list = communicatorController.listCommunicatorMessageRecipientsByUserAndMessage(user, messageId, false);
for (CommunicatorMessageRecipient r : list) {
communicatorController.updateRead(r, true);
}
return Response.noContent().build();
}
use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId 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.CommunicatorMessageId in project muikku by otavanopisto.
the class CommunicatorRESTService method deleteSentMessages.
@DELETE
@Path("/sentitems/{COMMUNICATORMESSAGEID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response deleteSentMessages(@PathParam("COMMUNICATORMESSAGEID") Long communicatorMessageId) throws AuthorizationException {
UserEntity user = sessionController.getLoggedUserEntity();
CommunicatorMessageId messageId = communicatorController.findCommunicatorMessageId(communicatorMessageId);
communicatorController.trashSentMessages(user, messageId);
return Response.noContent().build();
}
Aggregations