((NewWorkflow)oldRefill.getWorkflow()).removeTask(oldRefill); inventoryPlugin.publishRemove(oldRefill);
inventoryPlugin.removeSubTask(oldRefill);
  public void compareRefills(ArrayList newRefills, ArrayList oldRefills, Inventory inv) {    //Process all new Refill Tasks    LogisticsInventoryPG thePG = (LogisticsInventoryPG)inv.	searchForPropertyGroup(LogisticsInventoryPG.class);    if (logger.isDebugEnabled()) {      logger.debug("DiffSupply handling "+                   thePG.getResource().getTypeIdentificationPG().getTypeIdentification());    }    // Create bucket map from oldRefills for easy access during the compare    HashMap publishedTaskMap = new HashMap();    Task oldRefill=null;    Iterator oldIter = oldRefills.iterator();    while (oldIter.hasNext()) {      oldRefill = (Task)oldIter.next();      if (oldRefill != null) {        int bucket = thePG.convertTimeToBucket(getTaskUtils().getEndTime(oldRefill), false);        publishedTaskMap.put(new Integer(bucket), oldRefill);      }    }    // Compare new refills to old (published) refills    Task newRefill=null, publishedRefill=null, updatedTask=null;    Iterator newIter = newRefills.iterator();    while (newIter.hasNext()) {      newRefill = (Task) newIter.next();      int bucket = thePG.convertTimeToBucket(getTaskUtils().getEndTime(newRefill), false);      publishedRefill=(Task)publishedTaskMap.get(new Integer(bucket));      if (publishedRefill == null) {        // No published refill for the bucket, just publish the new refill        if (logger.isDebugEnabled()) {          logger.debug("DiffSupply "+getTimeUtils().dateString(thePG.convertBucketToTime(bucket))+" - "+                       "no refills on this day, add new task");        }        thePG.addRefillRequisition(newRefill);        inventoryPlugin.publishRefillTask(newRefill, inv);      } else {        // found a published refill for the bucket        oldRefills.remove(publishedRefill);        updatedTask = getTaskUtils().changeTask(publishedRefill, newRefill);        if (updatedTask == null) {// null indicates tasks are identical          if (logger.isDebugEnabled()) {            logger.debug("DiffSupply "+getTimeUtils().dateString(thePG.convertBucketToTime(bucket))+" - "+                         "new task identical to published task.");          }          thePG.addRefillRequisition(publishedRefill);        } else {// changeTask() returned the updated task          if (logger.isDebugEnabled()) {            logger.debug("DiffSupply "+getTimeUtils().dateString(thePG.convertBucketToTime(bucket))+" - "+                         "changed published task to match new task");          }          inventoryPlugin.publishChange(updatedTask);          thePG.addRefillRequisition(updatedTask);        }      }    }    //Rescind all old Refill Tasks that have not been accounted for    oldIter = oldRefills.iterator();    while (oldIter.hasNext()) {      oldRefill = (Task) oldIter.next();      // check for a null in the refills list!      if (oldRefill != null) {        // clean out the reference in the maintain inventory workflow        if (logger.isDebugEnabled()) {          logger.debug("DiffSupply Remove unwanted published task from previous plan "+                       getTaskUtils().taskDesc(oldRefill));        }        ((NewWorkflow)oldRefill.getWorkflow()).removeTask(oldRefill);	inventoryPlugin.publishRemove(oldRefill);      }    }        }