use of io.hops.hopsworks.persistence.entity.message.Message in project hopsworks by logicalclocks.
the class MessageService method getAllDeletedMessagesByUser.
@GET
@Path("deleted")
@Produces(MediaType.APPLICATION_JSON)
public Response getAllDeletedMessagesByUser(@Context SecurityContext sc) {
Users user = jWTHelper.getUserPrincipal(sc);
List<Message> list = msgFacade.getAllDeletedMessagesTo(user);
GenericEntity<List<Message>> msgs = new GenericEntity<List<Message>>(list) {
};
return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(msgs).build();
}
use of io.hops.hopsworks.persistence.entity.message.Message in project hopsworks by logicalclocks.
the class MessageController method sendToMany.
/**
* Sends message to multiple users.
* <p>
* @param recipients list of the receivers
* @param from the sender
* @param subject
* @param msg the message text
* @param requestPath requestPath if the message is a request this will
* contain the path
* to the requested dataset or project.
*/
public void sendToMany(List<Users> recipients, Users from, String subject, String msg, String requestPath) {
Date now = new Date();
if (recipients == null || recipients.isEmpty()) {
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.");
}
for (Users u : recipients) {
Message newMsg = // recipients,
new Message(from, u, now, msg, true, false);
newMsg.setPath(requestPath);
newMsg.setSubject(subject);
messageFacade.save(newMsg);
}
}
use of io.hops.hopsworks.persistence.entity.message.Message in project hopsworks by logicalclocks.
the class MessageController method reply.
/**
* Reply to a message by adding the reply to the original message and sending
* a new one.
* <p>
* @param user that is sending the reply
* @param msg that is replied to
* @param reply the reply text
*/
public void reply(Users user, Message msg, String reply) {
Date now = new Date();
if (msg.getFrom() == null) {
throw new IllegalArgumentException("Message does not contain a sender.");
}
if (reply == null || reply.isEmpty()) {
throw new IllegalArgumentException("Message is empty.");
}
if (reply.length() > MAX_MESSAGE_SIZE) {
throw new IllegalArgumentException("Message too long.");
}
String date = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(msg.getDateSent());
String dateAndWriter = "On " + date + ", " + user.getFname() + " " + user.getLname() + " wrote: <br><br>";
String replyMsg = REPLY_SEPARATOR + dateAndWriter + reply + msg.getContent();
if (replyMsg.length() > MAX_MESSAGE_SIZE) {
// size of text in db is 65535
replyMsg = REPLY_SEPARATOR + dateAndWriter + reply + MORE_MESSAGES;
}
boolean newMessage = false;
Message newMsg = msg.getReplyToMsg();
if (newMsg != null) {
newMsg = messageFacade.findMessageById(newMsg.getId());
} else {
newMessage = true;
newMsg = new Message(user, msg.getFrom(), now);
newMsg.setReplyToMsg(msg);
}
newMsg.setUnread(true);
newMsg.setDeleted(false);
newMsg.setContent(replyMsg);
String preview = user.getFname() + " replied ";
if (msg.getSubject() != null) {
preview = preview + "to your " + msg.getSubject().toLowerCase();
}
newMsg.setPreview(preview);
if (newMessage) {
messageFacade.save(newMsg);
} else {
messageFacade.update(newMsg);
}
msg.setContent(replyMsg);
if (msg.getReplyToMsg() == null) {
msg.setReplyToMsg(newMsg);
}
messageFacade.update(msg);
}
use of io.hops.hopsworks.persistence.entity.message.Message in project hopsworks by logicalclocks.
the class MessageService method deleteMessage.
@DELETE
@Path("{msgId}")
@Produces(MediaType.APPLICATION_JSON)
public Response deleteMessage(@PathParam("msgId") Integer msgId, @Context SecurityContext sc) throws RequestException {
Users user = jWTHelper.getUserPrincipal(sc);
Message msg = msgFacade.find(msgId);
if (msg == null) {
throw new RequestException(RESTCodes.RequestErrorCode.MESSAGE_NOT_FOUND, Level.FINE);
}
// check if the user is the owner of the message
checkMsgUser(msg, user);
msgFacade.remove(msg);
return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).build();
}
use of io.hops.hopsworks.persistence.entity.message.Message in project hopsworks by logicalclocks.
the class MessageService method reply.
@POST
@Path("reply/{msgId}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.TEXT_PLAIN)
public Response reply(@PathParam("msgId") Integer msgId, String content, @Context SecurityContext sc) throws RequestException {
Users user = jWTHelper.getUserPrincipal(sc);
Message msg = msgFacade.find(msgId);
if (msg == null) {
throw new RequestException(RESTCodes.RequestErrorCode.MESSAGE_NOT_FOUND, Level.FINE);
}
if (content == null) {
throw new IllegalArgumentException("content was not provided.");
}
// check if the user is the owner of the message
checkMsgUser(msg, user);
msgController.reply(user, msg, content);
return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(msg).build();
}
Aggregations