Ejemplo n.º 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"));
    }
  }
Ejemplo n.º 2
0
  private void loadFiles(final IBasicFile[] jsonFiles, final JSONArray result, final String type)
      throws IOException {

    Arrays.sort(
        jsonFiles,
        new Comparator<IBasicFile>() {

          @Override
          public int compare(IBasicFile file1, IBasicFile file2) {
            if (file1 == null && file2 == null) {
              return 0;
            } else {
              return file1.getFullPath().toLowerCase().compareTo(file2.getFullPath().toLowerCase());
            }
          }
        });

    IReadAccess access = CdeEnvironment.getPluginSystemReader(SYSTEM_CDF_DD_TEMPLATES);

    for (int i = 0; i < jsonFiles.length; i++) {
      final JSONObject template = new JSONObject();

      String imgResourcePath = resoureUrl + "unknown.png";

      if (access.fileExists(jsonFiles[i].getName().replace(".cdfde", ".png"))) {
        imgResourcePath = resoureUrl + jsonFiles[i].getName().replace(".cdfde", ".png");
      }

      template.put("img", imgResourcePath);
      template.put("type", type);
      template.put("structure", JsonUtils.readJsonFromInputStream(jsonFiles[i].getContents()));
      result.add(template);
    }
  }
Ejemplo n.º 3
0
 @GET
 @Path("/syncronizeStyles")
 @Produces(MimeTypes.JSON)
 public void syncStyles(@Context HttpServletResponse response)
     throws IOException, DashboardDesignerException, JSONException {
   final CdfStyles cdfStyles = new CdfStyles();
   JsonUtils.buildJsonResult(response.getOutputStream(), true, cdfStyles.liststyles());
 }
Ejemplo n.º 4
0
 @GET
 @Path("/getCubes")
 @Produces("text/javascript")
 public void getCubes(
     @QueryParam(MethodParams.CATALOG) String catalog,
     @Context HttpServletRequest request,
     @Context HttpServletResponse response)
     throws IOException, JSONException {
   OlapUtils olapUtils = new OlapUtils();
   JSONObject result = olapUtils.getOlapCubes();
   JsonUtils.buildJsonResult(response.getOutputStream(), result != null, result);
 }
Ejemplo n.º 5
0
 @GET
 @Path("/getLevelMembersStructure")
 @Produces("text/javascript")
 public void getLevelMembersStructure(
     @QueryParam(MethodParams.CATALOG) String catalog,
     @QueryParam(MethodParams.CUBE) String cube,
     @QueryParam(MethodParams.MEMBER) String member,
     @QueryParam(MethodParams.DIRECTION) String direction,
     @Context HttpServletResponse response)
     throws IOException, JSONException {
   OlapUtils olapUtils = new OlapUtils();
   JSONObject result = olapUtils.getLevelMembersStructure(catalog, cube, member, direction);
   JsonUtils.buildJsonResult(response.getOutputStream(), result != null, result);
 }
Ejemplo n.º 6
0
  public MobileDashboard(
      IParameterProvider pathParams, DashboardDesignerContentGenerator generator) {
    super(pathParams, generator);
    IPentahoSession userSession = PentahoSessionHolder.getSession();
    final ISolutionRepository solutionRepository =
        PentahoSystem.get(ISolutionRepository.class, userSession);

    final String absRoot =
        pathParams.hasParameter("root")
            ? !pathParams.getParameter("root").toString().isEmpty()
                ? "http://" + pathParams.getParameter("root").toString()
                : ""
            : "";
    final boolean absolute =
        (!absRoot.isEmpty())
            || pathParams.hasParameter("absolute")
                && pathParams.getParameter("absolute").equals("true");

    final RenderMobileLayout layoutRenderer = new RenderMobileLayout();
    final RenderComponents componentsRenderer = new RenderComponents();

    try {
      final JSONObject json =
          (JSONObject)
              JsonUtils.readJsonFromInputStream(
                  solutionRepository.getResourceInputStream(dashboardLocation, true));

      json.put("settings", getWcdf().toJSON());
      final JXPathContext doc = JXPathContext.newContext(json);

      final StringBuilder dashboardBody = new StringBuilder();

      dashboardBody.append(layoutRenderer.render(doc));
      dashboardBody.append(componentsRenderer.render(doc));

      // set all dashboard members
      this.content = replaceTokens(dashboardBody.toString(), absolute, absRoot);

      this.header = renderHeaders(pathParams, this.content.toString());
      this.loaded = new Date();
    } catch (Exception e) {
      logger.error(e);
    }
  }
