use of org.entando.entando.aps.system.services.page.model.PageDto in project entando-core by entando.
the class PageController method getPages.
@RestAccessControl(permission = Permission.MANAGE_PAGES)
@RequestMapping(value = "/pages", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getPages(@ModelAttribute("user") UserDetails user, @RequestParam(value = "parentCode", required = false, defaultValue = "homepage") String parentCode) {
logger.debug("getting page tree for parent {}", parentCode);
List<PageDto> result = this.getAuthorizationService().filterList(user, this.getPageService().getPages(parentCode));
Map<String, String> metadata = new HashMap<>();
metadata.put("parentCode", parentCode);
return new ResponseEntity<>(new RestResponse(result, new ArrayList<>(), metadata), HttpStatus.OK);
}
use of org.entando.entando.aps.system.services.page.model.PageDto in project entando-core by entando.
the class PageController method updatePage.
@RestAccessControl(permission = Permission.MANAGE_PAGES)
@RequestMapping(value = "/pages/{pageCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> updatePage(@ModelAttribute("user") UserDetails user, @PathVariable String pageCode, @Valid @RequestBody PageRequest pageRequest, BindingResult bindingResult) {
logger.debug("updating page {} with request {}", pageCode, pageRequest);
if (!this.getAuthorizationService().isAuth(user, pageCode)) {
return new ResponseEntity<>(new RestResponse(new PageDto()), HttpStatus.UNAUTHORIZED);
}
// field validations
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
this.getPageValidator().validateBodyCode(pageCode, pageRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
PageDto page = this.getPageService().updatePage(pageCode, pageRequest);
Map<String, String> metadata = new HashMap<>();
return new ResponseEntity<>(new RestResponse(page, new ArrayList<>(), metadata), HttpStatus.OK);
}
use of org.entando.entando.aps.system.services.page.model.PageDto in project entando-core by entando.
the class PageService method getPages.
@Override
public List<PageDto> getPages(String parentCode) {
List<PageDto> res = new ArrayList<>();
IPage parent = this.getPageManager().getDraftPage(parentCode);
Optional.ofNullable(parent).ifPresent(root -> Optional.ofNullable(parent.getChildrenCodes()).ifPresent(children -> Arrays.asList(children).forEach(childCode -> {
IPage childO = this.getPageManager().getOnlinePage(childCode), childD = this.getPageManager().getDraftPage(childCode);
PageDto child = null;
if (childO != null) {
child = dtoBuilder.convert(childO);
if (childO.isChanged()) {
child.setStatus(STATUS_DRAFT);
}
} else {
child = dtoBuilder.convert(childD);
child.setStatus(STATUS_UNPUBLISHED);
}
child.setChildren(Arrays.asList(childD.getChildrenCodes()));
res.add(child);
})));
return res;
}
use of org.entando.entando.aps.system.services.page.model.PageDto in project entando-core by entando.
the class PageControllerTest method shouldValidatePutPathMismatch.
@Test
public void shouldValidatePutPathMismatch() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
String mockJsonResult = "{\n" + " \"code\": \"hello_page\",\n" + " \"status\": \"draft\",\n" + " \"displayedInMenu\": true,\n" + " \"pageModel\": \"service\",\n" + " \"charset\": \"utf8\",\n" + " \"contentType\": \"text/html\",\n" + " \"parentCode\": \"service\",\n" + " \"seo\": false,\n" + " \"titles\": {\n" + " \"en\": \"My Title\",\n" + " \"it\": \"Mio Titolo\"\n" + " },\n" + " \"ownerGroup\": \"free\",\n" + " \"joinGroups\": [\n" + " \"free\",\n" + " \"administrators\"\n" + " ],\n" + " \"position\": 7\n" + " }";
PageDto mockResult = (PageDto) this.createMetadata(mockJsonResult, PageDto.class);
when(pageService.updatePage(any(String.class), any(PageRequest.class))).thenReturn(mockResult);
when(authorizationService.isAuth(any(UserDetails.class), any(String.class))).thenReturn(true);
ResultActions result = mockMvc.perform(put("/pages/{pageCode}", "wrong_page").sessionAttr("user", user).contentType(MediaType.APPLICATION_JSON).content(mockJsonResult).header("Authorization", "Bearer " + accessToken));
String response = result.andReturn().getResponse().getContentAsString();
result.andExpect(status().isBadRequest());
result.andExpect(jsonPath("$.errors", hasSize(1)));
result.andExpect(jsonPath("$.errors[0].code", is(PageController.ERRCODE_URINAME_MISMATCH)));
}
use of org.entando.entando.aps.system.services.page.model.PageDto in project entando-core by entando.
the class PageControllerTest method shouldLoadAPageTree.
@Test
public void shouldLoadAPageTree() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
String mockJsonResult = "[\n" + " {\n" + " \"code\": \"notfound\",\n" + " \"status\": \"draft\",\n" + " \"displayedInMenu\": true,\n" + " \"pageModel\": \"service\",\n" + " \"charset\": null,\n" + " \"contentType\": null,\n" + " \"parentCode\": \"service\",\n" + " \"seo\": false,\n" + " \"titles\": {\"en\": \"Page not found\",\n" + " \"it\": \"Pagina non trovata\"\n" + " },\n" + " \"ownerGroup\": \"free\",\n" + " \"joinGroups\": [],\n" + " \"position\": 4\n" + " },\n" + " {\n" + " \"code\": \"errorpage\",\n" + " \"status\": \"draft\",\n" + " \"displayedInMenu\": true,\n" + " \"pageModel\": \"service\",\n" + " \"charset\": null,\n" + " \"contentType\": null,\n" + " \"parentCode\": \"service\",\n" + " \"seo\": false,\n" + " \"titles\": {\n" + " \"en\": \"Error page\",\n" + " \"it\": \"Pagina di errore\"\n" + " },\n" + " \"ownerGroup\": \"free\",\n" + " \"joinGroups\": [],\n" + " \"position\": 5\n" + " },\n" + " {\n" + " \"code\": \"login\",\n" + " \"status\": \"draft\",\n" + " \"displayedInMenu\": true,\n" + " \"pageModel\": \"service\",\n" + " \"charset\": null,\n" + " \"contentType\": null,\n" + " \"parentCode\": \"service\",\n" + " \"seo\": false,\n" + " \"titles\": {\n" + " \"en\": \"Login\",\n" + " \"it\": \"Pagina di login\"\n" + " },\n" + " \"ownerGroup\": \"free\",\n" + " \"joinGroups\": [],\n" + " \"position\": 6\n" + " },\n" + " {\n" + " \"code\": \"hello_page\",\n" + " \"status\": \"draft\",\n" + " \"displayedInMenu\": true,\n" + " \"pageModel\": \"service\",\n" + " \"charset\": \"utf8\",\n" + " \"contentType\": \"text/html\",\n" + " \"parentCode\": \"service\",\n" + " \"seo\": false,\n" + " \"titles\": {\n" + " \"en\": \"My Title\",\n" + " \"it\": \"Mio Titolo\"\n" + " },\n" + " \"ownerGroup\": \"free\",\n" + " \"joinGroups\": [\n" + " \"free\",\n" + " \"administrators\"\n" + " ],\n" + " \"position\": 7\n" + " }\n" + " ]";
List<PageDto> mockResult = (List<PageDto>) this.createMetadataList(mockJsonResult);
when(pageService.getPages(any(String.class))).thenReturn(mockResult);
when(authorizationService.isAuth(any(UserDetails.class), any(String.class))).thenReturn(true);
ResultActions result = mockMvc.perform(get("/pages").param("parentCode", "service").sessionAttr("user", user).header("Authorization", "Bearer " + accessToken));
String response = result.andReturn().getResponse().getContentAsString();
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.errors", hasSize(0)));
}
Aggregations