Search in sources :

Example 6 with Message

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();
}
Also used : Message(io.hops.hopsworks.persistence.entity.message.Message) GenericEntity(javax.ws.rs.core.GenericEntity) List(java.util.List) Users(io.hops.hopsworks.persistence.entity.user.Users) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 7 with Message

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);
    }
}
Also used : Message(io.hops.hopsworks.persistence.entity.message.Message) Users(io.hops.hopsworks.persistence.entity.user.Users) Date(java.util.Date)

Example 8 with Message

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);
}
Also used : Message(io.hops.hopsworks.persistence.entity.message.Message) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 9 with Message

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();
}
Also used : Message(io.hops.hopsworks.persistence.entity.message.Message) Users(io.hops.hopsworks.persistence.entity.user.Users) RequestException(io.hops.hopsworks.exceptions.RequestException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 10 with Message

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();
}
Also used : Message(io.hops.hopsworks.persistence.entity.message.Message) Users(io.hops.hopsworks.persistence.entity.user.Users) RequestException(io.hops.hopsworks.exceptions.RequestException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

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