コード例 #1
0
  /**
   * For test purpose only
   *
   * @param entities
   * @return
   */
  @POST
  @Consumes({"application/json"})
  @Produces({"application/json"})
  public Response post(List<Product> entities, @Context UriInfo info)
      throws UnknownResourceException {

    if (entities == null) {
      return Response.status(Response.Status.BAD_REQUEST.getStatusCode()).build();
    }

    int previousRows = productInventoryFacade.count();
    int affectedRows = 0;

    // Try to persist entities
    try {
      for (Product entitie : entities) {
        productInventoryFacade.checkCreation(entitie);
        productInventoryFacade.create(entitie);
        entitie.setHref(info.getAbsolutePath() + "/" + Long.toString(entitie.getId()));
        productInventoryFacade.edit(entitie);
        affectedRows = affectedRows + 1;
        //                publisher.createNotification(entitie, new Date());
      }
    } catch (BadUsageException e) {
      return Response.status(Response.Status.BAD_REQUEST.getStatusCode()).build();
    }

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

    // 201 OK
    return Response.created(null).entity(stat).build();
  }
コード例 #2
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;
  }
コード例 #3
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;
  }
コード例 #4
0
 /** @return */
 @GET
 @Path("count")
 @Produces({"application/json"})
 public Report count() {
   return new Report(productInventoryFacade.count());
 }