コード例 #1
0
  /**
   * 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;
  }
コード例 #2
0
  @DELETE
  @Path("event")
  public Report deleteAllEvent() {

    int previousRows = eventFacade.count();
    eventFacade.removeAll();
    int currentRows = eventFacade.count();
    int affectedRows = previousRows - currentRows;

    Report stat = new Report(currentRows);
    stat.setAffectedRows(affectedRows);
    stat.setPreviousRows(previousRows);

    return stat;
  }
コード例 #3
0
  @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;
  }
コード例 #4
0
  /**
   * For test purpose only
   *
   * @return
   * @throws org.tmf.dsmapi.commons.exceptions.UnknownResourceException
   */
  @DELETE
  public Report deleteAll() throws UnknownResourceException {

    eventFacade.removeAll();
    int previousRows = productInventoryFacade.count();
    productInventoryFacade.removeAll();
    List<Product> pis = productInventoryFacade.findAll();
    for (Product pi : pis) {
      delete(pi.getId());
    }

    int currentRows = productInventoryFacade.count();
    int affectedRows = previousRows - currentRows;

    Report stat = new Report(currentRows);
    stat.setAffectedRows(affectedRows);
    stat.setPreviousRows(previousRows);

    return stat;
  }
コード例 #5
0
 @GET
 @Produces({"application/json"})
 @Path("event")
 public List<ProductEvent> findAllEvents() {
   return eventFacade.findAll();
 }