Search in sources :

Example 16 with PageMetadata

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

the class ContentViewerWidgetAction method validate.

@Override
public void validate() {
    super.validate();
    if (this.getFieldErrors().isEmpty()) {
        try {
            Content publishingContent = this.getContentManager().loadContent(this.getContentId(), true);
            if (null == publishingContent) {
                this.addFieldError("contentId", this.getText("error.widget.viewer.nullContent"));
            } else {
                IPage currentPage = this.getCurrentPage();
                if (!CmsPageUtil.isContentPublishableOnPageDraft(publishingContent, currentPage)) {
                    PageMetadata metadata = currentPage.getMetadata();
                    List<String> pageGroups = new ArrayList<String>();
                    pageGroups.add(currentPage.getGroup());
                    if (null != metadata.getExtraGroups()) {
                        pageGroups.addAll(metadata.getExtraGroups());
                    }
                    this.addFieldError("contentId", this.getText("error.widget.viewer.invalidContent", new String[] { pageGroups.toString() }));
                }
            }
        } catch (Throwable t) {
            _logger.error("Error validating content {}", this.getContentId(), t);
            throw new RuntimeException("Errore in validazione contenuto con id " + this.getContentId(), t);
        }
    }
    if (this.getFieldErrors().size() > 0) {
        try {
            this.createValuedShowlet();
        } catch (Throwable t) {
            _logger.error("error creating new widget", t);
            throw new RuntimeException("Errore in creazione widget valorizzato", t);
        }
    }
}
Also used : PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) IPage(com.agiletec.aps.system.services.page.IPage) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) ArrayList(java.util.ArrayList)

Example 17 with PageMetadata

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

the class TestPageAction method addPage.

private void addPage(String pageCode) throws ApsSystemException {
    IPage parentPage = _pageManager.getOnlinePage("service");
    PageModel pageModel = parentPage.getMetadata().getModel();
    PageMetadata metadata = PageTestUtil.createPageMetadata(pageModel.getCode(), true, "pagina temporanea", null, null, false, null, null);
    ApsProperties config = PageTestUtil.createProperties("tempKey", "tempValue", "contentId", "ART1");
    Widget widgetToAdd = PageTestUtil.createWidget("content_viewer", config, this._widgetTypeManager);
    Widget[] widgets = { widgetToAdd };
    Page pageToAdd = PageTestUtil.createPage(pageCode, parentPage, "free", metadata, widgets);
    this._pageManager.addPage(pageToAdd);
}
Also used : PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) IPage(com.agiletec.aps.system.services.page.IPage) Widget(com.agiletec.aps.system.services.page.Widget) Page(com.agiletec.aps.system.services.page.Page) IPage(com.agiletec.aps.system.services.page.IPage) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 18 with PageMetadata

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

the class TestPageAction method testSavePage.

public void testSavePage() throws Throwable {
    String pageCode = "customer_subpage_2";
    IPage page = this._pageManager.getDraftPage(pageCode);
    assertNotNull(page);
    try {
        PageMetadata metadata = page.getMetadata();
        this.setUserOnSession("admin");
        this.initAction("/do/Page", "save");
        this.addParameter("strutsAction", String.valueOf(ApsAdminSystemConstants.EDIT));
        this.addParameter("langit", "");
        this.addParameter("langen", metadata.getTitle("en"));
        this.addParameter("model", metadata.getModel().getCode());
        this.addParameter("group", page.getGroup());
        this.addParameter("pageCode", pageCode);
        Collection<String> extraGroups = metadata.getExtraGroups();
        if (null != extraGroups) {
            Iterator<String> extraGroupIter = extraGroups.iterator();
            while (extraGroupIter.hasNext()) {
                String extraGroup = (String) extraGroupIter.next();
                this.addParameter("extraGroups", extraGroup);
            }
        }
        this.addParameter("extraGroups", "management");
        String result = this.executeAction();
        assertEquals(Action.INPUT, result);
        ActionSupport action = this.getAction();
        assertEquals(2, action.getFieldErrors().size());
        assertEquals(1, action.getFieldErrors().get("langit").size());
        assertEquals(1, action.getFieldErrors().get("extraGroups").size());
    } catch (Throwable t) {
        this._pageManager.updatePage(page);
        throw t;
    }
}
Also used : PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) IPage(com.agiletec.aps.system.services.page.IPage) ActionSupport(com.opensymphony.xwork2.ActionSupport)

Example 19 with PageMetadata

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

the class ContentActionHelper method scanReferences.

