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