private void unsuspendCase(String caseID) {
   connect();
   try {
     List<WorkItemRecord> wirList = _ibClient.getWorkItemsForCase(caseID, _handle);
     for (WorkItemRecord i : wirList) {
       if (i.getStatus().equalsIgnoreCase("Suspended")) {
         _ibClient.unsuspendWorkItem(i.getID(), _handle);
       }
     }
   } catch (IOException e1) {
     e1.printStackTrace();
   }
 }
  private org.jdom2.Element getDataforCase(String specName, String caseID, String data) {
    String caseData = "";
    try {
      caseData = _ibClient.getCaseData(caseID, _handle);
    } catch (IOException e) {
      e.printStackTrace();
    }
    org.jdom2.Element result = new org.jdom2.Element(specName);

    SAXBuilder builder = new SAXBuilder();
    org.jdom2.Element root = null;
    List<org.jdom2.Element> ls = null;
    try {
      org.jdom2.Document document = builder.build(new StringReader(data));
      root = document.getRootElement();

      ls = document.getRootElement().getChildren();
    } catch (Exception e) {
      System.out.println(e);
    }
    for (org.jdom2.Element l : ls) {
      String paramName = l.getName();
      org.jdom2.Element advElem = root.getChild(paramName);
      try {
        if (advElem != null) {
          org.jdom2.Element copy = (org.jdom2.Element) advElem.clone();
          result.addContent(copy);
        } else {
          result.addContent(new org.jdom2.Element(paramName));
        }
      } catch (IllegalAddException iae) {
      }
    }
    return result;
  }
  private void suspendCase(String caseID) {
    connect();
    try {
      List<WorkItemRecord> wirList = null;
      wirList = _ibClient.getLiveWorkItemsForIdentifier("case", caseID, _handle);

      System.out.println(
          "---- There are totally "
              + (wirList == null ? "null" : Integer.valueOf(wirList.size()))
              + " workitems");
      for (WorkItemRecord i : wirList) {
        if (!_ibClient.successful(_ibClient.suspendWorkItem(i.getID(), _handle))) {
          System.out.println(" * problem is suspending the workitem with id " + i.getID());
        }
      }
    } catch (Exception e1) {
      System.out.println("---- error is suspendsion:" + e1.getMessage());
      e1.printStackTrace();
    }
  }
 private void connect() {
   if (_ibClient == null) {
     _ibClient = new InterfaceB_EnvironmentBasedClient("http://localhost:8080/yawl/ib");
     try {
       _handle = _ibClient.connect(this.engineLogonName, this.engineLogonPassword);
     } catch (IOException e) {
       System.out.println("************ Error ***************");
       e.printStackTrace();
       return;
     }
   }
 }
 private List<YParameter> getInputParams(String specId) {
   connect();
   List<SpecificationData> loadedSpecs = new ArrayList();
   try {
     loadedSpecs = _ibClient.getSpecificationList(_handle);
   } catch (IOException ioe) {
   }
   for (SpecificationData thisSpec : loadedSpecs) {
     if (specId.equals(thisSpec.getSpecIdentifier())) {
       return thisSpec.getInputParams();
     }
   }
   return null;
 }
 private boolean isUploaded(String adviceID) throws IOException {
   connect();
   if (adviceID == null) {
     return false;
   }
   List<SpecificationData> _loadedSpecs = new ArrayList();
   _loadedSpecs = _ibClient.getSpecificationList(_handle);
   for (SpecificationData onespec : _loadedSpecs) {
     if (adviceID.equals(onespec.getSpecIdentifier())) {
       return true;
     }
   }
   return false;
 }
  private void ItemPostConstraint(WorkItemRecord wir, String data) {
    AdviceQuery query = new AdviceQuery();

    List<Advice> advs = query.getAdvicesByAdviceJoinPointID(wir.getID());
    if ((advs != null) && (advs.size() > 0)) {
      suspendCase(wir.getCaseID().substring(0, wir.getCaseID().indexOf('.')));
      System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
      System.out.println(
          "suspended case is " + wir.getCaseID().substring(0, wir.getCaseID().indexOf('.')));
      for (Advice advice : advs) {
        SAXBuilder builder = new SAXBuilder();

        List<org.jdom2.Element> ls = null;
        org.jdom2.Element root = null;
        try {
          org.jdom2.Document document = builder.build(new StringReader(data));
          ls = document.getRootElement().getChildren();
        } catch (Exception e) {
          System.out.println(e);
        }
        String s = "<" + advice.getProceedName() + ">";
        for (org.jdom2.Element l : ls) {
          s = s + "<" + l.getName() + ">" + l.getText() + "</" + l.getName() + ">";
        }
        s = s + "</" + advice.getProceedName() + ">";

        connect();

        advice.setSynched(false);
        this._Persister.beginTransaction();
        this._Persister.update(advice);
        this._Persister.commit();

        System.out.println(
            "*** try to checkin workitem with proceed id of "
                + advice.getProceedID()
                + " - with data: "
                + s);
        try {
          _ibClient.checkInWorkItem(advice.getProceedID(), s, "", _handle);
        } catch (IOException e) {
          System.out.println("************************ problem in checkin");
          e.printStackTrace();
        }
      }
    }
  }
 private String getWorkItemData(String taskID, String workitemID) {
   String result = null;
   connect();
   try {
     List<WorkItemRecord> wirl = _ibClient.getWorkItemsForTask(taskID, _handle);
     for (WorkItemRecord r : wirl) {
       if (r.getID().equalsIgnoreCase(workitemID)) {
         result = r.getDataListString();
         if (result == null) {
           System.out.println("---------- the workitem is not yet updated ------------");
           result = getWorkItemData(taskID, workitemID);
         }
       }
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
   return result;
 }
  private void handleProceedPlaceholder(WorkItemRecord enabledWorkItem) {
    connect();
    try {
      WorkItemRecord childWorkItem = checkOut(enabledWorkItem.getID(), _handle);
      AdviceQuery query = new AdviceQuery();

      List<Advice> advs = query.getByAdviceName(enabledWorkItem.getSpecURI());
      System.out.println(">>>> Number of the same advices are " + advs.size());
      if ((advs != null) && (advs.size() > 0)) {
        System.out.println(">>>> Number of the launched advices are " + advs.size());
        do {
          advs = query.getByAdviceCaseID(enabledWorkItem.getCaseID());
        } while ((advs == null) || (advs.size() == 0));
        System.out.println(">>>> Number of the launched advices are " + advs.size());

        Advice advice = (Advice) advs.get(0);
        advice.setSynched(true);
        advice.setProceedName(enabledWorkItem.getTaskName());
        advice.setProceedID(childWorkItem.getID());

        this._Persister.beginTransaction();
        this._Persister.update(advice);
        this._Persister.commit();

        System.out.println(">>>> Proceed Name is " + advice.getProceedName());
        System.out.println(">>>> Proceed ID is " + advice.getProceedID());

        org.jdom2.Element d =
            getDataforCase(
                advice.getParentSpecName(),
                advice.getParentCaseID(),
                _ibClient.getCaseData(enabledWorkItem.getCaseID(), _handle));

        this._ixClient.updateCaseData(advice.getParentCaseID(), d, _handle);

        weaving(advice.getParentCaseID(), advice.getAdjpID(), false);
      }
    } catch (IOException | YAWLException e) {
      e.printStackTrace();
    }
  }
  protected boolean uploadAdvice(String adviceName) throws IOException {
    connect();
    String fileName = _specFolder + adviceName + ".yawl";
    if (isUploaded(getAdviceID(adviceName))) {
      return true;
    }
    try {
      String engineURI = "http://localhost:8080/yawl/ia";

      InterfaceA_EnvironmentBasedClient _interfaceAClient =
          new InterfaceA_EnvironmentBasedClient(engineURI);

      String h = _interfaceAClient.connect("admin", "YAWL");

      File file = new File(fileName);
      if (file.exists()) {
        System.out.println("- - - - - - file name is " + file.getName());
        System.out.println("- - - - - - file path is " + file.getPath());
        System.out.println("- - - - - - file getAbsolutePath() is " + file.getAbsolutePath());
        System.out.println("- - - - - - _handle is " + h);
        System.out.println(
            "- - - - - - _interfaceAClient.getBackEndURI() is "
                + _interfaceAClient.getBackEndURI());

        String result = _interfaceAClient.uploadSpecification(file, h);
        if (_ibClient.successful(result)) {
          return true;
        }
        return false;
      }
      System.out.println("Aspect not exists");
    } catch (IOException ioe) {
      return false;
    }
    return false;
  }
 private String launchAdvice(String adviceID, String caseParams) throws IOException {
   connect();
   return _ibClient.launchCase(adviceID, caseParams, _handle, _observer);
 }