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