Search in sources :

Example 61 with WidgetType

use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.

the class TestWidgetTypeAction method testTrashType.

public void testTrashType() throws Throwable {
    String pageCode = "pagina_1";
    int frame = 1;
    String widgetTypeCode = "test_widgetType_trash3";
    try {
        assertNull(this._widgetTypeManager.getWidgetType(widgetTypeCode));
        WidgetType type = this.createNewWidgetType(widgetTypeCode);
        this._widgetTypeManager.addWidgetType(type);
        assertNotNull(this._widgetTypeManager.getWidgetType(widgetTypeCode));
        IPage pagina_1 = this._pageManager.getDraftPage(pageCode);
        assertNull(pagina_1.getWidgets()[frame]);
        String result = this.executeJoinWidget(pageCode, frame, widgetTypeCode, "admin");
        assertEquals(Action.SUCCESS, result);
        pagina_1 = this._pageManager.getDraftPage(pageCode);
        assertNotNull(pagina_1.getWidgets()[frame]);
        result = this.executeTrash(widgetTypeCode, "admin");
        assertEquals("inputWidgetTypes", result);
        ActionSupport action = this.getAction();
        assertEquals(1, action.getActionErrors().size());
        result = this.executeDeleteWidgetFromPage(pageCode, frame, "admin");
        assertEquals(Action.SUCCESS, result);
        result = this.executeTrash(widgetTypeCode, "admin");
        assertEquals(Action.SUCCESS, result);
        result = this.executeDelete(widgetTypeCode, "admin");
        assertEquals(Action.SUCCESS, result);
        assertNull(this._widgetTypeManager.getWidgetType(widgetTypeCode));
    } catch (Throwable t) {
        throw t;
    } finally {
        IPage pagina_1 = this._pageManager.getDraftPage(pageCode);
        pagina_1.getWidgets()[frame] = null;
        this._pageManager.updatePage(pagina_1);
        if (null != this._widgetTypeManager.getWidgetType(widgetTypeCode)) {
            this._mockWidgetTypeDAO.deleteWidgetType(widgetTypeCode);
        }
        ((IManager) this._widgetTypeManager).refresh();
        assertNull(this._widgetTypeManager.getWidgetType(widgetTypeCode));
    }
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) IManager(com.agiletec.aps.system.common.IManager) ActionSupport(com.opensymphony.xwork2.ActionSupport) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType)

Example 62 with WidgetType

use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.

the class TestWidgetTypeAction method testPasteNewWidgetType_2.

public void testPasteNewWidgetType_2() throws Throwable {
    String widgetTypeCode = "randomWidgetCode-2";
    String pageDest = "pagina_1";
    int frameDest = 1;
    Widget temp = this._pageManager.getDraftPage("pagina_11").getWidgets()[2];
    assertNotNull(temp);
    assertEquals("content_viewer", temp.getType().getCode());
    IPage page = this._pageManager.getDraftPage(pageDest);
    try {
        assertNull(page.getWidgets()[frameDest]);
        page.getWidgets()[frameDest] = temp;
        this._pageManager.updatePage(page);
        this.setUserOnSession("admin");
        this.initAction("/do/Portal/WidgetType", "save");
        this.addParameter("widgetTypeCode", widgetTypeCode);
        this.addParameter("englishTitle", "en");
        this.addParameter("italianTitle", "it");
        this.addParameter("pageCode", pageDest);
        this.addParameter("framePos", frameDest);
        this.addParameter("strutsAction", ApsAdminSystemConstants.PASTE);
        this.addParameter("replaceOnPage", "true");
        String result = this.executeAction();
        assertEquals("replaceOnPage", result);
        Widget newWidget = this._pageManager.getDraftPage(pageDest).getWidgets()[frameDest];
        assertNotNull(newWidget);
        assertNotNull(newWidget.getConfig());
        WidgetType addedType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
        assertNotNull(addedType);
        assertEquals(newWidget.getType().getCode(), addedType.getCode());
        ApsProperties config = addedType.getConfig();
        Iterator<Object> keysIter = config.keySet().iterator();
        while (keysIter.hasNext()) {
            String key = (String) keysIter.next();
            assertEquals(newWidget.getConfig().getProperty(key), config.getProperty(key));
        }
    } catch (Throwable t) {
        throw t;
    } finally {
        page.getWidgets()[frameDest] = null;
        this._pageManager.updatePage(page);
        this._widgetTypeManager.deleteWidgetType(widgetTypeCode);
    }
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) Widget(com.agiletec.aps.system.services.page.Widget) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 63 with WidgetType