Ejemplo n.º 7
0
 @GET
 @Path("/getPaginatedLevelMembers")
 @Produces("text/javascript")
 public void getPaginatedLevelMembers(
     @QueryParam(MethodParams.CATALOG) String catalog,
     @QueryParam(MethodParams.CUBE) String cube,
     @QueryParam(MethodParams.LEVEL) String level,
     @QueryParam(MethodParams.START_MEMBER) String startMember,
     @QueryParam(MethodParams.CONTEXT) String context,
     @QueryParam(MethodParams.SEARCH_TERM) String searchTerm,
     @QueryParam(MethodParams.PAGE_SIZE) long pageSize,
     @QueryParam(MethodParams.PAGE_START) long pageStart,
     @Context HttpServletResponse response)
     throws IOException, JSONException {
   OlapUtils olapUtils = new OlapUtils();
   JSONObject result =
       olapUtils.getPaginatedLevelMembers(
           catalog, cube, level, startMember, context, searchTerm, pageSize, pageStart);
   JsonUtils.buildJsonResult(response.getOutputStream(), result != null, result);
 }
Ejemplo n.º 8
0
  @POST
  @Path("/syncronizeTemplates")
  @Produces(MimeTypes.JSON)
  public void syncTemplates(
      @FormParam(MethodParams.OPERATION) String operation,
      @FormParam(MethodParams.FILE) String file,
      @FormParam(MethodParams.DASHBOARD_STRUCTURE) String cdfStructure,
      @FormParam(MethodParams.RENDERER_TYPE) String rendererType,
      @Context HttpServletResponse response)
      throws IOException, DashboardStructureException, JSONException {
    final CdfTemplates cdfTemplates = new CdfTemplates(GET_RESOURCE);
    Object result = null;

    if (OPERATION_LOAD.equalsIgnoreCase(operation)) {
      result = cdfTemplates.load(rendererType);
    } else if (OPERATION_SAVE.equalsIgnoreCase(operation)) {
      cdfTemplates.save(file, cdfStructure, rendererType);
    }

    JsonUtils.buildJsonResult(response.getOutputStream(), true, result);
  }
Ejemplo n.º 9
0
  @POST
  @Path("/syncronizeDashboard")
  @Produces(MimeTypes.JSON)
  public String syncronize(
      @FormParam(MethodParams.FILE) @DefaultValue("") String file,
      @FormParam(MethodParams.PATH) @DefaultValue("") String path,
      @FormParam(MethodParams.TITLE) @DefaultValue("") String title,
      @FormParam(MethodParams.AUTHOR) @DefaultValue("") String author,
      @FormParam(MethodParams.DESCRIPTION) @DefaultValue("") String description,
      @FormParam(MethodParams.STYLE) @DefaultValue("") String style,
      @FormParam(MethodParams.WIDGET_NAME) @DefaultValue("") String widgetName,
      @FormParam(MethodParams.WIDGET) boolean widget,
      @FormParam(MethodParams.RENDERER_TYPE) @DefaultValue("") String rendererType,
      @FormParam(MethodParams.WIDGET_PARAMETERS) List<String> widgetParams,
      @FormParam(MethodParams.DASHBOARD_STRUCTURE) String cdfStructure,
      @FormParam(MethodParams.OPERATION) String operation,
      @FormParam(MethodParams.REQUIRE) boolean require,
      @Context HttpServletRequest request,
      @Context HttpServletResponse response)
      throws Exception {

    boolean isPreview = false;

    if (!file.isEmpty() && !file.equals(UNSAVED_FILE_PATH)) {

      file = Utils.getURLDecoded(file, CharsetHelper.getEncoding());

      // check access to path folder
      String fileDir =
          file.contains(".wcdf") || file.contains(".cdfde")
              ? file.substring(0, file.lastIndexOf("/"))
              : file;

      isPreview = (file.contains("_tmp.cdfde") || file.contains("_tmp.wcdf"));

      IReadAccess rwAccess = Utils.getSystemOrUserRWAccess(file);

      if (rwAccess == null) {
        String msg =
            "Access denied for the syncronize method syncronizeDashboard."
                + operation
                + " : "
                + file;
        logger.warn(msg);
        return JsonUtils.getJsonResult(false, msg);
      }
    }

    try {
      final DashboardStructure dashboardStructure = new DashboardStructure();
      Object result = null;
      HashMap<String, Object> params = new HashMap<String, Object>();
      params.put(MethodParams.FILE, file);
      params.put(MethodParams.WIDGET, String.valueOf(widget));
      params.put(MethodParams.REQUIRE, String.valueOf(require));
      if (!author.isEmpty()) {
        params.put(MethodParams.AUTHOR, author);
      }
      if (!style.isEmpty()) {
        params.put(MethodParams.STYLE, style);
      }
      if (!widgetName.isEmpty()) {
        params.put(MethodParams.WIDGET_NAME, widgetName);
      }
      if (!rendererType.isEmpty()) {
        params.put(MethodParams.RENDERER_TYPE, rendererType);
      }
      if (!title.isEmpty()) {
        params.put(MethodParams.TITLE, title);
      }
      if (!description.isEmpty()) {
        params.put(MethodParams.DESCRIPTION, description);
      }
      String[] widgetParameters = widgetParams.toArray(new String[0]);
      if (widgetParameters.length > 0) {
        params.put(MethodParams.WIDGET_PARAMETERS, widgetParameters);
      }

      String wcdfdeFile = file.replace(".wcdf", ".cdfde");

      if (OPERATION_LOAD.equalsIgnoreCase(operation)) {
        return dashboardStructure.load(wcdfdeFile);
      } else if (OPERATION_DELETE.equalsIgnoreCase(operation)) {
        dashboardStructure.delete(params);
      } else if (OPERATION_DELETE_PREVIEW.equalsIgnoreCase(operation)) {
        dashboardStructure.deletePreviewFiles(wcdfdeFile);
      } else if (OPERATION_SAVE.equalsIgnoreCase(operation)) {
        result = dashboardStructure.save(file, cdfStructure);
      } else if (OPERATION_SAVE_AS.equalsIgnoreCase(operation)) {
        if (StringUtils.isEmpty(title)) {
          title = FilenameUtils.getBaseName(file);
        }
        result = dashboardStructure.saveAs(file, title, description, cdfStructure, isPreview);
      } else if (OPERATION_NEW_FILE.equalsIgnoreCase(operation)) {
        dashboardStructure.newfile(params);
      } else if (OPERATION_SAVE_SETTINGS.equalsIgnoreCase(operation)) {

        // check if user is attempting to save settings over a new (non yet saved)
        // dashboard/widget/template
        if (StringUtils.isEmpty(file) || file.equals(UNSAVED_FILE_PATH)) {
          logger.warn(getMessage("CdfTemplates.ERROR_003_SAVE_DASHBOARD_FIRST"));
          return JsonUtils.getJsonResult(
              false, getMessage("CdfTemplates.ERROR_003_SAVE_DASHBOARD_FIRST"));
        }
        dashboardStructure.savesettings(params);
      } else {
        logger.error("Unknown operation: " + operation);
      }
      return JsonUtils.getJsonResult(true, result);
    } catch (Exception e) {
      if (e.getCause() != null) {
        if (e.getCause() instanceof DashboardStructureException) {
          JsonUtils.buildJsonResult(response.getOutputStream(), false, e.getCause().getMessage());
        } else if (e instanceof InvocationTargetException) {
          throw (Exception) e.getCause();
        }
      }
      throw e;
    }
  }
