Search in sources :

Example 11 with Message

use of io.hops.hopsworks.persistence.entity.message.Message in project hopsworks by logicalclocks.

the class MessageController method send.

/**
 * Sends a message to a single user
 * <p>
 * @param to
 * @param from
 * @param subject
 * @param preview
 * @param msg
 * @param requestPath if the message is a request this will contain the path
 * to the requested dataset or project.
 */
public void send(Users to, Users from, String subject, String preview, String msg, String requestPath) {
    Date now = new Date();
    if (to == null) {
        throw new IllegalArgumentException("No recipient specified.");
    }
    if (msg == null || msg.isEmpty()) {
        throw new IllegalArgumentException("Message is empty.");
    }
    if (msg.length() > MAX_MESSAGE_SIZE) {
        throw new IllegalArgumentException("Message too long.");
    }
    String date = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(now);
    String dateAndWriter = "On " + date + ", " + from.getFname() + " " + from.getLname() + " wrote: <br><br>";
    String message = REPLY_SEPARATOR + dateAndWriter + msg;
    Message newMsg = new Message(from, to, now, message, true, false);
    newMsg.setPath(requestPath);
    newMsg.setSubject(subject);
    newMsg.setPreview(preview);
    messageFacade.save(newMsg);
}
Also used : Message(io.hops.hopsworks.persistence.entity.message.Message) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

Message (io.hops.hopsworks.persistence.entity.message.Message)11 Users (io.hops.hopsworks.persistence.entity.user.Users)9 Produces (javax.ws.rs.Produces)8 Path (javax.ws.rs.Path)7 RequestException (io.hops.hopsworks.exceptions.RequestException)4 DatasetRequest (io.hops.hopsworks.persistence.entity.dataset.DatasetRequest)3 Date (java.util.Date)3 PUT (javax.ws.rs.PUT)3 SimpleDateFormat (java.text.SimpleDateFormat)2 List (java.util.List)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 GenericEntity (javax.ws.rs.core.GenericEntity)2 RESTApiJsonResponse (io.hops.hopsworks.api.util.RESTApiJsonResponse)1 DatasetException (io.hops.hopsworks.exceptions.DatasetException)1 ProjectException (io.hops.hopsworks.exceptions.ProjectException)1 Dataset (io.hops.hopsworks.persistence.entity.dataset.Dataset)1 Inode (io.hops.hopsworks.persistence.entity.hdfs.inode.Inode)1 Project (io.hops.hopsworks.persistence.entity.project.Project)1 ProjectTeam (io.hops.hopsworks.persistence.entity.project.team.ProjectTeam)1