use of org.craftercms.core.util.cache.CacheTemplate in project engine by craftercms.
the class SiteContextFactory method createContext.
public SiteContext createContext(String siteName) {
Map<String, String> macroValues = new HashMap<>();
macroValues.put(siteNameMacroName, siteName);
if (publishingTargetResolver instanceof SiteAwarePublishingTargetResolver) {
String target = ((SiteAwarePublishingTargetResolver) publishingTargetResolver).getPublishingTarget(siteName);
macroValues.put(publishingTargetMacroName, target);
}
String resolvedRootFolderPath = macroResolver.resolveMacros(rootFolderPath, macroValues);
Context context = storeService.getContext(UUID.randomUUID().toString(), storeType, resolvedRootFolderPath, mergingOn, cacheOn, maxAllowedItemsInCache, ignoreHiddenFiles);
try {
SiteContext siteContext = new SiteContext();
siteContext.setInitTimeout(initTimeout);
siteContext.setStoreService(storeService);
siteContext.setCacheTemplate(cacheTemplate);
siteContext.setSiteName(siteName);
siteContext.setContext(context);
siteContext.setStaticAssetsPath(staticAssetsPath);
siteContext.setTemplatesPath(templatesPath);
siteContext.setInitScriptPath(initScriptPath);
siteContext.setFreeMarkerConfig(freeMarkerConfigFactory.getObject());
siteContext.setUrlTransformationEngine(urlTransformationEngine);
siteContext.setRestScriptsPath(restScriptsPath);
siteContext.setControllerScriptsPath(controllerScriptsPath);
siteContext.setGraphQLFactory(graphQLFactory);
siteContext.setShutdownTimeout(shutdownTimeout);
if (disableVariableRestrictions) {
siteContext.setServletContext(servletContext);
}
if (cacheWarmUpEnabled) {
siteContext.setCacheWarmer(cacheWarmer);
}
String[] resolvedConfigPaths = new String[configPaths.length];
for (int i = 0; i < configPaths.length; i++) {
resolvedConfigPaths[i] = macroResolver.resolveMacros(configPaths[i], macroValues);
}
String[] resolvedAppContextPaths = new String[applicationContextPaths.length];
for (int i = 0; i < applicationContextPaths.length; i++) {
resolvedAppContextPaths[i] = macroResolver.resolveMacros(applicationContextPaths[i], macroValues);
}
String[] resolvedUrlRewriteConfPaths = new String[urlRewriteConfPaths.length];
for (int i = 0; i < urlRewriteConfPaths.length; i++) {
resolvedUrlRewriteConfPaths[i] = macroResolver.resolveMacros(urlRewriteConfPaths[i], macroValues);
}
List<String> resolvedProxyConfPaths = Stream.of(proxyConfigPaths).map(path -> macroResolver.resolveMacros(path, macroValues)).collect(toList());
ResourceLoader resourceLoader = new ContentStoreResourceLoader(siteContext);
HierarchicalConfiguration<?> config = getConfig(siteContext, resolvedConfigPaths, resourceLoader);
configureScriptSandbox(siteContext, resourceLoader);
URLClassLoader classLoader = getClassLoader(siteContext);
ScriptFactory scriptFactory = getScriptFactory(siteContext, classLoader);
ConfigurableApplicationContext appContext = getApplicationContext(siteContext, classLoader, config, resolvedAppContextPaths, resourceLoader);
UrlRewriter urlRewriter = getUrlRewriter(siteContext, resolvedUrlRewriteConfPaths, resourceLoader);
HierarchicalConfiguration proxyConfig = getProxyConfig(siteContext, resolvedProxyConfPaths, resourceLoader);
siteContext.setScriptFactory(scriptFactory);
siteContext.setConfig(config);
siteContext.setGlobalApplicationContext(globalApplicationContext);
siteContext.setApplicationContext(appContext);
siteContext.setClassLoader(classLoader);
siteContext.setUrlRewriter(urlRewriter);
siteContext.setProxyConfig(proxyConfig);
if (config != null) {
siteContext.setAllowedTemplatePaths(config.getStringArray(CONFIG_KEY_ALLOWED_TEMPLATE_PATHS));
}
Scheduler scheduler = scheduleJobs(siteContext);
siteContext.setScheduler(scheduler);
return siteContext;
} catch (Exception e) {
logger.error("Error creating context for site '" + siteName + "'", e);
// Destroy context if the site context creation failed
storeService.destroyContext(context);
throw e;
}
}
use of org.craftercms.core.util.cache.CacheTemplate in project engine by craftercms.
the class Dom4jExtensionTest method createSiteContext.
private SiteContext createSiteContext(ContentStoreService storeService) {
CacheTemplate cacheTemplate = CacheTemplateMockUtils.createCacheTemplate();
SiteContext siteContext = spy(new SiteContext());
when(siteContext.getSiteName()).thenReturn("default");
when(siteContext.getStoreService()).thenReturn(storeService);
when(siteContext.getCacheTemplate()).thenReturn(cacheTemplate);
return siteContext;
}
use of org.craftercms.core.util.cache.CacheTemplate in project engine by craftercms.
the class RestScriptsControllerTest method createSiteContext.
private SiteContext createSiteContext(ContentStoreService storeService) {
SiteContext siteContext = spy(new SiteContext());
CacheTemplate cacheTemplate = CacheTemplateMockUtils.createCacheTemplate();
ContentStoreResourceConnector resourceConnector = new ContentStoreResourceConnector(siteContext);
ScriptFactory scriptFactory = new GroovyScriptFactory(siteContext, resourceConnector, Collections.emptyMap(), false);
when(siteContext.getSiteName()).thenReturn("test");
when(siteContext.getContext()).thenReturn(mock(Context.class));
when(siteContext.getRestScriptsPath()).thenReturn("/scripts");
when(siteContext.getStoreService()).thenReturn(storeService);
when(siteContext.getScriptFactory()).thenReturn(scriptFactory);
when(siteContext.getCacheTemplate()).thenReturn(cacheTemplate);
return siteContext;
}
use of org.craftercms.core.util.cache.CacheTemplate in project engine by craftercms.
the class GroovyScriptFactoryTest method createSiteContext.
private SiteContext createSiteContext(ContentStoreService storeService) {
CacheTemplate cacheTemplate = CacheTemplateMockUtils.createCacheTemplate();
SiteContext siteContext = spy(new SiteContext());
when(siteContext.getSiteName()).thenReturn("default");
when(siteContext.getContext()).thenReturn(mock(Context.class));
when(siteContext.getStoreService()).thenReturn(storeService);
when(siteContext.getCacheTemplate()).thenReturn(cacheTemplate);
return siteContext;
}
use of org.craftercms.core.util.cache.CacheTemplate in project engine by craftercms.
the class CacheTemplateMockUtils method createCacheTemplate.
public static CacheTemplate createCacheTemplate() {
CacheTemplate mock = mock(CacheTemplate.class);
setUpWithNoCaching(mock);
return mock;
}
Aggregations