Пример #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"));
    }
  }
Пример #2
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());
 }
Пример #3
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);
 }
Пример #4
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);
 }
Пример #5
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);
 }
Пример #6
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);
  }
Пример #7
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;
    }
  }
Пример #8
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;
    }
  }