use of com.enonic.xp.site.SiteConfig in project xp by enonic.
the class ExceptionRendererImpl method doRenderCustomError.
private PortalResponse doRenderCustomError(final PortalRequest req, final WebException cause, final String handlerMethod) {
final PortalError portalError = PortalError.create().status(cause.getStatus()).message(cause.getMessage()).exception(cause).request(req).build();
final Site siteInRequest = req.getSite();
final Site site = siteInRequest != null ? siteInRequest : callAsContentAdmin(() -> this.contentService.findNearestSiteByPath(req.getContentPath()));
if (site != null) {
req.setSite(site);
try {
for (SiteConfig siteConfig : site.getSiteConfigs()) {
final ApplicationKey applicationKey = siteConfig.getApplicationKey();
for (final String scriptPath : SITE_ERROR_SCRIPT_PATHS) {
final PortalResponse response = renderApplicationCustomError(applicationKey, scriptPath, portalError, handlerMethod);
if (response != null) {
if (response.isPostProcess()) {
req.setApplicationKey(applicationKey);
}
return response;
}
}
}
} finally {
req.setSite(siteInRequest);
}
} else if (req.getApplicationKey() != null) {
final ApplicationKey applicationKey = req.getApplicationKey();
final PortalResponse response = renderApplicationCustomError(applicationKey, GENERIC_ERROR_SCRIPT_PATH, portalError, handlerMethod);
if (response != null) {
if (response.isPostProcess()) {
req.setApplicationKey(applicationKey);
}
return response;
}
}
return null;
}
use of com.enonic.xp.site.SiteConfig in project xp by enonic.
the class ContentFixtures method newSite.
public static Site newSite() {
final PropertyTree siteConfigConfig = new PropertyTree();
siteConfigConfig.setLong("Field", 42L);
final SiteConfig siteConfig = SiteConfig.create().application(ApplicationKey.from("myapplication")).config(siteConfigConfig).build();
final Site.Builder site = Site.create();
site.id(ContentId.from("100123"));
site.siteConfigs(SiteConfigs.from(siteConfig));
site.name("my-content");
site.parentPath(ContentPath.ROOT);
return site.build();
}
use of com.enonic.xp.site.SiteConfig in project xp by enonic.
the class MappingHandlerTest method createSite.
private Site createSite(final String id, final String path, final String contentTypeName) {
PropertyTree rootDataSet = new PropertyTree();
rootDataSet.addString("property1", "value1");
Page page = Page.create().template(PageTemplateKey.from("my-page")).config(rootDataSet).build();
final SiteConfig siteConfig = SiteConfig.create().application(ApplicationKey.from("myapplication")).config(new PropertyTree()).build();
return Site.create().siteConfigs(SiteConfigs.from(siteConfig)).id(ContentId.from(id)).path(ContentPath.from(path)).owner(PrincipalKey.from("user:myStore:me")).displayName("My Content").modifier(PrincipalKey.from("user:system:admin")).type(ContentTypeName.from(contentTypeName)).page(page).build();
}
use of com.enonic.xp.site.SiteConfig in project xp by enonic.
the class ServiceHandlerTest method createSite.
private Site createSite(final String id, final String path, final String contentTypeName) {
PropertyTree rootDataSet = new PropertyTree();
rootDataSet.addString("property1", "value1");
Page page = Page.create().template(PageTemplateKey.from("my-page")).config(rootDataSet).build();
final SiteConfig siteConfig = SiteConfig.create().application(ApplicationKey.from("demo")).config(new PropertyTree()).build();
return Site.create().addSiteConfig(siteConfig).id(ContentId.from(id)).path(ContentPath.from(path)).owner(PrincipalKey.from("user:myStore:me")).displayName("My Content").modifier(PrincipalKey.from("user:system:admin")).type(ContentTypeName.from(contentTypeName)).page(page).build();
}
use of com.enonic.xp.site.SiteConfig in project xp by enonic.
the class ValidateContentDataCommandTest method testSiteConfigTextRegexpPasses.
@Test
public void testSiteConfigTextRegexpPasses() {
final ContentType contentType = ContentType.create().superType(ContentTypeName.structured()).name(ContentTypeName.site()).build();
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(contentType);
PropertyTree rootDataSet = new PropertyTree();
PropertyTree siteConfigDataSet = new PropertyTree();
siteConfigDataSet.setString("textInput-1", "1234");
SiteConfig siteConfig = SiteConfig.create().application(ApplicationKey.from("myapp")).config(siteConfigDataSet).build();
new SiteConfigsDataSerializer().toProperties(SiteConfigs.from(siteConfig), rootDataSet.getRoot());
Mockito.when(siteService.getDescriptor(Mockito.isA(ApplicationKey.class))).thenReturn(createSiteDescriptor());
// exercise
final ValidationErrors result = executeValidation(rootDataSet, ContentTypeName.site());
assertFalse(result.hasErrors());
}
Aggregations