use of org.entando.entando.web.page.model.PageRequest in project entando-core by entando.
the class PageService method valueMetadataFromRequest.
private void valueMetadataFromRequest(PageMetadata metadata, PageRequest request) {
metadata.setGroup(request.getOwnerGroup());
metadata.setShowable(request.isDisplayedInMenu());
metadata.setUseExtraTitles(request.isSeo());
Optional<Map<String, String>> titles = Optional.ofNullable(request.getTitles());
ApsProperties apsTitles = new ApsProperties();
titles.ifPresent(values -> values.keySet().forEach((lang) -> {
apsTitles.put(lang, values.get(lang));
}));
metadata.setTitles(apsTitles);
if (metadata.getExtraGroups() != null) {
List<String> oldGroups = new ArrayList<>(metadata.getExtraGroups());
oldGroups.forEach(metadata::removeExtraGroup);
}
if (request.getJoinGroups() != null) {
request.getJoinGroups().forEach(metadata::addExtraGroup);
}
String charset = request.getCharset();
metadata.setCharset(StringUtils.isNotBlank(charset) ? charset : null);
String mimetype = request.getContentType();
metadata.setMimeType(StringUtils.isNotBlank(mimetype) ? mimetype : null);
}
use of org.entando.entando.web.page.model.PageRequest in project entando-core by entando.
the class PageService method createPage.
private IPage createPage(PageRequest pageRequest) {
Page page = new Page();
page.setCode(pageRequest.getCode());
page.setShowable(pageRequest.isDisplayedInMenu());
PageModel model = this.getPageModelManager().getPageModel(pageRequest.getPageModel());
page.setModel(model);
page.setWidgets(new Widget[model.getFrames().length]);
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());
Optional<List<String>> groups = Optional.ofNullable(pageRequest.getJoinGroups());
groups.ifPresent(values -> values.forEach((group) -> {
page.addExtraGroup(group);
}));
page.setParentCode(pageRequest.getParentCode());
if (pageRequest.getParentCode() != null) {
IPage parent = this.getPageManager().getDraftPage(pageRequest.getParentCode());
page.setParentCode(parent.getCode());
}
PageMetadata metadata = page.getMetadata();
this.valueMetadataFromRequest(metadata, pageRequest);
page.setMetadata(metadata);
return page;
}
use of org.entando.entando.web.page.model.PageRequest in project entando-core by entando.
the class PageController method patchPage.
@RestAccessControl(permission = Permission.MANAGE_PAGES)
@RequestMapping(value = "/pages/{pageCode}", method = RequestMethod.PATCH, produces = MediaType.APPLICATION_JSON_VALUE, consumes = "application/json-patch+json")
public ResponseEntity<RestResponse<PageDto, Map<String, String>>> patchPage(@ModelAttribute("user") UserDetails user, @PathVariable String pageCode, @RequestBody JsonNode patchRequest, BindingResult bindingResult) {
logger.debug("update page {} with jsonpatch-request {}", pageCode, patchRequest);
this.getPageValidator().validateJsonPatchRequest(patchRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
PageDto updatedPageDto = this.getPageService().getPatchedPage(pageCode, patchRequest);
PageRequest pageRequest = this.pageDtoToRequestConverter.convert(updatedPageDto);
return this.updatePage(user, pageCode, pageRequest, bindingResult);
}
use of org.entando.entando.web.page.model.PageRequest in project entando-core by entando.
the class PageValidator method validate.
@Override
public void validate(Object target, Errors errors) {
PageRequest request = (PageRequest) target;
String pageCode = request.getCode();
if (null != this.getPageManager().getDraftPage(pageCode)) {
errors.reject(ERRCODE_PAGE_ALREADY_EXISTS, new String[] { pageCode }, "page.exists");
}
}
use of org.entando.entando.web.page.model.PageRequest in project entando-core by entando.
the class PageServiceTest method shouldRemoveExtraGroup.
@Test
public void shouldRemoveExtraGroup() {
PageDto dto = new PageDto();
dto.addJoinGroup("free");
when(dtoBuilder.convert(any(IPage.class))).thenReturn(dto);
PageModel pageModel = PageMockHelper.mockServicePageModel();
when(pageModelManager.getPageModel(pageModel.getCode())).thenReturn(pageModel);
Page page = PageMockHelper.mockTestPage(PageMockHelper.PAGE_CODE);
page.setExtraGroups(new HashSet<>(Arrays.asList("free", "admin")));
when(pageManager.getDraftPage(page.getCode())).thenReturn(page);
PageRequest request = PageMockHelper.mockPageRequest(page);
request.setJoinGroups(Arrays.asList("free"));
when(pageManager.getDraftPage(request.getParentCode())).thenReturn(new Page());
PageDto pageDto = pageService.updatePage(page.getCode(), request);
assertThat(pageDto.getJoinGroups()).containsExactly("free");
}
Aggregations