/**
  * Creates a WidgetGrid
  *
  * <p>After creating an instance of this class <CODE>validate</CODE> should be called.
  *
  * @param type The type of the widget, currently only TYPE_DIAL is supported
  * @param definitionPath The path and name of the XML definition of the dial
  * @param widgetWidth The width of the image to be created
  * @param widgetHeight The height of the image to be created
  * @param urlFactory The urlFactory for the content
  * @param messages The messages list for any logger messages
  */
 public WidgetGridComponent(
     final String definitionPath, final IPentahoUrlFactory urlFactory, final List messages) {
   super(urlFactory, messages, null);
   this.definitionPath = definitionPath;
   ActionInfo info = ActionInfo.parseActionString(definitionPath);
   if (info != null) {
     setSourcePath(info.getSolutionName() + File.separator + info.getPath());
   }
   setXsl("text/html", "DialWidget.xsl"); // $NON-NLS-1$ //$NON-NLS-2$
 }
 public FilterPanelComponent(
     final String definitionPath,
     String xslName,
     final IPentahoUrlFactory urlFactory,
     final List messages) {
   super(urlFactory, messages, null);
   this.definitionPath = definitionPath;
   if (xslName == null) {
     // use a default XSL
     xslName = "FilterPanelDefault.xsl"; // $NON-NLS-1$
   }
   ActionInfo info = ActionInfo.parseActionString(definitionPath);
   if (info != null) {
     setSourcePath(info.getSolutionName() + File.separator + info.getPath());
   }
   this.xslName = xslName;
   defaultValues = new HashMap();
 }
 /**
  * Creates a DashboardWidgetComponent.
  *
  * <p>After creating an instance of this class <CODE>validate</CODE> should be called.
  *
  * @param type The type of the widget, currently only TYPE_DIAL is supported
  * @param definitionPath The path and name of the XML definition of the dial
  * @param width The width of the image to be created
  * @param height The height of the image to be created
  * @param urlFactory The urlFactory for the content
  * @param messages The messages list for any logger messages
  */
 public DashboardWidgetComponent(
     final int type,
     final String definitionPath,
     final int width,
     final int height,
     final IPentahoUrlFactory urlFactory,
     final List messages) {
   super(urlFactory, messages, null);
   this.type = type;
   this.definitionPath = definitionPath;
   this.width = width;
   this.height = height;
   ActionInfo info = ActionInfo.parseActionString(definitionPath);
   if (info != null) {
     setSourcePath(info.getSolutionName() + File.separator + info.getPath());
   }
   // Set the XSL file to be used to generate the HTML
   setXsl("text/html", "DialWidget.xsl"); // $NON-NLS-1$ //$NON-NLS-2$
 }
  protected IPentahoResultSet getActionData() {
    // create an instance of the solution engine to execute the specified
    // action

    ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, getSession());
    solutionEngine.setLoggingLevel(ILogger.DEBUG);
    solutionEngine.init(getSession());

    HashMap parameterProviders = getParameterProviders();

    OutputStream outputStream = null;
    SimpleOutputHandler outputHandler = null;
    outputHandler = new SimpleOutputHandler(outputStream, false);

    ArrayList messages = new ArrayList();
    String processId = this.getClass().getName();

    String actionSeqPath = ActionInfo.buildSolutionPath(solution, actionPath, actionName);

    context =
        solutionEngine.execute(
            actionSeqPath,
            processId,
            false,
            true,
            instanceId,
            false,
            parameterProviders,
            outputHandler,
            null,
            urlFactory,
            messages);

    if (actionOutput != null) {
      if (context.getOutputNames().contains(actionOutput)) {
        IActionParameter output = context.getOutputParameter(actionOutput);
        IPentahoResultSet results = output.getValueAsResultSet();
        if (results != null) {
          results = results.memoryCopy();
        }
        return results;
      } else {
        // this is an error
        return null;
      }
    } else {
      // return the first list that we find...
      Iterator it = context.getOutputNames().iterator();
      while (it.hasNext()) {
        IActionParameter output = (IActionParameter) it.next();
        if (output.getType().equalsIgnoreCase(IActionParameter.TYPE_RESULT_SET)) {
          IPentahoResultSet results = output.getValueAsResultSet();
          if (results != null) {
            results = results.memoryCopy();
          }
          return results;
        }
      }
    }
    return null;
  }
