Search in sources :

Example 1 with RequestException

use of io.hops.hopsworks.exceptions.RequestException in project hopsworks by logicalclocks.

the class MessageService method moveToTrash.

@PUT
@Path("moveToTrash/{msgId}")
@Produces(MediaType.APPLICATION_JSON)
public Response moveToTrash(@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);
    }
    // Delete Dataset request from the database
    if (!Strings.isNullOrEmpty(msg.getSubject())) {
        DatasetRequest dsReq = dsReqFacade.findByMessageId(msg);
        if (dsReq != null) {
            dsReqFacade.remove(dsReq);
        }
    }
    // check if the user is the owner of the message
    checkMsgUser(msg, user);
    msg.setDeleted(true);
    msgFacade.update(msg);
    return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).build();
}
Also used : Message(io.hops.hopsworks.persistence.entity.message.Message) DatasetRequest(io.hops.hopsworks.persistence.entity.dataset.DatasetRequest) Users(io.hops.hopsworks.persistence.entity.user.Users) RequestException(io.hops.hopsworks.exceptions.RequestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 2 with RequestException

use of io.hops.hopsworks.exceptions.RequestException in project hopsworks by logicalclocks.

the class MessageService method restoreFromTrash.

@PUT
@Path("restoreFromTrash/{msgId}")
@Produces(MediaType.APPLICATION_JSON)
public Response restoreFromTrash(@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);
    msg.setDeleted(false);
    msgFacade.update(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) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 3 with RequestException

use of io.hops.hopsworks.exceptions.RequestException 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 4 with RequestException

use of io.hops.hopsworks.exceptions.RequestException 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

RequestException (io.hops.hopsworks.exceptions.RequestException)4 Message (io.hops.hopsworks.persistence.entity.message.Message)4 Users (io.hops.hopsworks.persistence.entity.user.Users)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 PUT (javax.ws.rs.PUT)2 DatasetRequest (io.hops.hopsworks.persistence.entity.dataset.DatasetRequest)1 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1