Search in sources :

Example 11 with PageRequest

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);
}
Also used : ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) Arrays(java.util.Arrays) BeanComparator(org.apache.commons.beanutils.BeanComparator) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) Group(com.agiletec.aps.system.services.group.Group) IPage(com.agiletec.aps.system.services.page.IPage) PageConfigurationDto(org.entando.entando.aps.system.services.page.model.PageConfigurationDto) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) PageSearchDto(org.entando.entando.aps.system.services.page.model.PageSearchDto) IGroupManager(com.agiletec.aps.system.services.group.IGroupManager) WidgetValidatorFactory(org.entando.entando.aps.system.services.widgettype.validators.WidgetValidatorFactory) Widget(com.agiletec.aps.system.services.page.Widget) Map(java.util.Map) PagePositionRequest(org.entando.entando.web.page.model.PagePositionRequest) PageDtoBuilder(org.entando.entando.aps.system.services.page.model.PageDtoBuilder) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) JsonNode(com.fasterxml.jackson.databind.JsonNode) PageModelUtilizer(com.agiletec.aps.system.services.pagemodel.PageModelUtilizer) PageSearchRequest(org.entando.entando.web.page.model.PageSearchRequest) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) DataBinder(org.springframework.validation.DataBinder) ComponentUsageEntity(org.entando.entando.web.component.ComponentUsageEntity) Collectors(java.util.stream.Collectors) PagesStatus(com.agiletec.aps.system.services.page.PagesStatus) PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) List(java.util.List) RestListRequest(org.entando.entando.web.common.model.RestListRequest) GroupUtilizer(com.agiletec.aps.system.services.group.GroupUtilizer) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) 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) PageUtils(org.entando.entando.aps.util.PageUtils) WidgetConfigurationDto(org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto) ApplicationContextAware(org.springframework.context.ApplicationContextAware) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) BeanUtils(org.springframework.beans.BeanUtils) JsonPatchService(org.entando.entando.aps.system.services.jsonpatch.JsonPatchService) Page(com.agiletec.aps.system.services.page.Page) HashMap(java.util.HashMap) BindingResult(org.springframework.validation.BindingResult) ApsProperties(com.agiletec.aps.util.ApsProperties) IWidgetTypeManager(org.entando.entando.aps.system.services.widgettype.IWidgetTypeManager) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) PageUtilizer(com.agiletec.aps.system.services.page.PageUtilizer) ArrayList(java.util.ArrayList) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IPageManager(com.agiletec.aps.system.services.page.IPageManager) IManager(com.agiletec.aps.system.common.IManager) PagedMetadataMapper(org.entando.entando.web.common.assembler.PagedMetadataMapper) WidgetConfigurationRequest(org.entando.entando.web.page.model.WidgetConfigurationRequest) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) GroupServiceUtilizer(org.entando.entando.aps.system.services.group.GroupServiceUtilizer) PageSearchMapper(org.entando.entando.web.common.assembler.PageSearchMapper) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) PageRequest(org.entando.entando.web.page.model.PageRequest) PagesStatusDto(org.entando.entando.aps.system.services.page.model.PagesStatusDto) BeansException(org.springframework.beans.BeansException) PageValidator(org.entando.entando.web.page.validator.PageValidator) ApplicationContext(org.springframework.context.ApplicationContext) PageModelServiceUtilizer(org.entando.entando.aps.system.services.pagemodel.PageModelServiceUtilizer) WidgetProcessorFactory(org.entando.entando.aps.system.services.widgettype.validators.WidgetProcessorFactory) Collections(java.util.Collections) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 12 with PageRequest

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;
}
Also used : ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) Arrays(java.util.Arrays) BeanComparator(org.apache.commons.beanutils.BeanComparator) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) Group(com.agiletec.aps.system.services.group.Group) IPage(com.agiletec.aps.system.services.page.IPage) PageConfigurationDto(org.entando.entando.aps.system.services.page.model.PageConfigurationDto) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) PageSearchDto(org.entando.entando.aps.system.services.page.model.PageSearchDto) IGroupManager(com.agiletec.aps.system.services.group.IGroupManager) WidgetValidatorFactory(org.entando.entando.aps.system.services.widgettype.validators.WidgetValidatorFactory) Widget(com.agiletec.aps.system.services.page.Widget) Map(java.util.Map) PagePositionRequest(org.entando.entando.web.page.model.PagePositionRequest) PageDtoBuilder(org.entando.entando.aps.system.services.page.model.PageDtoBuilder) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) JsonNode(com.fasterxml.jackson.databind.JsonNode) PageModelUtilizer(com.agiletec.aps.system.services.pagemodel.PageModelUtilizer) PageSearchRequest(org.entando.entando.web.page.model.PageSearchRequest) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) DataBinder(org.springframework.validation.DataBinder) ComponentUsageEntity(org.entando.entando.web.component.ComponentUsageEntity) Collectors(java.util.stream.Collectors) PagesStatus(com.agiletec.aps.system.services.page.PagesStatus) PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) List(java.util.List) RestListRequest(org.entando.entando.web.common.model.RestListRequest) GroupUtilizer(com.agiletec.aps.system.services.group.GroupUtilizer) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) 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) PageUtils(org.entando.entando.aps.util.PageUtils) WidgetConfigurationDto(org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto) ApplicationContextAware(org.springframework.context.ApplicationContextAware) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) BeanUtils(org.springframework.beans.BeanUtils) JsonPatchService(org.entando.entando.aps.system.services.jsonpatch.JsonPatchService) Page(com.agiletec.aps.system.services.page.Page) HashMap(java.util.HashMap) BindingResult(org.springframework.validation.BindingResult) ApsProperties(com.agiletec.aps.util.ApsProperties) IWidgetTypeManager(org.entando.entando.aps.system.services.widgettype.IWidgetTypeManager) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) PageUtilizer(com.agiletec.aps.system.services.page.PageUtilizer) ArrayList(java.util.ArrayList) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IPageManager(com.agiletec.aps.system.services.page.IPageManager) IManager(com.agiletec.aps.system.common.IManager) PagedMetadataMapper(org.entando.entando.web.common.assembler.PagedMetadataMapper) WidgetConfigurationRequest(org.entando.entando.web.page.model.WidgetConfigurationRequest) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) GroupServiceUtilizer(org.entando.entando.aps.system.services.group.GroupServiceUtilizer) PageSearchMapper(org.entando.entando.web.common.assembler.PageSearchMapper) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) PageRequest(org.entando.entando.web.page.model.PageRequest) PagesStatusDto(org.entando.entando.aps.system.services.page.model.PagesStatusDto) BeansException(org.springframework.beans.BeansException) PageValidator(org.entando.entando.web.page.validator.PageValidator) ApplicationContext(org.springframework.context.ApplicationContext) PageModelServiceUtilizer(org.entando.entando.aps.system.services.pagemodel.PageModelServiceUtilizer) WidgetProcessorFactory(org.entando.entando.aps.system.services.widgettype.validators.WidgetProcessorFactory) Collections(java.util.Collections) PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) IPage(com.agiletec.aps.system.services.page.IPage) IPage(com.agiletec.aps.system.services.page.IPage) Page(com.agiletec.aps.system.services.page.Page) List(java.util.List) ArrayList(java.util.ArrayList) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) Map(java.util.Map) HashMap(java.util.HashMap) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 13 with PageRequest

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

