Search in sources :

Example 6 with CommunicatorMessageCategory

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

Example 7 with CommunicatorMessageCategory

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

Example 8 with CommunicatorMessageCategory

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());
}
Also used : Locale(java.util.Locale) CommunicatorMessageCategory(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageCategory) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace)

Example 9 with CommunicatorMessageCategory

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();
}
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

CommunicatorMessageCategory (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageCategory)9 CommunicatorMessageId (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId)4 Tag (fi.otavanopisto.muikku.model.base.Tag)3 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)3 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)3 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)3 CommunicatorMessage (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)3 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)3 ArrayList (java.util.ArrayList)3 Locale (java.util.Locale)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 EntityTag (javax.ws.rs.core.EntityTag)2 UserGroupUserEntity (fi.otavanopisto.muikku.model.users.UserGroupUserEntity)1 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)1 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)1 CommunicatorMessageSent (fi.otavanopisto.muikku.plugins.communicator.events.CommunicatorMessageSent)1 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)1 HashMap (java.util.HashMap)1 EntityManager (javax.persistence.EntityManager)1