Search in sources :

Example 41 with WidgetType

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

the class GuiFragmentDtoBuilder method toDto.

@Override
protected GuiFragmentDto toDto(GuiFragment src) {
    if (null == src) {
        return null;
    }
    WidgetType type = null;
    if (StringUtils.isNotEmpty(src.getWidgetTypeCode())) {
        type = this.getWidgetTypeManager().getWidgetType(src.getWidgetTypeCode());
    }
    GuiFragmentDto dest = new GuiFragmentDto(src, type);
    ListableBeanFactory factory = (ListableBeanFactory) this.beanFactory;
    String[] defNames = factory.getBeanNamesForType(GuiFragmentUtilizer.class);
    for (String defName : defNames) {
        GuiFragmentUtilizer utilizers = null;
        try {
            utilizers = this.beanFactory.getBean(defName, GuiFragmentUtilizer.class);
            List<Object> references = utilizers.getGuiFragmentUtilizers(src.getCode());
            if (null != references) {
                for (Object reference : references) {
                    if (reference instanceof GuiFragment) {
                        dest.addFragmentRef((GuiFragment) reference);
                    } else if (reference instanceof PageModel) {
                        dest.addPageModelRef((PageModel) reference);
                    } else {
                        logger.info("unexpected reference - type {}", reference.getClass());
                    }
                }
            }
        } catch (Throwable t) {
            logger.error("Error extracting reference from bean '{}'", defName);
            utilizers = null;
        }
    }
    return dest;
}
Also used : GuiFragmentUtilizer(org.entando.entando.aps.system.services.guifragment.GuiFragmentUtilizer) GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory)

Example 42 with WidgetType

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

the class TestDataObjectViewerHelper method init.

private void init() throws Exception {
    try {
        _requestContext = this.getRequestContext();
        Lang lang = new Lang();
        lang.setCode("it");
        lang.setDescr("italiano");
        _requestContext.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG, lang);
        Widget widget = new Widget();
        IWidgetTypeManager showletTypeMan = (IWidgetTypeManager) this.getService(SystemConstants.WIDGET_TYPE_MANAGER);
        WidgetType showletType = showletTypeMan.getWidgetType("content_viewer");
        widget.setType(showletType);
        widget.setConfig(new ApsProperties());
        _requestContext.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_WIDGET, widget);
        this._helper = (IDataObjectViewerHelper) this.getApplicationContext().getBean("DataObjectViewerHelper");
    } catch (Throwable t) {
        throw new Exception(t);
    }
}
Also used : IWidgetTypeManager(org.entando.entando.aps.system.services.widgettype.IWidgetTypeManager) Widget(com.agiletec.aps.system.services.page.Widget) Lang(com.agiletec.aps.system.services.lang.Lang) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 43 with WidgetType

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

the class TestApiWidgetTypeInterface method testDeleteJaxbWidgetType_3.

public void testDeleteJaxbWidgetType_3() throws Throwable {
    String code = "jaxb_test_delete_2";
    String pageCode = "homepage";
    int frame = 5;
    assertNull(this._widgetTypeManager.getWidgetType(code));
    IPage homepage = this._pageManager.getDraftPage(pageCode);
    assertNull(homepage.getWidgets()[frame]);
    assertNull(homepage.getWidgets()[frame]);
    try {
        this.addMockWidget(code);
        WidgetType addedWidgetType = this._widgetTypeManager.getWidgetType(code);
        assertNotNull(addedWidgetType);
        Widget widget = new Widget();
        widget.setType(addedWidgetType);
        this.setPageWidgets(pageCode, frame, widget);
        homepage = this._pageManager.getDraftPage(pageCode);
        this.testInvokeDeleteJaxbNoLogicWidgetType(code, false);
        this.setPageWidgets(pageCode, frame, null);
        this._pageManager.updatePage(homepage);
        this.testInvokeDeleteJaxbNoLogicWidgetType(code, true);
    } catch (Throwable t) {
        this.setPageWidgets(pageCode, frame, null);
        throw t;
    } finally {
        this._widgetTypeManager.deleteWidgetType(code);
        assertNull(this._widgetTypeManager.getWidgetType(code));
    }
}
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 44 with WidgetType

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

