Exemplo n.º 1
0
  /**
   * Edits the container and all of the children containers.
   *
   * @pre parameters != null
   * @pre canEditContainer( newContainer ) == true
   * @post if( checkCanEdit(container) ) { edit(container); }
   * @param oldContainer The original container
   * @param newContainer The new container values
   * @throws IllegalArgumentException if oldContainer == null or newContainer == null or
   *     newContainer.canEdit == false
   */
  public void editContainer(Container oldContainer, Container newContainer)
      throws IllegalArgumentException {

    if (oldContainer == null || newContainer == null || !canEditContainer(newContainer)) {
      throw new IllegalArgumentException();
    }

    System.out.println(" ------ Editing container --------");
    System.out.println("Before: " + oldContainer + "\nAfter:" + newContainer + "");

    if (oldContainer instanceof ProductGroup) {
      Container parent = oldContainer.getContainer(); // added for bug fix
      parent.getProductGroups().remove((ProductGroup) oldContainer);
      oldContainer.setName(newContainer.getName());
      ((ProductGroup) oldContainer)
          .setThreeMonthSupply(((ProductGroup) newContainer).getThreeMonthSupply());
      parent.getProductGroups().add((ProductGroup) oldContainer);
    } else {
      storageUnits.remove(oldContainer);
      oldContainer.setName(newContainer.getName());
      storageUnits.add((StorageUnit) oldContainer); // added for bug fix
    }

    containerDAO.update(new ContainerDTO(oldContainer));
    ChangeObject hint = getHintObject(oldContainer);
    setChanged();
    notifyObservers(hint);
  }
Exemplo n.º 2
0
 /**
  * Abstract Method, Checks to see if given productsName is unique among the list of ProductGroups.
  *
  * @pre container != null
  * @param groupName String name in question
  * @return True if all of the qualifications are met and false otherwise.
  */
 private boolean isUniqueProductGroupName(Container container) {
   assert container != null;
   if (container.getName() == null) {
     return false;
   }
   for (ProductGroup productGroup : container.getContainer().getProductGroups()) {
     if (container.getName().equals(productGroup.getName())) {
       return false;
     }
   }
   return true;
 }
Exemplo n.º 3
0
  /**
   * Deletes the container and all of the children containers.
   *
   * @pre Container.items() == 0, recursively, see condition below ***(can't assert that items == 0,
   *     have to trust)***
   * @pre container.exists() == true
   * @post delete(container), recursively
   * @param container Current container to be deleted
   * @throws IllegalArgumentException if container.container == null && container instanceof
   *     ProductGroup
   */
  public void deleteContainer(Container container) throws IllegalArgumentException {

    Container parent = container.getContainer();
    if (container instanceof ProductGroup) {
      if (parent == null) {
        throw new IllegalArgumentException();
      }
      Set<ProductGroup> productGroupList = container.getContainer().getProductGroups();
      productGroupList.remove(container);
    } else {
      storageUnits.remove(container);
    }
    ChangeObject hint;
    if (parent == null || parent.getProductGroups().isEmpty()) {
      hint = getHintObject(parent);
    } else {
      hint = getHintObject(parent.getProductGroups().iterator().next());
    }

    containerDAO.delete(new ContainerDTO(container));
    idToContainer.remove(container.getId());
    setChanged();
    notifyObservers(hint);
  }