Ejemplo n.º 1
0
  /**
   * This method updates the template structure by adding to it the current dashboard's style and
   * renderer type.
   *
   * <p>This is done by getting the current dashboard from within the json structure, loading it's
   * wcdfDescriptor and fetching its stored style and renderer type.
   *
   * <p>These values then are added to the template structure itself.
   *
   * <p>
   *
   * @param origStructure original template structure
   * @return original template structure updated to include the dashboard's style and renderer type
   * @throws DashboardStructureException
   */
  protected String addDashboardStyleAndRendererTypeToTemplate(String origStructure)
      throws DashboardStructureException {

    if (origStructure == null) {
      return origStructure; // nothing to do here
    }

    try {

      String updatedStructure = origStructure; // starts off as the original one

      JSONObject jsonObj = JSONObject.fromObject(origStructure);

      if (jsonObj != null && jsonObj.containsKey("filename")) {

        DashboardWcdfDescriptor wcdf = loadWcdfDescriptor(jsonObj.getString("filename"));

        if (wcdf != null) {

          // update the template structure
          jsonObj.put("style", wcdf.getStyle());
          jsonObj.put("rendererType", wcdf.getRendererType());

          updatedStructure = jsonObj.toString(2);
        }
      }

      return updatedStructure;

    } catch (Exception e) {
      logger.error(e);
      throw new DashboardStructureException(e.getMessage());
    }
  }
Ejemplo n.º 2
0
 // useful to mock the DashboardWcdfDescriptor when unit testing CdfTemplates
 protected DashboardWcdfDescriptor loadWcdfDescriptor(String wcdfFile) throws IOException {
   return DashboardWcdfDescriptor.load(wcdfFile);
 }