Search in sources :

Example 21 with CommunicatorMessage

use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage 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 22 with CommunicatorMessage

use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage 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 23 with CommunicatorMessage

use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage in project muikku by otavanopisto.

the class CommunicatorController method trashAllThreadMessages.

public void trashAllThreadMessages(UserEntity user, CommunicatorMessageId messageId) {
    List<CommunicatorMessageRecipient> received = communicatorMessageRecipientDAO.listByUserAndMessageId(user, messageId, false, false);
    for (CommunicatorMessageRecipient recipient : received) {
        communicatorMessageRecipientDAO.updateTrashedByReceiver(recipient, true);
    }
    List<CommunicatorMessage> sentMessages = communicatorMessageDAO.listMessagesInSentThread(user, messageId, false, false);
    for (CommunicatorMessage message : sentMessages) {
        communicatorMessageDAO.updateTrashedBySender(message, true);
    }
}
Also used : CommunicatorMessageRecipient(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient) CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)

Example 24 with CommunicatorMessage

use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage in project muikku by otavanopisto.

the class CommunicatorMessageSentNotifier method onCommunicatorMessageSent.

@Asynchronous
@AccessTimeout(value = 30, unit = TimeUnit.MINUTES)
@Transactional(value = TxType.REQUIRES_NEW)
public void onCommunicatorMessageSent(@Observes(during = TransactionPhase.AFTER_COMPLETION) CommunicatorMessageSent event) {
    CommunicatorMessage communicatorMessage = communicatorController.findCommunicatorMessageById(event.getCommunicatorMessageId());
    UserEntity sender = userEntityController.findUserEntityById(communicatorMessage.getSender());
    UserEntity recipient = userEntityController.findUserEntityById(event.getRecipientUserEntityId());
    if ((communicatorMessage != null) && (sender != null) && (recipient != null)) {
        if (!Objects.equals(sender.getId(), recipient.getId())) {
            Map<String, Object> params = new HashMap<String, Object>();
            User senderUser = userController.findUserByUserEntityDefaults(sender);
            params.put("sender", String.format("%s %s", senderUser.getFirstName(), senderUser.getLastName()));
            params.put("subject", communicatorMessage.getCaption());
            params.put("content", communicatorMessage.getContent());
            params.put("url", String.format("%s/communicator", event.getBaseUrl()));
            // TODO Hash paramters cannot be utilized in redirect URLs
            // params.put("url", String.format("%s/communicator#inbox/%d", baseUrl, message.getCommunicatorMessageId().getId()));
            notifierController.sendNotification(communicatorNewInboxMessageNotification, sender, recipient, params);
        }
    } else {
        logger.log(Level.SEVERE, String.format("Communicator couldn't send notifications as some entity was not found"));
    }
}
Also used : CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage) User(fi.otavanopisto.muikku.schooldata.entity.User) HashMap(java.util.HashMap) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Asynchronous(javax.ejb.Asynchronous) AccessTimeout(javax.ejb.AccessTimeout) Transactional(javax.transaction.Transactional)

Example 25 with CommunicatorMessage

use of fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage in project muikku by otavanopisto.

the class CommunicatorAssessmentRequestController method sendAssessmentRequestMessage.

