Search in sources :

Example 1 with Site

use of com.enonic.xp.site.Site in project xp by enonic.

the class GetCurrentSiteScriptTest method insufficientRights.

@Test
public void insufficientRights() {
    final Site site = TestDataFixtures.newSite().permissions(AccessControlList.of(AccessControlEntry.create().principal(RoleKeys.ADMIN).allow(Permission.READ).build())).build();
    this.portalRequest.setSite(site);
    runFunction("/test/getCurrentSite-test.js", "noCurrentSite");
}
Also used : Site(com.enonic.xp.site.Site) Test(org.junit.jupiter.api.Test)

Example 2 with Site

use of com.enonic.xp.site.Site in project xp by enonic.

the class GetCurrentSiteConfigScriptTest method currentSite.

@Test
public void currentSite() {
    final Site site = TestDataFixtures.newSite().build();
    this.portalRequest.setSite(site);
    runFunction("/test/getCurrentSiteConfig-test.js", "currentSite");
}
Also used : Site(com.enonic.xp.site.Site) Test(org.junit.jupiter.api.Test)

Example 3 with Site

use of com.enonic.xp.site.Site in project xp by enonic.

the class ContentResolver method resolveInEditMode.

private ContentResolverResult resolveInEditMode(final ContentPath contentPath) {
    final ContentId contentId = ContentId.from(contentPath.toString().substring(1));
    final Content content = Optional.ofNullable(getContentById(contentId)).orElseGet(() -> getContentByPath(contentPath));
    final boolean contentExists = content != null || contentExistsById(contentId) || contentExistsByPath(contentPath);
    final Site site = content != null ? callAsContentAdmin(() -> this.contentService.getNearestSite(content.getId())) : null;
    return new ContentResolverResult(content, contentExists, site, siteRelativePath(site, content == null ? null : content.getPath()), contentPath.toString());
}
Also used : Site(com.enonic.xp.site.Site) Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId)

Example 4 with Site

use of com.enonic.xp.site.Site 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 5 with Site

use of com.enonic.xp.site.Site in project xp by enonic.

the class ContentResolverTest method resolve_non_existing_in_live_mode.

@Test
void resolve_non_existing_in_live_mode() {
    final Site site = newSite();
    final PortalRequest request = new PortalRequest();
    final ContentPath contentPath = ContentPath.from("/mysite/landing-page/non-existing");
    request.setContentPath(contentPath);
    when(this.contentService.getByPath(contentPath)).thenThrow(new ContentNotFoundException(contentPath, null));
    when(this.contentService.contentExists(contentPath)).thenReturn(false);
    when(this.contentService.findNearestSiteByPath(contentPath)).thenReturn(site);
    final ContentResolverResult result = new ContentResolver(contentService).resolve(request);
    assertNull(result.getContent());
    assertSame(site, result.getNearestSite());
    assertEquals("/landing-page/non-existing", result.getSiteRelativePath());
    final WebException e = assertThrows(WebException.class, result::getContentOrElseThrow);
    assertEquals(HttpStatus.NOT_FOUND, e.getStatus());
}
Also used : Site(com.enonic.xp.site.Site) WebException(com.enonic.xp.web.WebException) ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ContentPath(com.enonic.xp.content.ContentPath) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Aggregations

Site (com.enonic.xp.site.Site)78 Test (org.junit.jupiter.api.Test)51 Content (com.enonic.xp.content.Content)41 PortalRequest (com.enonic.xp.portal.PortalRequest)17 PropertyTree (com.enonic.xp.data.PropertyTree)14 Page (com.enonic.xp.page.Page)12 ContentId (com.enonic.xp.content.ContentId)10 ContentPath (com.enonic.xp.content.ContentPath)10 SiteConfig (com.enonic.xp.site.SiteConfig)10 WebException (com.enonic.xp.web.WebException)10 ApplicationKey (com.enonic.xp.app.ApplicationKey)9 PageTemplate (com.enonic.xp.page.PageTemplate)8 PortalResponse (com.enonic.xp.portal.PortalResponse)7 ControllerMappingDescriptor (com.enonic.xp.site.mapping.ControllerMappingDescriptor)7 SiteDescriptor (com.enonic.xp.site.SiteDescriptor)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 DescriptorKey (com.enonic.xp.page.DescriptorKey)5 SiteConfigs (com.enonic.xp.site.SiteConfigs)5 Branch (com.enonic.xp.branch.Branch)4 ContentService (com.enonic.xp.content.ContentService)4