Exemple #1
0
  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"));
    }
  }
Exemple #2
0
  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 "";
    }
  }
  /**
   * 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;
  }