Search in sources :

Example 51 with Widget

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

the class PreviewWidgetExecutorAspect method checkContentPreview.

@After("execution(* org.entando.entando.aps.system.services.controller.executor.WidgetExecutorService.service(..)) && args(reqCtx)")
public void checkContentPreview(RequestContext reqCtx) {
    HttpServletRequest request = reqCtx.getRequest();
    String contentOnSessionMarker = (String) request.getAttribute("contentOnSessionMarker");
    if (null == contentOnSessionMarker || contentOnSessionMarker.trim().length() == 0) {
        contentOnSessionMarker = request.getParameter("contentOnSessionMarker");
    }
    if (null == contentOnSessionMarker) {
        return;
    }
    Content contentOnSession = (Content) request.getSession().getAttribute(ContentActionConstants.SESSION_PARAM_NAME_CURRENT_CONTENT_PREXIX + contentOnSessionMarker);
    if (null == contentOnSession) {
        return;
    }
    try {
        IPage currentPage = (IPage) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE);
        Widget[] widgets = currentPage.getWidgets();
        for (int frame = 0; frame < widgets.length; frame++) {
            Widget widget = widgets[frame];
            if (widget != null && "viewerConfig".equals(widget.getType().getAction())) {
                if ((currentPage.getCode().equals(contentOnSession.getViewPage()) && (widget.getConfig() == null || widget.getConfig().size() == 0)) || (widget.getConfig() != null && widget.getConfig().get("contentId") != null && widget.getConfig().get("contentId").equals(contentOnSession.getId()))) {
                    reqCtx.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_WIDGET, widget);
                    reqCtx.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_FRAME, new Integer(frame));
                    String output = super.extractJspOutput(reqCtx, CONTENT_VIEWER_JSP);
                    String[] widgetOutput = (String[]) reqCtx.getExtraParam("ShowletOutput");
                    widgetOutput[frame] = output;
                    return;
                }
            }
        }
    } catch (Throwable t) {
        String msg = "Error detected while include content preview";
        _logger.error(msg, t);
        throw new RuntimeException(msg, t);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IPage(com.agiletec.aps.system.services.page.IPage) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) Widget(com.agiletec.aps.system.services.page.Widget) After(org.aspectj.lang.annotation.After)

Example 52 with Widget

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

the class TestWidgetExecutorService method testExecutor.

public void testExecutor() throws Exception {
    super.setUserOnSession("admin");
    IPageManager pageManager = (IPageManager) super.getApplicationContext().getBean(SystemConstants.PAGE_MANAGER);
    IPage currentPage = pageManager.getOnlinePage("homepage");
    super.getRequestContext().addExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE, currentPage);
    ExecutorServiceInterface wes = (ExecutorServiceInterface) super.getApplicationContext().getBean("WidgetExecutorService");
    wes.service(super.getRequestContext());
    String[] widgetOutput = (String[]) super.getRequestContext().getExtraParam("ShowletOutput");
    assertNotNull(widgetOutput);
    assertEquals(currentPage.getModel().getFrames().length, widgetOutput.length);
    for (int i = 0; i < widgetOutput.length; i++) {
        String output = widgetOutput[i];
        assertNotNull(output);
        Widget currentWidget = currentPage.getWidgets()[i];
        if (null == currentWidget) {
            assertTrue(StringUtils.isBlank(output));
        } else {
            GuiFragment fragment = this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(currentWidget.getType().getCode());
            if (null == fragment) {
                assertTrue(StringUtils.isBlank(output));
            } else {
                assertTrue(StringUtils.isNotBlank(output));
            }
        }
    }
}
Also used : IPageManager(com.agiletec.aps.system.services.page.IPageManager) IPage(com.agiletec.aps.system.services.page.IPage) GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) Widget(com.agiletec.aps.system.services.page.Widget)

Example 53 with Widget

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

the class DataObjectListHelper method extractContentsId.

