コード例 #1
0
ファイル: CdfStyles.java プロジェクト: pstoellberger/cde
  public void syncronize(
      IPentahoSession userSession, OutputStream out, IParameterProvider requestParams)
      throws Exception {

    // Read parameters
    Iterator<String> keys = requestParams.getParameterNames();
    HashMap<String, String> parameters = new HashMap<String, String>();
    while (keys.hasNext()) {
      String key = keys.next();
      parameters.put(key, requestParams.getStringParameter(key, null));
    }

    String operation = requestParams.getStringParameter("operation", "").toLowerCase();

    // Call sync method
    try {

      Class<?>[] params = new Class[1];
      params[0] = HashMap.class;
      Method mthd = this.getClass().getMethod(operation, params);
      Object result = mthd.invoke(this, parameters);
      if (result != null) {
        JsonUtils.buildJsonResult(out, true, result);
      }

      JsonUtils.buildJsonResult(out, true, null);

    } catch (NoSuchMethodException e) {
      throw new Exception(
          Messages.getString("CdfTemplates.ERROR_001_INVALID_SYNCRONIZE_METHOD_EXCEPTION"));
    }
  }
  private static String callPlugin(
      final String pluginName, final String method, final Map<String, Object> parameters)
      throws ReportDataFactoryException {

    final IPentahoSession userSession = PentahoSessionHolder.getSession();
    final IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, userSession);

    try {
      Object cdaBean = pluginManager.getBean("cda.api");
      Class cdaBeanClass = cdaBean.getClass();

      Class[] paramTypes;
      Object[] paramValues;
      Method m;
      final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

      if ("listParameters".equals(method)) {
        IParameterProvider params = new SimpleParameterProvider(parameters);

        paramTypes =
            new Class[] {
              String.class,
              String.class,
              String.class,
              String.class,
              String.class,
              HttpServletResponse.class,
              HttpServletRequest.class
            };
        m = cdaBeanClass.getMethod("listParameters", paramTypes);
        paramValues = new Object[7];
        paramValues[0] = params.getStringParameter("path", null);
        paramValues[1] = params.getStringParameter("solution", "");
        paramValues[2] = params.getStringParameter("file", "");
        paramValues[3] = params.getStringParameter("outputType", "json");
        paramValues[4] = params.getStringParameter("dataAccessId", "<blank>");
        paramValues[5] = getResponse(outputStream);
        paramValues[6] = getRequest(parameters);

        m.invoke(cdaBean, paramValues);

        return outputStream.toString();

      } else {
        paramTypes = new Class[] {HttpServletRequest.class};
        m = cdaBeanClass.getMethod("doQueryInterPlugin", paramTypes);

        paramValues = new Object[1];
        paramValues[0] = getRequest(parameters);

        return (String) m.invoke(cdaBean, paramValues);
      }

    } catch (Exception e) {
      throw new ReportDataFactoryException("Failed to acquire " + pluginName + " plugin: ", e);
    }
  }
コード例 #3
0
ファイル: DashboardContext.java プロジェクト: kolinus/cdf
  public String getContext(IParameterProvider requestParams) {
    try {
      String solution = requestParams.getStringParameter("solution", ""),
          path = requestParams.getStringParameter("path", ""),
          // Fix #29. Because there is no file parameter in CDF, but action parameter
          // file parameter is used in CDE
          file =
              requestParams.getStringParameter(
                  "file", requestParams.getStringParameter("action", "")),
          fullPath = ("/" + solution + "/" + path + "/" + file).replaceAll("/+", "/");
      final JSONObject context = new JSONObject();
      Calendar cal = Calendar.getInstance();

      Document config = getConfigFile();

      context.put("queryData", processAutoIncludes(fullPath, config));
      context.put("sessionAttributes", processSessionAttributes(config));

      context.put("serverLocalDate", cal.getTimeInMillis());
      context.put("serverUTCDate", cal.getTimeInMillis() + cal.getTimeZone().getRawOffset());
      context.put("user", userSession.getName());
      context.put("locale", userSession.getLocale());
      context.put("solution", solution);
      context.put("path", path);
      context.put("file", file);
      context.put("fullPath", fullPath);

      SecurityParameterProvider securityParams = new SecurityParameterProvider(userSession);
      context.put("roles", securityParams.getParameter("principalRoles"));

      JSONObject params = new JSONObject();

      Iterator it = requestParams.getParameterNames();
      while (it.hasNext()) {
        String p = (String) it.next();
        if (p.indexOf("param") == 0) {
          params.put(p.substring(5), requestParams.getParameter(p));
        }
      }
      context.put("params", params);

      final StringBuilder s = new StringBuilder();
      s.append("\n<script language=\"javascript\" type=\"text/javascript\">\n");
      s.append("  Dashboards.context = ");
      s.append(context.toString(2) + "\n");
      s.append("</script>\n");
      // setResponseHeaders(MIME_PLAIN,0,null);
      logger.info(
          "[Timing] Finished building context: "
              + (new SimpleDateFormat("HH:mm:ss.SSS")).format(new Date()));

      return s.toString();
    } catch (JSONException e) {
      return "";
    }
  }
