Esempio n. 1
0
  public static Boolean checkProduct(ShopOrder order, Boolean execOrder) {

    boolean result = false;

    execOrder = false;

    OrderService os = new OrderService();

    Stock stock = (Stock) wirc.getByPath("localhost:8180", "Stock", "prdid", order.getProductID());

    System.out.println("O.qty" + order.getQty());
    System.out.println("s.qty" + stock.getQty());

    if (order.getQty() <= stock.getQty()) {
      result = true;
      if (execOrder) {
        stock.setQty(stock.getQty() - order.getQty());
        order.setPrice(os.calculatePriceLocal(order) * order.getQty());
        order.setTotalPrice(order.getPrice().intValue());
        wirc.putObject("localhost:8180", stock, stock.getId());
      }
      order.setStatus("OK");
    } else {
      order.setStatus("FAIL:QTY");
      result = false;
    }

    if (execOrder) {
      Long id = wirc.putObject("localhost:8180", order, null);
      order.setId(id);
    }

    return new Boolean(result);
  }
Esempio n. 2
0
 @POST
 @Consumes("application/json")
 public Response create(Stock entity) {
   em.persist(entity);
   return Response.created(
           UriBuilder.fromResource(StockEndpoint.class)
               .path(String.valueOf(entity.getId()))
               .build())
       .build();
 }
Esempio n. 3
0
  @PUT
  @Path("/{id:[0-9][0-9]*}")
  @Consumes("application/json")
  public Response update(@PathParam("id") Long id, Stock entity) {
    if (entity == null) {
      return Response.status(Status.BAD_REQUEST).build();
    }
    if (id == null) {
      return Response.status(Status.BAD_REQUEST).build();
    }
    if (!id.equals(entity.getId())) {
      return Response.status(Status.CONFLICT).entity(entity).build();
    }
    if (em.find(Stock.class, id) == null) {
      return Response.status(Status.NOT_FOUND).build();
    }
    try {
      entity = em.merge(entity);
    } catch (OptimisticLockException e) {
      return Response.status(Response.Status.CONFLICT).entity(e.getEntity()).build();
    }

    return Response.noContent().build();
  }