Search in sources :

Example 1 with SiteConfig

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;
}
Also used : Site(com.enonic.xp.site.Site) ApplicationKey(com.enonic.xp.app.ApplicationKey) PortalResponse(com.enonic.xp.portal.PortalResponse) PortalError(com.enonic.xp.portal.impl.error.PortalError) SiteConfig(com.enonic.xp.site.SiteConfig)

Example 2 with SiteConfig

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();
}
Also used : Site(com.enonic.xp.site.Site) PropertyTree(com.enonic.xp.data.PropertyTree) SiteConfig(com.enonic.xp.site.SiteConfig)

Example 3 with SiteConfig

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();
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Page(com.enonic.xp.page.Page) SiteConfig(com.enonic.xp.site.SiteConfig)

Example 4 with SiteConfig

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();
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Page(com.enonic.xp.page.Page) SiteConfig(com.enonic.xp.site.SiteConfig)

Example 5 with SiteConfig

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());
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ApplicationKey(com.enonic.xp.app.ApplicationKey) ContentType(com.enonic.xp.schema.content.ContentType) SiteConfigsDataSerializer(com.enonic.xp.site.SiteConfigsDataSerializer) ValidationErrors(com.enonic.xp.content.ValidationErrors) PropertyTree(com.enonic.xp.data.PropertyTree) SiteConfig(com.enonic.xp.site.SiteConfig) Test(org.junit.jupiter.api.Test)

Aggregations

SiteConfig (com.enonic.xp.site.SiteConfig)16 PropertyTree (com.enonic.xp.data.PropertyTree)11 Site (com.enonic.xp.site.Site)6 ApplicationKey (com.enonic.xp.app.ApplicationKey)5 SiteConfigsDataSerializer (com.enonic.xp.site.SiteConfigsDataSerializer)4 SiteDescriptor (com.enonic.xp.site.SiteDescriptor)4 Test (org.junit.jupiter.api.Test)3 ValidationErrors (com.enonic.xp.content.ValidationErrors)2 Page (com.enonic.xp.page.Page)2 ContentType (com.enonic.xp.schema.content.ContentType)2 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)2 ResponseProcessorDescriptor (com.enonic.xp.site.processor.ResponseProcessorDescriptor)2 MacroDescriptor (com.enonic.xp.macro.MacroDescriptor)1 MacroDescriptors (com.enonic.xp.macro.MacroDescriptors)1 PortalResponse (com.enonic.xp.portal.PortalResponse)1 PortalError (com.enonic.xp.portal.impl.error.PortalError)1 SiteConfigs (com.enonic.xp.site.SiteConfigs)1 ResponseProcessorDescriptors (com.enonic.xp.site.processor.ResponseProcessorDescriptors)1 ArrayList (java.util.ArrayList)1