コード例 #4
0
ファイル: DashboardFactory.java プロジェクト: eliassouza/cde
  private String getWcdfPath(final IParameterProvider pathParams) {
    final String path =
        "/"
            + pathParams.getStringParameter(MethodParams.SOLUTION, null)
            + "/"
            + pathParams.getStringParameter(MethodParams.PATH, null)
            + "/"
            + pathParams.getStringParameter(MethodParams.FILE, null);

    return path.replaceAll("//+", "/");
  }
コード例 #5
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  public static String executeXml(
      RepositoryFile file,
      HttpServletRequest httpServletRequest,
      HttpServletResponse httpServletResponse,
      IPentahoSession userSession)
      throws Exception {
    try {
      HttpSessionParameterProvider sessionParameters =
          new HttpSessionParameterProvider(userSession);
      HttpRequestParameterProvider requestParameters =
          new HttpRequestParameterProvider(httpServletRequest);
      Map parameterProviders = new HashMap();
      parameterProviders.put("request", requestParameters); // $NON-NLS-1$
      parameterProviders.put("session", sessionParameters); // $NON-NLS-1$
      List messages = new ArrayList();
      IParameterProvider requestParams = new HttpRequestParameterProvider(httpServletRequest);
      httpServletResponse.setContentType("text/xml"); // $NON-NLS-1$
      httpServletResponse.setCharacterEncoding(LocaleHelper.getSystemEncoding());
      boolean forcePrompt =
          "true"
              .equalsIgnoreCase(
                  requestParams.getStringParameter(
                      "prompt", "false")); // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$

      OutputStream contentStream = new ByteArrayOutputStream();
      SimpleOutputHandler outputHandler = new SimpleOutputHandler(contentStream, false);
      IRuntimeContext runtime = null;
      try {
        runtime =
            executeInternal(
                file,
                requestParams,
                httpServletRequest,
                outputHandler,
                parameterProviders,
                userSession,
                forcePrompt,
                messages);
        Document responseDoc =
            SoapHelper.createSoapResponseDocument(runtime, outputHandler, contentStream, messages);
        OutputFormat format = OutputFormat.createCompactFormat();
        format.setSuppressDeclaration(true);
        format.setEncoding("utf-8"); // $NON-NLS-1$
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        XMLWriter writer = new XMLWriter(outputStream, format);
        writer.write(responseDoc);
        writer.flush();
        return outputStream.toString("utf-8"); // $NON-NLS-1$
      } finally {
        if (runtime != null) {
          runtime.dispose();
        }
      }
    } catch (Exception e) {
      logger.warn(
          Messages.getInstance().getString("XactionUtil.XML_OUTPUT_NOT_SUPPORTED")); // $NON-NLS-1$
      throw e;
    }
  }
コード例 #6
0
    @Override
    public void createContent() throws Exception {
      try {
        IContentItem responseContentItem =
            outputHandler.getOutputContentItem(
                IOutputHandler.RESPONSE, IOutputHandler.CONTENT, null, null);
        // mime type setting will blow up since servlet api used by grizzly is too old
        try {
          responseContentItem.setMimeType("text/plain");
        } catch (Throwable t) {
        }
        OutputStream outputStream = responseContentItem.getOutputStream(null);
        IParameterProvider pathParams = parameterProviders.get("path");
        String command = pathParams.getStringParameter("cmd", "");

        Object testParamValue =
            parameterProviders.get(IParameterProvider.SCOPE_REQUEST).getParameter("testParam");
        assertEquals("testParam is missing from request", "testParamValue", testParamValue);

        IOUtils.write(
            "hello this is service content generator servicing command " + command, outputStream);
        outputStream.close();
      } catch (Throwable t) {
        t.printStackTrace();
      }
    }
コード例 #7
0
    @Override
    public void execute() throws Exception {
      IParameterProvider pathParams = parameterProviders.get("path");
      String command = pathParams.getStringParameter("cmd", "");

      IOUtils.write("hello this is service content generator servicing command " + command, out);
      out.close();
    }