the class TestApiWidgetTypeInterface method testInvokeUpdateJaxbNoLogicWidgetType.

private void testInvokeUpdateJaxbNoLogicWidgetType(String widgetTypeCode, ApsProperties titles, boolean removeParametersFromCall, String customSingleGui, boolean expectedSuccess) throws Throwable {
    WidgetType widgetType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
    assertNotNull(widgetType);
    WidgetType widgetTypeToEdit = widgetType.clone();
    GuiFragment previousFragment = this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode);
    ApsProperties originalTitles = widgetType.getTitles();
    try {
        JAXBWidgetType jaxbWidgetType = this.getJaxbWidgetType(widgetTypeToEdit);
        if (StringUtils.isNotBlank(customSingleGui)) {
            jaxbWidgetType.setGui(customSingleGui);
        }
        if (null != titles) {
            jaxbWidgetType.setTitles(titles);
        }
        if (removeParametersFromCall) {
            jaxbWidgetType.setTypeParameters(null);
        }
        this._apiWidgetTypeInterface.updateWidgetType(jaxbWidgetType);
        if (!expectedSuccess) {
            fail();
        }
        WidgetType extractedWidgetType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
        assertNotNull(extractedWidgetType);
        assertEquals(widgetType.getMainGroup(), extractedWidgetType.getMainGroup());
        assertEquals(titles, extractedWidgetType.getTitles());
        assertEquals(widgetType.getTypeParameters(), extractedWidgetType.getTypeParameters());
        assertEquals(widgetType.isLocked(), extractedWidgetType.isLocked());
        if (StringUtils.isNotBlank(customSingleGui) && null == previousFragment) {
            assertNotNull(this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode));
        }
    } catch (ApiException ae) {
        if (expectedSuccess) {
            fail();
        }
    } catch (Throwable t) {
        throw t;
    } finally {
        if (null == previousFragment) {
            List<String> codes = this._guiFragmentManager.getGuiFragmentCodesByWidgetType(widgetTypeCode);
            if (null != codes) {
                for (int i = 0; i < codes.size(); i++) {
                    String code = codes.get(i);
                    this._guiFragmentManager.deleteGuiFragment(code);
                }
            }
        } else {
            if (null == this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode)) {
                this._guiFragmentManager.addGuiFragment(previousFragment);
            } else {
                this._guiFragmentManager.updateGuiFragment(previousFragment);
            }
        }
        this._widgetTypeManager.updateWidgetType(widgetType.getCode(), originalTitles, widgetType.getConfig(), widgetType.getMainGroup());
    }
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApsProperties(com.agiletec.aps.util.ApsProperties) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 45 with WidgetType

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

the class TestApiWidgetTypeInterface method testInvokeDeleteJaxbNoLogicWidgetType.

private void testInvokeDeleteJaxbNoLogicWidgetType(String widgetTypeCode, boolean expectedSuccess) throws Throwable {
    Properties properties = new Properties();
    properties.put(SystemConstants.API_USER_PARAMETER, super.getUser("admin"));
    properties.put("code", widgetTypeCode);
    WidgetType widgetType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
    assertNotNull(widgetType);
    WidgetType widgetTypeToDelete = widgetType.clone();
    GuiFragment previousFragment = this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode);
    try {
        this._apiWidgetTypeInterface.deleteWidgetType(properties);
        if (!expectedSuccess) {
            fail();
        }
        assertNull(this._widgetTypeManager.getWidgetType(widgetTypeCode));
        assertNull(this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode));
    } catch (ApiException ae) {
        if (expectedSuccess) {
            fail();
        }
    } catch (Throwable t) {
        throw t;
    } finally {
        if (null != previousFragment && null == this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode)) {
            this._guiFragmentManager.addGuiFragment(previousFragment);
        }
        if (null == this._widgetTypeManager.getWidgetType(widgetTypeCode)) {
            this._widgetTypeManager.addWidgetType(widgetTypeToDelete);
        }
    }
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) Properties(java.util.Properties) ApsProperties(com.agiletec.aps.util.ApsProperties) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

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