Search in sources :

Example 1 with PageDto

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) HashMap(java.util.HashMap) RestResponse(org.entando.entando.web.common.model.RestResponse) ArrayList(java.util.ArrayList) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with PageDto

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) HashMap(java.util.HashMap) RestResponse(org.entando.entando.web.common.model.RestResponse) ArrayList(java.util.ArrayList) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with PageDto

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;
}
Also used : Arrays(java.util.Arrays) Page(com.agiletec.aps.system.services.page.Page) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ApsProperties(com.agiletec.aps.util.ApsProperties) IWidgetTypeManager(org.entando.entando.aps.system.services.widgettype.IWidgetTypeManager) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) IPage(com.agiletec.aps.system.services.page.IPage) PageConfigurationDto(org.entando.entando.aps.system.services.page.model.PageConfigurationDto) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IGroupManager(com.agiletec.aps.system.services.group.IGroupManager) IPageManager(com.agiletec.aps.system.services.page.IPageManager) WidgetValidatorFactory(org.entando.entando.aps.system.services.widgettype.validators.WidgetValidatorFactory) Widget(com.agiletec.aps.system.services.page.Widget) Map(java.util.Map) IManager(com.agiletec.aps.system.common.IManager) PagePositionRequest(org.entando.entando.web.page.model.PagePositionRequest) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) WidgetConfigurationRequest(org.entando.entando.web.page.model.WidgetConfigurationRequest) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) GroupServiceUtilizer(org.entando.entando.aps.system.services.group.GroupServiceUtilizer) Logger(org.slf4j.Logger) PageRequest(org.entando.entando.web.page.model.PageRequest) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) List(java.util.List) GroupUtilizer(com.agiletec.aps.system.services.group.GroupUtilizer) WidgetProcessorFactory(org.entando.entando.aps.system.services.widgettype.validators.WidgetProcessorFactory) 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) WidgetConfigurationDto(org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) IPage(com.agiletec.aps.system.services.page.IPage) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) ArrayList(java.util.ArrayList)

Example 4 with PageDto

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)));
}
Also used : PageRequest(org.entando.entando.web.page.model.PageRequest) UserDetails(com.agiletec.aps.system.services.user.UserDetails) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 5 with PageDto

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)));
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) ArrayList(java.util.ArrayList) List(java.util.List) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Aggregations

PageDto (org.entando.entando.aps.system.services.page.model.PageDto)18 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)9 HashMap (java.util.HashMap)7 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)7 RestResponse (org.entando.entando.web.common.model.RestResponse)7 PageRequest (org.entando.entando.web.page.model.PageRequest)7 ResponseEntity (org.springframework.http.ResponseEntity)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)6 UserDetails (com.agiletec.aps.system.services.user.UserDetails)3 List (java.util.List)3 PagePositionRequest (org.entando.entando.web.page.model.PagePositionRequest)3 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)2 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)2 ResultActions (org.springframework.test.web.servlet.ResultActions)2 IManager (com.agiletec.aps.system.common.IManager)1 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 GroupUtilizer (com.agiletec.aps.system.services.group.GroupUtilizer)1 IGroupManager (com.agiletec.aps.system.services.group.IGroupManager)1