Пример #5
0
  public static int saveAnalysis(
      final IPentahoSession session,
      final HashMap props,
      final String path,
      String fileName,
      final boolean overwrite) {

    if ("true"
        .equals(
            PentahoSystem.getSystemSetting(
                "kiosk-mode", "false"))) { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      throw new RuntimeException(
          Messages.getInstance()
              .getErrorString("ANALYSISSAVER.ERROR_0006_SAVE_IS_DISABLED")); // $NON-NLS-1$
    }

    int result = 0;
    try {
      AnalysisSaver.logger = LogFactory.getLog(AnalysisSaver.class);
      String baseUrl = PentahoSystem.getApplicationContext().getSolutionPath(""); // $NON-NLS-1$
      ISolutionRepository solutionRepository =
          PentahoSystem.get(ISolutionRepository.class, session);

      // We will (at this point in time) always have an original action sequence to start from...
      String originalActionReference = (String) props.get("actionreference"); // $NON-NLS-1$

      if (originalActionReference == null) {
        throw new MissingParameterException(
            Messages.getInstance()
                .getErrorString(
                    "ANALYSISSAVER.ERROR_0001_MISSING_ACTION_REFERENCE")); //$NON-NLS-1$
      }

      Document document = null;
      try {
        org.dom4j.io.SAXReader reader = new org.dom4j.io.SAXReader();
        reader.setEntityResolver(new SolutionURIResolver());
        document =
            reader.read(
                ActionSequenceResource.getInputStream(
                    originalActionReference, LocaleHelper.getLocale()));
      } catch (Throwable t) {
        // XML document can't be read. We'll just return a null document.
      }

      // Update the document with the stuff we passed in on the props
      document = AnalysisSaver.updateDocument(document, props);
      fileName =
          fileName.endsWith(AnalysisSaver.SUFFIX) ? fileName : fileName + AnalysisSaver.SUFFIX;
      result =
          solutionRepository.publish(
              baseUrl,
              path,
              fileName,
              document.asXML().getBytes(document.getXMLEncoding()),
              overwrite);

      // Now save the resource files
      ActionInfo actionInfo = ActionInfo.parseActionString(originalActionReference);
      String originalPath =
          actionInfo.getSolutionName() + "/" + actionInfo.getPath(); // $NON-NLS-1$
      String originalFileName = actionInfo.getActionName();
      originalFileName =
          originalFileName.substring(0, originalFileName.lastIndexOf(AnalysisSaver.SUFFIX));
      ISolutionFile[] parentFiles =
          solutionRepository
              .getSolutionFile(originalPath, ISolutionRepository.ACTION_EXECUTE)
              .listFiles();
      String baseFileName = fileName.substring(0, fileName.lastIndexOf(AnalysisSaver.SUFFIX));
      for (ISolutionFile aSolutionFile : parentFiles) {
        if (!aSolutionFile.isDirectory()
            && aSolutionFile.getFileName().startsWith(originalFileName)
            && aSolutionFile
                .getFileName()
                .toLowerCase()
                .endsWith(AnalysisSaver.PROPERTIES_SUFFIX)) {
          String newFileName =
              aSolutionFile.getFileName().replaceFirst(originalFileName, baseFileName);
          result =
              result
                  & solutionRepository.publish(
                      baseUrl, path, newFileName, aSolutionFile.getData(), overwrite);
        }
      }

      solutionRepository.resetRepository();
    } catch (Exception e) {
      AnalysisSaver.logger.error(
          Messages.getInstance().getErrorString("ANALYSISSAVER.ERROR_0000_UNKNOWN"),
          e); //$NON-NLS-1$
      result = ISolutionRepository.FILE_ADD_FAILED;
    }

    return result;
  }