Ejemplo n.º 10
0
  @POST
  @Path("/saveDashboard")
  @Produces(MimeTypes.JSON)
  @Consumes("multipart/form-data")
  public String saveDashboard(
      @FormDataParam(MethodParams.FILE) @DefaultValue("") String file,
      @FormDataParam(MethodParams.TITLE) @DefaultValue("") String title,
      @FormDataParam(MethodParams.DESCRIPTION) @DefaultValue("") String description,
      @FormDataParam(MethodParams.DASHBOARD_STRUCTURE) String cdfStructure,
      @FormDataParam(MethodParams.OPERATION) String operation,
      @Context HttpServletResponse response)
      throws Exception {

    boolean isPreview = false;

    if (!file.isEmpty()
        && !(file.equals(UNSAVED_FILE_PATH)
            || Utils.getURLDecoded(file).equals(UNSAVED_FILE_PATH))) {

      file = Utils.getURLDecoded(file, CharsetHelper.getEncoding());

      if (StringUtils.isEmpty(title)) {
        title = FilenameUtils.getBaseName(file);
      }

      // check access to path folder
      String fileDir =
          file.contains(".wcdf") || file.contains(".cdfde")
              ? file.substring(0, file.lastIndexOf("/"))
              : file;

      isPreview = (file.contains("_tmp.cdfde") || file.contains("_tmp.wcdf"));

      IReadAccess rwAccess;
      if (OPERATION_SAVE_AS.equalsIgnoreCase(operation) && !isPreview) {
        rwAccess = Utils.getSystemOrUserRWAccess(fileDir);
      } else {
        rwAccess = Utils.getSystemOrUserRWAccess(file);
      }

      if (rwAccess == null) {
        String msg =
            "Access denied for the syncronize method saveDashboard." + operation + " : " + file;
        logger.warn(msg);
        return JsonUtils.getJsonResult(false, msg);
      }
    }

    try {
      final DashboardStructure dashboardStructure = new DashboardStructure();
      Object result = null;

      if (OPERATION_SAVE.equalsIgnoreCase(operation)) {
        result = dashboardStructure.save(file, cdfStructure);
      } else if (OPERATION_SAVE_AS.equalsIgnoreCase(operation)) {
        result = dashboardStructure.saveAs(file, title, description, cdfStructure, isPreview);
      } else {
        logger.error("Unknown operation: " + operation);
      }
      return JsonUtils.getJsonResult(true, result);
    } catch (Exception e) {
      if (e.getCause() != null) {
        if (e.getCause() instanceof DashboardStructureException) {
          JsonUtils.buildJsonResult(response.getOutputStream(), false, e.getCause().getMessage());
        } else if (e instanceof InvocationTargetException) {
          throw (Exception) e.getCause();
        }
      }
      throw e;
    }
  }