Search in sources :

Example 21 with CommunicatorMessageId

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();
}
Also used : CommunicatorMessageId(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 22 with CommunicatorMessageId

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();
}
Also used : CommunicatorMessageIdLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel) CommunicatorMessageId(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId) CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 23 with CommunicatorMessageId

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();
    }
}
Also used : CommunicatorMessageIdLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel) CommunicatorMessageId(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId) CommunicatorLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorLabel) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 24 with CommunicatorMessageId

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();
    }
}
Also used : CommunicatorMessageIdLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel) CommunicatorMessageId(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId) CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage) CommunicatorUserLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorUserLabel) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 25 with CommunicatorMessageId

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();
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) CommunicatorMessageId(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CommunicatorMessageCategory(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageCategory) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Tag(fi.otavanopisto.muikku.model.base.Tag) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Aggregations

CommunicatorMessageId (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId)26 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)22 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)20 Path (javax.ws.rs.Path)20 CommunicatorMessage (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)10 CommunicatorMessageIdLabel (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel)8 GET (javax.ws.rs.GET)8 POST (javax.ws.rs.POST)8 CommunicatorMessageRecipient (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient)6 ArrayList (java.util.ArrayList)6 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)5 CommunicatorMessageCategory (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageCategory)4 Tag (fi.otavanopisto.muikku.model.base.Tag)3 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)3 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)3 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)3 DELETE (javax.ws.rs.DELETE)3 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)2 User (fi.otavanopisto.muikku.schooldata.entity.User)2 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)2