Search in sources :

Example 1 with PageRequest

use of org.entando.entando.web.page.model.PageRequest in project entando-core by entando.

the class PageService method updatePage.

private IPage updatePage(IPage oldPage, PageRequest pageRequest) {
    Page page = new Page();
    PageMetadata metadata = oldPage.getMetadata();
    if (metadata == null) {
        metadata = new PageMetadata();
    }
    this.valueMetadataFromRequest(metadata, pageRequest);
    page.setMetadata(metadata);
    page.setCode(pageRequest.getCode());
    page.setShowable(pageRequest.isDisplayedInMenu());
    if (!oldPage.getModel().getCode().equals(pageRequest.getPageModel())) {
        PageModel model = this.getPageModelManager().getPageModel(pageRequest.getPageModel());
        model.setCode(pageRequest.getPageModel());
        page.setModel(model);
        page.setWidgets(new Widget[model.getFrames().length]);
    } else {
        page.setWidgets(oldPage.getWidgets());
    }
    page.setCharset(pageRequest.getCharset());
    page.setMimeType(pageRequest.getContentType());
    page.setParentCode(pageRequest.getParentCode());
    page.setUseExtraTitles(pageRequest.isSeo());
    Optional<Map<String, String>> titles = Optional.ofNullable(pageRequest.getTitles());
    ApsProperties apsTitles = new ApsProperties();
    titles.ifPresent(values -> values.keySet().forEach((lang) -> {
        apsTitles.put(lang, values.get(lang));
    }));
    page.setTitles(apsTitles);
    page.setGroup(pageRequest.getOwnerGroup());
    if (page.getExtraGroups() != null) {
        List<String> oldGroups = new ArrayList<>(page.getExtraGroups());
        oldGroups.forEach(page::removeExtraGroup);
    }
    if (pageRequest.getJoinGroups() != null) {
        pageRequest.getJoinGroups().forEach(page::addExtraGroup);
    }
    page.setParentCode(pageRequest.getParentCode());
    page.setPosition(oldPage.getPosition());
    page.setChildrenCodes(oldPage.getChildrenCodes());
    return page;
}
Also used : ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) Arrays(java.util.Arrays) BeanComparator(org.apache.commons.beanutils.BeanComparator) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) Group(com.agiletec.aps.system.services.group.Group) IPage(com.agiletec.aps.system.services.page.IPage) PageConfigurationDto(org.entando.entando.aps.system.services.page.model.PageConfigurationDto) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) PageSearchDto(org.entando.entando.aps.system.services.page.model.PageSearchDto) IGroupManager(com.agiletec.aps.system.services.group.IGroupManager) WidgetValidatorFactory(org.entando.entando.aps.system.services.widgettype.validators.WidgetValidatorFactory) Widget(com.agiletec.aps.system.services.page.Widget) Map(java.util.Map) PagePositionRequest(org.entando.entando.web.page.model.PagePositionRequest) PageDtoBuilder(org.entando.entando.aps.system.services.page.model.PageDtoBuilder) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) JsonNode(com.fasterxml.jackson.databind.JsonNode) PageModelUtilizer(com.agiletec.aps.system.services.pagemodel.PageModelUtilizer) PageSearchRequest(org.entando.entando.web.page.model.PageSearchRequest) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) DataBinder(org.springframework.validation.DataBinder) ComponentUsageEntity(org.entando.entando.web.component.ComponentUsageEntity) Collectors(java.util.stream.Collectors) PagesStatus(com.agiletec.aps.system.services.page.PagesStatus) PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) List(java.util.List) RestListRequest(org.entando.entando.web.common.model.RestListRequest) GroupUtilizer(com.agiletec.aps.system.services.group.GroupUtilizer) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) Optional(java.util.Optional) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) IPageModelManager(com.agiletec.aps.system.services.pagemodel.IPageModelManager) PageUtils(org.entando.entando.aps.util.PageUtils) WidgetConfigurationDto(org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto) ApplicationContextAware(org.springframework.context.ApplicationContextAware) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) BeanUtils(org.springframework.beans.BeanUtils) JsonPatchService(org.entando.entando.aps.system.services.jsonpatch.JsonPatchService) Page(com.agiletec.aps.system.services.page.Page) HashMap(java.util.HashMap) BindingResult(org.springframework.validation.BindingResult) ApsProperties(com.agiletec.aps.util.ApsProperties) IWidgetTypeManager(org.entando.entando.aps.system.services.widgettype.IWidgetTypeManager) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) PageUtilizer(com.agiletec.aps.system.services.page.PageUtilizer) ArrayList(java.util.ArrayList) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IPageManager(com.agiletec.aps.system.services.page.IPageManager) IManager(com.agiletec.aps.system.common.IManager) PagedMetadataMapper(org.entando.entando.web.common.assembler.PagedMetadataMapper) WidgetConfigurationRequest(org.entando.entando.web.page.model.WidgetConfigurationRequest) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) GroupServiceUtilizer(org.entando.entando.aps.system.services.group.GroupServiceUtilizer) PageSearchMapper(org.entando.entando.web.common.assembler.PageSearchMapper) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) PageRequest(org.entando.entando.web.page.model.PageRequest) PagesStatusDto(org.entando.entando.aps.system.services.page.model.PagesStatusDto) BeansException(org.springframework.beans.BeansException) PageValidator(org.entando.entando.web.page.validator.PageValidator) ApplicationContext(org.springframework.context.ApplicationContext) PageModelServiceUtilizer(org.entando.entando.aps.system.services.pagemodel.PageModelServiceUtilizer) WidgetProcessorFactory(org.entando.entando.aps.system.services.widgettype.validators.WidgetProcessorFactory) Collections(java.util.Collections) PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) ArrayList(java.util.ArrayList) IPage(com.agiletec.aps.system.services.page.IPage) Page(com.agiletec.aps.system.services.page.Page) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) Map(java.util.Map) HashMap(java.util.HashMap) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 2 with PageRequest

