Ejemplo n.º 1
0
  public ActionDefinition(final Node actionRootNode, final ILogger logger) {

    this.actionRootNode = actionRootNode;

    errorCode = ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK;
    // this.sequenceData = sequenceData;

    // get the input parameter definitions
    actionInputDefinitions = new ListOrderedMap();
    actionInputMapping = new ListOrderedMap();
    errorCode =
        SequenceDefinition.parseParameters(
            actionRootNode,
            logger,
            "action-inputs/*",
            actionInputDefinitions,
            actionInputMapping,
            true); //$NON-NLS-1$

    // get the ouput definitions
    actionOutputDefinitions = new ListOrderedMap();
    actionOutputMapping = new ListOrderedMap();
    errorCode =
        SequenceDefinition.parseParameters(
            actionRootNode,
            logger,
            "action-outputs/*",
            actionOutputDefinitions,
            actionOutputMapping,
            false); //$NON-NLS-1$

    // get the resource definitions
    actionResourceMapping = new ListOrderedMap();
    if (actionRootNode.selectNodes("action-resources/*").size() > 0) { // $NON-NLS-1$
      hasActionResources = true;
      errorCode =
          SequenceDefinition.parseActionResourceDefinitions(
              actionRootNode, logger, "action-resources/*", actionResourceMapping); // $NON-NLS-1$
    }

    componentName = XmlDom4JHelper.getNodeText("component-name", actionRootNode); // $NON-NLS-1$
    String loggingLevelString =
        XmlDom4JHelper.getNodeText("logging-level", actionRootNode); // $NON-NLS-1$
    loggingLevel = Logger.getLogLevel(loggingLevelString);

    // get the component payload
    componentNode = actionRootNode.selectSingleNode("component-definition"); // $NON-NLS-1$
    if (componentNode == null) {
      componentNode = ((Element) actionRootNode).addElement("component-definition"); // $NON-NLS-1$
    }

    // TODO populate preExecuteAuditList and postExecuteAuditList
  }
  private SequenceDefinition(
      final Node sequenceRootNode,
      final String solutionPath,
      final ILogger logger,
      final IApplicationContext applicationContext) {

    // initialize this object from the contents of the xml

    this.xactionPath = solutionPath;
    this.applicationContext = applicationContext;

    // get the descriptive entries
    version = XmlDom4JHelper.getNodeText("version", sequenceRootNode); // $NON-NLS-1$
    title = XmlDom4JHelper.getNodeText("title", sequenceRootNode); // $NON-NLS-1$

    isWebService =
        "true"
            .equals(
                XmlDom4JHelper.getNodeText(
                    "web-service", sequenceRootNode)); // $NON-NLS-1$ //$NON-NLS-2$
    loggingLevel =
        Logger.getLogLevel(
            XmlDom4JHelper.getNodeText("logging-level", sequenceRootNode)); // $NON-NLS-1$

    description =
        XmlDom4JHelper.getNodeText("documentation/description", sequenceRootNode); // $NON-NLS-1$
    help = XmlDom4JHelper.getNodeText("documentation/help", sequenceRootNode); // $NON-NLS-1$
    author = XmlDom4JHelper.getNodeText("documentation/author", sequenceRootNode); // $NON-NLS-1$
    resultType =
        XmlDom4JHelper.getNodeText("documentation/result-type", sequenceRootNode); // $NON-NLS-1$
    iconPath = XmlDom4JHelper.getNodeText("documentation/icon", sequenceRootNode); // $NON-NLS-1$

    // get the input parameter definitions
    inputDefinitions = new ListOrderedMap();
    errorCode =
        SequenceDefinition.parseParameters(
            sequenceRootNode, logger, "inputs/*", inputDefinitions, null, true); // $NON-NLS-1$

    // get the ouput definitions
    outputDefinitions = new ListOrderedMap();
    errorCode =
        SequenceDefinition.parseParameters(
            sequenceRootNode, logger, "outputs/*", outputDefinitions, null, false); // $NON-NLS-1$
    if (errorCode != ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK) {
      logger.info(
          Messages.getInstance()
              .getString(
                  "SequenceDefinition.INFO_OUTPUT_PARAMETERS_NOT_DEFINED")); //$NON-NLS-1$
    }
    // get the resource definitions
    errorCode = parseResourceDefinitions(sequenceRootNode, logger);
    if (errorCode != ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK) {
      logger.info(
          Messages.getInstance()
              .getString(
                  "SequenceDefinition.INFO_RESOURCES_PARAMETERS_NOT_DEFINED")); //$NON-NLS-1$
    }
  }
