((NewWorkflow)task.getWorkflow()).removeTask(task); inventoryPlugin.publishRemove(task);
inventoryPlugin.removeSubTask(task);
  public void compareRefillProjections(ArrayList newRefillProjs,                                        ArrayList oldRefillProjs,                                       Inventory inv) {    LogisticsInventoryPG thePG = (LogisticsInventoryPG)inv.	searchForPropertyGroup(LogisticsInventoryPG.class);    if (logger.isDebugEnabled()) {      logger.debug("DiffProj handling "+                   thePG.getResource().getTypeIdentificationPG().getTypeIdentification());    }    // Check for an empty schedule    if ((newRefillProjs == null) || newRefillProjs.isEmpty()) {      // Rescind all tasks as there is no longer any demand.      if (logger.isDebugEnabled()) {        logger.debug("DiffProj, New Task List empty: "+newRefillProjs);      }      Iterator list  = oldRefillProjs.iterator();      while (list.hasNext()) {        Task oldRefill = (Task)list.next();        if (logger.isDebugEnabled()) {          logger.debug("DiffProj \n"+getTaskUtils().taskDesc(oldRefill));        }        if (oldRefill != null) {	  // clean out the reference in the maintain inventory workflow	  ((NewWorkflow)oldRefill.getWorkflow()).removeTask(oldRefill);          inventoryPlugin.publishRemove(oldRefill);        }      }      return;    }    Schedule publishedSchedule = getTaskUtils().newObjectSchedule(oldRefillProjs);    Schedule newTaskSchedule = getTaskUtils().newObjectSchedule(newRefillProjs);    // Compare new tasks to previously scheduled tasks, if a published task is found that    // spans the new task's start time then adjust the published task (if needed) and publish    // the change.  If no task is found than add new_task to list of tasks to be published.    long start;    Task new_task=null, published_task=null;    ObjectScheduleElement ose=null;    Collection c=null;    while (!newTaskSchedule.isEmpty()) {      start = newTaskSchedule.getStartTime();      ose = (ObjectScheduleElement)ScheduleUtils.getElementWithTime(newTaskSchedule, start);      if (ose != null) {        new_task = (Task)ose.getObject();        ((NewSchedule)newTaskSchedule).removeScheduleElement(ose);      }      else {        logger.error("DiffProj, Bad Schedule: "+newTaskSchedule);        return;      }      // Get overlapping schedule elements from start to end of new task      c = publishedSchedule.getScheduleElementsWithTime(start);      if (!c.isEmpty()) {        // change the task to look like new task        ose = (ObjectScheduleElement)c.iterator().next();        published_task = (Task)ose.getObject();        Task saveTask = published_task;        ((NewSchedule)publishedSchedule).removeScheduleElement(ose);//         logger.debug(" Comparing plublished task  "+getTaskUtils().taskDesc(published_task)+//                      " with \n"+getTaskUtils().taskDesc(new_task));        // changeTask returns the changed published task if the 2 tasks are different and         // null if the tasks are identical.        published_task = getTaskUtils().changeTask(published_task, new_task);        if (published_task != null) {          if (logger.isDebugEnabled()) {            logger.debug("DiffProj published task changed "+ getTaskUtils().taskDesc(published_task));          }          inventoryPlugin.publishChange(published_task);          thePG.addRefillProjection(published_task);        }else{ // published and new task are the same, so add the published task back into the BG          thePG.addRefillProjection(saveTask);          if (logger.isDebugEnabled()) {            logger.debug("DiffProj published task identical to new task");          }        }      }      else {        // no task exists that covers this timespan, publish it and        // apply the Task to the LogisticsInventoryBG        if (logger.isDebugEnabled()) {          logger.debug("No task exists that covers this timespan, publish task "+                       getTaskUtils().taskDesc(new_task));        }        thePG.addRefillProjection(new_task);        // hook the task in with the MaintainInventory workflow and publish        inventoryPlugin.publishRefillTask(new_task, inv);      }    }    // Rescind any tasks that were not accounted for    Enumeration e = publishedSchedule.getAllScheduleElements();    while (e.hasMoreElements()) {      Task task = (Task) ((ObjectScheduleElement) e.nextElement()).getObject();      if (logger.isDebugEnabled()) {        logger.debug("DiffProj Remove unwanted published task from previous plan "+                     getTaskUtils().taskDesc(task));      }      ((NewWorkflow)task.getWorkflow()).removeTask(task);      inventoryPlugin.publishRemove(task);    }  }