protected List<String> extractContentsId(IDataObjectListTagBean bean, RequestContext reqCtx) throws ApsSystemException {
    List<String> contentsId = null;
    try {
        List<UserFilterOptionBean> userFilters = bean.getUserFilterOptions();
        Widget widget = (Widget) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_WIDGET);
        ApsProperties config = (null != widget) ? widget.getConfig() : null;
        if (null == bean.getDataType() && null != config) {
            bean.setContentType(config.getProperty(WIDGET_PARAM_CONTENT_TYPE));
        }
        if (null == bean.getDataType()) {
            throw new ApsSystemException("Tipo contenuto non definito");
        }
        if (null == bean.getCategory() && null != config && null != config.getProperty(SHOWLET_PARAM_CATEGORY)) {
            bean.setCategory(config.getProperty(SHOWLET_PARAM_CATEGORY));
        }
        this.addWidgetFilters(bean, config, WIDGET_PARAM_FILTERS, reqCtx);
        if (null != userFilters && userFilters.size() > 0) {
            for (int i = 0; i < userFilters.size(); i++) {
                UserFilterOptionBean userFilter = userFilters.get(i);
                EntitySearchFilter filter = userFilter.getEntityFilter();
                if (null != filter) {
                    bean.addFilter(filter);
                }
            }
        }
        String[] categories = this.getCategories(bean.getCategories(), config, userFilters);
        Collection<String> userGroupCodes = this.getAllowedGroups(reqCtx);
        boolean orCategoryFilterClause = this.extractOrCategoryFilterClause(config);
        contentsId = this.getDataObjectManager().loadDataObjectsId(bean.getDataType(), categories, orCategoryFilterClause, bean.getFilters(), userGroupCodes);
    } catch (Throwable t) {
        _logger.error("Error extracting contents id", t);
        throw new ApsSystemException("Error extracting contents id", t);
    }
    return contentsId;
}
Also used : Widget(com.agiletec.aps.system.services.page.Widget) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApsProperties(com.agiletec.aps.util.ApsProperties) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter)

Example 54 with Widget

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

the class DataObjectListHelper method buildCacheKey.

protected static String buildCacheKey(String listName, Collection<String> userGroupCodes, RequestContext reqCtx) {
    IPage page = (null != reqCtx) ? (IPage) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE) : null;
    StringBuilder cacheKey = (null != page) ? new StringBuilder(page.getCode()) : new StringBuilder("NOTFOUND");
    Widget currentWidget = (null != reqCtx) ? (Widget) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_WIDGET) : null;
    if (null != currentWidget && null != currentWidget.getType()) {
        cacheKey.append("_").append(currentWidget.getType().getCode());
    }
    if (null != reqCtx) {
        Integer frame = (Integer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_FRAME);
        if (null != frame) {
            cacheKey.append("_").append(frame.intValue());
        }
        Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
        if (null != currentLang) {
            cacheKey.append("_LANG").append(currentLang.getCode()).append("_");
        }
    }
    List<String> groupCodes = new ArrayList<String>(userGroupCodes);
    if (!groupCodes.contains(Group.FREE_GROUP_NAME)) {
        groupCodes.add(Group.FREE_GROUP_NAME);
    }
    Collections.sort(groupCodes);
    for (int i = 0; i < groupCodes.size(); i++) {
        String code = (String) groupCodes.get(i);
        cacheKey.append("_").append(code);
    }
    if (null != currentWidget && null != currentWidget.getConfig()) {
        List<String> paramKeys = new ArrayList(currentWidget.getConfig().keySet());
        Collections.sort(paramKeys);
        for (int i = 0; i < paramKeys.size(); i++) {
            if (i == 0) {
                cacheKey.append("_WIDGETPARAM");
            } else {
                cacheKey.append(",");
            }
            String paramkey = (String) paramKeys.get(i);
            cacheKey.append(paramkey).append("=").append(currentWidget.getConfig().getProperty(paramkey));
        }
    }
    if (null != listName) {
        cacheKey.append("_LISTNAME").append(listName);
    }
    return cacheKey.toString();
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) Widget(com.agiletec.aps.system.services.page.Widget) ArrayList(java.util.ArrayList) Lang(com.agiletec.aps.system.services.lang.Lang)

Example 55 with Widget

use of com.agiletec.aps.system.services.page.Widget 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)

Aggregations

Widget (com.agiletec.aps.system.services.page.Widget)117 ApsProperties (com.agiletec.aps.util.ApsProperties)60 IPage (com.agiletec.aps.system.services.page.IPage)41 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)20 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)17 HashMap (java.util.HashMap)12 Lang (com.agiletec.aps.system.services.lang.Lang)10 Page (com.agiletec.aps.system.services.page.Page)7 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)7 ArrayList (java.util.ArrayList)7 PageMetadata (com.agiletec.aps.system.services.page.PageMetadata)6 NavigatorExpression (com.agiletec.aps.system.services.page.widget.NavigatorExpression)6 Properties (java.util.Properties)6 RequestContext (com.agiletec.aps.system.RequestContext)5 ActionSupport (com.opensymphony.xwork2.ActionSupport)4 JspException (javax.servlet.jsp.JspException)4 WidgetTypeParameter (org.entando.entando.aps.system.services.widgettype.WidgetTypeParameter)4 List (java.util.List)3 ServletRequest (javax.servlet.ServletRequest)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3