/** * For test purpose only * * @param id * @return * @throws UnknownResourceException */ @DELETE @Path("{id}") public Response delete(@PathParam("id") Long id) throws UnknownResourceException { int previousRows = productInventoryFacade.count(); Product entity = productInventoryFacade.find(id); // Event deletion // publisher.deletionNotification(entity, new Date()); try { // Pause for 4 seconds to finish notification Thread.sleep(4000); } catch (InterruptedException ex) { Logger.getLogger(ProductAdminResource.class.getName()).log(Level.SEVERE, null, ex); } // remove event(s) binding to the resource List<ProductEvent> events = eventFacade.findAll(); for (ProductEvent event : events) { if (event.getResource().getId().equals(id)) { eventFacade.remove(event.getId()); } } // remove resource productInventoryFacade.remove(id); int affectedRows = 1; Report stat = new Report(productInventoryFacade.count()); stat.setAffectedRows(affectedRows); stat.setPreviousRows(previousRows); // 200 Response response = Response.ok(stat).build(); return response; }
@DELETE @Path("event/{id}") public Response deleteEvent(@PathParam("id") String id) throws UnknownResourceException { int previousRows = eventFacade.count(); List<ProductEvent> events = eventFacade.findAll(); for (ProductEvent event : events) { if (event.getResource().getId().equals(id)) { eventFacade.remove(event.getId()); } } int currentRows = eventFacade.count(); int affectedRows = previousRows - currentRows; Report stat = new Report(currentRows); stat.setAffectedRows(affectedRows); stat.setPreviousRows(previousRows); // 200 Response response = Response.ok(stat).build(); return response; }
@GET @Produces({"application/json"}) @Path("event") public List<ProductEvent> findAllEvents() { return eventFacade.findAll(); }