/** * Update the running state of a ticket * * <p>// TODO: add manifest ingest as form/multipart * * @param ticket * @param isError * @param description * @param isFinished * @param response */ @POST @Path("{ticket}") public void setStatus( @PathParam("ticket") String ticket, @FormParam("isError") @DefaultValue(value = "false") boolean isError, @FormParam("description") String description, @FormParam("isFinished") @DefaultValue(value = "false") boolean isFinished, @Context HttpServletResponse response) { try { NDC.push("U" + ticket); LOG.info("Ticket Request ID: " + ticket + " error: " + isError + " finished: " + isFinished); if (isError) { tm.errorTicket(ticket, description); } else if (isFinished) { tm.completeTicket(ticket, description); } else { tm.updateMessage(ticket, description); } } finally { LOG.info("Completed Ticket Request ID: " + ticket); NDC.pop(); } }
/** * response set to bad_request for non-existent tickets 200/OK for open tickets 201/CREATED for * successfully finished tickets 500/INTERNAL ERROR for requests that errored out 404/NOT_FOUND * * @param ticket * @param response * @return ticket object */ @GET @Path("{ticket}") @Produces("application/json") public Response getStatus( @PathParam("ticket") String ticketId, @Context HttpServletResponse response) { try { NDC.push("T" + ticketId); LOG.info("Ticket Request ID: " + ticketId); Ticket ticket = tm.getTicket(ticketId); ResponseBuilder rb; if (ticket != null) { switch (ticket.getStatus()) { case Ticket.STATUS_OPEN: rb = Response.status(Status.OK).header("Retry-After", "120").entity(ticket); break; case Ticket.STATUS_FINISHED: // finished case, return 201, response body set to stored manifest return Response.status(Status.CREATED).entity(ticket).build(); case Ticket.STATUS_ERROR: rb = Response.status(Status.INTERNAL_SERVER_ERROR).entity(ticket); break; default: LOG.error("Unknown response case: " + ticket.getStatusMessage()); rb = Response.status(Status.INTERNAL_SERVER_ERROR).entity(ticket); } } else { LOG.debug("Returning not-found, ticket ID unknown: " + ticketId); rb = Response.status(Status.NOT_FOUND); rb.type(MediaType.TEXT_PLAIN_TYPE); rb.entity("No such ticket " + ticketId); } return rb.build(); } finally { LOG.info("Completed Ticket Request ID: " + ticketId); NDC.pop(); } }
/** * Return list of all ticket. * * @return */ @GET @Produces("application/json") public List<Ticket> listTickets() { return tm.listAll(); }