use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId in project muikku by otavanopisto.
the class CommunicatorTrashRESTService method getCommunicatorMessageMessageCount.
@GET
@Path("/trash/{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, true);
return Response.ok(result).build();
}
use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId in project muikku by otavanopisto.
the class CommunicatorTrashRESTService method listUserCommunicatorMessagesByMessageId.
@GET
@Path("/trash/{COMMUNICATORMESSAGEID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listUserCommunicatorMessagesByMessageId(@PathParam("COMMUNICATORMESSAGEID") Long communicatorMessageId) {
UserEntity user = sessionController.getLoggedUserEntity();
CommunicatorMessageId threadId = communicatorController.findCommunicatorMessageId(communicatorMessageId);
List<CommunicatorMessage> receivedItems = communicatorController.listMessagesByMessageId(user, threadId, true);
List<CommunicatorMessageIdLabel> labels = communicatorController.listMessageIdLabelsByUserEntity(user, threadId);
List<CommunicatorMessageIdLabelRESTModel> restLabels = restModels.restLabel(labels);
CommunicatorMessageId olderThread = communicatorController.findOlderThreadId(user, threadId, CommunicatorFolderType.TRASH, null);
CommunicatorMessageId newerThread = communicatorController.findNewerThreadId(user, threadId, CommunicatorFolderType.TRASH, null);
return Response.ok(restModels.restThreadViewModel(receivedItems, olderThread, newerThread, restLabels)).build();
}
use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId in project muikku by otavanopisto.
the class CommunicatorLabelRESTService method createMessageIdLabel.
@POST
@Path("/messages/{COMMUNICATORMESSAGEID}/labels")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createMessageIdLabel(@PathParam("COMMUNICATORMESSAGEID") Long communicatorMessageId, CommunicatorMessageIdLabelRESTModel newLabel) throws AuthorizationException {
CommunicatorMessageId messageId = communicatorController.findCommunicatorMessageId(communicatorMessageId);
UserEntity userEntity = sessionController.getLoggedUserEntity();
CommunicatorLabel label = communicatorController.findUserLabelById(newLabel.getLabelId());
if ((label != null) && canAccessLabel(userEntity, label)) {
CommunicatorMessageIdLabel userLabel = communicatorController.findMessageIdLabel(userEntity, messageId, label);
if (userLabel == null) {
userLabel = communicatorController.createMessageIdLabel(userEntity, messageId, label);
return Response.ok(restModels.restLabel(userLabel)).build();
} else {
return Response.status(Status.BAD_REQUEST).build();
}
} else {
return Response.status(Status.NOT_FOUND).build();
}
}
use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId in project muikku by otavanopisto.
the class CommunicatorLabelRESTService method listUserUnreadCommunicatorMessagesByMessageId.
@GET
@Path("/userLabels/{USERLABELID}/messages/{COMMUNICATORMESSAGEID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listUserUnreadCommunicatorMessagesByMessageId(@PathParam("USERLABELID") Long userLabelId, @PathParam("COMMUNICATORMESSAGEID") Long communicatorMessageId) {
UserEntity userEntity = sessionController.getLoggedUserEntity();
CommunicatorUserLabel userLabel = communicatorController.findUserLabelById(userLabelId);
if ((userLabel != null) && canAccessLabel(userEntity, userLabel)) {
CommunicatorMessageId threadId = communicatorController.findCommunicatorMessageId(communicatorMessageId);
List<CommunicatorMessage> receivedItems = communicatorController.listMessagesByMessageId(userEntity, threadId, false);
List<CommunicatorMessageIdLabel> labels = communicatorController.listMessageIdLabelsByUserEntity(userEntity, threadId);
List<CommunicatorMessageIdLabelRESTModel> restLabels = restModels.restLabel(labels);
CommunicatorMessageId olderThread = communicatorController.findOlderThreadId(userEntity, threadId, CommunicatorFolderType.LABEL, userLabel);
CommunicatorMessageId newerThread = communicatorController.findNewerThreadId(userEntity, threadId, CommunicatorFolderType.LABEL, userLabel);
return Response.ok(restModels.restThreadViewModel(receivedItems, olderThread, newerThread, restLabels)).build();
} else {
return Response.status(Status.NOT_FOUND).build();
}
}
use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId 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