Example 14 with PageRequest

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");
    }
}
Also used : PageRequest(org.entando.entando.web.page.model.PageRequest)

Example 15 with PageRequest

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");
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) PageRequest(org.entando.entando.web.page.model.PageRequest) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) Page(com.agiletec.aps.system.services.page.Page) IPage(com.agiletec.aps.system.services.page.IPage) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) Test(org.junit.Test)

Aggregations

PageRequest (org.entando.entando.web.page.model.PageRequest)27 Test (org.junit.Test)16 HashMap (java.util.HashMap)12 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)11 UserDetails (com.agiletec.aps.system.services.user.UserDetails)9 IPage (com.agiletec.aps.system.services.page.IPage)8 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)8 ResultActions (org.springframework.test.web.servlet.ResultActions)8 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)7 Page (com.agiletec.aps.system.services.page.Page)6 PagePositionRequest (org.entando.entando.web.page.model.PagePositionRequest)6 WidgetConfigurationRequest (org.entando.entando.web.page.model.WidgetConfigurationRequest)5 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)4 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)3 IManager (com.agiletec.aps.system.common.IManager)3 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)3 Group (com.agiletec.aps.system.services.group.Group)3 GroupUtilizer (com.agiletec.aps.system.services.group.GroupUtilizer)3 IGroupManager (com.agiletec.aps.system.services.group.IGroupManager)3