Ejemplo n.º 1
0
  public void testStartProcessWithLinking() {
    LogUtil.info(getClass().getName(), ">>> testStartProcessWithLinking");

    // start and get instant id of 1st process
    String packageVersion = workflowManager.getCurrentPackageVersion(packageId);
    WorkflowProcessResult result =
        workflowManager.processStart(packageId + "#" + packageVersion + "#" + processId);
    String process1Id = result.getProcess().getInstanceId();
    LogUtil.info(
        getClass().getName(), "-------------  process one id : " + process1Id + "  -------------");

    // start 2nd process with 1st process instant id and get 2nd process instant id
    WorkflowProcessResult nextResult =
        workflowManager.processStartWithLinking(
            packageId + "#" + packageVersion + "#" + processId, null, null, process1Id);
    String process2Id = nextResult.getProcess().getInstanceId();
    LogUtil.info(
        getClass().getName(), "-------------  process two id : " + process2Id + "  -------------");

    // check process linking data is correct or not
    WorkflowProcessLink link = workflowManager.getWorkflowProcessLink(process2Id);
    LogUtil.info(
        getClass().getName(),
        "-------------  origin process id : " + link.getOriginProcessId() + "  -------------");
    workflowManager.internalDeleteWorkflowProcessLink(link);
    Assert.assertNotNull(link);
    Assert.assertTrue(
        process1Id.equals(link.getOriginProcessId())
            && process1Id.equals(link.getParentProcessId()));
  }
Ejemplo n.º 2
0
  public void testStartActivityC() {
    LogUtil.info(getClass().getName(), ">>> testStartActivityC");

    String currentActivityDef = "B";
    String desiredActivityDef = "C";

    // get process instance
    Map runningActivities =
        workflowManager.getActivityInstanceByProcessIdAndStatus(processId, null);
    String activityId = String.valueOf(runningActivities.get(currentActivityDef));
    WorkflowActivity wa = workflowManager.getActivityById(activityId);
    String processInstanceId = wa.getProcessId();

    // abort running activities and start activity C
    boolean started = workflowManager.activityStart(processInstanceId, desiredActivityDef, true);

    // check running activities
    runningActivities = workflowManager.getActivityInstanceByProcessIdAndStatus(processId, null);
    String abortedActivity = (String) runningActivities.get(currentActivityDef);
    String runningActivity = (String) runningActivities.get(desiredActivityDef);
    LogUtil.info(
        getClass().getName(), "Running activities: " + runningActivities + "; Result: " + started);

    Assert.assertTrue(abortedActivity == null && runningActivity != null);
  }
Ejemplo n.º 3
0
  public void testCopyProcess() {
    LogUtil.info(getClass().getName(), ">>> testCopyProcess");

    boolean valid = false;

    // start and get instance id of the 1st process
    String packageVersion = workflowManager.getCurrentPackageVersion(packageId);
    WorkflowProcessResult result =
        workflowManager.processStart(packageId + "#" + packageVersion + "#" + processId);
    String processInstanceId = result.getProcess().getInstanceId();
    LogUtil.info(
        getClass().getName(),
        "-------------  process one id : " + processInstanceId + "  -------------");

    // abort running activities and start activity B
    String firstActivityDef = "A";
    String desiredActivityDef = "B";
    boolean started = workflowManager.activityStart(processInstanceId, desiredActivityDef, true);

    if (started) {
      // start 2nd process from the 1st process instance id
      WorkflowProcessResult nextResult =
          workflowManager.processCopyFromInstanceId(
              processInstanceId, packageId + "#" + packageVersion + "#" + processId, true);
      WorkflowProcess processStarted = nextResult.getProcess();

      if (processStarted != null) {
        // check for the aborted and running activities
        String newProcessId = processStarted.getInstanceId();
        Collection<WorkflowActivity> activityList =
            workflowManager.getActivityList(newProcessId, 0, 1000, null, null);
        for (WorkflowActivity act : activityList) {
          if (act.getState().startsWith("open")) {
            if (firstActivityDef.equals(act.getActivityDefId())) {
              valid = false;
              break;
            }
            if (desiredActivityDef.equals(act.getActivityDefId())) {
              valid = true;
            }
          }
        }
        LogUtil.info(
            getClass().getName(),
            "-------------  new process id : " + newProcessId + "  ------------- " + valid);

        // cleanup
        WorkflowProcessLink link = workflowManager.getWorkflowProcessLink(newProcessId);
        workflowManager.internalDeleteWorkflowProcessLink(link);
      }
    }

    Assert.assertTrue(valid);
  }
