Ejemplo n.º 1
0
  private List<String> listQueries(String cda) {
    SAXReader reader = new SAXReader();
    List<String> queryOutput = new ArrayList<String>();
    try {
      Map<String, Object> params = new HashMap<String, Object>();

      params.put("path", cda);
      params.put("outputType", "xml");
      String reply =
          InterPluginComms.callPlugin(InterPluginComms.Plugin.CDA, "listQueries", params);
      Document queryList = reader.read(new StringReader(reply));
      List<Node> queries = queryList.selectNodes("//ResultSet/Row/Col[1]");
      for (Node query : queries) {
        queryOutput.add(query.getText());
      }
    } catch (DocumentException e) {
      return null;
    }
    return queryOutput;
  }
Ejemplo n.º 2
0
  private JSONObject processAutoIncludes(String dashboardPath, Document config) {

    JSONObject queries = new JSONObject();
    /* Bail out immediately if CDA isn' available */
    if (!InterPluginComms.isPluginAvailable("cda")) {
      logger.warn("Couldn't find CDA. Skipping auto-includes");
      return queries;
    }
    //        Document config = getConfigFile();
    logger.info(
        "[Timing] Getting solution repo for auto-includes: "
            + (new SimpleDateFormat("HH:mm:ss.SSS")).format(new Date()));
    Document solution = getRepository();
    List<Node> includes, cdas;
    includes = config.selectNodes("//autoincludes/autoinclude");
    cdas = solution.selectNodes("//leaf[ends-with(leafText,'cda')]");
    logger.info(
        "[Timing] Starting testing includes: "
            + (new SimpleDateFormat("HH:mm:ss.SSS")).format(new Date()));
    for (Node include : includes) {
      String re = XmlDom4JHelper.getNodeText("cda", include, "");
      for (Node cda : cdas) {
        String path = (String) cda.selectObject("string(path)");

        /* There's a stupid bug in the filebased rep that makes this not work (see BISERVER-3538)
         * Path comes out as pentaho-solutions/<solution>/..., and filebase rep doesn't handle that well
         * We'll remote the initial part and that apparently works ok
         */
        path = path.substring(path.indexOf('/', 1) + 1);

        if (!path.matches(re)) {
          continue;
        }
        logger.debug(path + " matches the rule " + re);
        Pattern pat = Pattern.compile(re);
        if (canInclude(dashboardPath, include.selectNodes("dashboards/*"), pat.matcher(path))) {
          logger.debug("Accepted dashboard " + dashboardPath);
          List<String> ids = listQueries(path);
          String idPattern = (String) cda.selectObject("string(ids)");
          for (String id : ids) {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("dataAccessId", id);
            params.put("path", path);
            logger.info(
                "[Timing] Executing autoinclude query: "
                    + (new SimpleDateFormat("HH:mm:ss.SSS")).format(new Date()));
            String reply =
                InterPluginComms.callPlugin(InterPluginComms.Plugin.CDA, "doQuery", params, true);
            logger.info(
                "[Timing] Done executing autoinclude query: "
                    + (new SimpleDateFormat("HH:mm:ss.SSS")).format(new Date()));
            try {
              queries.put(id, new JSONObject(reply));
            } catch (JSONException e) {
              logger.error("Failed to add query " + id + " to contex object");
            }
          }
        }
      }
    }
    logger.info(
        "[Timing] Finished testing includes: "
            + (new SimpleDateFormat("HH:mm:ss.SSS")).format(new Date()));

    return queries;
  }