use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.

the class PageAction method setViewerPageAPI.

public String setViewerPageAPI() {
    IPage page = null;
    try {
        page = this.getPage(this.getPageCode());
        int mainFrame = page.getMetadata().getModel().getMainFrame();
        if (mainFrame > -1) {
            IWidgetTypeManager showletTypeManager = (IWidgetTypeManager) ApsWebApplicationUtils.getBean(SystemConstants.WIDGET_TYPE_MANAGER, this.getRequest());
            Widget viewer = new Widget();
            viewer.setConfig(new ApsProperties());
            WidgetType type = showletTypeManager.getWidgetType(this.getViewerWidgetCode());
            if (null == type) {
                _logger.warn("No widget found for on-the-fly publishing config for page {}", page.getCode());
                return SUCCESS;
            }
            viewer.setType(type);
            Widget[] widgets = page.getWidgets();
            widgets[mainFrame] = viewer;
        }
        this.getPageManager().updatePage(page);
    } catch (Throwable t) {
        _logger.error("Error setting on-the-fly publishing config to page {}", page.getCode(), t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) IWidgetTypeManager(org.entando.entando.aps.system.services.widgettype.IWidgetTypeManager) Widget(com.agiletec.aps.system.services.page.Widget) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 64 with WidgetType

use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.

the class PageConfigAction method joinWidgetJson.

public String joinWidgetJson() {
    try {
        String result = this.checkBaseParams();
        if (null != result) {
            return result;
        }
        IPage page = this.getPage(this.getPageCode());
        if (null != page.getWidgets()[this.getFrame()]) {
            this.addActionError(this.getText("error.page.join.frameNotEmpty"));
            return "pageTree";
        }
        if (null != this.getWidgetTypeCode() && this.getWidgetTypeCode().length() == 0) {
            this.addActionError(this.getText("error.page.widgetTypeCodeUnknown"));
            return INPUT;
        }
        _logger.debug("code={}, pageCode={}, frame={}" + this.getWidgetTypeCode(), this.getPageCode(), this.getFrame());
        WidgetType widgetType = this.getShowletType(this.getWidgetTypeCode());
        if (null == widgetType) {
            this.addActionError(this.getText("error.page.widgetTypeCodeUnknown"));
            return INPUT;
        }
        if (null == widgetType.getConfig() && null != widgetType.getAction()) {
            this.setWidgetAction(widgetType.getAction());
            // continue to widget configuration
            return "configureSpecialWidget";
        }
        Widget widget = new Widget();
        widget.setType(widgetType);
        this.getPageManager().joinWidget(this.getPageCode(), widget, this.getFrame());
        this.addActivityStreamInfo(ApsAdminSystemConstants.ADD, true);
    } catch (Exception e) {
        _logger.error("error in joinWidget", e);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) Widget(com.agiletec.aps.system.services.page.Widget) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType)

Example 65 with WidgetType

use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.

the class WidgetTypeAction method save.

/**
 * Save a widget type.
 *
 * @return The result code.
 */
public String save() {
    try {
        if (this.getStrutsAction() != ApsAdminSystemConstants.EDIT && (this.getStrutsAction() != ApsAdminSystemConstants.ADD)) {
            if (!this.hasCurrentUserPermission(Permission.SUPERUSER)) {
                return USER_NOT_ALLOWED;
            }
            return this.saveUserWidget();
        }
        WidgetType type = null;
        if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) {
            type = new WidgetType();
            type.setCode(this.getWidgetTypeCode());
        } else {
            String check = this.checkWidgetType();
            if (null != check) {
                return check;
            }
            type = this.getWidgetTypeManager().getWidgetType(this.getWidgetTypeCode());
        }
        ApsProperties titles = new ApsProperties();
        titles.put("it", this.getItalianTitle());
        titles.put("en", this.getEnglishTitle());
        String mainGroupToSet = (this.hasCurrentUserPermission(Permission.SUPERUSER)) ? this.getMainGroup() : type.getMainGroup();
        if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) {
            type.setTitles(titles);
            type.setMainGroup(mainGroupToSet);
            this.getWidgetTypeManager().addWidgetType(type);
        } else {
            ApsProperties configToSet = type.getConfig();
            if (type.isLogic() && type.isUserType() && !type.isLocked() && this.hasCurrentUserPermission(Permission.SUPERUSER)) {
                configToSet = this.extractWidgetTypeConfig(type.getParentType().getTypeParameters());
            }
            this.getWidgetTypeManager().updateWidgetType(this.getWidgetTypeCode(), titles, configToSet, mainGroupToSet);
        }
        if (!type.isLogic() && !super.isInternalServletWidget(this.getWidgetTypeCode())) {
            GuiFragment guiFragment = this.extractUniqueGuiFragment(this.getWidgetTypeCode());
            if (StringUtils.isNotBlank(this.getGui())) {
                if (null == guiFragment) {
                    guiFragment = new GuiFragment();
                    String code = this.extractUniqueGuiFragmentCode(this.getWidgetTypeCode());
                    guiFragment.setCode(code);
                    guiFragment.setPluginCode(type.getPluginCode());
                    guiFragment.setGui(this.getGui());
                    guiFragment.setWidgetTypeCode(this.getWidgetTypeCode());
                    this.getGuiFragmentManager().addGuiFragment(guiFragment);
                } else {
                    guiFragment.setGui(this.getGui());
                    this.getGuiFragmentManager().updateGuiFragment(guiFragment);
                }
            } else if (null != guiFragment) {
                if (StringUtils.isNotBlank(guiFragment.getDefaultGui())) {
                    guiFragment.setGui(null);
                    this.getGuiFragmentManager().updateGuiFragment(guiFragment);
                } else {
                    this.getGuiFragmentManager().deleteGuiFragment(guiFragment.getCode());
                }
            }
        } else if (type.isLogic()) /* && super.isInternalServletWidget(type.getParentType().getCode())*/
        {
            this.buildGuisFromForm(type);
            List<String> guiFragmentCodes = this.extractGuiFragmentCodes(type.getCode());
            for (int i = 0; i < guiFragmentCodes.size(); i++) {
                String guiFragmentCode = guiFragmentCodes.get(i);
                GuiFragment guiFragment = this.getGuiFragment(guiFragmentCode);
                String fieldName = type.getCode() + "_" + guiFragmentCode;
                String value = this.getGuis().getProperty(fieldName);
                if ((null == value && null != guiFragment.getGui()) || (null != value && (StringUtils.isBlank(guiFragment.getGui()) || !value.equals(guiFragment.getGui())))) {
                    guiFragment.setGui(value);
                    this.getGuiFragmentManager().updateGuiFragment(guiFragment);
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("error in save", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) ArrayList(java.util.ArrayList) List(java.util.List) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApsProperties(com.agiletec.aps.util.ApsProperties)

Aggregations

WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)70 ApsProperties (com.agiletec.aps.util.ApsProperties)33 Widget (com.agiletec.aps.system.services.page.Widget)20 IPage (com.agiletec.aps.system.services.page.IPage)11 GuiFragment (org.entando.entando.aps.system.services.guifragment.GuiFragment)10 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)5 WidgetTypeParameter (org.entando.entando.aps.system.services.widgettype.WidgetTypeParameter)5 ActionSupport (com.opensymphony.xwork2.ActionSupport)4 IManager (com.agiletec.aps.system.common.IManager)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)3 Lang (com.agiletec.aps.system.services.lang.Lang)3 List (java.util.List)3 JAXBGuiFragment (org.entando.entando.aps.system.services.guifragment.api.JAXBGuiFragment)3 IWidgetTypeManager (org.entando.entando.aps.system.services.widgettype.IWidgetTypeManager)3 ILangManager (com.agiletec.aps.system.services.lang.ILangManager)2 SelectItem (com.agiletec.aps.util.SelectItem)2 Properties (java.util.Properties)2 ApiMethod (org.entando.entando.aps.system.services.api.model.ApiMethod)2