Search in sources :

Example 11 with PageMetadata

use of com.agiletec.aps.system.services.page.PageMetadata in project entando-core by entando.

the class CmsPageUtil method isContentPublishableOnPage.

/**
 * Check if is possible to publish the content in the given page, checking
 * the given page metadata.
 *
 * @param publishingContent
 * The publishing content.
 * @param page
 * The page where you want to publish the content.
 * @param metadata
 * The metadata of the page where you want to publish the content.
 * @return True/false if is possible to publish the content in the given
 * page.
 */
public static boolean isContentPublishableOnPage(Content publishingContent, IPage page) {
    if (publishingContent.getMainGroup().equals(Group.FREE_GROUP_NAME) || publishingContent.getGroups().contains(Group.FREE_GROUP_NAME)) {
        return true;
    }
    // tutti i gruppi posseduti dalla pagina devono essere contemplati nel
    // contenuto.
    List<String> pageGroups = new ArrayList<String>();
    pageGroups.add(page.getGroup());
    PageMetadata metadata = page.getMetadata();
    if (metadata != null && null != metadata.getExtraGroups()) {
        pageGroups.addAll(metadata.getExtraGroups());
    }
    List<String> contentGroups = getContentGroups(publishingContent);
    for (int i = 0; i < pageGroups.size(); i++) {
        String pageGroup = pageGroups.get(i);
        if (!pageGroup.equals(Group.ADMINS_GROUP_NAME) && !contentGroups.contains(pageGroup))
            return false;
    }
    return true;
}
Also used : PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) ArrayList(java.util.ArrayList)

Example 12 with PageMetadata

use of com.agiletec.aps.system.services.page.PageMetadata in project entando-core by entando.

the class CmsPageUtil method isOnlineFreeViewerPage.

/**
 * Check whether the page can publish free content, related to the online
 * configuration of the page.
 *
 * @param page
 * The page to check.
 * @param viewerWidgetCode
 * The code of the viewer widget (optional)
 * @return True if the page can publish free content, false else.
 */
public static boolean isOnlineFreeViewerPage(IPage page, String viewerWidgetCode) {
    if (!page.isOnlineInstance()) {
        _logger.warn("this check expects an online instance of the page");
        return false;
    }
    boolean found = false;
    PageMetadata metadata = page.getMetadata();
    Widget[] widgets = page.getWidgets();
    if (metadata != null) {
        found = isFreeViewerPage(metadata.getModel(), widgets, viewerWidgetCode);
    }
    return found;
}
Also used : PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) Widget(com.agiletec.aps.system.services.page.Widget)

Example 13 with PageMetadata

use of com.agiletec.aps.system.services.page.PageMetadata in project entando-core by entando.

the class PageServiceWidgetIntegrationTest method testRemovePageWidget.

public void testRemovePageWidget() throws JsonProcessingException, ApsSystemException {
    String pageCode = "temp001";
    IPage parentPage = pageManager.getDraftRoot();
    PageModel pageModel = parentPage.getMetadata().getModel();
    PageMetadata metadata = PageTestUtil.createPageMetadata(pageModel.getCode(), true, pageCode, null, null, false, null, null);
    Page pageToAdd = PageTestUtil.createPage(pageCode, parentPage, "free", metadata, null);
    try {
        pageManager.addPage(pageToAdd);
        WidgetConfigurationDto widgetConfigurationDto = this.pageService.getWidgetConfiguration(pageToAdd.getCode(), 0, IPageService.STATUS_DRAFT);
        assertThat(widgetConfigurationDto, is(nullValue()));
        WidgetConfigurationRequest widgetConfigurationRequest = new WidgetConfigurationRequest();
        widgetConfigurationRequest.setCode("login_form");
        widgetConfigurationRequest.setConfig(null);
        this.pageService.updateWidgetConfiguration(pageCode, 0, widgetConfigurationRequest);
        assertThat(this.pageService.getWidgetConfiguration(pageToAdd.getCode(), 0, IPageService.STATUS_DRAFT).getCode(), is("login_form"));
        this.pageService.deleteWidgetConfiguration(pageToAdd.getCode(), 0);
        assertThat(widgetConfigurationDto, is(nullValue()));
    } finally {
        pageManager.deletePage(pageCode);
    }
}
Also used : WidgetConfigurationRequest(org.entando.entando.web.page.model.WidgetConfigurationRequest) PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) IPage(com.agiletec.aps.system.services.page.IPage) WidgetConfigurationDto(org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto) Page(com.agiletec.aps.system.services.page.Page) IPage(com.agiletec.aps.system.services.page.IPage) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel)

Example 14 with PageMetadata

use of com.agiletec.aps.system.services.page.PageMetadata in project entando-core by entando.

the class PageService method valueMetadataFromRequest.

private void valueMetadataFromRequest(PageMetadata metadata, PageRequest request) {
    if (metadata.getModel() == null || !metadata.getModel().getCode().equals(request.getPageModel())) {
        // Ho cambiato modello e allora cancello tutte le showlets
        // Precedenti
        PageModel model = this.getPageModelManager().getPageModel(request.getPageModel());
        metadata.setModel(model);
    }
    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);
    Optional<List<String>> groups = Optional.ofNullable(request.getJoinGroups());
    groups.ifPresent(values -> values.forEach((group) -> {
        metadata.addExtraGroup(group);
    }));
    String charset = request.getCharset();
    metadata.setCharset(StringUtils.isNotBlank(charset) ? charset : null);
    String mimetype = request.getContentType();
    metadata.setMimeType(StringUtils.isNotBlank(mimetype) ? mimetype : null);
}
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) ArrayList(java.util.ArrayList) List(java.util.List) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) Map(java.util.Map) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 15 with PageMetadata

use of com.agiletec.aps.system.services.page.PageMetadata 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.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.setParent(parent);
    }
    PageMetadata metadata = new PageMetadata();
    this.valueMetadataFromRequest(metadata, pageRequest);
    page.setMetadata(metadata);
    return page;
}
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) PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) IPage(com.agiletec.aps.system.services.page.IPage) Page(com.agiletec.aps.system.services.page.Page) IPage(com.agiletec.aps.system.services.page.IPage) ArrayList(java.util.ArrayList) List(java.util.List) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) Map(java.util.Map) ApsProperties(com.agiletec.aps.util.ApsProperties)

Aggregations

PageMetadata (com.agiletec.aps.system.services.page.PageMetadata)23 IPage (com.agiletec.aps.system.services.page.IPage)18 Page (com.agiletec.aps.system.services.page.Page)13 Widget (com.agiletec.aps.system.services.page.Widget)9 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)9 ArrayList (java.util.ArrayList)7 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)6 ApsProperties (com.agiletec.aps.util.ApsProperties)6 WidgetConfigurationDto (org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto)5 WidgetConfigurationRequest (org.entando.entando.web.page.model.WidgetConfigurationRequest)5 List (java.util.List)4 IManager (com.agiletec.aps.system.common.IManager)3 GroupUtilizer (com.agiletec.aps.system.services.group.GroupUtilizer)3 IGroupManager (com.agiletec.aps.system.services.group.IGroupManager)3 IPageManager (com.agiletec.aps.system.services.page.IPageManager)3 IPageModelManager (com.agiletec.aps.system.services.pagemodel.IPageModelManager)3 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)3 Arrays (java.util.Arrays)3 Map (java.util.Map)3 Optional (java.util.Optional)3