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;
}
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;
}
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");
}
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);
}
}
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);
}
}
Aggregations