Search in sources :

Example 41 with PageModel

use of com.agiletec.aps.system.services.pagemodel.PageModel 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 42 with PageModel

use of com.agiletec.aps.system.services.pagemodel.PageModel in project entando-core by entando.

the class PageModelControllerIntegrationTest method testDeletePageModel.

@Test
public void testDeletePageModel() throws Exception {
    String pageModelCode = "testPM";
    try {
        PageModel pageModel = new PageModel();
        pageModel.setCode(pageModelCode);
        pageModel.setDescription(pageModelCode);
        this.pageModelManager.addPageModel(pageModel);
        UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
        String accessToken = mockOAuthInterceptor(user);
        ResultActions result = mockMvc.perform(delete("/pagemodels/{code}", pageModelCode).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        // System.out.println(result.andReturn().getResponse().getContentAsString());
        result.andExpect(status().isOk());
    } finally {
        this.pageModelManager.deletePageModel(pageModelCode);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 43 with PageModel

use of com.agiletec.aps.system.services.pagemodel.PageModel in project entando-core by entando.

the class PageModelControllerTest method should_load_the_list_of_pageModels_1.

@Test
public void should_load_the_list_of_pageModels_1() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    PageModelDto singleDto = new PageModelDto();
    List<PageModelDto> dtos = new ArrayList<>();
    dtos.add(singleDto);
    PageModel model = new PageModel();
    List<PageModel> models = new ArrayList<>();
    models.add(model);
    SearcherDaoPaginatedResult<PageModel> sdpr = new SearcherDaoPaginatedResult<>(1, models);
    PagedMetadata<PageModelDto> meta = new PagedMetadata<>(new RestListRequest(), sdpr);
    meta.setBody(dtos);
    when(pageModelService.getPageModels(any(RestListRequest.class))).thenReturn(meta);
    ResultActions result = mockMvc.perform(get("/pagemodels").header("Authorization", "Bearer " + accessToken));
    System.out.println(result.andReturn().getResponse().getContentAsString());
    result.andExpect(status().isOk());
    RestListRequest restListReq = new RestListRequest();
    Mockito.verify(pageModelService, Mockito.times(1)).getPageModels(restListReq);
}
Also used : PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) ArrayList(java.util.ArrayList) RestListRequest(org.entando.entando.web.common.model.RestListRequest) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PageModelDto(org.entando.entando.aps.system.services.pagemodel.model.PageModelDto) UserDetails(com.agiletec.aps.system.services.user.UserDetails) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 44 with PageModel

use of com.agiletec.aps.system.services.pagemodel.PageModel in project entando-core by entando.

the class PageExecutorService method service.

@Override
public void service(RequestContext reqCtx) {
    HttpServletRequest request = reqCtx.getRequest();
    HttpServletResponse response = reqCtx.getResponse();
    try {
        if (response.isCommitted()) {
            return;
        }
        IPage page = (IPage) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE);
        PageModel model = page.getModel();
        if (StringUtils.isBlank(model.getTemplate())) {
            String jspPath = model.getPageModelJspPath();
            RequestDispatcher dispatcher = request.getSession().getServletContext().getRequestDispatcher(jspPath);
            dispatcher.forward(request, response);
        } else {
            ExecutorBeanContainer ebc = (ExecutorBeanContainer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER);
            Template template = new Template(page.getCode(), new StringReader(model.getTemplate()), ebc.getConfiguration());
            try {
                template.process(ebc.getTemplateModel(), response.getWriter());
            } catch (Throwable t) {
                String msg = "Error detected while including a page model " + model.getCode();
                _logger.error(msg, t);
                throw new RuntimeException(msg, t);
            }
        }
    } catch (ServletException e) {
        String msg = "Error detected while including a page model";
        _logger.error(msg, e);
        throw new RuntimeException(msg, e);
    } catch (IOException e) {
        String msg = "IO error detected while including the page model";
        _logger.error(msg, e);
        throw new RuntimeException(msg, e);
    }
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) RequestDispatcher(javax.servlet.RequestDispatcher) Template(freemarker.template.Template) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) IPage(com.agiletec.aps.system.services.page.IPage) StringReader(java.io.StringReader) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel)

Example 45 with PageModel

use of com.agiletec.aps.system.services.pagemodel.PageModel in project entando-core by entando.

the class PageManager method checkPagePos.

/**
 * Utility method which perform checks on the parameters submitted when
 * editing the page.
 *
 * @param pageCode The code of the page
 * @param pos The given position
 * @throws ApsSystemException In case of database access error.
 */
private void checkPagePos(String pageCode, int pos) throws ApsSystemException {
    IPage currentPage = this.getDraftPage(pageCode);
    if (null == currentPage) {
        throw new ApsSystemException("The page '" + pageCode + "' does not exist!");
    }
    PageModel model = currentPage.getMetadata().getModel();
    if (pos < 0 || pos >= model.getFrames().length) {
        throw new ApsSystemException("The Position '" + pos + "' is not defined in the model '" + model.getDescription() + "' of the page '" + pageCode + "'!");
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel)

Aggregations

PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)47 IPage (com.agiletec.aps.system.services.page.IPage)13 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)11 Page (com.agiletec.aps.system.services.page.Page)10 Widget (com.agiletec.aps.system.services.page.Widget)10 ApsProperties (com.agiletec.aps.util.ApsProperties)10 PageMetadata (com.agiletec.aps.system.services.page.PageMetadata)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 RestServerError (org.entando.entando.aps.system.exception.RestServerError)7 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)7 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)6 Frame (com.agiletec.aps.system.services.pagemodel.Frame)5 Map (java.util.Map)5 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)5 WidgetConfigurationDto (org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto)5 WidgetConfigurationRequest (org.entando.entando.web.page.model.WidgetConfigurationRequest)5 IPageModelManager (com.agiletec.aps.system.services.pagemodel.IPageModelManager)4 PageModelDOM (com.agiletec.aps.system.services.pagemodel.PageModelDOM)4 IDtoBuilder (org.entando.entando.aps.system.services.IDtoBuilder)4