コード例 #8
0
  @SuppressWarnings("rawtypes")
  protected static IRuntimeContext executeInternal(
      RepositoryFile file,
      IParameterProvider requestParams,
      HttpServletRequest httpServletRequest,
      IOutputHandler outputHandler,
      Map<String, IParameterProvider> parameterProviders,
      IPentahoSession userSession,
      boolean forcePrompt,
      List messages)
      throws Exception {
    String processId = XactionUtil.class.getName();
    String instanceId = httpServletRequest.getParameter("instance-id"); // $NON-NLS-1$
    SimpleUrlFactory urlFactory = new SimpleUrlFactory(""); // $NON-NLS-1$
    ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, userSession);
    ISystemSettings systemSettings = PentahoSystem.getSystemSettings();

    if (solutionEngine == null) {
      throw new ObjectFactoryException("No Solution Engine");
    }

    boolean instanceEnds =
        "true"
            .equalsIgnoreCase(
                requestParams.getStringParameter(
                    "instanceends", "true")); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    String parameterXsl =
        systemSettings.getSystemSetting(
            "default-parameter-xsl", "DefaultParameterForm.xsl"); // $NON-NLS-1$ //$NON-NLS-2$

    solutionEngine.setLoggingLevel(2);
    solutionEngine.init(userSession);
    solutionEngine.setForcePrompt(forcePrompt);
    if (parameterXsl != null) {
      solutionEngine.setParameterXsl(parameterXsl);
    }
    return solutionEngine.execute(
        file.getPath(),
        processId,
        false,
        instanceEnds,
        instanceId,
        false,
        parameterProviders,
        outputHandler,
        null,
        urlFactory,
        messages);
  }
コード例 #9
0
ファイル: DashboardFactory.java プロジェクト: eliassouza/cde
  public Dashboard loadDashboard(Map<String, IParameterProvider> params)
      throws FileNotFoundException {
    IParameterProvider pathParams = params.get("path"), requestParams = params.get("request");
    String scheme =
        requestParams.hasParameter("inferScheme")
                && requestParams.getParameter("inferScheme").equals("false")
            ? ""
            : DashboardDesignerContentGenerator.getScheme(pathParams);
    String root = requestParams.getStringParameter("root", "");
    boolean
        absolute =
            (!root.equals(""))
                || requestParams.hasParameter("absolute")
                    && requestParams.getParameter("absolute").equals("true"),
        bypassCache =
            requestParams.hasParameter("bypassCache")
                && requestParams.getParameter("bypassCache").equals("true");
    final boolean debug =
        requestParams.hasParameter("debug") && requestParams.getParameter("debug").equals("true");

    String wcdfPath = getWcdfPath(requestParams);
    return loadDashboard(wcdfPath, debug, absolute, scheme, root, bypassCache, "");
  }
コード例 #10
0
  /**
   * Start Audit Event
   *
   * @param processId Id for the audit process (usually the plugin name)
   * @param actionName Name of the action
   * @param objectName Object of the action
   * @param userSession Pentaho User Session
   * @param logger Logger object
   * @param requestParams parameters associated to the request
   * @return UUID of start event
   */
  public static UUID startAudit(
      String processId,
      String actionName,
      String objectName,
      IPentahoSession userSession,
      ILogger logger,
      IParameterProvider requestParams) {
    UUID uuid = UUID.randomUUID();

    StringBuilder sb = new StringBuilder();
    if (requestParams != null) {
      @SuppressWarnings("unchecked")
      Iterator<String> iter = requestParams.getParameterNames();
      while (iter.hasNext()) {
        String paramName = iter.next().toString();
        sb.append(paramName)
            .append("=")
            .append(requestParams.getStringParameter(paramName, "novalue"))
            .append(";");
      }
    }

    AuditHelper.audit(
        userSession.getId(),
        userSession.getName(),
        actionName,
        objectName,
        processId,
        MessageTypes.INSTANCE_START,
        uuid.toString(),
        sb.toString(),
        0,
        logger);

    return uuid;
  }