Ejemplo n.º 3
0
  private static Object getDefaultValue(final Node parameterNode) {
    Node rootNode = parameterNode.selectSingleNode("default-value"); // $NON-NLS-1$
    if (rootNode == null) {
      return (null);
    }

    String dataType = XmlDom4JHelper.getNodeText("@type", rootNode); // $NON-NLS-1$
    if (dataType == null) {
      dataType = XmlDom4JHelper.getNodeText("@type", parameterNode); // $NON-NLS-1$
    }

    if ("string-list".equals(dataType)) { // $NON-NLS-1$
      List nodes = rootNode.selectNodes("list-item"); // $NON-NLS-1$
      if (nodes == null) {
        return (null);
      }

      ArrayList rtnList = new ArrayList();
      for (Iterator it = nodes.iterator(); it.hasNext(); ) {
        rtnList.add(((Node) it.next()).getText());
      }
      return (rtnList);
    } else if ("property-map-list".equals(dataType)) { // $NON-NLS-1$
      List nodes = rootNode.selectNodes("property-map"); // $NON-NLS-1$
      if (nodes == null) {
        return (null);
      }

      ArrayList rtnList = new ArrayList();
      for (Iterator it = nodes.iterator(); it.hasNext(); ) {
        Node mapNode = (Node) it.next();
        rtnList.add(SequenceDefinition.getMapFromNode(mapNode));
      }
      return (rtnList);
    } else if ("property-map".equals(dataType)) { // $NON-NLS-1$
      return (SequenceDefinition.getMapFromNode(
          rootNode.selectSingleNode("property-map"))); // $NON-NLS-1$
    } else if ("long".equals(dataType)) { // $NON-NLS-1$
      try {
        return (new Long(rootNode.getText()));
      } catch (Exception e) {
      }
      return (null);
    } else if ("result-set".equals(dataType)) { // $NON-NLS-1$

      return (MemoryResultSet.createFromActionSequenceInputsNode(parameterNode));
    } else { // Assume String
      return (rootNode.getText());
    }
  }
Ejemplo n.º 4
0
  /**
   * sbarkdull: method appears to never be used anywhere
   *
   * @param actionRootNode
   * @param logger
   * @param nodePath
   * @param mapTo
   * @return
   */
  static int parseActionResourceDefinitions(
      final Node actionRootNode, final ILogger logger, final String nodePath, final Map mapTo) {

    try {
      List resources = actionRootNode.selectNodes(nodePath);

      // TODO create objects to represent the types
      // TODO need source variable list
      Iterator resourcesIterator = resources.iterator();

      Node resourceNode;
      String resourceName;
      while (resourcesIterator.hasNext()) {
        resourceNode = (Node) resourcesIterator.next();
        resourceName = resourceNode.getName();
        if (mapTo != null) {
          mapTo.put(
              resourceName,
              XmlDom4JHelper.getNodeText("@mapping", resourceNode, resourceName)); // $NON-NLS-1$
        }
      }
      return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK;
    } catch (Exception e) {
      logger.error(
          Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0006_PARSING_RESOURCE"),
          e); //$NON-NLS-1$
    }
    return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_INVALID_ACTION_DOC;
  }
