Search in sources :

Example 26 with Page

use of com.agiletec.aps.system.services.page.Page in project entando-core by entando.

the class PageConfigurationControllerIntegrationTest method createPage.

protected Page createPage(String pageCode) {
    IPage parentPage = pageManager.getDraftPage("service");
    PageModel pageModel = parentPage.getMetadata().getModel();
    PageMetadata metadata = PageTestUtil.createPageMetadata(pageModel.getCode(), true, pageCode + "_title", null, null, false, null, null);
    ApsProperties config = PageTestUtil.createProperties("temp", "tempValue", "contentId", "ART11");
    Widget widgetToAdd = PageTestUtil.createWidget("content_viewer", config, this.widgetTypeManager);
    Widget[] widgets = { widgetToAdd };
    Page pageToAdd = PageTestUtil.createPage(pageCode, parentPage, "free", metadata, widgets);
    return pageToAdd;
}
Also used : PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) IPage(com.agiletec.aps.system.services.page.IPage) Widget(com.agiletec.aps.system.services.page.Widget) Page(com.agiletec.aps.system.services.page.Page) IPage(com.agiletec.aps.system.services.page.IPage) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 27 with Page

use of com.agiletec.aps.system.services.page.Page in project entando-core by entando.

the class PageConfigurationControllerWidgetsIntegrationTest method testContentViewer.

@Test
public void testContentViewer() throws Exception {
    String pageCode = "draft_page_100";
    try {
        Page mockPage = createPage(pageCode);
        this.pageManager.addPage(mockPage);
        IPage onlinePage = this.pageManager.getOnlinePage(pageCode);
        assertThat(onlinePage, is(nullValue()));
        IPage draftPage = this.pageManager.getDraftPage(pageCode);
        assertThat(draftPage, is(not(nullValue())));
        UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
        String accessToken = mockOAuthInterceptor(user);
        ResultActions result = mockMvc.perform(get("/pages/{pageCode}/configuration", new Object[] { pageCode }).param("status", IPageService.STATUS_DRAFT).header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk());
        String payloadWithInvalidContentId = "{\n" + "  \"code\": \"content_viewer\",\n" + "  \"config\": {\n" + "      \"contentId\": \"ART1120000000\",\n" + "      \"modelId\": \"default\"\n" + "  }\n" + "}";
        result = mockMvc.perform(put("/pages/{pageCode}/widgets/{frameId}", new Object[] { pageCode, 0 }).param("status", IPageService.STATUS_ONLINE).content(payloadWithInvalidContentId).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        System.out.println(result.andReturn().getResponse().getContentAsString());
        result.andExpect(status().isConflict());
        String validContentIdWithIncompatibleGroup = "{\n" + "  \"code\": \"content_viewer\",\n" + "  \"config\": {\n" + "      \"contentId\": \"ART112\",\n" + "      \"modelId\": \"default\"\n" + "  }\n" + "}";
        result = mockMvc.perform(put("/pages/{pageCode}/widgets/{frameId}", new Object[] { pageCode, 0 }).param("status", IPageService.STATUS_ONLINE).content(validContentIdWithIncompatibleGroup).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        System.out.println(result.andReturn().getResponse().getContentAsString());
        result.andExpect(status().isConflict());
    } finally {
        this.pageManager.deletePage(pageCode);
    }
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) UserDetails(com.agiletec.aps.system.services.user.UserDetails) Page(com.agiletec.aps.system.services.page.Page) IPage(com.agiletec.aps.system.services.page.IPage) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 28 with Page

use of com.agiletec.aps.system.services.page.Page in project entando-core by entando.

the class PageControllerTest method shouldValidateMovePageGroupMismatch.

@Test
public void shouldValidateMovePageGroupMismatch() throws ApsSystemException, Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    PagePositionRequest request = new PagePositionRequest();
    request.setCode("page_to_move");
    request.setParentCode("new_parent_page");
    request.setPosition(1);
    Page pageToMove = new Page();
    pageToMove.setCode("page_to_move");
    pageToMove.setParentCode("old_parent_page");
    pageToMove.setGroup("page_to_move_group");
    Page newParent = new Page();
    newParent.setCode("new_parent_page");
    newParent.setParentCode("another_parent_page");
    newParent.setGroup("another_group");
    when(authorizationService.isAuth(any(UserDetails.class), any(String.class))).thenReturn(true);
    when(this.controller.getPageValidator().getPageManager().getDraftPage("page_to_move")).thenReturn(pageToMove);
    when(this.controller.getPageValidator().getPageManager().getDraftPage("new_parent_page")).thenReturn(newParent);
    ResultActions result = mockMvc.perform(put("/pages/{pageCode}/position", "page_to_move").sessionAttr("user", user).content(convertObjectToJsonBytes(request)).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isBadRequest());
    String response = result.andReturn().getResponse().getContentAsString();
    result.andExpect(jsonPath("$.errors", hasSize(1)));
    result.andExpect(jsonPath("$.errors[0].code", is(PageController.ERRCODE_GROUP_MISMATCH)));
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) PagePositionRequest(org.entando.entando.web.page.model.PagePositionRequest) Page(com.agiletec.aps.system.services.page.Page) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 29 with Page

use of com.agiletec.aps.system.services.page.Page in project entando-core by entando.

the class PageManagerCacheWrapper method buildTreeHierarchy.

protected void buildTreeHierarchy(IPage root, Map<String, IPage> pagesMap, IPage page) {
    Page parent = (Page) pagesMap.get(page.getParentCode());
    ((Page) page).setParent(parent);
    if (!page.getCode().equals(root.getCode())) {
        parent.addChildCode(page.getCode());
    }
}
Also used : Page(com.agiletec.aps.system.services.page.Page) IPage(com.agiletec.aps.system.services.page.IPage)

Aggregations

Page (com.agiletec.aps.system.services.page.Page)29 IPage (com.agiletec.aps.system.services.page.IPage)23 PageMetadata (com.agiletec.aps.system.services.page.PageMetadata)12 Widget (com.agiletec.aps.system.services.page.Widget)9 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)9 Test (org.junit.Test)9 UserDetails (com.agiletec.aps.system.services.user.UserDetails)7 ResultActions (org.springframework.test.web.servlet.ResultActions)7 ApsProperties (com.agiletec.aps.util.ApsProperties)5 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)4 WidgetConfigurationDto (org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto)4 WidgetConfigurationRequest (org.entando.entando.web.page.model.WidgetConfigurationRequest)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)3 IManager (com.agiletec.aps.system.common.IManager)2 GroupUtilizer (com.agiletec.aps.system.services.group.GroupUtilizer)2 IGroupManager (com.agiletec.aps.system.services.group.IGroupManager)2