use of org.entando.entando.web.page.model.PageStatusRequest in project entando-core by entando.
the class PageControllerTest method shouldValidateStatusPutDraftRef.
@Test
public void shouldValidateStatusPutDraftRef() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
PageStatusRequest request = new PageStatusRequest();
request.setStatus("draft");
PageM pageToUnpublish = new PageM(true);
pageToUnpublish.setCode("page_to_unpublish");
pageToUnpublish.setParentCode("service");
pageToUnpublish.setChildrenCodes(new String[] { "child_page" });
PageM child = new PageM(true);
child.setCode("child_page");
child.setParentCode("page_to_unpublish");
PageM root = new PageM(true);
root.setCode("home");
root.setParentCode("home");
when(authorizationService.isAuth(any(UserDetails.class), any(String.class))).thenReturn(true);
when(this.controller.getPageValidator().getPageManager().getDraftPage(any(String.class))).thenReturn(pageToUnpublish, child);
when(this.controller.getPageValidator().getPageManager().getOnlineRoot()).thenReturn(root);
when(this.controller.getPageValidator().getPageUtilizer().getPageUtilizers(any(String.class))).thenReturn(new ArrayList());
ResultActions result = mockMvc.perform(put("/pages/{pageCode}/status", "page_to_publish").sessionAttr("user", user).content(convertObjectToJsonBytes(request)).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isBadRequest());
String response = result.andReturn().getResponse().getContentAsString();
System.out.println("RESPONSE: " + response);
result.andExpect(jsonPath("$.errors", hasSize(1)));
result.andExpect(jsonPath("$.errors[0].code", is(PageController.ERRCODE_REFERENCED_ONLINE_PAGE)));
}
use of org.entando.entando.web.page.model.PageStatusRequest in project entando-core by entando.
the class PageValidator method validateReferences.
public void validateReferences(String pageCode, PageStatusRequest pageStatusRequest, Errors errors) {
List<Content> contents = new ArrayList<>();
List<String> invalidRefs = new ArrayList<>();
IPage page = this.getPageManager().getDraftPage(pageCode);
try {
List<String> contentIds = this.getPageUtilizer().getPageUtilizers(pageCode);
Optional.ofNullable(contentIds).ifPresent(ids -> ids.forEach(id -> {
try {
contents.add(this.getContentManager().loadContent(id, true));
} catch (ApsSystemException e) {
logger.error("Error loadingreferences for page {}", pageCode, e);
throw new RestServerError("Error loadingreferences for page", e);
}
}));
} catch (ApsSystemException e) {
logger.error("Error loadingreferences for page {}", pageCode, e);
throw new RestServerError("Error loadingreferences for page", e);
}
if (pageStatusRequest.getStatus().equals(IPageService.STATUS_ONLINE)) {
contents.stream().forEach(content -> {
if (!content.isOnLine()) {
invalidRefs.add(content.getId());
}
});
IPage parent = null;
if (invalidRefs.isEmpty()) {
parent = this.getPageManager().getDraftPage(page.getParentCode());
}
if (!invalidRefs.isEmpty() || !parent.isOnline()) {
errors.reject(PageController.ERRCODE_REFERENCED_DRAFT_PAGE, new String[] { pageCode }, "page.status.invalid.draft.ref");
}
} else {
boolean isRoot = this.getPageManager().getOnlineRoot().getCode().equals(pageCode);
if (contents.isEmpty() && !isRoot) {
Optional.ofNullable(page.getChildrenCodes()).ifPresent(children -> Arrays.asList(children).forEach(child -> {
IPage childPage = this.getPageManager().getDraftPage(child);
if (childPage.isOnline()) {
invalidRefs.add(child);
}
}));
}
if (isRoot || !contents.isEmpty() || !invalidRefs.isEmpty()) {
errors.reject(PageController.ERRCODE_REFERENCED_ONLINE_PAGE, new String[] { pageCode }, "page.status.invalid.online.ref");
}
}
}
use of org.entando.entando.web.page.model.PageStatusRequest in project entando-core by entando.
the class PageServiceIntegrationTest method testUpdatePageStatus.
@Test
public void testUpdatePageStatus() {
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");
assertEquals("draft", addedPage.getStatus());
PageStatusRequest pageStatusRequest = new PageStatusRequest();
pageStatusRequest.setStatus("published");
PageDto modPage = pageService.updatePageStatus("pagina_13", pageStatusRequest.getStatus());
assertNotNull(modPage);
assertEquals("published", modPage.getStatus());
addedPage = pageService.getPage("pagina_13", "published");
assertNotNull(addedPage);
assertEquals("published", addedPage.getStatus());
pageService.removePage("pagina_13");
}
use of org.entando.entando.web.page.model.PageStatusRequest in project entando-core by entando.
the class PageControllerTest method shouldValidateStatusPutOnlineRef.
@Test
public void shouldValidateStatusPutOnlineRef() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
PageStatusRequest request = new PageStatusRequest();
request.setStatus("published");
PageM pageToPublish = new PageM(false);
pageToPublish.setCode("page_to_publish");
pageToPublish.setParentCode("unpublished");
PageM unpublished = new PageM(false);
unpublished.setCode("unpublished");
unpublished.setParentCode("service");
when(authorizationService.isAuth(any(UserDetails.class), any(String.class))).thenReturn(true);
when(this.controller.getPageValidator().getPageManager().getDraftPage(any(String.class))).thenReturn(pageToPublish, unpublished);
when(this.controller.getPageValidator().getPageUtilizer().getPageUtilizers(any(String.class))).thenReturn(new ArrayList());
ResultActions result = mockMvc.perform(put("/pages/{pageCode}/status", "page_to_publish").sessionAttr("user", user).content(convertObjectToJsonBytes(request)).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isBadRequest());
String response = result.andReturn().getResponse().getContentAsString();
System.out.println("RESPONSE: " + response);
result.andExpect(jsonPath("$.errors", hasSize(1)));
result.andExpect(jsonPath("$.errors[0].code", is(PageController.ERRCODE_REFERENCED_DRAFT_PAGE)));
}
Aggregations