Ejemplo n.º 5
0
  private static IActionSequence getNextLoopGroup(
      final ISequenceDefinition seqDef,
      final Node actionsNode,
      final String solutionPath,
      final String solutionName,
      final ILogger logger,
      final int loggingLevel) {

    String loopParameterName = XmlDom4JHelper.getNodeText("@loop-on", actionsNode); // $NON-NLS-1$
    boolean loopUsingPeek =
        "true"
            .equalsIgnoreCase(
                XmlDom4JHelper.getNodeText("@peek-only", actionsNode)); // $NON-NLS-1$ //$NON-NLS-2$

    Node actionDefinitionNode;
    ActionDefinition actionDefinition;

    List actionDefinitionList = new ArrayList();

    List nodeList = actionsNode.selectNodes("*"); // $NON-NLS-1$
    Iterator actionDefinitionNodes = nodeList.iterator();
    while (actionDefinitionNodes.hasNext()) {
      actionDefinitionNode = (Node) actionDefinitionNodes.next();
      if (actionDefinitionNode.getName().equals("actions")) { // $NON-NLS-1$
        actionDefinitionList.add(
            SequenceDefinition.getNextLoopGroup(
                seqDef, actionDefinitionNode, solutionPath, solutionName, logger, loggingLevel));
      } else if (actionDefinitionNode.getName().equals("action-definition")) { // $NON-NLS-1$
        actionDefinition = new ActionDefinition(actionDefinitionNode, logger);
        actionDefinition.setLoggingLevel(loggingLevel);
        actionDefinitionList.add(actionDefinition);
      }
    }
    // action sequences with 0 actions are valid, see: JIRA PLATFORM-837

    IConditionalExecution conditionalExecution =
        SequenceDefinition.parseConditionalExecution(
            actionsNode, logger, "condition"); // $NON-NLS-1$

    ActionSequence sequence =
        new ActionSequence(loopParameterName, seqDef, actionDefinitionList, loopUsingPeek);

    sequence.setConditionalExecution(conditionalExecution);
    return sequence;
  }
 public boolean setDataAction(final String widgetGridDataDefinition) {
   try {
     Document dataActionDocument = null;
     try {
       org.dom4j.io.SAXReader reader = new org.dom4j.io.SAXReader();
       reader.setEntityResolver(new SolutionURIResolver());
       dataActionDocument =
           reader.read(
               ActionSequenceResource.getInputStream(
                   widgetGridDataDefinition, LocaleHelper.getLocale()));
     } catch (Throwable t) {
       return false;
     }
     Node dataNode = dataActionDocument.selectSingleNode("widgetgrid/data"); // $NON-NLS-1$
     solution = XmlDom4JHelper.getNodeText("data-solution", dataNode); // $NON-NLS-1$
     actionPath = XmlDom4JHelper.getNodeText("data-path", dataNode); // $NON-NLS-1$
     actionName = XmlDom4JHelper.getNodeText("data-action", dataNode); // $NON-NLS-1$
     actionOutput = XmlDom4JHelper.getNodeText("data-output", dataNode); // $NON-NLS-1$
     valueItem = XmlDom4JHelper.getNodeText("data-value", dataNode); // $NON-NLS-1$
     nameItem = XmlDom4JHelper.getNodeText("data-name", dataNode); // $NON-NLS-1$
     widgetWidth =
         (int)
             XmlDom4JHelper.getNodeText(
                 "widgetgrid/width", dataActionDocument, 125); // $NON-NLS-1$
     widgetHeight =
         (int)
             XmlDom4JHelper.getNodeText(
                 "widgetgrid/height", dataActionDocument, 125); // $NON-NLS-1$
     columns =
         (int)
             XmlDom4JHelper.getNodeText(
                 "widgetgrid/columns", dataActionDocument, 2); // $NON-NLS-1$
     style = XmlDom4JHelper.getNodeText("widgetgrid/style", dataActionDocument); // $NON-NLS-1$
   } catch (Exception e) {
     error(
         Messages.getInstance()
             .getErrorString(
                 "WidgetGrid.ERROR_0003_DEFINITION_NOT_VALID", widgetGridDataDefinition),
         e); //$NON-NLS-1$
     return false;
   }
   return true;
 }
