public static void removeTask(WorkflowLoop object, ObjectBroker Objbroker) {
    Iterator<JobPlanTask> TaskIt = object.iterator();
    ArrayList<JobPlanTask> TasksToRemove = new ArrayList<JobPlanTask>();

    while (TaskIt.hasNext()) {
      JobPlanTask task = TaskIt.next();
      try {
        if (task.getTaskName().matches(ProcessSpecificCLI.U_REMTASK)) {
          System.out.println(
              "\t ++ UPDATE: Remove Task from JobPlan: [ "
                  + task.getTaskName()
                  + " | "
                  + task.getType()
                  + " | {"
                  + task.getX()
                  + ","
                  + task.getY()
                  + "} ]");
          TasksToRemove.add(task);
          // object.removeTask(task);
        }
      } catch (PatternSyntaxException e) {
        System.out.println(
            " -- Internal Error. The Regular Expression Used for one of the Filters is invalid - See Error Below: "
                + e.getDescription());
        System.out.println("\t\t" + e.toString());
        System.out.println(
            " %% HINT: '*' and '+' are NOT valid Regular Expressions on their own. '*' marks '0 or more' and '+' marks '1 or more', but you need to specify a preceeding character or string");
        System.out.println(
            " %% HINT: Ex: invalid expressions: '*ABC*', '*.123', '+DEF'. Valid expressions: '.*ABC.*', '.*.123', '.+DEF' ");

        System.exit(999);
      }
    }
    // seems like the for loop below could have been included in the while loop above? it cant
    // because it creates a problem of concurrence of requests (due to the fact that the removeTask
    // method uses also an iterator!!)
    for (int j = 0; j < TasksToRemove.size(); j++) {
      object.removeTask(TasksToRemove.get(j));
    }
  }
 public static void addTask(WorkflowLoop object, ObjectBroker Objbroker) throws IOException {
   List<SearchResultItem> items =
       Objbroker.searches.searchExecutableObjects(ProcessSpecificCLI.U_ADDTASK);
   if (items.isEmpty()) {
     System.out.println(" %% No Task Found Matching Pattern: " + ProcessSpecificCLI.U_ADDTASK);
   } else {
     for (int g = 0; g < items.size(); g++) {
       JobPlanTask jptask = Objbroker.jobPlans.getTaskFromName(items.get(g).getName());
       jptask.setX(g + 1);
       jptask.setY(2);
       System.out.println(
           "\t ++ UPDATE: Add Task to JobPlan: [ "
               + jptask.getTaskName()
               + " | "
               + jptask.getType()
               + " | {"
               + jptask.getX()
               + ","
               + jptask.getY()
               + "} ]");
       object.addTask(jptask);
     }
   }
 }
  public static void CopyTaskPreConditions(WorkflowLoop object, ObjectBroker Objbroker)
      throws IOException {
    // contains the list of tasks to modify in currently processing workflow
    ArrayList<JobPlanTask> selectedTasks = new ArrayList<JobPlanTask>();
    String TaskFilter = ProcessSpecificCLI.L_F_TASKNAME;
    if (ProcessSpecificCLI.F_TASKNAME.equals("")) {
      TaskFilter = ".*";
    }
    Iterator<JobPlanTask> iter = object.iterator();
    while (iter.hasNext()) {
      JobPlanTask jpt = iter.next();
      if (jpt.getTaskName().matches(TaskFilter)) {
        selectedTasks.add(jpt);
      }
    }

    // at this point, we know which tasks to update in the current workflow..
    String[] Patterns =
        consistencyUtils.getUpdatePattern(ProcessSpecificCLI.U_COPY_TASK_PRECONDITIONS);
    String JobNameToCopy = Patterns[0];
    String WorkflowNameToCopy = Patterns[1];
    // MISSING: check for the existence of both ... eventually ?

    // getting the actual task to copy from.
    UC4Object wrkObj = Objbroker.common.openObject(WorkflowNameToCopy, true);
    boolean WorkflowAndTaskOriginFound = true;
    if (wrkObj == null) {
      System.out.println(
          "\t -- Error. Workflow used as origin could not be found: " + WorkflowNameToCopy);
      WorkflowAndTaskOriginFound = false; // Workflow doesnt exist
    }

    if (WorkflowAndTaskOriginFound) {
      JobPlan OriJPlan = Objbroker.jobPlans.getJobPlanFromObject(wrkObj);
      JobPlanTask jptOrigin = Objbroker.jobPlans.getTaskFromNameAndJobPlan(OriJPlan, JobNameToCopy);
      if (jptOrigin == null) {
        System.out.println(
            "\t -- Error. Workflow used as origin was found, but a corrsponding task for the following object cound not be found: "
                + JobNameToCopy);
        WorkflowAndTaskOriginFound = false; // task doesnt exist
      }
      if (WorkflowAndTaskOriginFound) {
        // getting all preconditions in an array
        ArrayList<ConditionOrAction> AllActionsToCopy = new ArrayList<ConditionOrAction>();
        Iterator<ConditionOrAction> AllActionsIter = jptOrigin.preConditions().iterator();
        while (AllActionsIter.hasNext()) {
          ConditionOrAction CoA = AllActionsIter.next();
          AllActionsToCopy.add(CoA);
        }

        // Now, for each selected Tasks we copy over all preconditions
        for (int y = 0; y < selectedTasks.size(); y++) {
          System.out.println(
              "\t ++ UPDATE: Task Marked for PreCondition Copy - [Task Destination] <= [Task Source]: "
                  + "[ "
                  + selectedTasks.get(y).getTaskName()
                  + ":"
                  + object.getName()
                  + " ] <= [ "
                  + JobNameToCopy
                  + ":"
                  + WorkflowNameToCopy
                  + " ]");
          selectedTasks.get(y).preConditions().clear();
          for (int t = 0; t < AllActionsToCopy.size(); t++) {
            selectedTasks.get(y).preConditions().add(AllActionsToCopy.get(t));
          }
        }
      }
    }
  }