public OrderLineDTO addItem(Integer itemID, BigDecimal quantity) throws TaskException {
      LOG.debug("Adding item %s q: %s", itemID, quantity);

      BasicItemManager helper = new BasicItemManager();
      OrderLineDTO oldLine = order.getLine(itemID);
      FactHandle h = null;
      if (oldLine != null) {
        h = handlers.get(oldLine);
      }
      helper.addItem(
          itemID,
          quantity,
          language,
          userId,
          entityId,
          currencyId,
          order,
          records,
          lines,
          false,
          null,
          null);
      OrderLineDTO retValue = helper.getLatestLine();
      if (h != null) {
        LOG.debug("updating");
        session.update(h, retValue);
      } else {
        LOG.debug("inserting");
        handlers.put(retValue, session.insert(retValue));
      }

      LOG.debug("Now order line is %s , hash: %s", retValue, retValue.hashCode());
      return retValue;
    }
  private static void addItem(
      Integer itemID,
      BigDecimal quantity,
      Integer language,
      Integer userId,
      Integer currencyId,
      OrderDTO newOrder,
      OrderLineDTO myLine,
      boolean persist) {

    if (persist)
      throw new IllegalArgumentException("persist is oboleted"); // TODO remove the argument
    // check if the item is already in the order
    OrderLineDTO line = (OrderLineDTO) newOrder.getLine(itemID);

    if (myLine == null) {
      myLine = new OrderLineDTO();
      ItemDTO item = new ItemDTO();
      item.setId(itemID);
      myLine.setItem(item);
      myLine.setQuantity(quantity);
    }
    populateWithSimplePrice(
        newOrder, myLine, language, userId, currencyId, itemID, CommonConstants.BIGDECIMAL_SCALE);
    myLine.setDefaults();

    // create a new line if an existing line does not exist
    // if the line has a different description than the existing, treat it as a new line
    if (line == null
        || (myLine.getDescription() != null
            && !myLine.getDescription().equals(line.getDescription()))) {
      OrderLineDTO newLine = new OrderLineDTO(myLine);
      newOrder.getLines().add(newLine);
      newLine.setPurchaseOrder(newOrder);

      // save the order (with the new line). Otherwise
      // the diff line will have a '0' for the order id and the
      // saving of the mediation record lines gets really complicated
      if (persist) {
        new OrderDAS().save(newOrder);
      }
    } else {
      // the item is there, I just have to update the quantity
      line.setQuantity(line.getQuantity().add(quantity));

      // and also the total amount for this order line
      line.setAmount(
          line.getAmount()
              .setScale(CommonConstants.BIGDECIMAL_SCALE, CommonConstants.BIGDECIMAL_ROUND));
      line.setAmount(line.getAmount().add(myLine.getAmount()));
    }
  }
  public static void addLine(OrderDTO order, OrderLineDTO line, boolean persist) {
    if (persist)
      throw new IllegalArgumentException("persist is oboleted"); // TODO remove the argument
    UserBL user = new UserBL(order.getUserId());
    OrderLineDTO oldLine = order.getLine(line.getItemId());
    if (oldLine != null) {
      // get a copy of the old line
      oldLine = new OrderLineDTO(oldLine);
    }

    addItem(
        line.getItemId(),
        line.getQuantity(),
        user.getLanguage(),
        order.getUserId(),
        order.getCurrencyId(),
        order,
        line,
        persist);

    if (persist) {
      // generate NewQuantityEvent
      OrderLineDTO newLine = order.getLine(line.getItemId());
      OrderBL orderBl = new OrderBL();
      List<OrderLineDTO> oldLines = new ArrayList<OrderLineDTO>(1);
      List<OrderLineDTO> newLines = new ArrayList<OrderLineDTO>(1);
      if (oldLine != null) {
        oldLines.add(oldLine);
      }
      newLines.add(newLine);
      LOG.debug("Old line: %s", oldLine);
      LOG.debug("New line: %s", newLine);
      orderBl.checkOrderLineQuantities(
          oldLines, newLines, user.getEntity().getEntity().getId(), order.getId(), true);
    }
  }
    /**
     * Adds or updates an order line. Calculates a percentage item order line amount based on the
     * amount of another order line. This is added to the existing percentage order line's amount.
     */
    public OrderLineDTO percentageOnOrderLine(Integer percentageItemId, OrderLineDTO line)
        throws TaskException {
      // try to get percentage item order line
      OrderLineDTO percentageLine = order.getLine(percentageItemId);
      if (percentageLine == null) {
        // add percentage item
        percentageLine = addItem(percentageItemId);
        percentageLine.setAmount(BigDecimal.ZERO);
        percentageLine.setTotalReadOnly(true);
      }

      // now add the percentage amount based on the order line item amount
      BigDecimal percentage = percentageLine.getItem().getPercentage();
      BigDecimal base = line.getPrice().multiply(line.getQuantity());
      BigDecimal result =
          base.divide(new BigDecimal("100"), Constants.BIGDECIMAL_SCALE, Constants.BIGDECIMAL_ROUND)
              .multiply(percentage)
              .add(percentageLine.getAmount());
      percentageLine.setAmount(result);

      return percentageLine;
    }
 public void removeItem(Integer itemId) {
   removeObject(order.getLine(itemId));
   order.removeLine(itemId);
 }