如何使用java获取规则(文件夹结构)的路径

时间:2014-06-23 13:46:36

标签: java api center rule

我正在尝试使用java TEAMSERVER API获取规则的文件夹结构。

   IlrSessionFactory factory = new IlrRemoteSessionFactory();
   try {
        factory.connect(login, password, serverUrl, datasource);
        IlrSession session = factory.getSession();
        IlrRuleProject ruleProject = (IlrRuleProject) IlrSessionHelper.getProjectNamed(session, project);
        IlrBaseline currentBaseline = IlrSessionHelper.getCurrentBaseline(session, ruleProject);

        session.setWorkingBaseline(currentBaseline);
        String query = new String("Find all business rules such that the name of each business rule is \"R105_1_krl\"");
        IlrDefaultSearchCriteria criteria = new IlrDefaultSearchCriteria( query.toString());
        List summaries = session.findElements(criteria, IlrModelConstants.ELEMENT_SUMMARY); 

        for (int i = 0; i < summaries.size(); i++) {
              IlrElementSummary ruleSummary = (IlrElementSummary) summaries.get(i);
              String ruleName = ruleSummary.getName();
              System.out.println("\t" + ruleName);
        }

如果有名为R105_1_krl的规则,我可以使用java和DECİSİONCENTERAPI。但我需要这条规则的位置。如XYZ包/ abc文件夹/ def文件夹

另外,当我在循环中编写以下两行时,我可以达到这些属性; 到期日期,生效日期,创建者,上次更改时间...但是,我无法访问规则属性的文件夹信息。

    IlrActionRule rule = (IlrActionRule) elementDetails;
    String lastChangedBy = String.valueOf(rule.getPropertyValue("lastChangedBy"));

1 个答案:

答案 0 :(得分:0)

这是解决方案。

public static String getHierarchyPath (IlrElementDetails element) {
    try {
      if (!(element instanceof IlrRule))  return   element.getName();

      IlrRule rule = (IlrRule)element;
      StringBuffer sb = new StringBuffer ();

      // Get the rule name
      String name = rule.getName();
      // Get the rule package
      IlrRulePackage  current = rule.getRulePackage();

      Stack<String> stack = new Stack<String> ();
      while (true) {
        if (current==null) break;
        // Push the package name onto the stack     
        stack.push("/" + current.getName());
        // Next parent ...
        current = current.getParent();
      }
      // Pop the stack and build the path
      while (!stack.empty()) {
        String folder = (String) stack.pop();
        sb.append(folder);
      }
      // Append the rule name to the path
      sb.append("/").append(name);
      // Return the built path
      return sb.toString();
    } catch (Exception e) {
      return element.getName();
    }
  }