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; } }
public Dashboard loadDashboard( String wcdfPath, boolean debug, boolean absolute, String scheme, String absRoot, boolean bypassCache, String alias) throws FileNotFoundException { String dashboardPath = getDashboardPath(wcdfPath); IPentahoSession userSession = PentahoSessionHolder.getSession(); XmlStructure structure = new XmlStructure(userSession); Dashboard dashboard = null; WcdfDescriptor wcdf = null; DashboardCacheKey key; /* * First we must figure out what dashboard we should * be handling. We do this by loading up its wcdf * descriptor. */ try { if (!wcdfPath.isEmpty() && wcdfPath.endsWith(".wcdf")) { wcdf = structure.loadWcdfDescriptor(wcdfPath); } else { /* We didn't receive a valid path. We're in preview mode. * TODO: Support mobile preview mode (must remove dependency on setStyle()) */ wcdf = new WcdfDescriptor(); if (wcdfPath != null && wcdfPath.endsWith(".cdfde")) { wcdf.setWcdfPath(wcdfPath); } wcdf.setStyle(CdfStyles.DEFAULTSTYLE); wcdf.setRendererType(Renderers.BLUEPRINT.toString()); bypassCache = true; // no cache for preview } } catch (IOException ioe) { logger.error(ioe); return null; } /* Next, if we're using the cache, we try to find * the dashboard in there. */ key = new DashboardCacheKey( dashboardPath, CdfStyles.getInstance().getResourceLocation(wcdf.getStyle()), debug); key.setAbs(absolute); key.setRoot(scheme, absRoot); if (!bypassCache) { dashboard = getDashboardFromCache(key); } /* If it's not there, or we're bypassing the cache, * we load it up, and cache the newly loaded dashboard. */ if (dashboard == null) { Cache cache = getCache(); try { switch (Renderers.valueOf(wcdf.getRendererType().toUpperCase())) { case MOBILE: dashboard = new MobileDashboard(wcdf, absolute, absRoot, debug, scheme); break; /* Until we consider it safe to assume that all dashboards have * their renderer type correctly identified, we'll have to default * to assuming they're blueprint-style dashboards. */ case BLUEPRINT: default: if (wcdf.isWidget()) { dashboard = new BlueprintWidget(wcdf, absolute, absRoot, debug, scheme, alias); } else { dashboard = new BlueprintDashboard(wcdf, absolute, absRoot, debug, scheme); } break; } } catch (IllegalArgumentException e) { logger.error("Bad renderer type: " + wcdf.getRendererType()); return null; } cache.put(new Element(key, dashboard)); } return dashboard; }