public CommunicatorMessage sendAssessmentRequestMessage(WorkspaceAssessmentRequest assessmentRequest) {
    SchoolDataIdentifier workspaceUserIdentifier = new SchoolDataIdentifier(assessmentRequest.getWorkspaceUserIdentifier(), assessmentRequest.getWorkspaceUserSchoolDataSource());
    WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifier(workspaceUserIdentifier);
    if (workspaceUserEntity == null) {
        logger.severe(String.format("Could not find workspace user entity for identifier", workspaceUserIdentifier));
        return null;
    }
    UserSchoolDataIdentifier userSchoolDataIdentifier = workspaceUserEntity.getUserSchoolDataIdentifier();
    if (userSchoolDataIdentifier == null) {
        logger.severe(String.format("Could not find userSchoolDataIdentifier for workspace user entity %d", workspaceUserEntity.getId()));
        return null;
    }
    WorkspaceEntity workspaceEntity = workspaceUserEntity.getWorkspaceEntity();
    if (workspaceEntity == null) {
        logger.severe(String.format("Could not find workspaceEntity for workspace user entity %d", workspaceUserEntity.getId()));
        return null;
    }
    UserEntity studentEntity = userSchoolDataIdentifier.getUserEntity();
    if (studentEntity == null) {
        logger.severe(String.format("Could not find studentEntity for workspace user entity %d", workspaceUserEntity.getId()));
        return null;
    }
    CommunicatorMessageId communicatorMessageId = assessmentRequestController.findCommunicatorMessageId(workspaceUserEntity);
    schoolDataBridgeSessionController.startSystemSession();
    try {
        SchoolDataIdentifier studentIdentifier = new SchoolDataIdentifier(userSchoolDataIdentifier.getIdentifier(), userSchoolDataIdentifier.getDataSource().getIdentifier());
        List<UserEntity> teachers = new ArrayList<UserEntity>();
        List<WorkspaceUserEntity> workspaceTeachers = workspaceUserEntityController.listActiveWorkspaceStaffMembers(workspaceEntity);
        for (WorkspaceUserEntity workspaceTeacher : workspaceTeachers) {
            teachers.add(workspaceTeacher.getUserSchoolDataIdentifier().getUserEntity());
        }
        User student = userController.findUserByIdentifier(studentIdentifier);
        if (student == null) {
            logger.severe(String.format("Could not find student %s", studentIdentifier));
            return null;
        }
        Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
        if (workspace == null) {
            logger.severe(String.format("Could not find workspace for workspace entity %d", workspaceEntity.getId()));
            return null;
        }
        String messageCategory = getText("plugin.communicator.assessmentrequest.category");
        String messageTitle = assessmentRequestTitle(workspace, student);
        String messageBody = assessmentRequestBody(workspace, student, assessmentRequest.getRequestText());
        List<String> teacherEmails = new ArrayList<>(teachers.size());
        for (UserEntity teacher : teachers) {
            String teacherEmail = userEmailEntityController.getUserDefaultEmailAddress(teacher, false);
            if (StringUtils.isNotBlank(teacherEmail)) {
                teacherEmails.add(teacherEmail);
            }
        }
        if (!teacherEmails.isEmpty()) {
            mailer.sendMail(MailType.HTML, teacherEmails, messageTitle, messageBody);
        }
        if (communicatorMessageId != null) {
            return communicatorController.replyToMessage(studentEntity, messageCategory, messageTitle, messageBody, teachers, communicatorMessageId);
        } else {
            CommunicatorMessage postMessage = communicatorController.postMessage(studentEntity, messageCategory, messageTitle, messageBody, teachers);
            assessmentRequestController.setCommunicatorMessageId(assessmentRequest, postMessage.getCommunicatorMessageId());
            return postMessage;
        }
    } finally {
        schoolDataBridgeSessionController.endSystemSession();
    }
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) CommunicatorMessageId(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId) User(fi.otavanopisto.muikku.schooldata.entity.User) CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage) ArrayList(java.util.ArrayList) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace)

Aggregations

CommunicatorMessage (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)28 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)14 CommunicatorMessageRecipient (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipient)13 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)12 Path (javax.ws.rs.Path)12 CommunicatorMessageId (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId)10 CommunicatorMessageIdLabel (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel)10 GET (javax.ws.rs.GET)10 EntityManager (javax.persistence.EntityManager)8 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)8 ArrayList (java.util.ArrayList)7 Date (java.util.Date)6 UserBasicInfo (fi.otavanopisto.muikku.rest.model.UserBasicInfo)5 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)4 Tag (fi.otavanopisto.muikku.model.base.Tag)3 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)3 CommunicatorMessageCategory (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageCategory)3 CommunicatorMessageRecipientUserGroup (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientUserGroup)3 CommunicatorMessageRecipientWorkspaceGroup (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageRecipientWorkspaceGroup)3 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)2