Search in sources :

Example 16 with Widget

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

the class TestPageModelManager method testUpdateModel.

public void testUpdateModel() throws Throwable {
    String testPageModelCode = "test_pagemodel";
    assertNull(this._pageModelManager.getPageModel(testPageModelCode));
    try {
        PageModel mockModel = this.createMockPageModel(testPageModelCode);
        this._pageModelManager.addPageModel(mockModel);
        PageModel extractedMockModel = this._pageModelManager.getPageModel(testPageModelCode);
        extractedMockModel.setDescription("Modified Description");
        Frame[] configuration = extractedMockModel.getConfiguration();
        Frame[] newConfiguration = new Frame[4];
        for (int i = 0; i < configuration.length; i++) {
            newConfiguration[i] = configuration[i];
        }
        Frame frame3 = new Frame();
        frame3.setPos(3);
        frame3.setDescription("Freme 3");
        Widget defWidg3ToSet = new Widget();
        defWidg3ToSet.setType(this._widgetTypeManager.getWidgetType("content_viewer"));
        ApsProperties props3 = new ApsProperties();
        props3.setProperty("contentId", "ART187");
        defWidg3ToSet.setConfig(props3);
        frame3.setDefaultWidget(defWidg3ToSet);
        newConfiguration[3] = frame3;
        extractedMockModel.setConfiguration(newConfiguration);
        extractedMockModel.setTemplate("<strong>Modified Freemarker template content</strong>");
        this._pageModelManager.updatePageModel(extractedMockModel);
        extractedMockModel = this._pageModelManager.getPageModel(testPageModelCode);
        assertNotNull(extractedMockModel);
        assertEquals(testPageModelCode, extractedMockModel.getCode());
        assertEquals("Modified Description", extractedMockModel.getDescription());
        assertEquals(4, extractedMockModel.getFrames().length);
        Widget[] defaultWidgets = extractedMockModel.getDefaultWidget();
        assertEquals(4, defaultWidgets.length);
        Widget defWidg0 = defaultWidgets[0];
        assertNull(defWidg0);
        Widget defWidg1 = defaultWidgets[1];
        assertNotNull(defWidg1);
        assertEquals("content_viewer_list", defWidg1.getType().getCode());
        assertEquals(1, defWidg1.getConfig().size());
        assertEquals("ART", defWidg1.getConfig().get("contentType"));
        Widget defWidg2 = defaultWidgets[2];
        assertNotNull(defWidg2);
        assertEquals("login_form", defWidg2.getType().getCode());
        assertNull(defWidg2.getConfig());
        Widget defWidg3 = defaultWidgets[3];
        assertNotNull(defWidg3);
        assertEquals("content_viewer", defWidg3.getType().getCode());
        assertEquals(1, defWidg3.getConfig().size());
        assertEquals("ART187", defWidg3.getConfig().get("contentId"));
        assertEquals("<strong>Modified Freemarker template content</strong>", extractedMockModel.getTemplate());
    } catch (Exception e) {
        throw e;
    } finally {
        this._pageModelManager.deletePageModel(testPageModelCode);
        assertNull(this._pageModelManager.getPageModel(testPageModelCode));
    }
}
Also used : Widget(com.agiletec.aps.system.services.page.Widget) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 17 with Widget

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

the class TestPageModelManager method createMockPageModel.

private PageModel createMockPageModel(String code) {
    PageModel model = new PageModel();
    model.setCode(code);
    model.setDescription("Description of model " + code);
    Frame frame0 = new Frame();
    frame0.setPos(0);
    frame0.setDescription("Freme 0");
    frame0.setMainFrame(true);
    Frame frame1 = new Frame();
    frame1.setPos(1);
    frame1.setDescription("Freme 1");
    Widget defWidg1 = new Widget();
    defWidg1.setType(this._widgetTypeManager.getWidgetType("content_viewer_list"));
    ApsProperties props1 = new ApsProperties();
    props1.setProperty("contentType", "ART");
    defWidg1.setConfig(props1);
    frame1.setDefaultWidget(defWidg1);
    Frame frame2 = new Frame();
    frame2.setPos(1);
    frame2.setDescription("Freme 2");
    Widget defWidg2 = new Widget();
    defWidg2.setType(this._widgetTypeManager.getWidgetType("login_form"));
    frame2.setDefaultWidget(defWidg2);
    Frame[] configuration = { frame0, frame1, frame2 };
    model.setConfiguration(configuration);
    model.setTemplate("<strong>Freemarker template content</strong>");
    return model;
}
Also used : Widget(com.agiletec.aps.system.services.page.Widget) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 18 with Widget

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