use of org.entando.entando.web.page.model.PageRequest in project entando-core by entando.

the class PageDtoToRequestConverter method convert.

@Override
public PageRequest convert(PageDto source) {
    PageRequest pageRequest = new PageRequest();
    pageRequest.setCode(source.getCode());
    pageRequest.setCharset(source.getCharset());
    pageRequest.setContentType(source.getContentType());
    pageRequest.setDisplayedInMenu(source.isDisplayedInMenu());
    pageRequest.setJoinGroups(source.getJoinGroups());
    pageRequest.setOwnerGroup(source.getOwnerGroup());
    pageRequest.setPageModel(source.getPageModel());
    pageRequest.setParentCode(source.getParentCode());
    pageRequest.setStatus(source.getStatus());
    pageRequest.setTitles(source.getTitles());
    pageRequest.setSeo(source.isSeo());
    return pageRequest;
}
Also used : PageRequest(org.entando.entando.web.page.model.PageRequest)

Example 3 with PageRequest

use of org.entando.entando.web.page.model.PageRequest in project entando-core by entando.

the class PageServiceTest method shouldAddExtraGroup.

@Test
public void shouldAddExtraGroup() {
    PageDto dto = new PageDto();
    dto.addJoinGroup("free");
    dto.addJoinGroup("admin");
    when(dtoBuilder.convert(any(IPage.class))).thenReturn(dto);
    // PageModel pageModel = PageMockHelper.mockServicePageModel();
    Page page = PageMockHelper.mockTestPage(PageMockHelper.PAGE_CODE);
    page.setExtraGroups(new HashSet<>(Arrays.asList(PageMockHelper.GROUP)));
    when(pageManager.getDraftPage(page.getCode())).thenReturn(page);
    when(pageModelManager.getPageModel(page.getModel().getCode())).thenReturn(page.getModel());
    PageRequest request = PageMockHelper.mockPageRequest(page);
    request.setJoinGroups(Arrays.asList(PageMockHelper.GROUP, "admin"));
    when(pageManager.getDraftPage(request.getParentCode())).thenReturn(new Page());
    PageDto pageDto = pageService.updatePage(page.getCode(), request);
    assertThat(pageDto.getJoinGroups()).containsExactlyInAnyOrder(PageMockHelper.GROUP, "admin");
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) PageRequest(org.entando.entando.web.page.model.PageRequest) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) Page(com.agiletec.aps.system.services.page.Page) IPage(com.agiletec.aps.system.services.page.IPage) Test(org.junit.Test)

