コード例 #1
0
  private Map<String, String> getVariables(long processInstanceId) {
    Command<?> cmd = new FindVariableInstancesCommand(processInstanceId);

    Object result =
        internalDoKieSessionOperation(
            cmd, "Unable to retrieve process variables from process instance " + processInstanceId);
    List<VariableInstanceLog> varInstLogList = (List<VariableInstanceLog>) result;

    Map<String, String> vars = new HashMap<String, String>();
    if (varInstLogList.isEmpty()) {
      return vars;
    }

    Map<String, VariableInstanceLog> varLogMap = new HashMap<String, VariableInstanceLog>();
    for (VariableInstanceLog varLog : varInstLogList) {
      String varId = varLog.getVariableId();
      VariableInstanceLog prevVarLog = varLogMap.put(varId, varLog);
      if (prevVarLog != null) {
        if (prevVarLog.getDate().after(varLog.getDate())) {
          varLogMap.put(varId, prevVarLog);
        }
      }
    }

    for (Entry<String, VariableInstanceLog> varEntry : varLogMap.entrySet()) {
      vars.put(varEntry.getKey(), varEntry.getValue().getValue());
    }

    return vars;
  }
  @Test
  public void historyLogListTest() throws Exception {
    JaxbHistoryLogList resp = new JaxbHistoryLogList();

    testRoundTrip(resp);

    // vLog
    org.jbpm.process.audit.VariableInstanceLog vLog =
        new org.jbpm.process.audit.VariableInstanceLog(
            23, "process", "varInst", "var", "two", "one");
    vLog.setExternalId("domain");
    Field dateField = org.jbpm.process.audit.VariableInstanceLog.class.getDeclaredField("date");
    dateField.setAccessible(true);
    dateField.set(vLog, new Date());
    Field idField = org.jbpm.process.audit.VariableInstanceLog.class.getDeclaredField("id");
    idField.setAccessible(true);
    idField.set(vLog, 32l);
    resp.getHistoryLogList().add(new JaxbVariableInstanceLog(vLog));

    // pLog
    org.jbpm.process.audit.ProcessInstanceLog pLog =
        new org.jbpm.process.audit.ProcessInstanceLog(23, "process");
    pLog.setDuration(2000l);
    pLog.setEnd(new Date());
    pLog.setExternalId("domain");
    pLog.setIdentity("id");
    pLog.setOutcome("error");
    pLog.setParentProcessInstanceId(42);
    pLog.setProcessName("name");
    pLog.setProcessVersion("1-SNAP");
    pLog.setStatus(2);
    idField = org.jbpm.process.audit.ProcessInstanceLog.class.getDeclaredField("id");
    idField.setAccessible(true);
    idField.set(pLog, 32l);
    resp.getHistoryLogList().add(new JaxbProcessInstanceLog(pLog));

    // nLog
    org.jbpm.process.audit.NodeInstanceLog nLog =
        new org.jbpm.process.audit.NodeInstanceLog(0, 23, "process", "nodeInst", "node", "wally");
    idField = org.jbpm.process.audit.NodeInstanceLog.class.getDeclaredField("id");
    idField.setAccessible(true);
    idField.set(nLog, 32l);
    dateField = org.jbpm.process.audit.NodeInstanceLog.class.getDeclaredField("date");
    dateField.setAccessible(true);
    dateField.set(nLog, new Date());
    nLog.setNodeType("type");
    nLog.setWorkItemId(88l);
    nLog.setConnection("connex");
    nLog.setExternalId("domain");
    resp.getHistoryLogList().add(new JaxbNodeInstanceLog(nLog));

    testRoundTrip(resp);
  }
  @Test
  public void variableInstanceLogTest() throws Exception {
    Assume.assumeFalse(getType().equals(TestType.YAML));

    long processInstanceId = 23;
    String processId = "org.hospital.intern.rounds";
    String variableInstanceId = "patientNum-1";
    String variableId = "patientNum";
    String value = "33";
    String oldValue = "32";

    org.jbpm.process.audit.VariableInstanceLog origLog =
        new org.jbpm.process.audit.VariableInstanceLog(
            processInstanceId, processId, variableInstanceId, variableId, value, oldValue);

    origLog.setExternalId("outside-identity-representation");
    origLog.setOldValue("previous-data-that-this-variable-contains");
    origLog.setValue("the-new-data-that-has-been-put-in-this-variable");
    origLog.setVariableId("shortend-representation-of-this-representation");
    origLog.setVariableInstanceId("id-instance-variable");

    JaxbVariableInstanceLog xmlLog = new JaxbVariableInstanceLog(origLog);
    xmlLog.setCommandName("test-cmd");
    xmlLog.setIndex(2);
    JaxbVariableInstanceLog newXmlLog = testRoundTrip(xmlLog);
    ComparePair.compareObjectsViaFields(xmlLog, newXmlLog, "id");

    VariableInstanceLog newLog = newXmlLog.getResult();
    ComparePair.compareOrig(origLog, newLog, VariableInstanceLog.class);
  }