/**
 * Controlla le referenziazioni di un contenuto. Verifica la referenziazione
 * di un contenuto con altri contenuti o pagine nel caso di operazioni di
 * ripubblicazione di contenuti non del gruppo ad accesso libero.
 * L'operazione si rende necessaria per ovviare a casi nel cui il contenuto,
 * di un particolare gruppo, sia stato pubblicato precedentemente in una
 * pagina o referenziato in un'altro contenuto grazie alla associazione di
 * questo con altri gruppi abilitati alla visualizzazione. Il controllo
 * evidenzia quali devono essere i gruppi al quale il contenuto deve essere
 * necessariamente associato (ed il perchè) per salvaguardare le precedenti
 * relazioni.
 *
 * @param content
 * Il contenuto da analizzare.
 * @param action
 * L'action da valorizzare con i messaggi di errore.
 * @throws ApsSystemException
 * In caso di errore.
 */
@Override
public void scanReferences(Content content, ActionSupport action) throws ApsSystemException {
    if (!Group.FREE_GROUP_NAME.equals(content.getMainGroup()) && !content.getGroups().contains(Group.FREE_GROUP_NAME)) {
        HttpServletRequest request = ServletActionContext.getRequest();
        try {
            String[] defNames = ApsWebApplicationUtils.getWebApplicationContext(request).getBeanNamesForType(ContentUtilizer.class);
            for (int i = 0; i < defNames.length; i++) {
                Object service = null;
                try {
                    service = ApsWebApplicationUtils.getWebApplicationContext(request).getBean(defNames[i]);
                } catch (Throwable t) {
                    _logger.error("error loading ReferencingObject ", t);
                    service = null;
                }
                if (service != null) {
                    ContentUtilizer contentUtilizer = (ContentUtilizer) service;
                    List<Object> utilizers = contentUtilizer.getContentUtilizers(content.getId());
                    if (null == utilizers) {
                        continue;
                    }
                    Lang lang = this.getLangManager().getDefaultLang();
                    for (int j = 0; j < utilizers.size(); j++) {
                        Object object = utilizers.get(j);
                        if (service instanceof IContentManager && object instanceof String) {
                            // Content
                            // ID
                            Content refContent = this.getContentManager().loadContent(object.toString(), true);
                            if (!content.getMainGroup().equals(refContent.getMainGroup()) && !content.getGroups().contains(refContent.getMainGroup())) {
                                String[] args = { this.getGroupManager().getGroup(refContent.getMainGroup()).getDescription(), object.toString() + " '" + refContent.getDescription() + "'" };
                                action.addFieldError("mainGroup", action.getText("error.content.referencedContent.wrongGroups", args));
                            }
                        } else if (object instanceof IPage) {
                            // Content ID
                            IPage page = (IPage) object;
                            // page online, must be done the same check
                            if (!CmsPageUtil.isContentPublishableOnPageOnline(content, page)) {
                                PageMetadata metadata = page.getMetadata();
                                List<String> pageGroups = new ArrayList<String>();
                                pageGroups.add(page.getGroup());
                                if (metadata != null && null != metadata.getExtraGroups()) {
                                    pageGroups.addAll(metadata.getExtraGroups());
                                }
                                String[] args = { pageGroups.toString(), page.getTitle(lang.getCode()) };
                                action.addFieldError("mainGroup", action.getText("error.content.referencedPage.wrongGroups", args));
                            }
                        }
                    }
                }
            }
        } catch (Throwable t) {
            throw new ApsSystemException("Error in hasReferencingObject method", t);
        }
    }
}
Also used : PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) Lang(com.agiletec.aps.system.services.lang.Lang) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ContentUtilizer(com.agiletec.plugins.jacms.aps.system.services.content.ContentUtilizer) HttpServletRequest(javax.servlet.http.HttpServletRequest) IPage(com.agiletec.aps.system.services.page.IPage) IContentManager(com.agiletec.plugins.jacms.aps.system.services.content.IContentManager) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) ArrayList(java.util.ArrayList) List(java.util.List)

Example 20 with PageMetadata

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

the class PageAction method createTempPage.

private IPage createTempPage() {
    IPage pageOnEdit = (Page) this.getPage(this.getPageCode());
    Page page = new Page();
    page.setGroup(this.getGroup());
    PageMetadata metadata = new PageMetadata();
    metadata.setExtraGroups(this.getExtraGroups());
    page.setMetadata(metadata);
    page.setWidgets(pageOnEdit.getWidgets());
    page.setCode(this.getPageCode());
    return page;
}
Also used : 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)

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