Ejemplo n.º 4
0
  public Object execute(Map properties) {
    WorkflowAssignment wfAssignment = (WorkflowAssignment) properties.get("workflowAssignment");

    String jsonUrl = (String) properties.get("jsonUrl");
    GetMethod get = null;
    try {
      HttpClient client = new HttpClient();

      jsonUrl = WorkflowUtil.processVariable(jsonUrl, "", wfAssignment);

      jsonUrl = StringUtil.encodeUrlParam(jsonUrl);

      get = new GetMethod(jsonUrl);
      client.executeMethod(get);
      InputStream in = get.getResponseBodyAsStream();
      String jsonResponse = streamToString(in);

      Map object = PropertyUtil.getPropertiesValueFromJson(jsonResponse);

      storeToForm(wfAssignment, properties, object);
      storeToWorkflowVariable(wfAssignment, properties, object);

    } catch (Exception ex) {
      LogUtil.error(getClass().getName(), ex, "");
    } finally {
      if (get != null) {
        get.releaseConnection();
      }
    }

    return null;
  }
Ejemplo n.º 5
0
  public void testCloseAndRemovePackage() {
    LogUtil.info(getClass().getName(), ">>> testCloseAndRemovePackage");
    Collection<WorkflowProcess> processList =
        workflowManager.getRunningProcessList(packageId, null, null, null, null, null, 0, 100);

    for (WorkflowProcess process : processList)
      workflowManager.removeProcessInstance(process.getInstanceId());

    workflowManager.processDeleteAndUnload(packageId);
  }
Ejemplo n.º 6
0
 public void testAssignment() {
   LogUtil.info(getClass().getName(), ">>> testAssignment");
   Map activityInstance = workflowManager.getActivityInstanceByProcessIdAndStatus(processId, true);
   String activityId = String.valueOf(activityInstance.get("A"));
   WorkflowActivity wa = workflowManager.getActivityById(activityId);
   String processInstanceId = wa.getProcessId();
   WorkflowAssignment ass = workflowManager.getAssignmentByProcess(processInstanceId);
   WorkflowAssignment ass2 = workflowManager.getAssignment(activityId);
   Assert.assertTrue(
       ass != null && ass2 != null && ass.getActivityId().equals(ass2.getActivityId()));
 }
  protected DataList parseFromJsonParameter(
      ModelMap map, DataList dataList, String id, HttpServletRequest request) {
    // get parameters

    String jsonParam = new ParamEncoder(id).encodeParameterName("json");
    String json = request.getParameter(jsonParam);

    // use preview json if available
    if (json != null && json.trim().length() > 0) {
      try {
        String tempJson = json;
        if (tempJson.contains(SecurityUtil.ENVELOPE)
            || tempJson.contains(PropertyUtil.PASSWORD_PROTECTED_VALUE)) {
          AppDefinition appDef = AppUtil.getCurrentAppDefinition();
          DatalistDefinition datalist = datalistDefinitionDao.loadById(id, appDef);

          if (datalist != null) {
            tempJson = PropertyUtil.propertiesJsonStoreProcessing(datalist.getJson(), tempJson);
          }
        }

        dataList =
            dataListService.fromJson(AppUtil.processHashVariable(tempJson, null, null, null));
        dataList.setId(id);
      } catch (Exception ex) {
        map.addAttribute("dataListError", ex.toString());
      }
    } /* else {
      json = dataListService.toJson(dataList);
      }*/

    String jsonEncoded = null;
    try {
      if (json != null) {
        jsonEncoded = URLEncoder.encode(json, "UTF-8");
      }
    } catch (Exception ex) {
      LogUtil.error(this.getClass().getName(), ex, "parseFromJsonParameter Error!");
    }

    // set for view
    map.addAttribute("json", json);
    map.addAttribute("jsonEncoded", jsonEncoded);
    map.addAttribute("jsonParam", jsonParam);
    return dataList;
  }
Ejemplo n.º 8
0
  public void testUploadProcess() throws FileNotFoundException, IOException, Exception {
    LogUtil.info(getClass().getName(), ">>> testUploadProcess");

    BufferedReader reader = null;
    String fileContents = "";
    String line;

    try {
      reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(xpdl)));
      while ((line = reader.readLine()) != null) {
        fileContents += line + "\n";
      }
    } finally {
      if (reader != null) {
        reader.close();
      }
    }
    byte[] processDefinitionData = fileContents.getBytes();
    workflowManager.processUpload(null, processDefinitionData);
  }
Ejemplo n.º 9
0
  protected String streamToString(InputStream in) {
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    StringBuilder sb = new StringBuilder();

    String line = null;
    try {
      while ((line = reader.readLine()) != null) {
        sb.append(line + "\n");
      }
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        in.close();
      } catch (IOException e) {
        LogUtil.error(getClass().getName(), e, "");
      }
    }

    return sb.toString();
  }