コード例 #11
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  public static String doParameter(
      final RepositoryFile file,
      IParameterProvider parameterProvider,
      final IPentahoSession userSession)
      throws IOException {
    ActionSequenceJCRHelper helper = new ActionSequenceJCRHelper();
    final IActionSequence actionSequence =
        helper.getActionSequence(
            file.getPath(), PentahoSystem.loggingLevel, RepositoryFilePermission.READ);
    final Document document = DocumentHelper.createDocument();
    try {
      final Element parametersElement = document.addElement("parameters");

      // noinspection unchecked
      final Map<String, IActionParameter> params =
          actionSequence.getInputDefinitionsForParameterProvider(IParameterProvider.SCOPE_REQUEST);
      for (final Map.Entry<String, IActionParameter> entry : params.entrySet()) {
        final String paramName = entry.getKey();
        final IActionParameter paramDef = entry.getValue();
        final String value = paramDef.getStringValue();
        final Class type;
        // yes, the actual type-code uses equals-ignore-case and thus allows the user
        // to specify type information in a random case. sTrInG is equal to STRING is equal to the
        // value
        // defined as constant (string)
        if (IActionParameter.TYPE_LIST.equalsIgnoreCase(paramDef.getType())) {
          type = String[].class;
        } else {
          type = String.class;
        }
        final String label = paramDef.getSelectionDisplayName();

        final String[] values;
        if (StringUtils.isEmpty(value)) {
          values = new String[0];
        } else {
          values = new String[] {value};
        }

        createParameterElement(
            parametersElement, paramName, type, label, "user", "parameters", values);
      }

      createParameterElement(
          parametersElement,
          "path",
          String.class,
          null,
          "system",
          "system",
          new String[] {file.getPath()});
      createParameterElement(
          parametersElement,
          "prompt",
          String.class,
          null,
          "system",
          "system",
          new String[] {"yes", "no"});
      createParameterElement(
          parametersElement,
          "instance-id",
          String.class,
          null,
          "system",
          "system",
          new String[] {parameterProvider.getStringParameter("instance-id", null)});
      // no close, as far as I know tomcat does not like it that much ..
      OutputFormat format = OutputFormat.createCompactFormat();
      format.setSuppressDeclaration(true);
      format.setEncoding("utf-8"); // $NON-NLS-1$
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      XMLWriter writer = new XMLWriter(outputStream, format);
      writer.write(document);
      writer.flush();
      return outputStream.toString("utf-8");
    } catch (Exception e) {
      logger.warn(Messages.getInstance().getString("HttpWebService.ERROR_0003_UNEXPECTED"), e);
      return null;
    }
  }
コード例 #12
0
  /**
   * This method executes an xaction with forcePrompt=true and outputPreference=PARAMETERS, allowing
   * for the xaction to render the secure filter appropriately when being executed in the background
   * or while being scheduled.
   *
   * @param file the location of the xaction
   * @param httpServletRequest the request object
   * @param httpServletResponse the response object
   * @param userSession the user session
   * @return potential response message
   * @throws Exception
   */
  @SuppressWarnings({"unchecked", "rawtypes"})
  public static String executeScheduleUi(
      RepositoryFile file,
      HttpServletRequest httpServletRequest,
      HttpServletResponse httpServletResponse,
      IPentahoSession userSession,
      IMimeTypeListener mimeTypeListener)
      throws Exception {
    IParameterProvider requestParams = new HttpRequestParameterProvider(httpServletRequest);
    IRuntimeContext runtime = null;
    try {
      HttpSessionParameterProvider sessionParameters =
          new HttpSessionParameterProvider(userSession);
      HttpRequestParameterProvider requestParameters =
          new HttpRequestParameterProvider(httpServletRequest);

      boolean doMessages =
          "true"
              .equalsIgnoreCase(
                  requestParams.getStringParameter(
                      "debug", "false")); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      boolean doWrapper =
          "true"
              .equalsIgnoreCase(
                  requestParams.getStringParameter(
                      "wrapper", "true")); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

      IOutputHandler outputHandler =
          createOutputHandler(
              httpServletResponse, getOutputStream(httpServletResponse, doMessages));
      if (mimeTypeListener == null) {
        mimeTypeListener = new HttpMimeTypeListener(httpServletRequest, httpServletResponse, null);
      }
      outputHandler.setMimeTypeListener(mimeTypeListener);
      outputHandler.setSession(userSession);

      Map parameterProviders = new HashMap();
      parameterProviders.put("request", requestParameters); // $NON-NLS-1$
      parameterProviders.put("session", sessionParameters); // $NON-NLS-1$
      createOutputFileName(file, outputHandler);
      int outputPreference = IOutputHandler.OUTPUT_TYPE_PARAMETERS;
      outputHandler.setOutputPreference(outputPreference);
      List messages = new ArrayList();

      // forcePrompt=true when displaying the scheduling UI
      runtime =
          executeInternal(
              file,
              requestParams,
              httpServletRequest,
              outputHandler,
              parameterProviders,
              userSession,
              true,
              messages);
      String str =
          postExecute(
              runtime,
              doMessages,
              doWrapper,
              outputHandler,
              parameterProviders,
              httpServletRequest,
              httpServletResponse,
              messages,
              false);
      return str;
    } catch (Exception e) {
      logger.error(
          Messages.getInstance()
              .getString("XactionUtil.ERROR_EXECUTING_ACTION_SEQUENCE", file.getName()),
          e); //$NON-NLS-1$
      throw e;
    } finally {
      if (runtime != null) {
        runtime.dispose();
      }
    }
  }