Ejemplo n.º 7
0
  private static Map getMapFromNode(final Node mapNode) {
    Map rtnMap = new ListOrderedMap();

    if (mapNode != null) {
      List nodes = mapNode.selectNodes("entry"); // $NON-NLS-1$
      if (nodes != null) {
        for (Iterator it = nodes.iterator(); it.hasNext(); ) {
          Node entryNode = (Node) it.next();
          rtnMap.put(
              XmlDom4JHelper.getNodeText("@key", entryNode), entryNode.getText()); // $NON-NLS-1$
        }
      }
    }
    return (rtnMap);
  }
Ejemplo n.º 8
0
  private JSONObject processSessionAttributes(Document config) {

    JSONObject result = new JSONObject();

    @SuppressWarnings("unchecked")
    List<Node> attributes = config.selectNodes("//sessionattributes/attribute");
    for (Node attribute : attributes) {

      String name = attribute.getText();
      String key = XmlDom4JHelper.getNodeText("@name", attribute);
      if (key == null) key = name;

      try {
        result.put(key, userSession.getAttribute(name));
      } catch (JSONException e) {
        logger.error(e);
      }
    }

    return result;
  }
Ejemplo n.º 9
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;
  }
Ejemplo n.º 10
0
  private int parseResourceDefinitions(final Node actionRootNode, final ILogger logger) {

    resourceDefinitions = new ListOrderedMap();

    try {
      List resources = actionRootNode.selectNodes("resources/*"); // $NON-NLS-1$

      // TODO create objects to represent the types
      // TODO need source variable list
      Iterator resourcesIterator = resources.iterator();

      Node resourceNode;
      String resourceName;
      String resourceTypeName;
      String resourceMimeType;
      int resourceType;
      ActionResource resource;
      Node typeNode, mimeNode;
      while (resourcesIterator.hasNext()) {
        resourceNode = (Node) resourcesIterator.next();
        typeNode = resourceNode.selectSingleNode("./*"); // $NON-NLS-1$
        if (typeNode != null) {
          resourceName = resourceNode.getName();
          resourceTypeName = typeNode.getName();
          resourceType = ActionResource.getResourceType(resourceTypeName);
          String resourceLocation = XmlDom4JHelper.getNodeText("location", typeNode); // $NON-NLS-1$
          if (resourceType == IActionSequenceResource.SOLUTION_FILE_RESOURCE) {
            if (resourceLocation == null) {
              logger.error(
                  Messages.getInstance()
                      .getErrorString(
                          "SequenceDefinition.ERROR_0008_RESOURCE_NO_LOCATION",
                          resourceName)); //$NON-NLS-1$
              continue;
            }
          } else if (resourceType == IActionSequenceResource.STRING) {
            resourceLocation = XmlDom4JHelper.getNodeText("string", resourceNode); // $NON-NLS-1$
          } else if (resourceType == IActionSequenceResource.XML) {
            // resourceLocation = XmlHelper.getNodeText("xml", resourceNode); //$NON-NLS-1$
            Node xmlNode = typeNode.selectSingleNode("./location/*"); // $NON-NLS-1$
            // Danger, we have now lost the character encoding of the XML in this node
            // see BISERVER-895
            resourceLocation = (xmlNode == null) ? "" : xmlNode.asXML(); // $NON-NLS-1$
          }
          mimeNode = typeNode.selectSingleNode("mime-type"); // $NON-NLS-1$
          if (mimeNode != null) {
            resourceMimeType = mimeNode.getText();
            resource =
                new ActionResource(
                    resourceName,
                    resourceType,
                    resourceMimeType,
                    solutionName,
                    solutionPath,
                    resourceLocation);
            resourceDefinitions.put(resourceName, resource);
          } else {
            logger.error(
                Messages.getInstance()
                    .getErrorString(
                        "SequenceDefinition.ERROR_0007_RESOURCE_NO_MIME_TYPE",
                        resourceName)); //$NON-NLS-1$
          }
        }
        // input = new ActionParameter( resourceName, resourceType, null
        // );
        // resourceDefinitions.put( inputName, input );
      }
      return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK;
    } catch (Exception e) {
      logger.error(
          Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0006_PARSING_RESOURCE"),
          e); //$NON-NLS-1$
    }
    return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_INVALID_ACTION_DOC;
  }
