Ejemplo n.º 1
0
  protected Dashboard getDashboardFromCache(DashboardCacheKey key) {
    Dashboard dashboard;

    RepositoryAccess repository = RepositoryAccess.getRepository();

    try {
      Cache cache = getCache();
      Element cacheElement = cache.get(key);
      if (cacheElement == null) {
        return null;
      } else {
        dashboard = (Dashboard) cacheElement.getValue();
      }
      logger.info("Got dashboard from cache");
      ISolutionFile dash =
          repository.getSolutionFile(key.getCdfde(), FileAccess.READ); // was NO_PERM=0;
      if (dash == null) {
        logger.error(key.getCdfde() + " not found.");
        return null;
      }

      ISolutionFile templ;
      if (key.getTemplate() == null) {
        templ = null;
      } else {
        templ = repository.getSolutionFile(key.getTemplate(), FileAccess.READ);
      }

      /* Cache is invalidated if the dashboard or template have changed since
       * the cache was loaded, or at midnight every day, because of dynamic
       * generation of date parameters.
       */
      Calendar cal = Calendar.getInstance();
      cal.set(Calendar.HOUR_OF_DAY, 00);
      cal.set(Calendar.MINUTE, 00);
      cal.set(Calendar.SECOND, 1);
      boolean
          cacheInvalid =
              dash.getLastModified() > dashboard.getLoaded().getTime()
                  || (templ != null && templ.getLastModified() > dashboard.getLoaded().getTime()),
          cacheExpired = cal.getTime().after(dashboard.getLoaded());

      if (cacheExpired) {
        logger.info("Dashboard expired, re-rendering");
        return null;
      } else if (cacheInvalid) {
        logger.info("Dashboard cache invalidated, re-rendering");
        return null;
      } else {
        return dashboard;
      }
    } catch (CacheException ce) {
      logger.info("Dashboard cache invalidated, re-rendering");
      return null;
    }
  }
Ejemplo n.º 2
0
  public void saveDefinition(String[] file, String jsonString, IPentahoSession userSession)
      throws Exception {

    JSONObject json = (JSONObject) JSONSerializer.toJSON(jsonString);
    JXPathContext.newContext(json);

    switch (RepositoryAccess.getRepository(userSession)
        .publishFile(file[0], file[1], json.toString().getBytes("UTF-8"), true)) {
      case FAIL:
        logger.error("Could not save definition " + StringUtils.join(file, "/"));
    }
  }