public void createVendorPart(
      String partNumber, int revision, String description, double price, int vendorId) {
    try {
      PartKey pkey = new PartKey();
      pkey.setPartNumber(partNumber);
      pkey.setRevision(revision);

      Part part = em.find(Part.class, pkey);

      VendorPart vendorPart = new VendorPart(description, price, part);
      em.persist(vendorPart);

      Vendor vendor = em.find(Vendor.class, vendorId);
      vendor.addVendorPart(vendorPart);
      vendorPart.setVendor(vendor);
    } catch (Exception e) {
      throw new EJBException(e.getMessage());
    }
  }
  public void addLineItem(Integer orderId, String partNumber, int revision, int quantity) {
    try {
      CustomerOrder order = em.find(CustomerOrder.class, orderId);
      logger.log(Level.INFO, "Found order ID {0}", orderId);

      PartKey pkey = new PartKey();
      pkey.setPartNumber(partNumber);
      pkey.setRevision(revision);

      Part part = em.find(Part.class, pkey);

      LineItem lineItem = new LineItem(order, quantity, part.getVendorPart());
      order.addLineItem(lineItem);
    } catch (Exception e) {
      logger.log(
          Level.WARNING, "Couldn''t add {0} to order ID {1}.", new Object[] {partNumber, orderId});
      throw new EJBException(e.getMessage());
    }
  }
  public double getBillOfMaterialPrice(
      String bomPartNumber, int bomRevision, String partNumber, int revision) {
    double price = 0.0;
    try {
      PartKey bomkey = new PartKey();
      bomkey.setPartNumber(bomPartNumber);
      bomkey.setRevision(bomRevision);

      Part bom = em.find(Part.class, bomkey);
      Collection<Part> parts = bom.getParts();
      for (Part part : parts) {
        VendorPart vendorPart = part.getVendorPart();
        price += vendorPart.getPrice();
      }

    } catch (Exception e) {
      throw new EJBException(e.getMessage());
    }
    return price;
  }
  public void addPartToBillOfMaterial(
      String bomPartNumber, int bomRevision, String partNumber, int revision) {
    logger.log(Level.INFO, "BOM part number: {0}", bomPartNumber);
    logger.log(Level.INFO, "BOM revision: {0}", bomRevision);
    logger.log(Level.INFO, "Part number: {0}", partNumber);
    logger.log(Level.INFO, "Part revision: {0}", revision);
    try {
      PartKey bomKey = new PartKey();
      bomKey.setPartNumber(bomPartNumber);
      bomKey.setRevision(bomRevision);

      Part bom = em.find(Part.class, bomKey);
      logger.log(Level.INFO, "BOM Part found: {0}", bom.getPartNumber());

      PartKey partKey = new PartKey();
      partKey.setPartNumber(partNumber);
      partKey.setRevision(revision);

      Part part = em.find(Part.class, partKey);
      logger.log(Level.INFO, "Part found: {0}", part.getPartNumber());
      bom.getParts().add(part);
      part.setBomPart(bom);
    } catch (EJBException e) {
    }
  }