Ejemplo n.º 11
0
  static int parseParameters(
      final Node actionRootNode,
      final ILogger logger,
      final String nodePath,
      final Map parameterMap,
      final Map mapTo,
      final boolean inputVar) {
    try {
      List parameters = actionRootNode.selectNodes(nodePath);

      // TODO create objects to represent the types
      // TODO need source variable list
      Iterator parametersIterator = parameters.iterator();
      Node parameterNode;
      String parameterName;
      String parameterType;
      ActionParameter parameter;
      List variableNodes;
      List variables;
      Node variableNode;
      Iterator variablesIterator;
      String variableSource;
      String variableName;
      int variableIdx;
      Object defaultValue = null;

      while (parametersIterator.hasNext()) {
        parameterNode = (Node) parametersIterator.next();
        parameterName = parameterNode.getName();
        parameterType = XmlDom4JHelper.getNodeText("@type", parameterNode); // $NON-NLS-1$

        if (mapTo != null) {
          mapTo.put(
              parameterName,
              XmlDom4JHelper.getNodeText("@mapping", parameterNode, parameterName)); // $NON-NLS-1$
        }

        defaultValue = SequenceDefinition.getDefaultValue(parameterNode);
        // get the list of sources for this parameter
        variableNodes =
            parameterNode.selectNodes(
                (inputVar) ? "sources/*" : "destinations/*"); // $NON-NLS-1$ //$NON-NLS-2$
        variablesIterator = variableNodes.iterator();
        variableIdx = 1;
        variables = new ArrayList();
        while (variablesIterator.hasNext()) {
          variableNode = (Node) variablesIterator.next();
          // try to resolve the parameter value for this
          try {
            variableSource = variableNode.getName();
            variableName = variableNode.getText();
            ActionParameterSource variable =
                new ActionParameterSource(variableSource, variableName);
            if (SequenceDefinition.debug) {
              logger.debug(
                  Messages.getInstance()
                      .getString(
                          "SequenceDefinition.DEBUG_ADDING_SOURCE_FOR_PARAMETER",
                          variableSource,
                          parameterName)); //$NON-NLS-1$
            }

            variables.add(variable);
          } catch (Exception e) {
            logger.error(
                Messages.getInstance()
                    .getErrorString(
                        "SequenceDefinition.ERROR_0004_VARIABLE_SOURCE_NOT_VALID",
                        Integer.toString(variableIdx),
                        parameterName),
                e); //$NON-NLS-1$
          }
          variableIdx++;
        }
        if (defaultValue != null) {
          if (SequenceDefinition.debug) {
            logger.debug(
                Messages.getInstance()
                    .getString(
                        "SequenceDefinition.DEBUG_USING_DEFAULT_VALUE",
                        defaultValue.toString(),
                        parameterName)); //$NON-NLS-1$
          }
        }
        parameter =
            new ActionParameter(parameterName, parameterType, null, variables, defaultValue);
        parameterMap.put(parameterName, parameter);
      }
      return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK;
    } catch (Exception e) {
      logger.error(
          Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0005_PARSING_PARAMETERS"),
          e); //$NON-NLS-1$
    }

    return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_INVALID_ACTION_DOC;
  }