Example 4 with PageRequest

use of org.entando.entando.web.page.model.PageRequest in project entando-core by entando.

the class PageServiceIntegrationTest method testChangeNode.

@Test
public void testChangeNode() {
    String newPageCode = "pagina_13";
    try {
        PageDto pageToClone = pageService.getPage("pagina_11", "draft");
        assertNotNull(pageToClone);
        PageRequest pageRequest = this.createRequestFromDto(pageToClone);
        pageRequest.setCode(newPageCode);
        PageDto addedPage = pageService.addPage(pageRequest);
        assertNotNull(addedPage);
        assertEquals("pagina_1", addedPage.getParentCode());
        assertEquals(3, addedPage.getPosition());
        PagePositionRequest pagePosRequest = new PagePositionRequest();
        pagePosRequest.setCode(newPageCode);
        pagePosRequest.setParentCode("pagina_2");
        pagePosRequest.setPosition(1);
        addedPage = pageService.movePage(newPageCode, pagePosRequest);
        assertNotNull(addedPage);
        assertEquals("pagina_2", addedPage.getParentCode());
        assertEquals(1, addedPage.getPosition());
        List<PageDto> pages = pageService.getPages("pagina_2");
        assertNotNull(pages);
        assertEquals(1, pages.size());
        assertEquals(newPageCode, pages.get(0).getCode());
    } catch (Exception e) {
        throw e;
    } finally {
        pageService.removePage(newPageCode);
    }
}
Also used : PageRequest(org.entando.entando.web.page.model.PageRequest) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) PagePositionRequest(org.entando.entando.web.page.model.PagePositionRequest) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) Test(org.junit.Test)

Example 5 with PageRequest

use of org.entando.entando.web.page.model.PageRequest in project entando-core by entando.

the class PageServiceIntegrationTest method testAddAndRemovePage.

@Test
public void testAddAndRemovePage() throws Throwable {
    PageDto pageToClone = pageService.getPage("pagina_11", "draft");
    assertNotNull(pageToClone);
    PageRequest pageRequest = this.createRequestFromDto(pageToClone);
    pageRequest.setCode("pagina_13");
    PageDto addedPage = pageService.addPage(pageRequest);
    assertNotNull(addedPage);
    assertEquals("pagina_13", addedPage.getCode());
    assertEquals("pagina_1", addedPage.getParentCode());
    addedPage = pageService.getPage("pagina_13", "draft");
    assertNotNull(addedPage);
    assertEquals("pagina_13", addedPage.getCode());
    assertEquals("pagina_1", addedPage.getParentCode());
    pageService.removePage("pagina_13");
    try {
        addedPage = null;
        addedPage = pageService.getPage("pagina_13", "draft");
        fail("RestRourceNotFoundException not thrown");
    } catch (ResourceNotFoundException e) {
        assertNull(addedPage);
    }
}
Also used : PageRequest(org.entando.entando.web.page.model.PageRequest) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) Test(org.junit.Test)

Aggregations

PageRequest (org.entando.entando.web.page.model.PageRequest)27 Test (org.junit.Test)16 HashMap (java.util.HashMap)12 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)11 UserDetails (com.agiletec.aps.system.services.user.UserDetails)9 IPage (com.agiletec.aps.system.services.page.IPage)8 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)8 ResultActions (org.springframework.test.web.servlet.ResultActions)8 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)7 Page (com.agiletec.aps.system.services.page.Page)6 PagePositionRequest (org.entando.entando.web.page.model.PagePositionRequest)6 WidgetConfigurationRequest (org.entando.entando.web.page.model.WidgetConfigurationRequest)5 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)4 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)3 IManager (com.agiletec.aps.system.common.IManager)3 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)3 Group (com.agiletec.aps.system.services.group.Group)3 GroupUtilizer (com.agiletec.aps.system.services.group.GroupUtilizer)3 IGroupManager (com.agiletec.aps.system.services.group.IGroupManager)3