Ejemplo n.º 10
0
  public static String processHashVariable(
      String content,
      WorkflowAssignment wfAssignment,
      String escapeFormat,
      Map<String, String> replaceMap,
      AppDefinition appDef) {
    // check for hash # to avoid unnecessary processing
    if (!containsHashVariable(content)) {
      return content;
    }

    // parse content
    if (content != null) {
      Pattern pattern = Pattern.compile("\\#([^#^\"^ ])*\\.([^#^\"])*\\#");
      Matcher matcher = pattern.matcher(content);
      List<String> varList = new ArrayList<String>();
      while (matcher.find()) {
        varList.add(matcher.group());
      }

      try {
        if (!varList.isEmpty()) {
          PluginManager pluginManager = (PluginManager) appContext.getBean("pluginManager");
          PluginDefaultPropertiesDao pluginDefaultPropertiesDao =
              (PluginDefaultPropertiesDao) appContext.getBean("pluginDefaultPropertiesDao");
          Collection<Plugin> pluginList = pluginManager.list(HashVariablePlugin.class);
          Map<String, HashVariablePlugin> hashVariablePluginCache =
              new HashMap<String, HashVariablePlugin>();

          for (String var : varList) {
            String tempVar = var.replaceAll("#", "");

            for (Plugin p : pluginList) {
              HashVariablePlugin hashVariablePlugin = (HashVariablePlugin) p;
              if (tempVar.startsWith(hashVariablePlugin.getPrefix() + ".")) {
                tempVar = tempVar.replaceFirst(hashVariablePlugin.getPrefix() + ".", "");

                HashVariablePlugin cachedPlugin =
                    hashVariablePluginCache.get(hashVariablePlugin.getClassName());
                if (cachedPlugin == null) {
                  cachedPlugin =
                      (HashVariablePlugin)
                          pluginManager.getPlugin(hashVariablePlugin.getClassName());
                  // get default plugin properties

                  if (appDef == null) {
                    appDef = AppUtil.getCurrentAppDefinition();
                  }
                  PluginDefaultProperties pluginDefaultProperties =
                      pluginDefaultPropertiesDao.loadById(cachedPlugin.getClassName(), appDef);
                  if (pluginDefaultProperties != null
                      && pluginDefaultProperties.getPluginProperties() != null
                      && pluginDefaultProperties.getPluginProperties().trim().length() > 0) {
                    cachedPlugin.setProperties(
                        PropertyUtil.getPropertiesValueFromJson(
                            pluginDefaultProperties.getPluginProperties()));
                  }

                  // put appDef & wfAssignment to properties
                  cachedPlugin.setProperty("appDefinition", appDef);
                  cachedPlugin.setProperty("workflowAssignment", wfAssignment);
                  hashVariablePluginCache.put(hashVariablePlugin.getClassName(), cachedPlugin);
                }

                // process nested hash
                while (tempVar.contains("{") && tempVar.contains("}")) {
                  Pattern nestedPattern = Pattern.compile("\\{([^\\{^\\}])*\\}");
                  Matcher nestedMatcher = nestedPattern.matcher(tempVar);
                  while (nestedMatcher.find()) {
                    String nestedHash = nestedMatcher.group();
                    String nestedHashString = nestedHash.replace("{", "#");
                    nestedHashString = nestedHashString.replace("}", "#");

                    String processedNestedHashValue =
                        processHashVariable(
                            nestedHashString, wfAssignment, escapeFormat, replaceMap, appDef);
                    tempVar =
                        tempVar.replaceAll(
                            StringUtil.escapeString(nestedHash, StringUtil.TYPE_REGEX, null),
                            StringUtil.escapeString(
                                processedNestedHashValue, escapeFormat, replaceMap));
                  }
                }

                // get result from plugin
                String value = cachedPlugin.processHashVariable(tempVar);

                if (value != null && !StringUtil.TYPE_REGEX.equals(escapeFormat)) {
                  value = StringUtil.escapeRegex(value);
                }

                // escape special char in HashVariable
                var = cachedPlugin.escapeHashVariable(var);

                // replace
                if (value != null) {
                  content =
                      content.replaceAll(
                          var, StringUtil.escapeString(value, escapeFormat, replaceMap));
                }
              }
            }
          }
        }
      } catch (Exception ex) {
        LogUtil.error(AppUtil.class.getName(), ex, "");
      }
    }
    return content;
  }
Ejemplo n.º 11
0
 public void testAcceptedA() {
   LogUtil.info(getClass().getName(), ">>> testAcceptedA");
   Map activityInstance = workflowManager.getActivityInstanceByProcessIdAndStatus(processId, true);
   workflowManager.assignmentComplete(String.valueOf(activityInstance.get("A")));
 }
Ejemplo n.º 12
0
 public void testStartProcess() {
   LogUtil.info(getClass().getName(), ">>> testStartProcess");
   String packageVersion = workflowManager.getCurrentPackageVersion(packageId);
   workflowManager.processStart(packageId + "#" + packageVersion + "#" + processId);
 }