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);
}
}
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));
}
}
}
}
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;
}
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();
}
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;
}
Aggregations