the class TestPageAction method testSavePage_Draft_2.

public void testSavePage_Draft_2() throws Throwable {
    String pageCode = "pagina_test";
    assertNull(this._pageManager.getDraftPage(pageCode));
    try {
        IPage root = this._pageManager.getDraftRoot();
        Map<String, String> params = new HashMap<String, String>();
        params.put("strutsAction", String.valueOf(ApsAdminSystemConstants.ADD));
        params.put("parentPageCode", root.getCode());
        params.put("langit", "Pagina Test 2");
        params.put("langen", "Test Page 2");
        params.put("model", "internal");
        params.put("group", Group.FREE_GROUP_NAME);
        params.put("pageCode", pageCode);
        String result = this.executeSave(params, "admin");
        assertEquals(Action.SUCCESS, result);
        IPage addedPage = this._pageManager.getDraftPage(pageCode);
        this.executeSetDefaultWidgets(params, "admin");
        assertNotNull(addedPage);
        assertEquals("Pagina Test 2", addedPage.getMetadata().getTitles().getProperty("it"));
        Widget[] showlets = addedPage.getWidgets();
        assertEquals(addedPage.getMetadata().getModel().getFrames().length, showlets.length);
        for (int i = 0; i < showlets.length; i++) {
            Widget widget = showlets[i];
            if (i == 3) {
                assertNotNull(widget);
                WidgetType type = widget.getType();
                assertEquals("leftmenu", type.getCode());
                assertEquals(1, type.getTypeParameters().size());
                assertNull(type.getConfig());
                ApsProperties config = widget.getConfig();
                assertEquals(1, config.size());
                assertEquals("code(homepage).subtree(1)", config.getProperty("navSpec"));
            } else {
                assertNull(widget);
            }
        }
    } catch (Throwable t) {
        throw t;
    } finally {
        this._pageManager.deletePage(pageCode);
    }
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) HashMap(java.util.HashMap) Widget(com.agiletec.aps.system.services.page.Widget) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 19 with Widget

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

the class TestPageAction method testEditForCoachUser.

public void testEditForCoachUser() throws Throwable {
    String selectedPageCode = this._pageManager.getDraftRoot().getCode();
    String result = this.executeActionOnPage(selectedPageCode, "pageManagerCoach", "edit");
    assertEquals("pageTree", result);
    // PAGINA
    IPage customers_page = this._pageManager.getDraftPage("customers_page");
    // NON
    // PREDISPOSTA
    // PER
    // LA
    // PUBBLICAZIONE
    // VOLANTE...
    result = this.executeActionOnPage(customers_page.getCode(), "pageManagerCustomers", "edit");
    assertEquals(Action.SUCCESS, result);
    PageAction action = (PageAction) this.getAction();
    assertEquals(action.getStrutsAction(), ApsAdminSystemConstants.EDIT);
    assertEquals(customers_page.getCode(), action.getPageCode());
    assertEquals(customers_page.getModel().getCode(), action.getModel());
    assertTrue(action.isShowable());
    assertTrue(action.isGroupSelectLock());
    Widget widget = customers_page.getWidgets()[customers_page.getModel().getMainFrame()];
    if (null != widget) {
        assertEquals("content_viewer", widget.getType().getCode());
        assertTrue(null != widget.getConfig() && !widget.getConfig().isEmpty());
    }
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) Widget(com.agiletec.aps.system.services.page.Widget)

Example 20 with Widget

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

the class ContentListHelper method extractContentsId.

protected List<String> extractContentsId(IContentListTagBean 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.getContentType() && null != config) {
            bean.setContentType(config.getProperty(WIDGET_PARAM_CONTENT_TYPE));
        }
        if (null == bean.getContentType()) {
            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 (UserFilterOptionBean userFilter : userFilters) {
                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.getContentManager().loadPublicContentsId(bean.getContentType(), 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) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter) ApsProperties(com.agiletec.aps.util.ApsProperties)

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